Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: src/runtime/runtime-literals.cc

Issue 2632503003: [runtime] Allocate space for computed property names (Closed)
Patch Set: Fix some variable names. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/parsing/parser-base.h ('K') | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ast/compile-time-value.h" 10 #include "src/ast/compile-time-value.h"
11 #include "src/isolate-inl.h" 11 #include "src/isolate-inl.h"
12 #include "src/runtime/runtime.h" 12 #include "src/runtime/runtime.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 static Handle<Map> ComputeObjectLiteralMap( 17 static Handle<Map> ComputeObjectLiteralMap(
18 Handle<Context> context, Handle<FixedArray> constant_properties, 18 Handle<Context> context, Handle<ConstantProperties> constant_properties,
19 bool* is_result_from_cache) { 19 bool* is_result_from_cache) {
20 int properties_length = constant_properties->length(); 20 int number_of_properties = constant_properties->number_of_properties();
21 int number_of_properties = properties_length / 2;
22 21
23 for (int p = 0; p != properties_length; p += 2) { 22 for (int p = 0; p != constant_properties->length(); p += 2) {
24 Object* key = constant_properties->get(p); 23 Object* key = constant_properties->get(p);
25 uint32_t element_index = 0; 24 uint32_t element_index = 0;
26 if (key->ToArrayIndex(&element_index)) { 25 if (key->ToArrayIndex(&element_index)) {
27 // An index key does not require space in the property backing store. 26 // An index key does not require space in the property backing store.
28 number_of_properties--; 27 number_of_properties--;
29 } 28 }
30 } 29 }
31 Isolate* isolate = context->GetIsolate(); 30 Isolate* isolate = context->GetIsolate();
32 return isolate->factory()->ObjectLiteralMapFromCache( 31 return isolate->factory()->ObjectLiteralMapFromCache(
33 context, number_of_properties, is_result_from_cache); 32 context, number_of_properties, is_result_from_cache);
34 } 33 }
35 34
36 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate( 35 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate(
37 Isolate* isolate, Handle<LiteralsArray> literals, 36 Isolate* isolate, Handle<LiteralsArray> literals,
38 Handle<FixedArray> constant_properties); 37 Handle<ConstantProperties> constant_properties);
39 38
40 MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate( 39 MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
41 Isolate* isolate, Handle<LiteralsArray> literals, 40 Isolate* isolate, Handle<LiteralsArray> literals,
42 Handle<FixedArray> constant_properties, bool should_have_fast_elements) { 41 Handle<ConstantProperties> constant_properties,
42 bool should_have_fast_elements) {
43 Handle<Context> context = isolate->native_context(); 43 Handle<Context> context = isolate->native_context();
44 44
45 // In case we have function literals, we want the object to be in 45 // In case we have function literals, we want the object to be in
46 // slow properties mode for now. We don't go in the map cache because 46 // slow properties mode for now. We don't go in the map cache because
47 // maps with constant functions can't be shared if the functions are 47 // maps with constant functions can't be shared if the functions are
48 // not the same (which is the common case). 48 // not the same (which is the common case).
49 bool is_result_from_cache = false; 49 bool is_result_from_cache = false;
50 Handle<Map> map = ComputeObjectLiteralMap(context, constant_properties, 50 Handle<Map> map = ComputeObjectLiteralMap(context, constant_properties,
51 &is_result_from_cache); 51 &is_result_from_cache);
52 52
(...skipping 16 matching lines...) Expand all
69 JSObject::NormalizeProperties(boilerplate, KEEP_INOBJECT_PROPERTIES, 69 JSObject::NormalizeProperties(boilerplate, KEEP_INOBJECT_PROPERTIES,
70 length / 2, "Boilerplate"); 70 length / 2, "Boilerplate");
71 } 71 }
72 // TODO(verwaest): Support tracking representations in the boilerplate. 72 // TODO(verwaest): Support tracking representations in the boilerplate.
73 for (int index = 0; index < length; index += 2) { 73 for (int index = 0; index < length; index += 2) {
74 Handle<Object> key(constant_properties->get(index + 0), isolate); 74 Handle<Object> key(constant_properties->get(index + 0), isolate);
75 Handle<Object> value(constant_properties->get(index + 1), isolate); 75 Handle<Object> value(constant_properties->get(index + 1), isolate);
76 if (value->IsFixedArray()) { 76 if (value->IsFixedArray()) {
77 // The value contains the constant_properties of a 77 // The value contains the constant_properties of a
78 // simple object or array literal. 78 // simple object or array literal.
79 Handle<FixedArray> array = Handle<FixedArray>::cast(value); 79 Handle<ConstantProperties> array =
80 Handle<ConstantProperties>::cast(value);
80 ASSIGN_RETURN_ON_EXCEPTION( 81 ASSIGN_RETURN_ON_EXCEPTION(
81 isolate, value, CreateLiteralBoilerplate(isolate, literals, array), 82 isolate, value, CreateLiteralBoilerplate(isolate, literals, array),
82 Object); 83 Object);
83 } 84 }
84 MaybeHandle<Object> maybe_result; 85 MaybeHandle<Object> maybe_result;
85 uint32_t element_index = 0; 86 uint32_t element_index = 0;
86 if (key->ToArrayIndex(&element_index)) { 87 if (key->ToArrayIndex(&element_index)) {
87 // Array index (uint32). 88 // Array index (uint32).
88 if (value->IsUninitialized(isolate)) { 89 if (value->IsUninitialized(isolate)) {
89 value = handle(Smi::kZero, isolate); 90 value = handle(Smi::kZero, isolate);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 Handle<FixedArray> fixed_array_values = 158 Handle<FixedArray> fixed_array_values =
158 Handle<FixedArray>::cast(constant_elements_values); 159 Handle<FixedArray>::cast(constant_elements_values);
159 Handle<FixedArray> fixed_array_values_copy = 160 Handle<FixedArray> fixed_array_values_copy =
160 isolate->factory()->CopyFixedArray(fixed_array_values); 161 isolate->factory()->CopyFixedArray(fixed_array_values);
161 copied_elements_values = fixed_array_values_copy; 162 copied_elements_values = fixed_array_values_copy;
162 FOR_WITH_HANDLE_SCOPE( 163 FOR_WITH_HANDLE_SCOPE(
163 isolate, int, i = 0, i, i < fixed_array_values->length(), i++, { 164 isolate, int, i = 0, i, i < fixed_array_values->length(), i++, {
164 if (fixed_array_values->get(i)->IsFixedArray()) { 165 if (fixed_array_values->get(i)->IsFixedArray()) {
165 // The value contains the constant_properties of a 166 // The value contains the constant_properties of a
166 // simple object or array literal. 167 // simple object or array literal.
167 Handle<FixedArray> fa( 168 Handle<ConstantProperties> fa(
168 FixedArray::cast(fixed_array_values->get(i))); 169 ConstantProperties::cast(fixed_array_values->get(i)));
169 Handle<Object> result; 170 Handle<Object> result;
170 ASSIGN_RETURN_ON_EXCEPTION( 171 ASSIGN_RETURN_ON_EXCEPTION(
171 isolate, result, 172 isolate, result,
172 CreateLiteralBoilerplate(isolate, literals, fa), Object); 173 CreateLiteralBoilerplate(isolate, literals, fa), Object);
173 fixed_array_values_copy->set(i, *result); 174 fixed_array_values_copy->set(i, *result);
174 } 175 }
175 }); 176 });
176 } 177 }
177 } 178 }
178 object->set_elements(*copied_elements_values); 179 object->set_elements(*copied_elements_values);
179 object->set_length(Smi::FromInt(copied_elements_values->length())); 180 object->set_length(Smi::FromInt(copied_elements_values->length()));
180 181
181 JSObject::ValidateElements(object); 182 JSObject::ValidateElements(object);
182 return object; 183 return object;
183 } 184 }
184 185
185 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate( 186 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate(
186 Isolate* isolate, Handle<LiteralsArray> literals, 187 Isolate* isolate, Handle<LiteralsArray> literals,
187 Handle<FixedArray> array) { 188 Handle<ConstantProperties> array) {
188 Handle<HeapObject> elements = CompileTimeValue::GetElements(array); 189 Handle<HeapObject> elements = CompileTimeValue::GetElements(array);
189 switch (CompileTimeValue::GetLiteralType(array)) { 190 switch (CompileTimeValue::GetLiteralType(array)) {
190 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: { 191 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: {
191 Handle<FixedArray> props = Handle<FixedArray>::cast(elements); 192 Handle<ConstantProperties> props =
193 Handle<ConstantProperties>::cast(elements);
192 return CreateObjectLiteralBoilerplate(isolate, literals, props, true); 194 return CreateObjectLiteralBoilerplate(isolate, literals, props, true);
193 } 195 }
194 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: { 196 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: {
195 Handle<FixedArray> props = Handle<FixedArray>::cast(elements); 197 Handle<ConstantProperties> props =
198 Handle<ConstantProperties>::cast(elements);
196 return CreateObjectLiteralBoilerplate(isolate, literals, props, false); 199 return CreateObjectLiteralBoilerplate(isolate, literals, props, false);
197 } 200 }
198 case CompileTimeValue::ARRAY_LITERAL: { 201 case CompileTimeValue::ARRAY_LITERAL: {
199 Handle<ConstantElementsPair> elems = 202 Handle<ConstantElementsPair> elems =
200 Handle<ConstantElementsPair>::cast(elements); 203 Handle<ConstantElementsPair>::cast(elements);
201 return CreateArrayLiteralBoilerplate(isolate, literals, elems); 204 return CreateArrayLiteralBoilerplate(isolate, literals, elems);
202 } 205 }
203 default: 206 default:
204 UNREACHABLE(); 207 UNREACHABLE();
205 return MaybeHandle<Object>(); 208 return MaybeHandle<Object>();
(...skipping 18 matching lines...) Expand all
224 } 227 }
225 return *JSRegExp::Copy(Handle<JSRegExp>::cast(boilerplate)); 228 return *JSRegExp::Copy(Handle<JSRegExp>::cast(boilerplate));
226 } 229 }
227 230
228 231
229 RUNTIME_FUNCTION(Runtime_CreateObjectLiteral) { 232 RUNTIME_FUNCTION(Runtime_CreateObjectLiteral) {
230 HandleScope scope(isolate); 233 HandleScope scope(isolate);
231 DCHECK_EQ(4, args.length()); 234 DCHECK_EQ(4, args.length());
232 CONVERT_ARG_HANDLE_CHECKED(JSFunction, closure, 0); 235 CONVERT_ARG_HANDLE_CHECKED(JSFunction, closure, 0);
233 CONVERT_SMI_ARG_CHECKED(literals_index, 1); 236 CONVERT_SMI_ARG_CHECKED(literals_index, 1);
234 CONVERT_ARG_HANDLE_CHECKED(FixedArray, constant_properties, 2); 237 CONVERT_ARG_HANDLE_CHECKED(ConstantProperties, constant_properties, 2);
235 CONVERT_SMI_ARG_CHECKED(flags, 3); 238 CONVERT_SMI_ARG_CHECKED(flags, 3);
236 Handle<LiteralsArray> literals(closure->literals(), isolate); 239 Handle<LiteralsArray> literals(closure->literals(), isolate);
237 bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; 240 bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0;
238 bool enable_mementos = (flags & ObjectLiteral::kDisableMementos) == 0; 241 bool enable_mementos = (flags & ObjectLiteral::kDisableMementos) == 0;
239 242
240 CHECK(literals_index >= 0); 243 CHECK(literals_index >= 0);
241 CHECK(literals_index < literals->literals_count()); 244 CHECK(literals_index < literals->literals_count());
242 245
243 // Check if boilerplate exists. If not, create it first. 246 // Check if boilerplate exists. If not, create it first.
244 Handle<Object> literal_site(literals->literal(literals_index), isolate); 247 Handle<Object> literal_site(literals->literal(literals_index), isolate);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 354
352 Handle<LiteralsArray> literals(closure->literals(), isolate); 355 Handle<LiteralsArray> literals(closure->literals(), isolate);
353 RETURN_RESULT_OR_FAILURE( 356 RETURN_RESULT_OR_FAILURE(
354 isolate, 357 isolate,
355 CreateArrayLiteralImpl(isolate, literals, literals_index, elements, 358 CreateArrayLiteralImpl(isolate, literals, literals_index, elements,
356 ArrayLiteral::kShallowElements)); 359 ArrayLiteral::kShallowElements));
357 } 360 }
358 361
359 } // namespace internal 362 } // namespace internal
360 } // namespace v8 363 } // namespace v8
OLDNEW
« src/parsing/parser-base.h ('K') | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698