OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 JSObject::MigrateSlowToFast(boilerplate, | 107 JSObject::MigrateSlowToFast(boilerplate, |
108 boilerplate->map()->unused_property_fields(), | 108 boilerplate->map()->unused_property_fields(), |
109 "FastLiteral"); | 109 "FastLiteral"); |
110 } | 110 } |
111 return boilerplate; | 111 return boilerplate; |
112 } | 112 } |
113 | 113 |
114 static MaybeHandle<Object> CreateArrayLiteralBoilerplate( | 114 static MaybeHandle<Object> CreateArrayLiteralBoilerplate( |
115 Isolate* isolate, Handle<LiteralsArray> literals, | 115 Isolate* isolate, Handle<LiteralsArray> literals, |
116 Handle<FixedArray> elements) { | 116 Handle<FixedArray> elements) { |
| 117 // Create the JSArray. |
| 118 Handle<JSFunction> constructor = isolate->array_function(); |
| 119 |
| 120 PretenureFlag pretenure_flag = |
| 121 isolate->heap()->InNewSpace(*literals) ? NOT_TENURED : TENURED; |
| 122 |
| 123 Handle<JSArray> object = Handle<JSArray>::cast( |
| 124 isolate->factory()->NewJSObject(constructor, pretenure_flag)); |
| 125 |
117 ElementsKind constant_elements_kind = | 126 ElementsKind constant_elements_kind = |
118 static_cast<ElementsKind>(Smi::cast(elements->get(0))->value()); | 127 static_cast<ElementsKind>(Smi::cast(elements->get(0))->value()); |
119 DCHECK(IsFastElementsKind(constant_elements_kind)); | |
120 Handle<FixedArrayBase> constant_elements_values( | 128 Handle<FixedArrayBase> constant_elements_values( |
121 FixedArrayBase::cast(elements->get(1))); | 129 FixedArrayBase::cast(elements->get(1))); |
| 130 |
| 131 { |
| 132 DisallowHeapAllocation no_gc; |
| 133 DCHECK(IsFastElementsKind(constant_elements_kind)); |
| 134 Context* native_context = isolate->context()->native_context(); |
| 135 Object* map = |
| 136 native_context->get(Context::ArrayMapIndex(constant_elements_kind)); |
| 137 object->set_map(Map::cast(map)); |
| 138 } |
| 139 |
122 Handle<FixedArrayBase> copied_elements_values; | 140 Handle<FixedArrayBase> copied_elements_values; |
123 | |
124 if (IsFastDoubleElementsKind(constant_elements_kind)) { | 141 if (IsFastDoubleElementsKind(constant_elements_kind)) { |
125 copied_elements_values = isolate->factory()->CopyFixedDoubleArray( | 142 copied_elements_values = isolate->factory()->CopyFixedDoubleArray( |
126 Handle<FixedDoubleArray>::cast(constant_elements_values)); | 143 Handle<FixedDoubleArray>::cast(constant_elements_values)); |
127 } else { | 144 } else { |
128 DCHECK(IsFastSmiOrObjectElementsKind(constant_elements_kind)); | 145 DCHECK(IsFastSmiOrObjectElementsKind(constant_elements_kind)); |
129 const bool is_cow = (constant_elements_values->map() == | 146 const bool is_cow = (constant_elements_values->map() == |
130 isolate->heap()->fixed_cow_array_map()); | 147 isolate->heap()->fixed_cow_array_map()); |
131 if (is_cow) { | 148 if (is_cow) { |
132 copied_elements_values = constant_elements_values; | 149 copied_elements_values = constant_elements_values; |
133 #if DEBUG | 150 #if DEBUG |
(...skipping 18 matching lines...) Expand all Loading... |
152 FixedArray::cast(fixed_array_values->get(i))); | 169 FixedArray::cast(fixed_array_values->get(i))); |
153 Handle<Object> result; | 170 Handle<Object> result; |
154 ASSIGN_RETURN_ON_EXCEPTION( | 171 ASSIGN_RETURN_ON_EXCEPTION( |
155 isolate, result, | 172 isolate, result, |
156 CreateLiteralBoilerplate(isolate, literals, fa), Object); | 173 CreateLiteralBoilerplate(isolate, literals, fa), Object); |
157 fixed_array_values_copy->set(i, *result); | 174 fixed_array_values_copy->set(i, *result); |
158 } | 175 } |
159 }); | 176 }); |
160 } | 177 } |
161 } | 178 } |
162 // Create the JSArray. | 179 object->set_elements(*copied_elements_values); |
163 PretenureFlag pretenure_flag = | 180 object->set_length(Smi::FromInt(copied_elements_values->length())); |
164 isolate->heap()->InNewSpace(*literals) ? NOT_TENURED : TENURED; | 181 |
165 Handle<JSArray> object = isolate->factory()->NewJSArrayWithElements( | |
166 copied_elements_values, constant_elements_kind, | |
167 copied_elements_values->length(), pretenure_flag); | |
168 JSObject::ValidateElements(object); | 182 JSObject::ValidateElements(object); |
169 return object; | 183 return object; |
170 } | 184 } |
171 | 185 |
172 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate( | 186 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate( |
173 Isolate* isolate, Handle<LiteralsArray> literals, | 187 Isolate* isolate, Handle<LiteralsArray> literals, |
174 Handle<FixedArray> array) { | 188 Handle<FixedArray> array) { |
175 Handle<FixedArray> elements = CompileTimeValue::GetElements(array); | 189 Handle<FixedArray> elements = CompileTimeValue::GetElements(array); |
176 switch (CompileTimeValue::GetLiteralType(array)) { | 190 switch (CompileTimeValue::GetLiteralType(array)) { |
177 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: | 191 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 347 |
334 Handle<LiteralsArray> literals(closure->literals(), isolate); | 348 Handle<LiteralsArray> literals(closure->literals(), isolate); |
335 RETURN_RESULT_OR_FAILURE( | 349 RETURN_RESULT_OR_FAILURE( |
336 isolate, | 350 isolate, |
337 CreateArrayLiteralImpl(isolate, literals, literals_index, elements, | 351 CreateArrayLiteralImpl(isolate, literals, literals_index, elements, |
338 ArrayLiteral::kShallowElements)); | 352 ArrayLiteral::kShallowElements)); |
339 } | 353 } |
340 | 354 |
341 } // namespace internal | 355 } // namespace internal |
342 } // namespace v8 | 356 } // namespace v8 |
OLD | NEW |