| 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::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | 61 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, |
| 53 int origin_transition, | 62 int origin_transition, |
| 54 int target_transition) { | 63 int target_transition) { |
| 55 NoIncrementalWriteBarrierSet(target_transition, | 64 NoIncrementalWriteBarrierSet(target_transition, |
| 56 origin->GetKey(origin_transition), | 65 origin->GetKey(origin_transition), |
| 57 origin->GetTarget(origin_transition)); | 66 origin->GetTarget(origin_transition)); |
| 58 } | 67 } |
| 59 | 68 |
| 60 | 69 |
| 61 static bool InsertionPointFound(String* key1, String* key2) { | 70 static bool InsertionPointFound(String* key1, String* key2) { |
| 62 return key1->Hash() > key2->Hash(); | 71 return key1->Hash() > key2->Hash(); |
| 63 } | 72 } |
| 64 | 73 |
| 65 | 74 |
| 66 MaybeObject* TransitionArray::NewWith(String* name, Map* target) { | 75 MaybeObject* TransitionArray::NewWith( |
| 76 String* name, |
| 77 Map* target, |
| 78 JSGlobalPropertyCell* descriptors_pointer, |
| 79 Object* back_pointer) { |
| 67 TransitionArray* result; | 80 TransitionArray* result; |
| 68 | 81 |
| 69 MaybeObject* maybe_array = TransitionArray::Allocate(1); | 82 MaybeObject* maybe_array = TransitionArray::Allocate(1, descriptors_pointer); |
| 70 if (!maybe_array->To(&result)) return maybe_array; | 83 if (!maybe_array->To(&result)) return maybe_array; |
| 71 | 84 |
| 72 result->NoIncrementalWriteBarrierSet(0, name, target); | 85 result->NoIncrementalWriteBarrierSet(0, name, target); |
| 86 result->set_back_pointer_storage(back_pointer); |
| 73 return result; | 87 return result; |
| 74 } | 88 } |
| 75 | 89 |
| 76 | 90 |
| 77 MaybeObject* TransitionArray::CopyInsert(String* name, Map* target) { | 91 MaybeObject* TransitionArray::CopyInsert(String* name, Map* target) { |
| 78 TransitionArray* result; | 92 TransitionArray* result; |
| 79 | 93 |
| 80 int number_of_transitions = this->number_of_transitions(); | 94 int number_of_transitions = this->number_of_transitions(); |
| 81 int new_size = number_of_transitions; | 95 int new_size = number_of_transitions; |
| 82 | 96 |
| 83 int insertion_index = this->Search(name); | 97 int insertion_index = this->Search(name); |
| 84 if (insertion_index == kNotFound) ++new_size; | 98 if (insertion_index == kNotFound) ++new_size; |
| 85 | 99 |
| 86 MaybeObject* maybe_array; | 100 MaybeObject* maybe_array; |
| 87 maybe_array = TransitionArray::Allocate(new_size); | 101 maybe_array = TransitionArray::Allocate(new_size, descriptors_pointer()); |
| 88 if (!maybe_array->To(&result)) return maybe_array; | 102 if (!maybe_array->To(&result)) return maybe_array; |
| 89 | 103 |
| 90 if (HasElementsTransition()) { | 104 if (HasElementsTransition()) { |
| 91 result->set_elements_transition(elements_transition()); | 105 result->set_elements_transition(elements_transition()); |
| 92 } | 106 } |
| 93 | 107 |
| 94 if (HasPrototypeTransitions()) { | 108 if (HasPrototypeTransitions()) { |
| 95 result->SetPrototypeTransitions(GetPrototypeTransitions()); | 109 result->SetPrototypeTransitions(GetPrototypeTransitions()); |
| 96 } | 110 } |
| 97 | 111 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 112 this, insertion_index, insertion_index); | 126 this, insertion_index, insertion_index); |
| 113 } | 127 } |
| 114 | 128 |
| 115 result->NoIncrementalWriteBarrierSet(insertion_index, name, target); | 129 result->NoIncrementalWriteBarrierSet(insertion_index, name, target); |
| 116 | 130 |
| 117 for (; insertion_index < number_of_transitions; ++insertion_index) { | 131 for (; insertion_index < number_of_transitions; ++insertion_index) { |
| 118 result->NoIncrementalWriteBarrierCopyFrom( | 132 result->NoIncrementalWriteBarrierCopyFrom( |
| 119 this, insertion_index, insertion_index + 1); | 133 this, insertion_index, insertion_index + 1); |
| 120 } | 134 } |
| 121 | 135 |
| 136 result->set_back_pointer_storage(back_pointer_storage()); |
| 122 return result; | 137 return result; |
| 123 } | 138 } |
| 124 | 139 |
| 125 | 140 |
| 126 } } // namespace v8::internal | 141 } } // namespace v8::internal |
| OLD | NEW |