Moving the WhitenessWitness back to DescriptorArray.
[platform/upstream/v8.git] / src / transitions-inl.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_TRANSITIONS_INL_H_
29 #define V8_TRANSITIONS_INL_H_
30
31 #include "objects-inl.h"
32 #include "transitions.h"
33
34 namespace v8 {
35 namespace internal {
36
37
38 #define FIELD_ADDR(p, offset) \
39   (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag)
40
41 #define WRITE_FIELD(p, offset, value) \
42   (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value)
43
44 #define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode)    \
45   if (mode == UPDATE_WRITE_BARRIER) {                                   \
46     heap->incremental_marking()->RecordWrite(                           \
47       object, HeapObject::RawField(object, offset), value);             \
48     if (heap->InNewSpace(value)) {                                      \
49       heap->RecordWrite(object->address(), offset);                     \
50     }                                                                   \
51   }
52
53
54 TransitionArray* TransitionArray::cast(Object* object) {
55   ASSERT(object->IsTransitionArray());
56   return reinterpret_cast<TransitionArray*>(object);
57 }
58
59
60 Map* TransitionArray::elements_transition() {
61   Object* transition_map = get(kElementsTransitionIndex);
62   return Map::cast(transition_map);
63 }
64
65
66 void TransitionArray::ClearElementsTransition() {
67   WRITE_FIELD(this, kElementsTransitionOffset, Smi::FromInt(0));
68 }
69
70
71 bool TransitionArray::HasElementsTransition() {
72   return get(kElementsTransitionIndex) != Smi::FromInt(0);
73 }
74
75
76 void TransitionArray::set_elements_transition(Map* transition_map,
77                                               WriteBarrierMode mode) {
78   Heap* heap = GetHeap();
79   WRITE_FIELD(this, kElementsTransitionOffset, transition_map);
80   CONDITIONAL_WRITE_BARRIER(
81       heap, this, kElementsTransitionOffset, transition_map, mode);
82 }
83
84
85 DescriptorArray* TransitionArray::descriptors() {
86   return DescriptorArray::cast(descriptors_pointer()->value());
87 }
88
89
90 void TransitionArray::set_descriptors(DescriptorArray* descriptors) {
91   ASSERT(!this->descriptors()->IsDescriptorArray() ||
92          descriptors->number_of_descriptors() == 0 ||
93          descriptors->HasEnumCache() ||
94          !this->descriptors()->HasEnumCache());
95   descriptors_pointer()->set_value(descriptors);
96 }
97
98
99 JSGlobalPropertyCell* TransitionArray::descriptors_pointer() {
100   return JSGlobalPropertyCell::cast(get(kDescriptorsPointerIndex));
101 }
102
103
104 void TransitionArray::set_descriptors_pointer(JSGlobalPropertyCell* pointer) {
105   set(kDescriptorsPointerIndex, pointer);
106 }
107
108
109 Object* TransitionArray::back_pointer_storage() {
110   return get(kBackPointerStorageIndex);
111 }
112
113
114 void TransitionArray::set_back_pointer_storage(Object* back_pointer,
115                                                WriteBarrierMode mode) {
116   Heap* heap = GetHeap();
117   WRITE_FIELD(this, kBackPointerStorageOffset, back_pointer);
118   CONDITIONAL_WRITE_BARRIER(
119       heap, this, kBackPointerStorageOffset, back_pointer, mode);
120 }
121
122
123 bool TransitionArray::HasPrototypeTransitions() {
124   Object* prototype_transitions = get(kPrototypeTransitionsIndex);
125   return prototype_transitions != Smi::FromInt(0);
126 }
127
128
129 FixedArray* TransitionArray::GetPrototypeTransitions() {
130   Object* prototype_transitions = get(kPrototypeTransitionsIndex);
131   return FixedArray::cast(prototype_transitions);
132 }
133
134
135 HeapObject* TransitionArray::UncheckedPrototypeTransitions() {
136   ASSERT(HasPrototypeTransitions());
137   return reinterpret_cast<HeapObject*>(get(kPrototypeTransitionsIndex));
138 }
139
140
141 void TransitionArray::SetPrototypeTransitions(FixedArray* transitions,
142                                               WriteBarrierMode mode) {
143   ASSERT(this != NULL);
144   ASSERT(transitions->IsFixedArray());
145   Heap* heap = GetHeap();
146   WRITE_FIELD(this, kPrototypeTransitionsOffset, transitions);
147   CONDITIONAL_WRITE_BARRIER(
148       heap, this, kPrototypeTransitionsOffset, transitions, mode);
149 }
150
151
152 Object** TransitionArray::GetPrototypeTransitionsSlot() {
153   return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
154                               kPrototypeTransitionsOffset);
155 }
156
157
158 Object** TransitionArray::GetKeySlot(int transition_number) {
159   ASSERT(transition_number < number_of_transitions());
160   return HeapObject::RawField(
161       reinterpret_cast<HeapObject*>(this),
162       OffsetOfElementAt(ToKeyIndex(transition_number)));
163 }
164
165
166 String* TransitionArray::GetKey(int transition_number) {
167   ASSERT(transition_number < number_of_transitions());
168   return String::cast(get(ToKeyIndex(transition_number)));
169 }
170
171
172 void TransitionArray::SetKey(int transition_number, String* key) {
173   ASSERT(transition_number < number_of_transitions());
174   set(ToKeyIndex(transition_number), key);
175 }
176
177
178 Map* TransitionArray::GetTarget(int transition_number) {
179   ASSERT(transition_number < number_of_transitions());
180   return Map::cast(get(ToTargetIndex(transition_number)));
181 }
182
183
184 void TransitionArray::SetTarget(int transition_number, Map* value) {
185   ASSERT(transition_number < number_of_transitions());
186   set(ToTargetIndex(transition_number), value);
187 }
188
189
190 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) {
191   Map* map = GetTarget(transition_number);
192   DescriptorArray* descriptors = map->instance_descriptors();
193   int descriptor = map->LastAdded();
194   return descriptors->GetDetails(descriptor);
195 }
196
197
198 int TransitionArray::Search(String* name) {
199   return internal::Search<ALL_ENTRIES>(this, name);
200 }
201
202
203 void TransitionArray::NoIncrementalWriteBarrierSet(int transition_number,
204                                                    String* key,
205                                                    Map* target) {
206   FixedArray::NoIncrementalWriteBarrierSet(
207       this, ToKeyIndex(transition_number), key);
208   FixedArray::NoIncrementalWriteBarrierSet(
209       this, ToTargetIndex(transition_number), target);
210 }
211
212
213 #undef FIELD_ADDR
214 #undef WRITE_FIELD
215 #undef CONDITIONAL_WRITE_BARRIER
216
217
218 } }  // namespace v8::internal
219
220 #endif  // V8_TRANSITIONS_INL_H_