| 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 MaybeObject* TransitionArray::Allocate(int number_of_transitions) { | 38 MaybeObject* TransitionArray::Allocate(int number_of_transitions, |
| 39 JSGlobalPropertyCell* descriptors_cell) { |
| 39 Heap* heap = Isolate::Current()->heap(); | 40 Heap* heap = Isolate::Current()->heap(); |
| 41 |
| 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 |
| 40 // Use FixedArray to not use DescriptorArray::cast on incomplete object. | 48 // Use FixedArray to not use DescriptorArray::cast on incomplete object. |
| 41 FixedArray* array; | 49 FixedArray* array; |
| 42 MaybeObject* maybe_array = | 50 MaybeObject* maybe_array = |
| 43 heap->AllocateFixedArray(ToKeyIndex(number_of_transitions)); | 51 heap->AllocateFixedArray(ToKeyIndex(number_of_transitions)); |
| 44 if (!maybe_array->To(&array)) return maybe_array; | 52 if (!maybe_array->To(&array)) return maybe_array; |
| 45 | 53 |
| 54 array->set(kDescriptorsPointerIndex, descriptors_cell); |
| 46 array->set(kElementsTransitionIndex, Smi::FromInt(0)); | 55 array->set(kElementsTransitionIndex, Smi::FromInt(0)); |
| 47 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); | 56 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); |
| 48 return array; | 57 return array; |
| 49 } | 58 } |
| 50 | 59 |
| 51 | 60 |
| 52 void TransitionArray::CopyFrom(TransitionArray* origin, | 61 void TransitionArray::CopyFrom(TransitionArray* origin, |
| 53 int origin_transition, | 62 int origin_transition, |
| 54 int target_transition, | 63 int target_transition, |
| 55 const WhitenessWitness& witness) { | 64 const WhitenessWitness& witness) { |
| 56 Set(target_transition, | 65 Set(target_transition, |
| 57 origin->GetKey(origin_transition), | 66 origin->GetKey(origin_transition), |
| 58 origin->GetTarget(origin_transition), | 67 origin->GetTarget(origin_transition), |
| 59 witness); | 68 witness); |
| 60 } | 69 } |
| 61 | 70 |
| 62 | 71 |
| 63 static bool InsertionPointFound(String* key1, String* key2) { | 72 static bool InsertionPointFound(String* key1, String* key2) { |
| 64 return key1->Hash() > key2->Hash(); | 73 return key1->Hash() > key2->Hash(); |
| 65 } | 74 } |
| 66 | 75 |
| 67 | 76 |
| 68 MaybeObject* TransitionArray::NewWith(String* name, Map* target) { | 77 MaybeObject* TransitionArray::NewWith( |
| 78 String* name, |
| 79 Map* target, |
| 80 JSGlobalPropertyCell* descriptors_pointer, |
| 81 Object* back_pointer) { |
| 69 TransitionArray* result; | 82 TransitionArray* result; |
| 70 | 83 |
| 71 MaybeObject* maybe_array = TransitionArray::Allocate(1); | 84 MaybeObject* maybe_array = TransitionArray::Allocate(1, descriptors_pointer); |
| 72 if (!maybe_array->To(&result)) return maybe_array; | 85 if (!maybe_array->To(&result)) return maybe_array; |
| 73 | 86 |
| 74 FixedArray::WhitenessWitness witness(result); | 87 FixedArray::WhitenessWitness witness(result); |
| 75 | 88 |
| 76 result->Set(0, name, target, witness); | 89 result->Set(0, name, target, witness); |
| 90 result->set_back_pointer_storage(back_pointer); |
| 77 return result; | 91 return result; |
| 78 } | 92 } |
| 79 | 93 |
| 80 | 94 |
| 81 MaybeObject* TransitionArray::CopyInsert(String* name, Map* target) { | 95 MaybeObject* TransitionArray::CopyInsert(String* name, Map* target) { |
| 82 TransitionArray* result; | 96 TransitionArray* result; |
| 83 | 97 |
| 84 int number_of_transitions = this->number_of_transitions(); | 98 int number_of_transitions = this->number_of_transitions(); |
| 85 int new_size = number_of_transitions; | 99 int new_size = number_of_transitions; |
| 86 | 100 |
| 87 int insertion_index = this->Search(name); | 101 int insertion_index = this->Search(name); |
| 88 if (insertion_index == kNotFound) ++new_size; | 102 if (insertion_index == kNotFound) ++new_size; |
| 89 | 103 |
| 90 MaybeObject* maybe_array; | 104 MaybeObject* maybe_array; |
| 91 maybe_array = TransitionArray::Allocate(new_size); | 105 maybe_array = TransitionArray::Allocate(new_size, descriptors_pointer()); |
| 92 if (!maybe_array->To(&result)) return maybe_array; | 106 if (!maybe_array->To(&result)) return maybe_array; |
| 93 | 107 |
| 94 if (HasElementsTransition()) { | 108 if (HasElementsTransition()) { |
| 95 result->set_elements_transition(elements_transition()); | 109 result->set_elements_transition(elements_transition()); |
| 96 } | 110 } |
| 97 | 111 |
| 98 if (HasPrototypeTransitions()) { | 112 if (HasPrototypeTransitions()) { |
| 99 result->SetPrototypeTransitions(GetPrototypeTransitions()); | 113 result->SetPrototypeTransitions(GetPrototypeTransitions()); |
| 100 } | 114 } |
| 101 | 115 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 if (InsertionPointFound(GetKey(insertion_index), name)) break; | 128 if (InsertionPointFound(GetKey(insertion_index), name)) break; |
| 115 result->CopyFrom(this, insertion_index, insertion_index, witness); | 129 result->CopyFrom(this, insertion_index, insertion_index, witness); |
| 116 } | 130 } |
| 117 | 131 |
| 118 result->Set(insertion_index, name, target, witness); | 132 result->Set(insertion_index, name, target, witness); |
| 119 | 133 |
| 120 for (; insertion_index < number_of_transitions; ++insertion_index) { | 134 for (; insertion_index < number_of_transitions; ++insertion_index) { |
| 121 result->CopyFrom(this, insertion_index, insertion_index + 1, witness); | 135 result->CopyFrom(this, insertion_index, insertion_index + 1, witness); |
| 122 } | 136 } |
| 123 | 137 |
| 138 result->set_back_pointer_storage(back_pointer_storage()); |
| 124 return result; | 139 return result; |
| 125 } | 140 } |
| 126 | 141 |
| 127 | 142 |
| 128 } } // namespace v8::internal | 143 } } // namespace v8::internal |
| OLD | NEW |