From c918ccd392c2042bf7c785932269911fa86eade9 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Thu, 17 Apr 2014 13:15:22 +0000 Subject: [PATCH] Allocate filler objects in the factory. R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/240393003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20845 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/factory.cc | 10 ++++++++++ src/factory.h | 4 ++++ src/heap.cc | 16 ++++++++++++++++ src/heap.h | 6 ++++++ src/runtime.cc | 37 ++++++++++--------------------------- 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/factory.cc b/src/factory.cc index 854b625bcf..eec8642f89 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -32,6 +32,16 @@ Handle Factory::New(Handle map, } +Handle Factory::NewFillerObject(int size, + bool double_align, + AllocationSpace space) { + CALL_HEAP_FUNCTION( + isolate(), + isolate()->heap()->AllocateFillerObject(size, double_align, space), + HeapObject); +} + + Handle Factory::NewBox(Handle value) { Handle result = Handle::cast(NewStruct(BOX_TYPE)); result->set_value(*value); diff --git a/src/factory.h b/src/factory.h index a104dc9f20..d739b84003 100644 --- a/src/factory.h +++ b/src/factory.h @@ -269,6 +269,10 @@ class Factory V8_FINAL { int instance_size, ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND); + Handle NewFillerObject(int size, + bool double_align, + AllocationSpace space); + Handle NewFunctionPrototype(Handle function); Handle CopyFixedArray(Handle array); diff --git a/src/heap.cc b/src/heap.cc index 515c430289..d7a52216d8 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -2409,6 +2409,22 @@ MaybeObject* Heap::AllocateMap(InstanceType instance_type, } +MaybeObject* Heap::AllocateFillerObject(int size, + bool double_align, + AllocationSpace space) { + HeapObject* allocation; + { MaybeObject* maybe_allocation = AllocateRaw(size, space, space); + if (!maybe_allocation->To(&allocation)) return maybe_allocation; + } +#ifdef DEBUG + MemoryChunk* chunk = MemoryChunk::FromAddress(allocation->address()); + ASSERT(chunk->owner()->identity() == space); +#endif + CreateFillerObjectAt(allocation->address(), size); + return allocation; +} + + MaybeObject* Heap::AllocatePolymorphicCodeCache() { return AllocateStruct(POLYMORPHIC_CODE_CACHE_TYPE); } diff --git a/src/heap.h b/src/heap.h index 8557fd8947..5e08b3a6da 100644 --- a/src/heap.h +++ b/src/heap.h @@ -754,6 +754,12 @@ class Heap { MUST_USE_RESULT MaybeObject* AllocatePartialMap(InstanceType instance_type, int instance_size); + // Allocate a block of memory in the given space (filled with a filler). + // Used as a fall-back for generated code when the space is full. + MUST_USE_RESULT MaybeObject* AllocateFillerObject(int size, + bool double_align, + AllocationSpace space); + // Allocates an empty PolymorphicCodeCache. MUST_USE_RESULT MaybeObject* AllocatePolymorphicCodeCache(); diff --git a/src/runtime.cc b/src/runtime.cc index 4899273f45..5209c66fd8 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -9791,45 +9791,28 @@ RUNTIME_FUNCTION(ObjectPair, RuntimeHidden_ResolvePossiblyDirectEval) { } -// Allocate a block of memory in the given space (filled with a filler). -// Used as a fall-back for generated code when the space is full. -static MaybeObject* Allocate(Isolate* isolate, - int size, - bool double_align, - AllocationSpace space) { - Heap* heap = isolate->heap(); +RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_AllocateInNewSpace) { + HandleScope scope(isolate); + ASSERT(args.length() == 1); + CONVERT_SMI_ARG_CHECKED(size, 0); RUNTIME_ASSERT(IsAligned(size, kPointerSize)); RUNTIME_ASSERT(size > 0); RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize); - HeapObject* allocation; - { MaybeObject* maybe_allocation = heap->AllocateRaw(size, space, space); - if (!maybe_allocation->To(&allocation)) return maybe_allocation; - } -#ifdef DEBUG - MemoryChunk* chunk = MemoryChunk::FromAddress(allocation->address()); - ASSERT(chunk->owner()->identity() == space); -#endif - heap->CreateFillerObjectAt(allocation->address(), size); - return allocation; -} - - -RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_AllocateInNewSpace) { - SealHandleScope shs(isolate); - ASSERT(args.length() == 1); - CONVERT_SMI_ARG_CHECKED(size, 0); - return Allocate(isolate, size, false, NEW_SPACE); + return *isolate->factory()->NewFillerObject(size, false, NEW_SPACE); } RUNTIME_FUNCTION(MaybeObject*, RuntimeHidden_AllocateInTargetSpace) { - SealHandleScope shs(isolate); + HandleScope scope(isolate); ASSERT(args.length() == 2); CONVERT_SMI_ARG_CHECKED(size, 0); CONVERT_SMI_ARG_CHECKED(flags, 1); + RUNTIME_ASSERT(IsAligned(size, kPointerSize)); + RUNTIME_ASSERT(size > 0); + RUNTIME_ASSERT(size <= Page::kMaxRegularHeapObjectSize); bool double_align = AllocateDoubleAlignFlag::decode(flags); AllocationSpace space = AllocateTargetSpace::decode(flags); - return Allocate(isolate, size, double_align, space); + return *isolate->factory()->NewFillerObject(size, double_align, space); }