diff options
Diffstat (limited to 'deps/v8/src/runtime/runtime-literals.cc')
-rw-r--r-- | deps/v8/src/runtime/runtime-literals.cc | 104 |
1 files changed, 65 insertions, 39 deletions
diff --git a/deps/v8/src/runtime/runtime-literals.cc b/deps/v8/src/runtime/runtime-literals.cc index 6e17ba85d4a..d5111f7efab 100644 --- a/deps/v8/src/runtime/runtime-literals.cc +++ b/deps/v8/src/runtime/runtime-literals.cc @@ -2,15 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "src/runtime/runtime-utils.h" - #include "src/allocation-site-scopes.h" -#include "src/arguments.h" +#include "src/arguments-inl.h" #include "src/ast/ast.h" #include "src/isolate-inl.h" #include "src/objects/hash-table-inl.h" #include "src/objects/js-regexp-inl.h" #include "src/objects/literal-objects-inl.h" +#include "src/runtime/runtime-utils.h" #include "src/runtime/runtime.h" namespace v8 { @@ -22,7 +21,7 @@ bool IsUninitializedLiteralSite(Object* literal_site) { return literal_site == Smi::kZero; } -bool HasBoilerplate(Isolate* isolate, Handle<Object> literal_site) { +bool HasBoilerplate(Handle<Object> literal_site) { return !literal_site->IsSmi(); } @@ -196,7 +195,7 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk( UNREACHABLE(); break; -#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS: +#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype) case TYPE##_ELEMENTS: TYPED_ARRAYS(TYPED_ARRAY_CASE) #undef TYPED_ARRAY_CASE @@ -317,11 +316,11 @@ MaybeHandle<JSObject> DeepCopy(Handle<JSObject> object, return copy; } -struct ObjectBoilerplate { +struct ObjectLiteralHelper { static Handle<JSObject> Create(Isolate* isolate, Handle<HeapObject> description, int flags, PretenureFlag pretenure_flag) { - Handle<Context> native_context = isolate->native_context(); + Handle<NativeContext> native_context = isolate->native_context(); Handle<ObjectBoilerplateDescription> object_boilerplate_description = Handle<ObjectBoilerplateDescription>::cast(description); bool use_fast_elements = (flags & ObjectLiteral::kFastElements) != 0; @@ -392,7 +391,7 @@ struct ObjectBoilerplate { } }; -struct ArrayBoilerplate { +struct ArrayLiteralHelper { static Handle<JSObject> Create(Isolate* isolate, Handle<HeapObject> description, int flags, PretenureFlag pretenure_flag) { @@ -455,20 +454,43 @@ Handle<Object> InnerCreateBoilerplate(Isolate* isolate, if (description->IsObjectBoilerplateDescription()) { Handle<ObjectBoilerplateDescription> object_boilerplate_description = Handle<ObjectBoilerplateDescription>::cast(description); - return ObjectBoilerplate::Create(isolate, object_boilerplate_description, - object_boilerplate_description->flags(), - pretenure_flag); + return ObjectLiteralHelper::Create(isolate, object_boilerplate_description, + object_boilerplate_description->flags(), + pretenure_flag); } else { DCHECK(description->IsArrayBoilerplateDescription()); Handle<ArrayBoilerplateDescription> array_boilerplate_description = Handle<ArrayBoilerplateDescription>::cast(description); - return ArrayBoilerplate::Create( + return ArrayLiteralHelper::Create( isolate, array_boilerplate_description, array_boilerplate_description->elements_kind(), pretenure_flag); } } -template <typename Boilerplate> +inline DeepCopyHints DecodeCopyHints(int flags) { + DeepCopyHints copy_hints = + (flags & AggregateLiteral::kIsShallow) ? kObjectIsShallow : kNoHints; + if (FLAG_track_double_fields && !FLAG_unbox_double_fields) { + // Make sure we properly clone mutable heap numbers on 32-bit platforms. + copy_hints = kNoHints; + } + return copy_hints; +} + +template <typename LiteralHelper> +MaybeHandle<JSObject> CreateLiteralWithoutAllocationSite( + Isolate* isolate, Handle<HeapObject> description, int flags) { + Handle<JSObject> literal = + LiteralHelper::Create(isolate, description, flags, NOT_TENURED); + DeepCopyHints copy_hints = DecodeCopyHints(flags); + if (copy_hints == kNoHints) { + DeprecationUpdateContext update_context(isolate); + RETURN_ON_EXCEPTION(isolate, DeepWalk(literal, &update_context), JSObject); + } + return literal; +} + +template <typename LiteralHelper> MaybeHandle<JSObject> CreateLiteral(Isolate* isolate, Handle<FeedbackVector> vector, int literals_index, @@ -476,41 +498,25 @@ MaybeHandle<JSObject> CreateLiteral(Isolate* isolate, FeedbackSlot literals_slot(FeedbackVector::ToSlot(literals_index)); CHECK(literals_slot.ToInt() < vector->length()); Handle<Object> literal_site(vector->Get(literals_slot)->ToObject(), isolate); - DeepCopyHints copy_hints = - (flags & AggregateLiteral::kIsShallow) ? kObjectIsShallow : kNoHints; - if (FLAG_track_double_fields && !FLAG_unbox_double_fields) { - // Make sure we properly clone mutable heap numbers on 32-bit platforms. - copy_hints = kNoHints; - } + DeepCopyHints copy_hints = DecodeCopyHints(flags); Handle<AllocationSite> site; Handle<JSObject> boilerplate; - if (HasBoilerplate(isolate, literal_site)) { + if (HasBoilerplate(literal_site)) { site = Handle<AllocationSite>::cast(literal_site); boilerplate = Handle<JSObject>(site->boilerplate(), isolate); } else { // Eagerly create AllocationSites for literals that contain an Array. bool needs_initial_allocation_site = (flags & AggregateLiteral::kNeedsInitialAllocationSite) != 0; - // TODO(cbruni): Even in the case where we need an initial allocation site - // we could still create the boilerplate lazily to save memory. if (!needs_initial_allocation_site && IsUninitializedLiteralSite(*literal_site)) { PreInitializeLiteralSite(vector, literals_slot); - boilerplate = - Boilerplate::Create(isolate, description, flags, NOT_TENURED); - if (copy_hints == kNoHints) { - DeprecationUpdateContext update_context(isolate); - RETURN_ON_EXCEPTION(isolate, DeepWalk(boilerplate, &update_context), - JSObject); - } - return boilerplate; + return CreateLiteralWithoutAllocationSite<LiteralHelper>( + isolate, description, flags); } else { - PretenureFlag pretenure_flag = - Heap::InNewSpace(*vector) ? NOT_TENURED : TENURED; - boilerplate = - Boilerplate::Create(isolate, description, flags, pretenure_flag); + boilerplate = LiteralHelper::Create(isolate, description, flags, TENURED); } // Install AllocationSite objects. AllocationSiteCreationContext creation_context(isolate); @@ -544,8 +550,28 @@ RUNTIME_FUNCTION(Runtime_CreateObjectLiteral) { CONVERT_ARG_HANDLE_CHECKED(ObjectBoilerplateDescription, description, 2); CONVERT_SMI_ARG_CHECKED(flags, 3); RETURN_RESULT_OR_FAILURE( - isolate, CreateLiteral<ObjectBoilerplate>(isolate, vector, literals_index, - description, flags)); + isolate, CreateLiteral<ObjectLiteralHelper>( + isolate, vector, literals_index, description, flags)); +} + +RUNTIME_FUNCTION(Runtime_CreateObjectLiteralWithoutAllocationSite) { + HandleScope scope(isolate); + DCHECK_EQ(2, args.length()); + CONVERT_ARG_HANDLE_CHECKED(ObjectBoilerplateDescription, description, 0); + CONVERT_SMI_ARG_CHECKED(flags, 1); + RETURN_RESULT_OR_FAILURE( + isolate, CreateLiteralWithoutAllocationSite<ObjectLiteralHelper>( + isolate, description, flags)); +} + +RUNTIME_FUNCTION(Runtime_CreateArrayLiteralWithoutAllocationSite) { + HandleScope scope(isolate); + DCHECK_EQ(2, args.length()); + CONVERT_ARG_HANDLE_CHECKED(ArrayBoilerplateDescription, description, 0); + CONVERT_SMI_ARG_CHECKED(flags, 1); + RETURN_RESULT_OR_FAILURE( + isolate, CreateLiteralWithoutAllocationSite<ArrayLiteralHelper>( + isolate, description, flags)); } RUNTIME_FUNCTION(Runtime_CreateArrayLiteral) { @@ -556,8 +582,8 @@ RUNTIME_FUNCTION(Runtime_CreateArrayLiteral) { CONVERT_ARG_HANDLE_CHECKED(ArrayBoilerplateDescription, elements, 2); CONVERT_SMI_ARG_CHECKED(flags, 3); RETURN_RESULT_OR_FAILURE( - isolate, CreateLiteral<ArrayBoilerplate>(isolate, vector, literals_index, - elements, flags)); + isolate, CreateLiteral<ArrayLiteralHelper>( + isolate, vector, literals_index, elements, flags)); } RUNTIME_FUNCTION(Runtime_CreateRegExpLiteral) { @@ -573,7 +599,7 @@ RUNTIME_FUNCTION(Runtime_CreateRegExpLiteral) { // Check if boilerplate exists. If not, create it first. Handle<Object> literal_site(vector->Get(literal_slot)->ToObject(), isolate); Handle<Object> boilerplate; - if (!HasBoilerplate(isolate, literal_site)) { + if (!HasBoilerplate(literal_site)) { ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, boilerplate, JSRegExp::New(isolate, pattern, JSRegExp::Flags(flags))); |