From 53e29e5f1960c5c7888ce2d3167fc2bb9b692837 Mon Sep 17 00:00:00 2001 From: "bmeurer@chromium.org" Date: Mon, 13 Jan 2014 13:11:46 +0000 Subject: [PATCH] Inline AllocationMemento::FindForHeapObject() into the two call sites. R=mvstanton@chromium.org Review URL: https://codereview.chromium.org/136633002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18565 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/heap-inl.h | 42 ++++++++++++++++++++++++--------------- src/objects.cc | 54 +++++++++++++------------------------------------- src/objects.h | 4 ---- 3 files changed, 40 insertions(+), 60 deletions(-) diff --git a/src/heap-inl.h b/src/heap-inl.h index cc65389330..f70b6f701b 100644 --- a/src/heap-inl.h +++ b/src/heap-inl.h @@ -485,22 +485,32 @@ void Heap::ScavengePointer(HeapObject** p) { void Heap::UpdateAllocationSiteFeedback(HeapObject* object) { Heap* heap = object->GetHeap(); - if (FLAG_allocation_site_pretenuring && - heap->new_space_high_promotion_mode_active_ && - AllocationSite::CanTrack(object->map()->instance_type())) { - AllocationMemento* memento = AllocationMemento::FindForHeapObject( - object, heap, true); - if (memento != NULL) { - ASSERT(memento->IsValid()); - bool add_to_scratchpad = - memento->GetAllocationSite()->IncrementMementoFoundCount(); - if (add_to_scratchpad && heap->allocation_sites_scratchpad_length < - kAllocationSiteScratchpadSize) { - heap->allocation_sites_scratchpad[ - heap->allocation_sites_scratchpad_length++] = - memento->GetAllocationSite(); - } - } + ASSERT(heap->InNewSpace(object)); + + if (!FLAG_allocation_site_pretenuring || + !heap->new_space_high_promotion_mode_active_ || + !AllocationSite::CanTrack(object->map()->instance_type())) return; + + // Either object is the last object in the from space, or there is another + // object of at least word size (the header map word) following it, so + // suffices to compare ptr and top here. + Address ptr = object->address() + object->Size(); + Address top = heap->new_space()->FromSpacePageHigh(); + ASSERT(ptr == top || ptr + HeapObject::kHeaderSize <= top); + if (ptr == top) return; + + HeapObject* candidate = HeapObject::FromAddress(ptr); + if (candidate->map() != heap->allocation_memento_map()) return; + + AllocationMemento* memento = AllocationMemento::cast(candidate); + if (!memento->IsValid()) return; + + if (memento->GetAllocationSite()->IncrementMementoFoundCount() && + heap->allocation_sites_scratchpad_length < + kAllocationSiteScratchpadSize) { + heap->allocation_sites_scratchpad[ + heap->allocation_sites_scratchpad_length++] = + memento->GetAllocationSite(); } } diff --git a/src/objects.cc b/src/objects.cc index 5f24920017..2829ab5e01 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -9201,39 +9201,6 @@ Handle SeqString::Truncate(Handle string, int new_length) { } -AllocationMemento* AllocationMemento::FindForHeapObject(HeapObject* object, - Heap* heap, - bool in_GC) { - // AllocationMemento objects are only allocated immediately after objects in - // NewSpace. Detecting whether a memento is present involves carefully - // checking the object immediately after the current object (if there is one) - // to see if it's an AllocationMemento. - ASSERT(heap->InNewSpace(object)); - Address ptr_end = (reinterpret_cast
(object) - kHeapObjectTag) + - object->Size(); - Address top; - if (in_GC) { - top = heap->new_space()->FromSpacePageHigh(); - } else { - top = heap->NewSpaceTop(); - } - if ((ptr_end + AllocationMemento::kSize) <= top) { - // There is room in newspace for allocation info. Do we have some? - Map** possible_allocation_memento_map = - reinterpret_cast(ptr_end); - if (*possible_allocation_memento_map == - object->GetHeap()->allocation_memento_map()) { - AllocationMemento* memento = AllocationMemento::cast( - reinterpret_cast(ptr_end + kHeapObjectTag)); - if (memento->IsValid()) { - return memento; - } - } - } - return NULL; -} - - uint32_t StringHasher::MakeArrayIndexHash(uint32_t value, int length) { // For array indexes mix the length into the hash as an array index could // be zero. @@ -12904,17 +12871,24 @@ void JSObject::UpdateAllocationSite(Handle object, MaybeObject* JSObject::UpdateAllocationSite(ElementsKind to_kind) { - if (!IsJSArray()) { - return this; - } + if (!IsJSArray()) return this; Heap* heap = GetHeap(); if (!heap->InNewSpace(this)) return this; - AllocationMemento* memento = AllocationMemento::FindForHeapObject(this, heap); - if (memento == NULL || !memento->IsValid()) { - return this; - } + // Either object is the last object in the new space, or there is another + // object of at least word size (the header map word) following it, so + // suffices to compare ptr and top here. + Address ptr = address() + JSArray::kSize; + Address top = heap->NewSpaceTop(); + ASSERT(ptr == top || ptr + HeapObject::kHeaderSize <= top); + if (ptr == top) return this; + + HeapObject* candidate = HeapObject::FromAddress(ptr); + if (candidate->map() != heap->allocation_memento_map()) return this; + + AllocationMemento* memento = AllocationMemento::cast(candidate); + if (!memento->IsValid()) return this; // Walk through to the Allocation Site AllocationSite* site = memento->GetAllocationSite(); diff --git a/src/objects.h b/src/objects.h index f9e416a809..4fbc710443 100644 --- a/src/objects.h +++ b/src/objects.h @@ -8305,10 +8305,6 @@ class AllocationMemento: public Struct { DECLARE_PRINTER(AllocationMemento) DECLARE_VERIFIER(AllocationMemento) - // Returns NULL if no AllocationMemento is available for object. - static AllocationMemento* FindForHeapObject(HeapObject* object, - Heap* heap, - bool in_GC = false); static inline AllocationMemento* cast(Object* obj); private: