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

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

Issue 2445333002: Ensure slow properties for simple {__proto__:null} literals. (Closed)
Patch Set: fixing typo Created 3 years, 9 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
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(
18 Handle<Context> context,
19 Handle<BoilerplateDescription> boilerplate_description,
20 bool* is_result_from_cache) {
21 int number_of_properties = boilerplate_description->backing_store_size();
22 Isolate* isolate = context->GetIsolate();
23 return isolate->factory()->ObjectLiteralMapFromCache(
24 context, number_of_properties, is_result_from_cache);
25 }
26
27 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate( 17 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate(
28 Isolate* isolate, Handle<FeedbackVector> vector, 18 Isolate* isolate, Handle<FeedbackVector> vector,
29 Handle<BoilerplateDescription> boilerplate_description); 19 Handle<BoilerplateDescription> boilerplate_description);
30 20
31 MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate( 21 MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
32 Isolate* isolate, Handle<FeedbackVector> vector, 22 Isolate* isolate, Handle<FeedbackVector> vector,
33 Handle<BoilerplateDescription> boilerplate_description, 23 Handle<BoilerplateDescription> boilerplate_description,
34 bool should_have_fast_elements) { 24 bool use_fast_elements, bool has_null_prototype) {
35 Handle<Context> context = isolate->native_context(); 25 Handle<Context> context = isolate->native_context();
36 26
37 // In case we have function literals, we want the object to be in 27 // In case we have function literals, we want the object to be in
38 // slow properties mode for now. We don't go in the map cache because 28 // slow properties mode for now. We don't go in the map cache because
39 // maps with constant functions can't be shared if the functions are 29 // maps with constant functions can't be shared if the functions are
40 // not the same (which is the common case). 30 // not the same (which is the common case).
41 bool is_result_from_cache = false; 31 int number_of_properties = boilerplate_description->backing_store_size();
42 Handle<Map> map = ComputeObjectLiteralMap(context, boilerplate_description, 32 Handle<Map> map = isolate->factory()->ObjectLiteralMapFromCache(
43 &is_result_from_cache); 33 context, number_of_properties, has_null_prototype);
44 34
45 PretenureFlag pretenure_flag = 35 PretenureFlag pretenure_flag =
46 isolate->heap()->InNewSpace(*vector) ? NOT_TENURED : TENURED; 36 isolate->heap()->InNewSpace(*vector) ? NOT_TENURED : TENURED;
47 37
48 Handle<JSObject> boilerplate = 38 Handle<JSObject> boilerplate;
49 isolate->factory()->NewJSObjectFromMap(map, pretenure_flag); 39 if (map->is_dictionary_map()) {
40 boilerplate = isolate->factory()->NewSlowJSObjectFromMap(
41 map, number_of_properties, pretenure_flag);
42 } else {
43 boilerplate = isolate->factory()->NewJSObjectFromMap(map, pretenure_flag);
44 }
50 45
51 // Normalize the elements of the boilerplate to save space if needed. 46 // Normalize the elements of the boilerplate to save space if needed.
52 if (!should_have_fast_elements) JSObject::NormalizeElements(boilerplate); 47 if (!use_fast_elements) JSObject::NormalizeElements(boilerplate);
53 48
54 // Add the constant properties to the boilerplate. 49 // Add the constant properties to the boilerplate.
55 int length = boilerplate_description->size(); 50 int length = boilerplate_description->size();
56 bool should_transform =
57 !is_result_from_cache && boilerplate->HasFastProperties();
58 bool should_normalize = should_transform;
59 if (should_normalize) {
60 // TODO(verwaest): We might not want to ever normalize here.
61 JSObject::NormalizeProperties(boilerplate, KEEP_INOBJECT_PROPERTIES, length,
62 "Boilerplate");
63 }
64 // TODO(verwaest): Support tracking representations in the boilerplate. 51 // TODO(verwaest): Support tracking representations in the boilerplate.
65 for (int index = 0; index < length; index++) { 52 for (int index = 0; index < length; index++) {
66 Handle<Object> key(boilerplate_description->name(index), isolate); 53 Handle<Object> key(boilerplate_description->name(index), isolate);
67 Handle<Object> value(boilerplate_description->value(index), isolate); 54 Handle<Object> value(boilerplate_description->value(index), isolate);
68 if (value->IsBoilerplateDescription()) { 55 if (value->IsBoilerplateDescription()) {
69 // The value contains the boilerplate properties of a 56 // The value contains the boilerplate properties of a
70 // simple object or array literal. 57 // simple object or array literal.
71 Handle<BoilerplateDescription> boilerplate = 58 Handle<BoilerplateDescription> boilerplate =
72 Handle<BoilerplateDescription>::cast(value); 59 Handle<BoilerplateDescription>::cast(value);
73 ASSIGN_RETURN_ON_EXCEPTION( 60 ASSIGN_RETURN_ON_EXCEPTION(
(...skipping 11 matching lines...) Expand all
85 boilerplate, element_index, value, NONE); 72 boilerplate, element_index, value, NONE);
86 } else { 73 } else {
87 Handle<String> name = Handle<String>::cast(key); 74 Handle<String> name = Handle<String>::cast(key);
88 DCHECK(!name->AsArrayIndex(&element_index)); 75 DCHECK(!name->AsArrayIndex(&element_index));
89 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes(boilerplate, name, 76 maybe_result = JSObject::SetOwnPropertyIgnoreAttributes(boilerplate, name,
90 value, NONE); 77 value, NONE);
91 } 78 }
92 RETURN_ON_EXCEPTION(isolate, maybe_result, Object); 79 RETURN_ON_EXCEPTION(isolate, maybe_result, Object);
93 } 80 }
94 81
95 // Transform to fast properties if necessary. For object literals with 82 if (map->is_dictionary_map() && !has_null_prototype) {
96 // containing function literals we defer this operation until after all 83 // TODO(cbruni): avoid making the boilerplate fast again, the clone stub
97 // computed properties have been assigned so that we can generate 84 // supports dict-mode objects directly.
98 // constant function properties.
99 if (should_transform) {
100 JSObject::MigrateSlowToFast(boilerplate, 85 JSObject::MigrateSlowToFast(boilerplate,
101 boilerplate->map()->unused_property_fields(), 86 boilerplate->map()->unused_property_fields(),
102 "FastLiteral"); 87 "FastLiteral");
103 } 88 }
104 return boilerplate; 89 return boilerplate;
105 } 90 }
106 91
107 static MaybeHandle<Object> CreateArrayLiteralBoilerplate( 92 static MaybeHandle<Object> CreateArrayLiteralBoilerplate(
108 Isolate* isolate, Handle<FeedbackVector> vector, 93 Isolate* isolate, Handle<FeedbackVector> vector,
109 Handle<ConstantElementsPair> elements) { 94 Handle<ConstantElementsPair> elements) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 159
175 JSObject::ValidateElements(object); 160 JSObject::ValidateElements(object);
176 return object; 161 return object;
177 } 162 }
178 163
179 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate( 164 MUST_USE_RESULT static MaybeHandle<Object> CreateLiteralBoilerplate(
180 Isolate* isolate, Handle<FeedbackVector> vector, 165 Isolate* isolate, Handle<FeedbackVector> vector,
181 Handle<BoilerplateDescription> array) { 166 Handle<BoilerplateDescription> array) {
182 Handle<HeapObject> elements = CompileTimeValue::GetElements(array); 167 Handle<HeapObject> elements = CompileTimeValue::GetElements(array);
183 switch (CompileTimeValue::GetLiteralType(array)) { 168 switch (CompileTimeValue::GetLiteralType(array)) {
169 // TODO(cbruni): support slow inner literals.
184 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: { 170 case CompileTimeValue::OBJECT_LITERAL_FAST_ELEMENTS: {
185 Handle<BoilerplateDescription> props = 171 Handle<BoilerplateDescription> props =
186 Handle<BoilerplateDescription>::cast(elements); 172 Handle<BoilerplateDescription>::cast(elements);
187 return CreateObjectLiteralBoilerplate(isolate, vector, props, true); 173 return CreateObjectLiteralBoilerplate(isolate, vector, props, true,
174 false);
188 } 175 }
189 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: { 176 case CompileTimeValue::OBJECT_LITERAL_SLOW_ELEMENTS: {
190 Handle<BoilerplateDescription> props = 177 Handle<BoilerplateDescription> props =
191 Handle<BoilerplateDescription>::cast(elements); 178 Handle<BoilerplateDescription>::cast(elements);
192 return CreateObjectLiteralBoilerplate(isolate, vector, props, false); 179 return CreateObjectLiteralBoilerplate(isolate, vector, props, false,
180 false);
193 } 181 }
194 case CompileTimeValue::ARRAY_LITERAL: { 182 case CompileTimeValue::ARRAY_LITERAL: {
195 Handle<ConstantElementsPair> elems = 183 Handle<ConstantElementsPair> elems =
196 Handle<ConstantElementsPair>::cast(elements); 184 Handle<ConstantElementsPair>::cast(elements);
197 return CreateArrayLiteralBoilerplate(isolate, vector, elems); 185 return CreateArrayLiteralBoilerplate(isolate, vector, elems);
198 } 186 }
199 default: 187 default:
200 UNREACHABLE(); 188 UNREACHABLE();
201 return MaybeHandle<Object>(); 189 return MaybeHandle<Object>();
202 } 190 }
(...skipping 23 matching lines...) Expand all
226 214
227 RUNTIME_FUNCTION(Runtime_CreateObjectLiteral) { 215 RUNTIME_FUNCTION(Runtime_CreateObjectLiteral) {
228 HandleScope scope(isolate); 216 HandleScope scope(isolate);
229 DCHECK_EQ(4, args.length()); 217 DCHECK_EQ(4, args.length());
230 CONVERT_ARG_HANDLE_CHECKED(JSFunction, closure, 0); 218 CONVERT_ARG_HANDLE_CHECKED(JSFunction, closure, 0);
231 CONVERT_SMI_ARG_CHECKED(literals_index, 1); 219 CONVERT_SMI_ARG_CHECKED(literals_index, 1);
232 CONVERT_ARG_HANDLE_CHECKED(BoilerplateDescription, boilerplate_description, 220 CONVERT_ARG_HANDLE_CHECKED(BoilerplateDescription, boilerplate_description,
233 2); 221 2);
234 CONVERT_SMI_ARG_CHECKED(flags, 3); 222 CONVERT_SMI_ARG_CHECKED(flags, 3);
235 Handle<FeedbackVector> vector(closure->feedback_vector(), isolate); 223 Handle<FeedbackVector> vector(closure->feedback_vector(), isolate);
236 bool should_have_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; 224 bool use_fast_elements = (flags & ObjectLiteral::kFastElements) != 0;
237 bool enable_mementos = (flags & ObjectLiteral::kDisableMementos) == 0; 225 bool enable_mementos = (flags & ObjectLiteral::kDisableMementos) == 0;
226 bool has_null_prototype = (flags & ObjectLiteral::kHasNullPrototype) != 0;
238 227
239 FeedbackSlot literals_slot(FeedbackVector::ToSlot(literals_index)); 228 FeedbackSlot literals_slot(FeedbackVector::ToSlot(literals_index));
240 CHECK(literals_slot.ToInt() < vector->slot_count()); 229 CHECK(literals_slot.ToInt() < vector->slot_count());
241 230
242 // Check if boilerplate exists. If not, create it first. 231 // Check if boilerplate exists. If not, create it first.
243 Handle<Object> literal_site(vector->Get(literals_slot), isolate); 232 Handle<Object> literal_site(vector->Get(literals_slot), isolate);
244 Handle<AllocationSite> site; 233 Handle<AllocationSite> site;
245 Handle<JSObject> boilerplate; 234 Handle<JSObject> boilerplate;
246 if (literal_site->IsUndefined(isolate)) { 235 if (literal_site->IsUndefined(isolate)) {
247 Handle<Object> raw_boilerplate; 236 Handle<Object> raw_boilerplate;
248 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 237 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
249 isolate, raw_boilerplate, 238 isolate, raw_boilerplate,
250 CreateObjectLiteralBoilerplate(isolate, vector, boilerplate_description, 239 CreateObjectLiteralBoilerplate(isolate, vector, boilerplate_description,
251 should_have_fast_elements)); 240 use_fast_elements, has_null_prototype));
252 boilerplate = Handle<JSObject>::cast(raw_boilerplate); 241 boilerplate = Handle<JSObject>::cast(raw_boilerplate);
253 242
254 AllocationSiteCreationContext creation_context(isolate); 243 AllocationSiteCreationContext creation_context(isolate);
255 site = creation_context.EnterNewScope(); 244 site = creation_context.EnterNewScope();
256 RETURN_FAILURE_ON_EXCEPTION( 245 RETURN_FAILURE_ON_EXCEPTION(
257 isolate, JSObject::DeepWalk(boilerplate, &creation_context)); 246 isolate, JSObject::DeepWalk(boilerplate, &creation_context));
258 creation_context.ExitScope(site, boilerplate); 247 creation_context.ExitScope(site, boilerplate);
259 248
260 // Update the functions literal and return the boilerplate. 249 // Update the functions literal and return the boilerplate.
261 vector->Set(literals_slot, *site); 250 vector->Set(literals_slot, *site);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 340
352 Handle<FeedbackVector> vector(closure->feedback_vector(), isolate); 341 Handle<FeedbackVector> vector(closure->feedback_vector(), isolate);
353 FeedbackSlot literals_slot(FeedbackVector::ToSlot(literals_index)); 342 FeedbackSlot literals_slot(FeedbackVector::ToSlot(literals_index));
354 RETURN_RESULT_OR_FAILURE( 343 RETURN_RESULT_OR_FAILURE(
355 isolate, CreateArrayLiteralImpl(isolate, vector, literals_slot, elements, 344 isolate, CreateArrayLiteralImpl(isolate, vector, literals_slot, elements,
356 ArrayLiteral::kShallowElements)); 345 ArrayLiteral::kShallowElements));
357 } 346 }
358 347
359 } // namespace internal 348 } // namespace internal
360 } // namespace v8 349 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698