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