| 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(Isolate* isolate, int length) { | 38 Handle<TransitionArray> TransitionArray::Allocate(Isolate* isolate, |
| 39 // Use FixedArray to not use TransitionArray::cast on incomplete object. | 39 int number_of_transitions) { |
| 40 FixedArray* array; | 40 Handle<FixedArray> array = |
| 41 MaybeObject* maybe_array = isolate->heap()->AllocateFixedArray(length); | 41 isolate->factory()->NewFixedArray(ToKeyIndex(number_of_transitions)); |
| 42 if (!maybe_array->To(&array)) return maybe_array; | 42 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); |
| 43 return array; | 43 return Handle<TransitionArray>::cast(array); |
| 44 } | 44 } |
| 45 | 45 |
| 46 | 46 |
| 47 MaybeObject* TransitionArray::Allocate(Isolate* isolate, | 47 Handle<TransitionArray> TransitionArray::AllocateSimple(Isolate* isolate, |
| 48 int number_of_transitions) { | 48 Handle<Map> target) { |
| 49 FixedArray* array; | 49 Handle<FixedArray> array = |
| 50 MaybeObject* maybe_array = | 50 isolate->factory()->NewFixedArray(kSimpleTransitionSize); |
| 51 AllocateRaw(isolate, ToKeyIndex(number_of_transitions)); | 51 array->set(kSimpleTransitionTarget, *target); |
| 52 if (!maybe_array->To(&array)) return maybe_array; | 52 return Handle<TransitionArray>::cast(array); |
| 53 array->set(kPrototypeTransitionsIndex, Smi::FromInt(0)); | |
| 54 return array; | |
| 55 } | 53 } |
| 56 | 54 |
| 57 | 55 |
| 58 MaybeObject* TransitionArray::AllocateSimple(Isolate* isolate, | |
| 59 Map* target) { | |
| 60 FixedArray* array; | |
| 61 MaybeObject* maybe_array = | |
| 62 AllocateRaw(isolate, kSimpleTransitionSize); | |
| 63 if (!maybe_array->To(&array)) return maybe_array; | |
| 64 array->set(kSimpleTransitionTarget, target); | |
| 65 return array; | |
| 66 } | |
| 67 | |
| 68 | |
| 69 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | 56 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, |
| 70 int origin_transition, | 57 int origin_transition, |
| 71 int target_transition) { | 58 int target_transition) { |
| 72 NoIncrementalWriteBarrierSet(target_transition, | 59 NoIncrementalWriteBarrierSet(target_transition, |
| 73 origin->GetKey(origin_transition), | 60 origin->GetKey(origin_transition), |
| 74 origin->GetTarget(origin_transition)); | 61 origin->GetTarget(origin_transition)); |
| 75 } | 62 } |
| 76 | 63 |
| 77 | 64 |
| 78 static bool InsertionPointFound(Name* key1, Name* key2) { | 65 static bool InsertionPointFound(Name* key1, Name* key2) { |
| 79 return key1->Hash() > key2->Hash(); | 66 return key1->Hash() > key2->Hash(); |
| 80 } | 67 } |
| 81 | 68 |
| 82 | 69 |
| 83 Handle<TransitionArray> TransitionArray::NewWith(Handle<Map> map, | 70 Handle<TransitionArray> TransitionArray::NewWith(Handle<Map> map, |
| 84 Handle<Name> name, | 71 Handle<Name> name, |
| 85 Handle<Map> target, | 72 Handle<Map> target, |
| 86 SimpleTransitionFlag flag) { | 73 SimpleTransitionFlag flag) { |
| 87 Handle<TransitionArray> result; | 74 Handle<TransitionArray> result; |
| 88 Factory* factory = name->GetIsolate()->factory(); | 75 Isolate* isolate = name->GetIsolate(); |
| 89 | 76 |
| 90 if (flag == SIMPLE_TRANSITION) { | 77 if (flag == SIMPLE_TRANSITION) { |
| 91 result = factory->NewSimpleTransitionArray(target); | 78 result = AllocateSimple(isolate, target); |
| 92 } else { | 79 } else { |
| 93 result = factory->NewTransitionArray(1); | 80 result = Allocate(isolate, 1); |
| 94 result->NoIncrementalWriteBarrierSet(0, *name, *target); | 81 result->NoIncrementalWriteBarrierSet(0, *name, *target); |
| 95 } | 82 } |
| 96 result->set_back_pointer_storage(map->GetBackPointer()); | 83 result->set_back_pointer_storage(map->GetBackPointer()); |
| 97 return result; | 84 return result; |
| 98 } | 85 } |
| 99 | 86 |
| 100 | 87 |
| 101 MaybeObject* TransitionArray::ExtendToFullTransitionArray() { | 88 Handle<TransitionArray> TransitionArray::ExtendToFullTransitionArray( |
| 102 ASSERT(!IsFullTransitionArray()); | 89 Handle<TransitionArray> array) { |
| 103 int nof = number_of_transitions(); | 90 ASSERT(!array->IsFullTransitionArray()); |
| 104 TransitionArray* result; | 91 int nof = array->number_of_transitions(); |
| 105 MaybeObject* maybe_result = Allocate(GetIsolate(), nof); | 92 Handle<TransitionArray> result = Allocate(array->GetIsolate(), nof); |
| 106 if (!maybe_result->To(&result)) return maybe_result; | |
| 107 | 93 |
| 108 if (nof == 1) { | 94 if (nof == 1) { |
| 109 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); | 95 result->NoIncrementalWriteBarrierCopyFrom( |
| 96 *array, kSimpleTransitionIndex, 0); |
| 110 } | 97 } |
| 111 | 98 |
| 112 result->set_back_pointer_storage(back_pointer_storage()); | 99 result->set_back_pointer_storage(array->back_pointer_storage()); |
| 113 return result; | 100 return result; |
| 114 } | 101 } |
| 115 | 102 |
| 116 | 103 |
| 117 Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map, | 104 Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map, |
| 118 Handle<Name> name, | 105 Handle<Name> name, |
| 119 Handle<Map> target, | 106 Handle<Map> target, |
| 120 SimpleTransitionFlag flag) { | 107 SimpleTransitionFlag flag) { |
| 121 if (!map->HasTransitionArray()) { | 108 if (!map->HasTransitionArray()) { |
| 122 return TransitionArray::NewWith(map, name, target, flag); | 109 return TransitionArray::NewWith(map, name, target, flag); |
| 123 } | 110 } |
| 124 | 111 |
| 125 int number_of_transitions = map->transitions()->number_of_transitions(); | 112 int number_of_transitions = map->transitions()->number_of_transitions(); |
| 126 int new_size = number_of_transitions; | 113 int new_size = number_of_transitions; |
| 127 | 114 |
| 128 int insertion_index = map->transitions()->Search(*name); | 115 int insertion_index = map->transitions()->Search(*name); |
| 129 if (insertion_index == kNotFound) ++new_size; | 116 if (insertion_index == kNotFound) ++new_size; |
| 130 | 117 |
| 131 Handle<TransitionArray> result = | 118 Handle<TransitionArray> result = Allocate(map->GetIsolate(), new_size); |
| 132 map->GetIsolate()->factory()->NewTransitionArray(new_size); | |
| 133 | 119 |
| 134 // The map's transition array may have disappeared or grown smaller during | 120 // The map's transition array may have disappeared or grown smaller during |
| 135 // the allocation above as it was weakly traversed. Trim the result copy if | 121 // the allocation above as it was weakly traversed. Trim the result copy if |
| 136 // needed, and recompute variables. | 122 // needed, and recompute variables. |
| 137 DisallowHeapAllocation no_gc; | 123 DisallowHeapAllocation no_gc; |
| 138 if (!map->HasTransitionArray()) { | 124 if (!map->HasTransitionArray()) { |
| 139 if (flag == SIMPLE_TRANSITION) { | 125 if (flag == SIMPLE_TRANSITION) { |
| 140 ASSERT(result->length() >= kSimpleTransitionSize); | 126 ASSERT(result->length() >= kSimpleTransitionSize); |
| 141 result->Shrink(kSimpleTransitionSize); | 127 result->Shrink(kSimpleTransitionSize); |
| 142 result->set(kSimpleTransitionTarget, *target); | 128 result->set(kSimpleTransitionTarget, *target); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 result->NoIncrementalWriteBarrierCopyFrom( | 178 result->NoIncrementalWriteBarrierCopyFrom( |
| 193 array, insertion_index, insertion_index + 1); | 179 array, insertion_index, insertion_index + 1); |
| 194 } | 180 } |
| 195 | 181 |
| 196 result->set_back_pointer_storage(array->back_pointer_storage()); | 182 result->set_back_pointer_storage(array->back_pointer_storage()); |
| 197 return result; | 183 return result; |
| 198 } | 184 } |
| 199 | 185 |
| 200 | 186 |
| 201 } } // namespace v8::internal | 187 } } // namespace v8::internal |
| OLD | NEW |