5 #ifndef V8_TRANSITIONS_INL_H_ 6 #define V8_TRANSITIONS_INL_H_ 8 #include "src/transitions.h" 10 #include "src/ic/handler-configuration-inl.h" 11 #include "src/objects/fixed-array-inl.h" 12 #include "src/objects/maybe-object-inl.h" 13 #include "src/objects/slots.h" 14 #include "src/objects/smi.h" 17 #include "src/objects/object-macros.h" 22 TransitionArray* TransitionsAccessor::transitions() {
23 DCHECK_EQ(kFullTransitionArray, encoding());
24 return TransitionArray::cast(raw_transitions_->GetHeapObjectAssumeStrong());
27 CAST_ACCESSOR(TransitionArray)
29 bool TransitionArray::HasPrototypeTransitions() {
30 return Get(kPrototypeTransitionsIndex) != MaybeObject::FromSmi(Smi::zero());
33 WeakFixedArray* TransitionArray::GetPrototypeTransitions() {
34 DCHECK(HasPrototypeTransitions());
35 Object* prototype_transitions =
36 Get(kPrototypeTransitionsIndex)->GetHeapObjectAssumeStrong();
37 return WeakFixedArray::cast(prototype_transitions);
40 HeapObjectSlot TransitionArray::GetKeySlot(
int transition_number) {
41 DCHECK(transition_number < number_of_transitions());
42 return HeapObjectSlot(RawFieldOfElementAt(ToKeyIndex(transition_number)));
45 void TransitionArray::SetPrototypeTransitions(WeakFixedArray* transitions) {
46 DCHECK(transitions->IsWeakFixedArray());
47 WeakFixedArray::Set(kPrototypeTransitionsIndex,
48 HeapObjectReference::Strong(transitions));
51 int TransitionArray::NumberOfPrototypeTransitions(
52 WeakFixedArray* proto_transitions) {
53 if (proto_transitions->length() == 0)
return 0;
55 proto_transitions->Get(kProtoTransitionNumberOfEntriesOffset);
56 return raw.ToSmi().value();
59 Name TransitionArray::GetKey(
int transition_number) {
60 DCHECK(transition_number < number_of_transitions());
62 Get(ToKeyIndex(transition_number))->GetHeapObjectAssumeStrong());
65 Name TransitionsAccessor::GetKey(
int transition_number) {
69 case kMigrationTarget:
73 Map map = Map::cast(raw_transitions_->GetHeapObjectAssumeWeak());
74 return GetSimpleTransitionKey(map);
76 case kFullTransitionArray:
77 return transitions()->GetKey(transition_number);
82 void TransitionArray::SetKey(
int transition_number, Name key) {
83 DCHECK(transition_number < number_of_transitions());
84 WeakFixedArray::Set(ToKeyIndex(transition_number),
85 HeapObjectReference::Strong(key));
88 HeapObjectSlot TransitionArray::GetTargetSlot(
int transition_number) {
89 DCHECK(transition_number < number_of_transitions());
90 return HeapObjectSlot(RawFieldOfElementAt(ToTargetIndex(transition_number)));
94 PropertyDetails TransitionsAccessor::GetTargetDetails(Name name, Map target) {
95 DCHECK(!IsSpecialTransition(name->GetReadOnlyRoots(), name));
96 int descriptor = target->LastAdded();
97 DescriptorArray* descriptors = target->instance_descriptors();
99 DCHECK(descriptors->GetKey(descriptor)->Equals(name));
100 return descriptors->GetDetails(descriptor);
104 PropertyDetails TransitionsAccessor::GetSimpleTargetDetails(Map transition) {
105 return transition->GetLastDescriptorDetails();
109 Name TransitionsAccessor::GetSimpleTransitionKey(Map transition) {
110 int descriptor = transition->LastAdded();
111 return transition->instance_descriptors()->GetKey(descriptor);
115 Map TransitionsAccessor::GetTargetFromRaw(MaybeObject raw) {
116 return Map::cast(raw->GetHeapObjectAssumeWeak());
119 MaybeObject TransitionArray::GetRawTarget(
int transition_number) {
120 DCHECK(transition_number < number_of_transitions());
121 return Get(ToTargetIndex(transition_number));
124 Map TransitionArray::GetTarget(
int transition_number) {
125 MaybeObject raw = GetRawTarget(transition_number);
126 return TransitionsAccessor::GetTargetFromRaw(raw);
129 Map TransitionsAccessor::GetTarget(
int transition_number) {
130 switch (encoding()) {
133 case kMigrationTarget:
137 return Map::cast(raw_transitions_->GetHeapObjectAssumeWeak());
138 case kFullTransitionArray:
139 return transitions()->GetTarget(transition_number);
144 void TransitionArray::SetRawTarget(
int transition_number, MaybeObject value) {
145 DCHECK(transition_number < number_of_transitions());
146 DCHECK(value->IsWeak());
147 DCHECK(value->GetHeapObjectAssumeWeak()->IsMap());
148 WeakFixedArray::Set(ToTargetIndex(transition_number), value);
151 bool TransitionArray::GetTargetIfExists(
int transition_number, Isolate* isolate,
153 MaybeObject raw = GetRawTarget(transition_number);
154 HeapObject* heap_object;
155 if (raw->GetHeapObjectIfStrong(&heap_object) &&
156 heap_object->IsUndefined(isolate)) {
159 *target = TransitionsAccessor::GetTargetFromRaw(raw);
163 int TransitionArray::SearchNameForTesting(Name name,
int* out_insertion_index) {
164 return SearchName(name, out_insertion_index);
167 int TransitionArray::SearchSpecial(Symbol symbol,
int* out_insertion_index) {
168 return SearchName(symbol, out_insertion_index);
171 int TransitionArray::SearchName(Name name,
int* out_insertion_index) {
172 DCHECK(name->IsUniqueName());
173 return internal::Search<ALL_ENTRIES>(
this, name, number_of_entries(),
174 out_insertion_index);
177 int TransitionArray::number_of_transitions()
const {
178 if (length() < kFirstIndex)
return 0;
179 return Get(kTransitionLengthIndex).ToSmi().value();
182 int TransitionArray::CompareKeys(Name key1,
uint32_t hash1, PropertyKind kind1,
183 PropertyAttributes attributes1, Name key2,
185 PropertyAttributes attributes2) {
186 int cmp = CompareNames(key1, hash1, key2, hash2);
187 if (cmp != 0)
return cmp;
189 return CompareDetails(kind1, attributes1, kind2, attributes2);
192 int TransitionArray::CompareNames(Name key1,
uint32_t hash1, Name key2,
196 return hash1 <= hash2 ? -1 : 1;
202 int TransitionArray::CompareDetails(PropertyKind kind1,
203 PropertyAttributes attributes1,
205 PropertyAttributes attributes2) {
206 if (kind1 != kind2) {
207 return static_cast<int>(kind1) < static_cast<int>(kind2) ? -1 : 1;
210 if (attributes1 != attributes2) {
211 return static_cast<int>(attributes1) < static_cast<int>(attributes2) ? -1
218 void TransitionArray::Set(
int transition_number, Name key, MaybeObject target) {
219 WeakFixedArray::Set(ToKeyIndex(transition_number),
220 MaybeObject::FromObject(key));
221 WeakFixedArray::Set(ToTargetIndex(transition_number), target);
224 Name TransitionArray::GetSortedKey(
int transition_number) {
225 return GetKey(transition_number);
228 int TransitionArray::number_of_entries()
const {
229 return number_of_transitions();
232 int TransitionArray::Capacity() {
233 if (length() <= kFirstIndex)
return 0;
234 return (length() - kFirstIndex) / kEntrySize;
237 void TransitionArray::SetNumberOfTransitions(
int number_of_transitions) {
238 DCHECK(number_of_transitions <= Capacity());
240 kTransitionLengthIndex,
241 MaybeObject::FromSmi(Smi::FromInt(number_of_transitions)));
247 #include "src/objects/object-macros-undef.h" 249 #endif // V8_TRANSITIONS_INL_H_