From ee6e52f2924a0429afb2c5b78399523b715666bb Mon Sep 17 00:00:00 2001 From: "mvstanton@chromium.org" Date: Tue, 5 Nov 2013 09:54:59 +0000 Subject: [PATCH] Remove CreateArrayLiteralShallow, as it's fundamentally the same now as CreateArrayLiteral. R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/54333003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17470 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/code-stubs-arm.cc | 2 +- src/arm/full-codegen-arm.cc | 8 +++----- src/hydrogen.cc | 3 +-- src/ia32/code-stubs-ia32.cc | 2 +- src/ia32/full-codegen-ia32.cc | 11 +++-------- src/mips/code-stubs-mips.cc | 2 +- src/mips/full-codegen-mips.cc | 8 +++----- src/objects.cc | 4 +++- src/runtime.cc | 26 -------------------------- src/runtime.h | 1 - src/x64/code-stubs-x64.cc | 2 +- src/x64/full-codegen-x64.cc | 11 +++-------- test/cctest/test-api.cc | 28 ++++++++++++++++++++++++++++ 13 files changed, 48 insertions(+), 60 deletions(-) diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index 19993b0..95a04f7 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -77,7 +77,7 @@ void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( descriptor->register_param_count_ = 3; descriptor->register_params_ = registers; descriptor->deoptimization_handler_ = - Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; + Runtime::FunctionForId(Runtime::kCreateArrayLiteral)->entry; } diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index 4b9658c..1ee612b 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -1790,13 +1790,11 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { __ CallStub(&stub); __ IncrementCounter( isolate()->counters()->cow_arrays_created_stub(), 1, r1, r2); - } else if (expr->depth() > 1) { + } else if (expr->depth() > 1 || + Serializer::enabled() || + length > FastCloneShallowArrayStub::kMaximumClonedLength) { __ Push(r3, r2, r1); __ CallRuntime(Runtime::kCreateArrayLiteral, 3); - } else if (Serializer::enabled() || - length > FastCloneShallowArrayStub::kMaximumClonedLength) { - __ Push(r3, r2, r1); - __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); } else { ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || FLAG_smi_only_arrays); diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 5fc107c..2e05654 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -4498,8 +4498,7 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { // TODO(mvstanton): Consider a flag to turn off creation of any // AllocationMementos for this call: we are in crankshaft and should have // learned enough about transition behavior to stop emitting mementos. - Runtime::FunctionId function_id = (expr->depth() > 1) - ? Runtime::kCreateArrayLiteral : Runtime::kCreateArrayLiteralShallow; + Runtime::FunctionId function_id = Runtime::kCreateArrayLiteral; literal = Add(isolate()->factory()->empty_string(), Runtime::FunctionForId(function_id), 3); diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc index b6bbe04..941bb32 100644 --- a/src/ia32/code-stubs-ia32.cc +++ b/src/ia32/code-stubs-ia32.cc @@ -82,7 +82,7 @@ void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( descriptor->register_param_count_ = 3; descriptor->register_params_ = registers; descriptor->deoptimization_handler_ = - Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; + Runtime::FunctionForId(Runtime::kCreateArrayLiteral)->entry; } diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc index 704fb4e..09f5de1 100644 --- a/src/ia32/full-codegen-ia32.cc +++ b/src/ia32/full-codegen-ia32.cc @@ -1728,19 +1728,14 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { DONT_TRACK_ALLOCATION_SITE, length); __ CallStub(&stub); - } else if (expr->depth() > 1) { + } else if (expr->depth() > 1 || + Serializer::enabled() || + length > FastCloneShallowArrayStub::kMaximumClonedLength) { __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); __ push(Immediate(Smi::FromInt(expr->literal_index()))); __ push(Immediate(constant_elements)); __ CallRuntime(Runtime::kCreateArrayLiteral, 3); - } else if (Serializer::enabled() || - length > FastCloneShallowArrayStub::kMaximumClonedLength) { - __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); - __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); - __ push(Immediate(Smi::FromInt(expr->literal_index()))); - __ push(Immediate(constant_elements)); - __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); } else { ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || FLAG_smi_only_arrays); diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc index e334b28..0592f2e 100644 --- a/src/mips/code-stubs-mips.cc +++ b/src/mips/code-stubs-mips.cc @@ -78,7 +78,7 @@ void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( descriptor->register_param_count_ = 3; descriptor->register_params_ = registers; descriptor->deoptimization_handler_ = - Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; + Runtime::FunctionForId(Runtime::kCreateArrayLiteral)->entry; } diff --git a/src/mips/full-codegen-mips.cc b/src/mips/full-codegen-mips.cc index 7b25abe..13b2369 100644 --- a/src/mips/full-codegen-mips.cc +++ b/src/mips/full-codegen-mips.cc @@ -1793,13 +1793,11 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { __ CallStub(&stub); __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1, a1, a2); - } else if (expr->depth() > 1) { + } else if (expr->depth() > 1 || + Serializer::enabled() || + length > FastCloneShallowArrayStub::kMaximumClonedLength) { __ Push(a3, a2, a1); __ CallRuntime(Runtime::kCreateArrayLiteral, 3); - } else if (Serializer::enabled() || - length > FastCloneShallowArrayStub::kMaximumClonedLength) { - __ Push(a3, a2, a1); - __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); } else { ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || FLAG_smi_only_arrays); diff --git a/src/objects.cc b/src/objects.cc index 1dc9448..46da8a7 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -5837,7 +5837,9 @@ Handle JSObjectWalkVisitor::StructureWalk(Handle object) { case FAST_HOLEY_ELEMENTS: { Handle elements(FixedArray::cast(copy->elements())); if (elements->map() == isolate->heap()->fixed_cow_array_map()) { - isolate->counters()->cow_arrays_created_runtime()->Increment(); + if (copying) { + isolate->counters()->cow_arrays_created_runtime()->Increment(); + } #ifdef DEBUG for (int i = 0; i < elements->length(); i++) { ASSERT(!elements->get(i)->IsJSObject()); diff --git a/src/runtime.cc b/src/runtime.cc index 15cfc85..e3749af 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -575,32 +575,6 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteral) { } -RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateArrayLiteralShallow) { - HandleScope scope(isolate); - ASSERT(args.length() == 3); - CONVERT_ARG_HANDLE_CHECKED(FixedArray, literals, 0); - CONVERT_SMI_ARG_CHECKED(literals_index, 1); - CONVERT_ARG_HANDLE_CHECKED(FixedArray, elements, 2); - - Handle site = GetLiteralAllocationSite(isolate, literals, - literals_index, elements); - RETURN_IF_EMPTY_HANDLE(isolate, site); - - JSObject* boilerplate = JSObject::cast(site->transition_info()); - if (boilerplate->elements()->map() == - isolate->heap()->fixed_cow_array_map()) { - isolate->counters()->cow_arrays_created_runtime()->Increment(); - } - - if (AllocationSite::GetMode(boilerplate->GetElementsKind()) == - TRACK_ALLOCATION_SITE) { - return isolate->heap()->CopyJSObject(boilerplate, *site); - } - - return isolate->heap()->CopyJSObject(boilerplate); -} - - RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateSymbol) { HandleScope scope(isolate); ASSERT(args.length() == 1); diff --git a/src/runtime.h b/src/runtime.h index 1b7e32e..55276f8 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -300,7 +300,6 @@ namespace internal { F(MaterializeRegExpLiteral, 4, 1)\ F(CreateObjectLiteral, 4, 1) \ F(CreateArrayLiteral, 3, 1) \ - F(CreateArrayLiteralShallow, 3, 1) \ \ /* Harmony generators */ \ F(CreateJSGeneratorObject, 0, 1) \ diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc index b3ab8c1..93bc2b9 100644 --- a/src/x64/code-stubs-x64.cc +++ b/src/x64/code-stubs-x64.cc @@ -78,7 +78,7 @@ void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( descriptor->register_param_count_ = 3; descriptor->register_params_ = registers; descriptor->deoptimization_handler_ = - Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; + Runtime::FunctionForId(Runtime::kCreateArrayLiteral)->entry; } diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc index 02ba67b..4a99287 100644 --- a/src/x64/full-codegen-x64.cc +++ b/src/x64/full-codegen-x64.cc @@ -1751,19 +1751,14 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { DONT_TRACK_ALLOCATION_SITE, length); __ CallStub(&stub); - } else if (expr->depth() > 1) { + } else if (expr->depth() > 1 || + Serializer::enabled() || + length > FastCloneShallowArrayStub::kMaximumClonedLength) { __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); __ Push(Smi::FromInt(expr->literal_index())); __ Push(constant_elements); __ CallRuntime(Runtime::kCreateArrayLiteral, 3); - } else if (Serializer::enabled() || - length > FastCloneShallowArrayStub::kMaximumClonedLength) { - __ movq(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); - __ push(FieldOperand(rbx, JSFunction::kLiteralsOffset)); - __ Push(Smi::FromInt(expr->literal_index())); - __ Push(constant_elements); - __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); } else { ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || FLAG_smi_only_arrays); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index d5e838e..f33d02b 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -19815,6 +19815,34 @@ TEST(PrimaryStubCache) { } +static int cow_arrays_created_runtime = 0; + + +static int* LookupCounterCOWArrays(const char* name) { + if (strcmp(name, "c:V8.COWArraysCreatedRuntime") == 0) { + return &cow_arrays_created_runtime; + } + return NULL; +} + + +TEST(CheckCOWArraysCreatedRuntimeCounter) { + V8::SetCounterFunction(LookupCounterCOWArrays); +#ifdef DEBUG + i::FLAG_native_code_counters = true; + LocalContext env; + v8::HandleScope scope(env->GetIsolate()); + int initial_cow_arrays = cow_arrays_created_runtime; + CompileRun("var o = [1, 2, 3];"); + CHECK_EQ(1, cow_arrays_created_runtime - initial_cow_arrays); + CompileRun("var o = {foo: [4, 5, 6], bar: [3, 0]};"); + CHECK_EQ(3, cow_arrays_created_runtime - initial_cow_arrays); + CompileRun("var o = {foo: [1, 2, 3, [4, 5, 6]], bar: 'hi'};"); + CHECK_EQ(4, cow_arrays_created_runtime - initial_cow_arrays); +#endif +} + + TEST(StaticGetters) { LocalContext context; i::Factory* factory = CcTest::i_isolate()->factory(); -- 2.7.4