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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 int number_of_transitions) { | 48 int number_of_transitions) { |
49 FixedArray* array; | 49 FixedArray* array; |
50 MaybeObject* maybe_array = | 50 MaybeObject* maybe_array = |
51 AllocateRaw(isolate, ToKeyIndex(number_of_transitions)); | 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 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 |
58 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, | 69 void TransitionArray::NoIncrementalWriteBarrierCopyFrom(TransitionArray* origin, |
59 int origin_transition, | 70 int origin_transition, |
60 int target_transition) { | 71 int target_transition) { |
61 NoIncrementalWriteBarrierSet(target_transition, | 72 NoIncrementalWriteBarrierSet(target_transition, |
62 origin->GetKey(origin_transition), | 73 origin->GetKey(origin_transition), |
63 origin->GetTarget(origin_transition)); | 74 origin->GetTarget(origin_transition)); |
64 } | 75 } |
65 | 76 |
66 | 77 |
67 static bool InsertionPointFound(Name* key1, Name* key2) { | 78 static bool InsertionPointFound(Name* key1, Name* key2) { |
68 return key1->Hash() > key2->Hash(); | 79 return key1->Hash() > key2->Hash(); |
69 } | 80 } |
70 | 81 |
71 | 82 |
72 MaybeObject* TransitionArray::NewWith(SimpleTransitionFlag flag, | 83 Handle<TransitionArray> TransitionArray::NewWith(SimpleTransitionFlag flag, |
73 Name* key, | 84 Handle<Name> key, |
74 Map* target, | 85 Handle<Map> target, |
75 Object* back_pointer) { | 86 Handle<Object> back_pointer) { |
76 TransitionArray* result; | 87 Handle<TransitionArray> result; |
77 MaybeObject* maybe_result; | 88 Factory* factory = key->GetIsolate()->factory(); |
78 | 89 |
79 if (flag == SIMPLE_TRANSITION) { | 90 if (flag == SIMPLE_TRANSITION) { |
80 maybe_result = AllocateRaw(target->GetIsolate(), kSimpleTransitionSize); | 91 result = factory->NewSimpleTransitionArray(target); |
81 if (!maybe_result->To(&result)) return maybe_result; | |
82 result->set(kSimpleTransitionTarget, target); | |
83 } else { | 92 } else { |
84 maybe_result = Allocate(target->GetIsolate(), 1); | 93 result = factory->NewTransitionArray(1); |
85 if (!maybe_result->To(&result)) return maybe_result; | 94 result->NoIncrementalWriteBarrierSet(0, *key, *target); |
86 result->NoIncrementalWriteBarrierSet(0, key, target); | |
87 } | 95 } |
88 result->set_back_pointer_storage(back_pointer); | 96 result->set_back_pointer_storage(*back_pointer); |
89 return result; | 97 return result; |
90 } | 98 } |
91 | 99 |
92 | 100 |
93 MaybeObject* TransitionArray::ExtendToFullTransitionArray() { | 101 MaybeObject* TransitionArray::ExtendToFullTransitionArray() { |
94 ASSERT(!IsFullTransitionArray()); | 102 ASSERT(!IsFullTransitionArray()); |
95 int nof = number_of_transitions(); | 103 int nof = number_of_transitions(); |
96 TransitionArray* result; | 104 TransitionArray* result; |
97 MaybeObject* maybe_result = Allocate(GetIsolate(), nof); | 105 MaybeObject* maybe_result = Allocate(GetIsolate(), nof); |
98 if (!maybe_result->To(&result)) return maybe_result; | 106 if (!maybe_result->To(&result)) return maybe_result; |
99 | 107 |
100 if (nof == 1) { | 108 if (nof == 1) { |
101 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); | 109 result->NoIncrementalWriteBarrierCopyFrom(this, kSimpleTransitionIndex, 0); |
102 } | 110 } |
103 | 111 |
104 result->set_back_pointer_storage(back_pointer_storage()); | 112 result->set_back_pointer_storage(back_pointer_storage()); |
105 return result; | 113 return result; |
106 } | 114 } |
107 | 115 |
108 | 116 |
109 MaybeObject* TransitionArray::CopyInsert(Name* name, Map* target) { | 117 Handle<TransitionArray> TransitionArray::CopyInsert(Handle<Map> map, |
110 TransitionArray* result; | 118 Handle<Name> name, |
| 119 Handle<Map> target) { |
| 120 ASSERT(map->HasTransitionArray()); |
| 121 Handle<TransitionArray> result; |
111 | 122 |
112 int number_of_transitions = this->number_of_transitions(); | 123 int number_of_transitions = map->transitions()->number_of_transitions(); |
113 int new_size = number_of_transitions; | 124 int new_size = number_of_transitions; |
114 | 125 |
115 int insertion_index = this->Search(name); | 126 int insertion_index = map->transitions()->Search(*name); |
116 if (insertion_index == kNotFound) ++new_size; | 127 if (insertion_index == kNotFound) ++new_size; |
117 | 128 |
118 MaybeObject* maybe_array; | 129 result = map->GetIsolate()->factory()->NewTransitionArray(new_size); |
119 maybe_array = TransitionArray::Allocate(GetIsolate(), new_size); | |
120 if (!maybe_array->To(&result)) return maybe_array; | |
121 | 130 |
122 if (HasPrototypeTransitions()) { | 131 // The map's transition array may have grown smaller during the allocation |
123 result->SetPrototypeTransitions(GetPrototypeTransitions()); | 132 // above as it was weakly traversed. Trim the result copy if needed, and |
| 133 // recompute variables. |
| 134 DisallowHeapAllocation no_gc; |
| 135 TransitionArray* array = map->transitions(); |
| 136 if (array->number_of_transitions() != number_of_transitions) { |
| 137 ASSERT(array->number_of_transitions() < number_of_transitions); |
| 138 |
| 139 number_of_transitions = array->number_of_transitions(); |
| 140 new_size = number_of_transitions; |
| 141 |
| 142 insertion_index = array->Search(*name); |
| 143 if (insertion_index == kNotFound) ++new_size; |
| 144 |
| 145 result->Shrink(new_size); |
| 146 } |
| 147 |
| 148 if (array->HasPrototypeTransitions()) { |
| 149 result->SetPrototypeTransitions(array->GetPrototypeTransitions()); |
124 } | 150 } |
125 | 151 |
126 if (insertion_index != kNotFound) { | 152 if (insertion_index != kNotFound) { |
127 for (int i = 0; i < number_of_transitions; ++i) { | 153 for (int i = 0; i < number_of_transitions; ++i) { |
128 if (i != insertion_index) { | 154 if (i != insertion_index) { |
129 result->NoIncrementalWriteBarrierCopyFrom(this, i, i); | 155 result->NoIncrementalWriteBarrierCopyFrom(array, i, i); |
130 } | 156 } |
131 } | 157 } |
132 result->NoIncrementalWriteBarrierSet(insertion_index, name, target); | 158 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); |
133 result->set_back_pointer_storage(back_pointer_storage()); | 159 result->set_back_pointer_storage(array->back_pointer_storage()); |
134 return result; | 160 return result; |
135 } | 161 } |
136 | 162 |
137 insertion_index = 0; | 163 insertion_index = 0; |
138 for (; insertion_index < number_of_transitions; ++insertion_index) { | 164 for (; insertion_index < number_of_transitions; ++insertion_index) { |
139 if (InsertionPointFound(GetKey(insertion_index), name)) break; | 165 if (InsertionPointFound(array->GetKey(insertion_index), *name)) break; |
140 result->NoIncrementalWriteBarrierCopyFrom( | 166 result->NoIncrementalWriteBarrierCopyFrom( |
141 this, insertion_index, insertion_index); | 167 array, insertion_index, insertion_index); |
142 } | 168 } |
143 | 169 |
144 result->NoIncrementalWriteBarrierSet(insertion_index, name, target); | 170 result->NoIncrementalWriteBarrierSet(insertion_index, *name, *target); |
145 | 171 |
146 for (; insertion_index < number_of_transitions; ++insertion_index) { | 172 for (; insertion_index < number_of_transitions; ++insertion_index) { |
147 result->NoIncrementalWriteBarrierCopyFrom( | 173 result->NoIncrementalWriteBarrierCopyFrom( |
148 this, insertion_index, insertion_index + 1); | 174 array, insertion_index, insertion_index + 1); |
149 } | 175 } |
150 | 176 |
151 result->set_back_pointer_storage(back_pointer_storage()); | 177 result->set_back_pointer_storage(array->back_pointer_storage()); |
152 return result; | 178 return result; |
153 } | 179 } |
154 | 180 |
155 | 181 |
156 } } // namespace v8::internal | 182 } } // namespace v8::internal |
OLD | NEW |