OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_TRANSITIONS_INL_H_ | 5 #ifndef V8_TRANSITIONS_INL_H_ |
6 #define V8_TRANSITIONS_INL_H_ | 6 #define V8_TRANSITIONS_INL_H_ |
7 | 7 |
8 #include "src/transitions.h" | 8 #include "src/transitions.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 | 13 |
| 14 #define FIELD_ADDR(p, offset) \ |
| 15 (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) |
| 16 |
| 17 #define WRITE_FIELD(p, offset, value) \ |
| 18 (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) |
| 19 |
| 20 #define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \ |
| 21 if (mode == UPDATE_WRITE_BARRIER) { \ |
| 22 heap->incremental_marking()->RecordWrite( \ |
| 23 object, HeapObject::RawField(object, offset), value); \ |
| 24 if (heap->InNewSpace(value)) { \ |
| 25 heap->RecordWrite(object->address(), offset); \ |
| 26 } \ |
| 27 } |
| 28 |
| 29 |
14 TransitionArray* TransitionArray::cast(Object* object) { | 30 TransitionArray* TransitionArray::cast(Object* object) { |
15 DCHECK(object->IsTransitionArray()); | 31 DCHECK(object->IsTransitionArray()); |
16 return reinterpret_cast<TransitionArray*>(object); | 32 return reinterpret_cast<TransitionArray*>(object); |
17 } | 33 } |
18 | 34 |
19 | 35 |
| 36 bool TransitionArray::HasElementsTransition() { |
| 37 return SearchSpecial(GetHeap()->elements_transition_symbol()) != kNotFound; |
| 38 } |
| 39 |
| 40 |
| 41 Object* TransitionArray::back_pointer_storage() { |
| 42 return get(kBackPointerStorageIndex); |
| 43 } |
| 44 |
| 45 |
| 46 void TransitionArray::set_back_pointer_storage(Object* back_pointer, |
| 47 WriteBarrierMode mode) { |
| 48 Heap* heap = GetHeap(); |
| 49 WRITE_FIELD(this, kBackPointerStorageOffset, back_pointer); |
| 50 CONDITIONAL_WRITE_BARRIER( |
| 51 heap, this, kBackPointerStorageOffset, back_pointer, mode); |
| 52 } |
| 53 |
| 54 |
20 bool TransitionArray::HasPrototypeTransitions() { | 55 bool TransitionArray::HasPrototypeTransitions() { |
21 return get(kPrototypeTransitionsIndex) != Smi::FromInt(0); | 56 return IsFullTransitionArray() && |
| 57 get(kPrototypeTransitionsIndex) != Smi::FromInt(0); |
22 } | 58 } |
23 | 59 |
24 | 60 |
25 FixedArray* TransitionArray::GetPrototypeTransitions() { | 61 FixedArray* TransitionArray::GetPrototypeTransitions() { |
26 DCHECK(HasPrototypeTransitions()); // Callers must check first. | 62 DCHECK(IsFullTransitionArray()); |
27 Object* prototype_transitions = get(kPrototypeTransitionsIndex); | 63 Object* prototype_transitions = get(kPrototypeTransitionsIndex); |
28 return FixedArray::cast(prototype_transitions); | 64 return FixedArray::cast(prototype_transitions); |
29 } | 65 } |
30 | 66 |
31 | 67 |
32 void TransitionArray::SetPrototypeTransitions(FixedArray* transitions, | 68 void TransitionArray::SetPrototypeTransitions(FixedArray* transitions, |
33 WriteBarrierMode mode) { | 69 WriteBarrierMode mode) { |
| 70 DCHECK(IsFullTransitionArray()); |
34 DCHECK(transitions->IsFixedArray()); | 71 DCHECK(transitions->IsFixedArray()); |
35 set(kPrototypeTransitionsIndex, transitions, mode); | 72 Heap* heap = GetHeap(); |
| 73 WRITE_FIELD(this, kPrototypeTransitionsOffset, transitions); |
| 74 CONDITIONAL_WRITE_BARRIER( |
| 75 heap, this, kPrototypeTransitionsOffset, transitions, mode); |
36 } | 76 } |
37 | 77 |
38 | 78 |
39 Object** TransitionArray::GetPrototypeTransitionsSlot() { | 79 Object** TransitionArray::GetPrototypeTransitionsSlot() { |
40 return RawFieldOfElementAt(kPrototypeTransitionsIndex); | 80 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), |
| 81 kPrototypeTransitionsOffset); |
41 } | 82 } |
42 | 83 |
43 | 84 |
44 Object** TransitionArray::GetKeySlot(int transition_number) { | 85 Object** TransitionArray::GetKeySlot(int transition_number) { |
| 86 DCHECK(!IsSimpleTransition()); |
45 DCHECK(transition_number < number_of_transitions()); | 87 DCHECK(transition_number < number_of_transitions()); |
46 return RawFieldOfElementAt(ToKeyIndex(transition_number)); | 88 return RawFieldOfElementAt(ToKeyIndex(transition_number)); |
47 } | 89 } |
48 | 90 |
49 | 91 |
50 Name* TransitionArray::GetKey(int transition_number) { | 92 Name* TransitionArray::GetKey(int transition_number) { |
| 93 if (IsSimpleTransition()) { |
| 94 Map* target = GetTarget(kSimpleTransitionIndex); |
| 95 int descriptor = target->LastAdded(); |
| 96 Name* key = target->instance_descriptors()->GetKey(descriptor); |
| 97 return key; |
| 98 } |
51 DCHECK(transition_number < number_of_transitions()); | 99 DCHECK(transition_number < number_of_transitions()); |
52 return Name::cast(get(ToKeyIndex(transition_number))); | 100 return Name::cast(get(ToKeyIndex(transition_number))); |
53 } | 101 } |
54 | 102 |
55 | 103 |
56 Name* TransitionArray::GetKey(Object* raw_transitions, int transition_number) { | |
57 if (IsSimpleTransition(raw_transitions)) { | |
58 DCHECK(transition_number == 0); | |
59 return GetSimpleTransitionKey(GetSimpleTransition(raw_transitions)); | |
60 } | |
61 DCHECK(IsFullTransitionArray(raw_transitions)); | |
62 return TransitionArray::cast(raw_transitions)->GetKey(transition_number); | |
63 } | |
64 | |
65 | |
66 void TransitionArray::SetKey(int transition_number, Name* key) { | 104 void TransitionArray::SetKey(int transition_number, Name* key) { |
| 105 DCHECK(!IsSimpleTransition()); |
67 DCHECK(transition_number < number_of_transitions()); | 106 DCHECK(transition_number < number_of_transitions()); |
68 set(ToKeyIndex(transition_number), key); | 107 set(ToKeyIndex(transition_number), key); |
69 } | 108 } |
70 | 109 |
71 | 110 |
72 Map* TransitionArray::GetTarget(int transition_number) { | 111 Map* TransitionArray::GetTarget(int transition_number) { |
| 112 if (IsSimpleTransition()) { |
| 113 DCHECK(transition_number == kSimpleTransitionIndex); |
| 114 return Map::cast(get(kSimpleTransitionTarget)); |
| 115 } |
73 DCHECK(transition_number < number_of_transitions()); | 116 DCHECK(transition_number < number_of_transitions()); |
74 return Map::cast(get(ToTargetIndex(transition_number))); | 117 return Map::cast(get(ToTargetIndex(transition_number))); |
75 } | 118 } |
76 | 119 |
77 | 120 |
78 Map* TransitionArray::GetTarget(Object* raw_transitions, | 121 void TransitionArray::SetTarget(int transition_number, Map* value) { |
79 int transition_number) { | 122 if (IsSimpleTransition()) { |
80 if (IsSimpleTransition(raw_transitions)) { | 123 DCHECK(transition_number == kSimpleTransitionIndex); |
81 DCHECK(transition_number == 0); | 124 return set(kSimpleTransitionTarget, value); |
82 return GetSimpleTransition(raw_transitions); | |
83 } | 125 } |
84 DCHECK(IsFullTransitionArray(raw_transitions)); | |
85 return TransitionArray::cast(raw_transitions)->GetTarget(transition_number); | |
86 } | |
87 | |
88 | |
89 void TransitionArray::SetTarget(int transition_number, Map* value) { | |
90 DCHECK(transition_number < number_of_transitions()); | 126 DCHECK(transition_number < number_of_transitions()); |
91 set(ToTargetIndex(transition_number), value); | 127 set(ToTargetIndex(transition_number), value); |
92 } | 128 } |
93 | 129 |
94 | 130 |
| 131 PropertyDetails TransitionArray::GetTargetDetails(int transition_number) { |
| 132 Map* map = GetTarget(transition_number); |
| 133 return map->GetLastDescriptorDetails(); |
| 134 } |
| 135 |
| 136 |
| 137 Object* TransitionArray::GetTargetValue(int transition_number) { |
| 138 Map* map = GetTarget(transition_number); |
| 139 return map->instance_descriptors()->GetValue(map->LastAdded()); |
| 140 } |
| 141 |
| 142 |
95 int TransitionArray::SearchName(Name* name, int* out_insertion_index) { | 143 int TransitionArray::SearchName(Name* name, int* out_insertion_index) { |
| 144 if (IsSimpleTransition()) { |
| 145 Name* key = GetKey(kSimpleTransitionIndex); |
| 146 if (key->Equals(name)) return kSimpleTransitionIndex; |
| 147 if (out_insertion_index != NULL) { |
| 148 *out_insertion_index = key->Hash() > name->Hash() ? 0 : 1; |
| 149 } |
| 150 return kNotFound; |
| 151 } |
96 return internal::Search<ALL_ENTRIES>(this, name, 0, out_insertion_index); | 152 return internal::Search<ALL_ENTRIES>(this, name, 0, out_insertion_index); |
97 } | 153 } |
98 | 154 |
99 | 155 |
100 #ifdef DEBUG | 156 #ifdef DEBUG |
101 bool TransitionArray::IsSpecialTransition(Name* name) { | 157 bool TransitionArray::IsSpecialTransition(Name* name) { |
102 if (!name->IsSymbol()) return false; | 158 if (!name->IsSymbol()) return false; |
103 Heap* heap = name->GetHeap(); | 159 Heap* heap = name->GetHeap(); |
104 return name == heap->nonextensible_symbol() || | 160 return name == heap->nonextensible_symbol() || |
105 name == heap->sealed_symbol() || name == heap->frozen_symbol() || | 161 name == heap->sealed_symbol() || name == heap->frozen_symbol() || |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 Name* key, | 218 Name* key, |
163 Map* target) { | 219 Map* target) { |
164 FixedArray::NoIncrementalWriteBarrierSet( | 220 FixedArray::NoIncrementalWriteBarrierSet( |
165 this, ToKeyIndex(transition_number), key); | 221 this, ToKeyIndex(transition_number), key); |
166 FixedArray::NoIncrementalWriteBarrierSet( | 222 FixedArray::NoIncrementalWriteBarrierSet( |
167 this, ToTargetIndex(transition_number), target); | 223 this, ToTargetIndex(transition_number), target); |
168 } | 224 } |
169 | 225 |
170 | 226 |
171 void TransitionArray::SetNumberOfTransitions(int number_of_transitions) { | 227 void TransitionArray::SetNumberOfTransitions(int number_of_transitions) { |
172 DCHECK(number_of_transitions <= Capacity(this)); | 228 if (IsFullTransitionArray()) { |
173 set(kTransitionLengthIndex, Smi::FromInt(number_of_transitions)); | 229 DCHECK(number_of_transitions <= number_of_transitions_storage()); |
| 230 WRITE_FIELD(this, kTransitionLengthOffset, |
| 231 Smi::FromInt(number_of_transitions)); |
| 232 } |
174 } | 233 } |
175 | 234 |
| 235 |
| 236 #undef FIELD_ADDR |
| 237 #undef WRITE_FIELD |
| 238 #undef CONDITIONAL_WRITE_BARRIER |
| 239 |
| 240 |
176 } } // namespace v8::internal | 241 } } // namespace v8::internal |
177 | 242 |
178 #endif // V8_TRANSITIONS_INL_H_ | 243 #endif // V8_TRANSITIONS_INL_H_ |
OLD | NEW |