| OLD | NEW |
| 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 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "objects.h" | 30 #include "objects.h" |
| 31 #include "transitions-inl.h" | 31 #include "transitions-inl.h" |
| 32 #include "utils.h" | 32 #include "utils.h" |
| 33 | 33 |
| 34 namespace v8 { | 34 namespace v8 { |
| 35 namespace internal { | 35 namespace internal { |
| 36 | 36 |
| 37 | 37 |
| 38 static MaybeObject* AllocateRaw(int length, | 38 MaybeObject* TransitionArray::Allocate(int number_of_transitions) { |
| 39 JSGlobalPropertyCell* descriptors_cell) { | |
| 40 Heap* heap = Isolate::Current()->heap(); | 39 Heap* heap = Isolate::Current()->heap(); |
| 41 | 40 // Use FixedArray to not use DescriptorArray::cast on incomplete object. |
| 42 if (descriptors_cell == NULL) { | |
| 43 MaybeObject* maybe_cell = | |
| 44 heap->AllocateJSGlobalPropertyCell(heap->empty_descriptor_array()); | |
| 45 if (!maybe_cell->To(&descriptors_cell)) return maybe_cell; | |
| 46 } | |
| 47 | |
| 48 // Use FixedArray to not use TransitionArray::cast on incomplete object. | |
| 49 FixedArray* array; | 41 FixedArray* array; |
| 50 MaybeObject* maybe_array = heap->AllocateFixedArray(length); | 42 MaybeObject* maybe_array = |
| 43 heap->AllocateFixedArray(ToKeyIndex(number_of_transitions)); |
| 51 if (!maybe_array->To(&array)) return maybe_array; | 44 if (!maybe_array->To(&array)) return maybe_array; |
| 52 | 45 |
| 53 array->set(TransitionArray::kDescriptorsPointerIndex, descriptors_cell); | |
| 54 return array; | |
| 55 } | |
| 56 | |
| 57 | |
| 58 MaybeObject* TransitionArray::Allocate(int number_of_transitions, | |
| 59 JSGlobalPropertyCell* descriptors_cell) { | |
| 60 FixedArray* array; | |
| 61 MaybeObject* maybe_array = | |
| 62 AllocateRaw(ToKeyIndex(number_of_transitions), descriptors_cell); | |
| 63 if (!maybe_array->To(&array)) return maybe_array; | |
| 64 array->set(kElementsTransitionIndex, Smi::FromInt(0)); | 46 array->set(kElementsTransitionIndex, Smi::FromInt(0)); |
| 65 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); | 47 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); |
| 66 return array; | 48 return array; |
| 67 } | 49 } |
| 68 | 50 |
| 69 | 51 |
| 70 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | 52 void TransitionArray::CopyFrom(TransitionArray* origin, |
| 71 int origin_transition, | 53 int origin_transition, |
| 72 int target_transition) { | 54 int target_transition, |
| 73 NoIncrementalWriteBarrierSet(target_transition, | 55 const WhitenessWitness& witness) { |
| 74 origin->GetKey(origin_transition), | 56 Set(target_transition, |
| 75 origin->GetTarget(origin_transition)); | 57 origin->GetKey(origin_transition), |
| 58 origin->GetTarget(origin_transition), |
| 59 witness); |
| 76 } | 60 } |
| 77 | 61 |
| 78 | 62 |
| 79 static bool InsertionPointFound(String* key1, String* key2) { | 63 static bool InsertionPointFound(String* key1, String* key2) { |
| 80 return key1->Hash() > key2->Hash(); | 64 return key1->Hash() > key2->Hash(); |
| 81 } | 65 } |
| 82 | 66 |
| 83 | 67 |
| 84 MaybeObject* TransitionArray::NewWith(SimpleTransitionFlag flag, | 68 MaybeObject* TransitionArray::NewWith(String* name, Map* target) { |
| 85 String* key, | |
| 86 Map* target, | |
| 87 JSGlobalPropertyCell* descriptors_pointer, | |
| 88 Object* back_pointer) { | |
| 89 TransitionArray* result; | 69 TransitionArray* result; |
| 90 MaybeObject* maybe_result; | |
| 91 | 70 |
| 92 if (flag == SIMPLE_TRANSITION) { | 71 MaybeObject* maybe_array = TransitionArray::Allocate(1); |
| 93 maybe_result = AllocateRaw(kSimpleTransitionSize, descriptors_pointer); | 72 if (!maybe_array->To(&result)) return maybe_array; |
| 94 if (!maybe_result->To(&result)) return maybe_result; | 73 |
| 95 result->set(kSimpleTransitionTarget, target); | 74 FixedArray::WhitenessWitness witness(result); |
| 96 } else { | 75 |
| 97 maybe_result = Allocate(1, descriptors_pointer); | 76 result->Set(0, name, target, witness); |
| 98 if (!maybe_result->To(&result)) return maybe_result; | |
| 99 result->NoIncrementalWriteBarrierSet(0, key, target); | |
| 100 } | |
| 101 result->set_back_pointer_storage(back_pointer); | |
| 102 return result; | 77 return result; |
| 103 } | 78 } |
| 104 | 79 |
| 105 | |
| 106 MaybeObject* TransitionArray::AllocateDescriptorsHolder( | |
| 107 JSGlobalPropertyCell* descriptors_pointer) { | |
| 108 return AllocateRaw(kDescriptorsHolderSize, descriptors_pointer); | |
| 109 } | |
| 110 | |
| 111 | |
| 112 MaybeObject* TransitionArray::ExtendToFullTransitionArray() { | |
| 113 ASSERT(!IsFullTransitionArray()); | |
| 114 int nof = number_of_transitions(); | |
| 115 TransitionArray* result; | |
| 116 MaybeObject* maybe_result = Allocate(nof, descriptors_pointer()); | |
| 117 if (!maybe_result->To(&result)) return maybe_result; | |
| 118 | |
| 119 if (nof == 1) { | |
| 120 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); | |
| 121 } | |
| 122 | |
| 123 result->set_back_pointer_storage(back_pointer_storage()); | |
| 124 return result; | |
| 125 } | |
| 126 | |
| 127 | 80 |
| 128 MaybeObject* TransitionArray::CopyInsert(String* name, Map* target) { | 81 MaybeObject* TransitionArray::CopyInsert(String* name, Map* target) { |
| 129 TransitionArray* result; | 82 TransitionArray* result; |
| 130 | 83 |
| 131 int number_of_transitions = this->number_of_transitions(); | 84 int number_of_transitions = this->number_of_transitions(); |
| 132 int new_size = number_of_transitions; | 85 int new_size = number_of_transitions; |
| 133 | 86 |
| 134 int insertion_index = this->Search(name); | 87 int insertion_index = this->Search(name); |
| 135 if (insertion_index == kNotFound) ++new_size; | 88 if (insertion_index == kNotFound) ++new_size; |
| 136 | 89 |
| 137 MaybeObject* maybe_array; | 90 MaybeObject* maybe_array; |
| 138 maybe_array = TransitionArray::Allocate(new_size, descriptors_pointer()); | 91 maybe_array = TransitionArray::Allocate(new_size); |
| 139 if (!maybe_array->To(&result)) return maybe_array; | 92 if (!maybe_array->To(&result)) return maybe_array; |
| 140 | 93 |
| 141 if (HasElementsTransition()) { | 94 if (HasElementsTransition()) { |
| 142 result->set_elements_transition(elements_transition()); | 95 result->set_elements_transition(elements_transition()); |
| 143 } | 96 } |
| 144 | 97 |
| 145 if (HasPrototypeTransitions()) { | 98 if (HasPrototypeTransitions()) { |
| 146 result->SetPrototypeTransitions(GetPrototypeTransitions()); | 99 result->SetPrototypeTransitions(GetPrototypeTransitions()); |
| 147 } | 100 } |
| 148 | 101 |
| 102 FixedArray::WhitenessWitness witness(result); |
| 103 |
| 149 if (insertion_index != kNotFound) { | 104 if (insertion_index != kNotFound) { |
| 150 for (int i = 0; i < number_of_transitions; ++i) { | 105 for (int i = 0; i < number_of_transitions; ++i) { |
| 151 if (i != insertion_index) { | 106 if (i != insertion_index) result->CopyFrom(this, i, i, witness); |
| 152 result->NoIncrementalWriteBarrierCopyFrom(this, i, i); | |
| 153 } | |
| 154 } | 107 } |
| 155 result->NoIncrementalWriteBarrierSet(insertion_index, name, target); | 108 result->Set(insertion_index, name, target, witness); |
| 156 return result; | 109 return result; |
| 157 } | 110 } |
| 158 | 111 |
| 159 insertion_index = 0; | 112 insertion_index = 0; |
| 160 for (; insertion_index < number_of_transitions; ++insertion_index) { | 113 for (; insertion_index < number_of_transitions; ++insertion_index) { |
| 161 if (InsertionPointFound(GetKey(insertion_index), name)) break; | 114 if (InsertionPointFound(GetKey(insertion_index), name)) break; |
| 162 result->NoIncrementalWriteBarrierCopyFrom( | 115 result->CopyFrom(this, insertion_index, insertion_index, witness); |
| 163 this, insertion_index, insertion_index); | |
| 164 } | 116 } |
| 165 | 117 |
| 166 result->NoIncrementalWriteBarrierSet(insertion_index, name, target); | 118 result->Set(insertion_index, name, target, witness); |
| 167 | 119 |
| 168 for (; insertion_index < number_of_transitions; ++insertion_index) { | 120 for (; insertion_index < number_of_transitions; ++insertion_index) { |
| 169 result->NoIncrementalWriteBarrierCopyFrom( | 121 result->CopyFrom(this, insertion_index, insertion_index + 1, witness); |
| 170 this, insertion_index, insertion_index + 1); | |
| 171 } | 122 } |
| 172 | 123 |
| 173 result->set_back_pointer_storage(back_pointer_storage()); | |
| 174 return result; | 124 return result; |
| 175 } | 125 } |
| 176 | 126 |
| 177 | 127 |
| 178 } } // namespace v8::internal | 128 } } // namespace v8::internal |
| OLD | NEW |