From 599511d0c072cc5b7eab543a565649a2a381db29 Mon Sep 17 00:00:00 2001 From: "hpayer@chromium.org" Date: Tue, 4 Jun 2013 13:20:13 +0000 Subject: [PATCH] Added pretenuring support for call new. BUG= R=mvstanton@chromium.org Review URL: https://codereview.chromium.org/16226012 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14935 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/flag-definitions.h | 3 +++ src/hydrogen.cc | 10 +++++++++- test/cctest/test-heap.cc | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/flag-definitions.h b/src/flag-definitions.h index 8fe6778..d006876 100644 --- a/src/flag-definitions.h +++ b/src/flag-definitions.h @@ -193,6 +193,9 @@ DEFINE_bool(clever_optimizations, true, "Optimize object size, Array shift, DOM strings and string +") DEFINE_bool(pretenuring, true, "allocate objects in old space") +// TODO(hpayer): We will remove this flag as soon as we have pretenuring +// support for specific allocation sites. +DEFINE_bool(pretenuring_call_new, false, "pretenure call new") DEFINE_bool(track_fields, true, "track fields with only smi values") DEFINE_bool(track_double_fields, true, "track fields with double values") DEFINE_bool(track_heap_object_fields, true, "track fields with heap values") diff --git a/src/hydrogen.cc b/src/hydrogen.cc index f424a47..98b1340 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -8780,11 +8780,19 @@ void HOptimizedGraphBuilder::VisitCallNew(CallNew* expr) { HValue* size_in_bytes = AddInstruction(new(zone()) HConstant(instance_size, Representation::Integer32())); + + HAllocate::Flags flags = HAllocate::DefaultFlags(); + if (FLAG_pretenuring_call_new && + isolate()->heap()->ShouldGloballyPretenure()) { + flags = static_cast( + flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE); + } + HInstruction* receiver = AddInstruction(new(zone()) HAllocate(context, size_in_bytes, HType::JSObject(), - HAllocate::DefaultFlags())); + flags)); HAllocate::cast(receiver)->set_known_initial_map(initial_map); // Load the initial map from the constructor. diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc index 39e3758..68ed83d 100644 --- a/test/cctest/test-heap.cc +++ b/test/cctest/test-heap.cc @@ -2183,6 +2183,30 @@ TEST(OptimizedAllocationArrayLiterals) { } +TEST(OptimizedPretenuringCallNew) { + i::FLAG_allow_natives_syntax = true; + i::FLAG_pretenuring_call_new = true; + CcTest::InitializeVM(); + if (!i::V8::UseCrankshaft() || i::FLAG_always_opt) return; + if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; + v8::HandleScope scope(CcTest::isolate()); + HEAP->SetNewSpaceHighPromotionModeActive(true); + + AlwaysAllocateScope always_allocate; + v8::Local res = CompileRun( + "function g() { this.a = 0; }" + "function f() {" + " return new g();" + "};" + "f(); f(); f();" + "%OptimizeFunctionOnNextCall(f);" + "f();"); + + Handle o = + v8::Utils::OpenHandle(*v8::Handle::Cast(res)); + CHECK(HEAP->InOldPointerSpace(*o)); +} + static int CountMapTransitions(Map* map) { return map->transitions()->number_of_transitions(); } -- 2.7.4