| 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 static MaybeObject* AllocateRaw(Isolate* isolate, int length) { |
| 39 Heap* heap = Isolate::Current()->heap(); | |
| 40 | |
| 41 // Use FixedArray to not use TransitionArray::cast on incomplete object. | 39 // Use FixedArray to not use TransitionArray::cast on incomplete object. |
| 42 FixedArray* array; | 40 FixedArray* array; |
| 43 MaybeObject* maybe_array = heap->AllocateFixedArray(length); | 41 MaybeObject* maybe_array = isolate->heap()->AllocateFixedArray(length); |
| 44 if (!maybe_array->To(&array)) return maybe_array; | 42 if (!maybe_array->To(&array)) return maybe_array; |
| 45 return array; | 43 return array; |
| 46 } | 44 } |
| 47 | 45 |
| 48 | 46 |
| 49 MaybeObject* TransitionArray::Allocate(int number_of_transitions) { | 47 MaybeObject* TransitionArray::Allocate(Isolate* isolate, |
| 48 int number_of_transitions) { |
| 50 FixedArray* array; | 49 FixedArray* array; |
| 51 MaybeObject* maybe_array = AllocateRaw(ToKeyIndex(number_of_transitions)); | 50 MaybeObject* maybe_array = |
| 51 AllocateRaw(isolate, ToKeyIndex(number_of_transitions)); |
| 52 if (!maybe_array->To(&array)) return maybe_array; | 52 if (!maybe_array->To(&array)) return maybe_array; |
| 53 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); | 53 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); |
| 54 return array; | 54 return array; |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | 58 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, |
| 59 int origin_transition, | 59 int origin_transition, |
| 60 int target_transition) { | 60 int target_transition) { |
| 61 NoIncrementalWriteBarrierSet(target_transition, | 61 NoIncrementalWriteBarrierSet(target_transition, |
| 62 origin->GetKey(origin_transition), | 62 origin->GetKey(origin_transition), |
| 63 origin->GetTarget(origin_transition)); | 63 origin->GetTarget(origin_transition)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 | 66 |
| 67 static bool InsertionPointFound(Name* key1, Name* key2) { | 67 static bool InsertionPointFound(Name* key1, Name* key2) { |
| 68 return key1->Hash() > key2->Hash(); | 68 return key1->Hash() > key2->Hash(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 MaybeObject* TransitionArray::NewWith(SimpleTransitionFlag flag, | 72 MaybeObject* TransitionArray::NewWith(SimpleTransitionFlag flag, |
| 73 Name* key, | 73 Name* key, |
| 74 Map* target, | 74 Map* target, |
| 75 Object* back_pointer) { | 75 Object* back_pointer) { |
| 76 TransitionArray* result; | 76 TransitionArray* result; |
| 77 MaybeObject* maybe_result; | 77 MaybeObject* maybe_result; |
| 78 | 78 |
| 79 if (flag == SIMPLE_TRANSITION) { | 79 if (flag == SIMPLE_TRANSITION) { |
| 80 maybe_result = AllocateRaw(kSimpleTransitionSize); | 80 maybe_result = AllocateRaw(target->GetIsolate(), kSimpleTransitionSize); |
| 81 if (!maybe_result->To(&result)) return maybe_result; | 81 if (!maybe_result->To(&result)) return maybe_result; |
| 82 result->set(kSimpleTransitionTarget, target); | 82 result->set(kSimpleTransitionTarget, target); |
| 83 } else { | 83 } else { |
| 84 maybe_result = Allocate(1); | 84 maybe_result = Allocate(target->GetIsolate(), 1); |
| 85 if (!maybe_result->To(&result)) return maybe_result; | 85 if (!maybe_result->To(&result)) return maybe_result; |
| 86 result->NoIncrementalWriteBarrierSet(0, key, target); | 86 result->NoIncrementalWriteBarrierSet(0, key, target); |
| 87 } | 87 } |
| 88 result->set_back_pointer_storage(back_pointer); | 88 result->set_back_pointer_storage(back_pointer); |
| 89 return result; | 89 return result; |
| 90 } | 90 } |
| 91 | 91 |
| 92 | 92 |
| 93 MaybeObject* TransitionArray::ExtendToFullTransitionArray() { | 93 MaybeObject* TransitionArray::ExtendToFullTransitionArray() { |
| 94 ASSERT(!IsFullTransitionArray()); | 94 ASSERT(!IsFullTransitionArray()); |
| 95 int nof = number_of_transitions(); | 95 int nof = number_of_transitions(); |
| 96 TransitionArray* result; | 96 TransitionArray* result; |
| 97 MaybeObject* maybe_result = Allocate(nof); | 97 MaybeObject* maybe_result = Allocate(GetIsolate(), nof); |
| 98 if (!maybe_result->To(&result)) return maybe_result; | 98 if (!maybe_result->To(&result)) return maybe_result; |
| 99 | 99 |
| 100 if (nof == 1) { | 100 if (nof == 1) { |
| 101 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); | 101 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); |
| 102 } | 102 } |
| 103 | 103 |
| 104 result->set_back_pointer_storage(back_pointer_storage()); | 104 result->set_back_pointer_storage(back_pointer_storage()); |
| 105 return result; | 105 return result; |
| 106 } | 106 } |
| 107 | 107 |
| 108 | 108 |
| 109 MaybeObject* TransitionArray::CopyInsert(Name* name, Map* target) { | 109 MaybeObject* TransitionArray::CopyInsert(Name* name, Map* target) { |
| 110 TransitionArray* result; | 110 TransitionArray* result; |
| 111 | 111 |
| 112 int number_of_transitions = this->number_of_transitions(); | 112 int number_of_transitions = this->number_of_transitions(); |
| 113 int new_size = number_of_transitions; | 113 int new_size = number_of_transitions; |
| 114 | 114 |
| 115 int insertion_index = this->Search(name); | 115 int insertion_index = this->Search(name); |
| 116 if (insertion_index == kNotFound) ++new_size; | 116 if (insertion_index == kNotFound) ++new_size; |
| 117 | 117 |
| 118 MaybeObject* maybe_array; | 118 MaybeObject* maybe_array; |
| 119 maybe_array = TransitionArray::Allocate(new_size); | 119 maybe_array = TransitionArray::Allocate(GetIsolate(), new_size); |
| 120 if (!maybe_array->To(&result)) return maybe_array; | 120 if (!maybe_array->To(&result)) return maybe_array; |
| 121 | 121 |
| 122 if (HasPrototypeTransitions()) { | 122 if (HasPrototypeTransitions()) { |
| 123 result->SetPrototypeTransitions(GetPrototypeTransitions()); | 123 result->SetPrototypeTransitions(GetPrototypeTransitions()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 if (insertion_index != kNotFound) { | 126 if (insertion_index != kNotFound) { |
| 127 for (int i = 0; i < number_of_transitions; ++i) { | 127 for (int i = 0; i < number_of_transitions; ++i) { |
| 128 if (i != insertion_index) { | 128 if (i != insertion_index) { |
| 129 result->NoIncrementalWriteBarrierCopyFrom(this, i, i); | 129 result->NoIncrementalWriteBarrierCopyFrom(this, i, i); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 147 result->NoIncrementalWriteBarrierCopyFrom( | 147 result->NoIncrementalWriteBarrierCopyFrom( |
| 148 this, insertion_index, insertion_index + 1); | 148 this, insertion_index, insertion_index + 1); |
| 149 } | 149 } |
| 150 | 150 |
| 151 result->set_back_pointer_storage(back_pointer_storage()); | 151 result->set_back_pointer_storage(back_pointer_storage()); |
| 152 return result; | 152 return result; |
| 153 } | 153 } |
| 154 | 154 |
| 155 | 155 |
| 156 } } // namespace v8::internal | 156 } } // namespace v8::internal |
| OLD | NEW |