From 2f1f203bffb2f89b56c1041a66bed23f1f999233 Mon Sep 17 00:00:00 2001 From: "erik.corry@gmail.com" Date: Tue, 20 Sep 2011 10:08:39 +0000 Subject: [PATCH] Fix pc to code cache so it can cope with a pointer to the start of the code object. Rename it to be the inner pointer to code cache. Review URL: http://codereview.chromium.org/7969013 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9336 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/frames-inl.h | 2 +- src/frames.cc | 61 +++++++++++++++++++++----------------- src/frames.h | 22 +++++++------- src/heap.cc | 3 +- src/incremental-marking.cc | 4 +-- src/isolate.cc | 8 ++--- src/isolate.h | 8 +++-- src/mark-compact.cc | 2 +- src/objects-inl.h | 5 ++-- 9 files changed, 62 insertions(+), 53 deletions(-) diff --git a/src/frames-inl.h b/src/frames-inl.h index 7ba79bf1b..c7d71ec17 100644 --- a/src/frames-inl.h +++ b/src/frames-inl.h @@ -106,7 +106,7 @@ inline StackHandler* StackFrame::top_handler() const { inline Code* StackFrame::GetContainingCode(Isolate* isolate, Address pc) { - return isolate->pc_to_code_cache()->GetCacheEntry(pc)->code; + return isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; } diff --git a/src/frames.cc b/src/frames.cc index 9405ccdbd..4444aad48 100644 --- a/src/frames.cc +++ b/src/frames.cc @@ -366,16 +366,17 @@ void SafeStackTraceFrameIterator::Advance() { Code* StackFrame::GetSafepointData(Isolate* isolate, - Address pc, + Address inner_pointer, SafepointEntry* safepoint_entry, unsigned* stack_slots) { - PcToCodeCache::PcToCodeCacheEntry* entry = - isolate->pc_to_code_cache()->GetCacheEntry(pc); + InnerPointerToCodeCache::InnerPointerToCodeCacheEntry* entry = + isolate->inner_pointer_to_code_cache()->GetCacheEntry(inner_pointer); if (!entry->safepoint_entry.is_valid()) { - entry->safepoint_entry = entry->code->GetSafepointEntry(pc); + entry->safepoint_entry = entry->code->GetSafepointEntry(inner_pointer); ASSERT(entry->safepoint_entry.is_valid()); } else { - ASSERT(entry->safepoint_entry.Equals(entry->code->GetSafepointEntry(pc))); + ASSERT(entry->safepoint_entry.Equals( + entry->code->GetSafepointEntry(inner_pointer))); } // Fill in the results and return the code. @@ -819,7 +820,8 @@ DeoptimizationInputData* OptimizedFrame::GetDeoptimizationData( // back to a slow search in this case to find the original optimized // code object. if (!code->contains(pc())) { - code = isolate()->pc_to_code_cache()->GcSafeFindCodeForPc(pc()); + code = isolate()->inner_pointer_to_code_cache()-> + GcSafeFindCodeForInnerPointer(pc()); } ASSERT(code != NULL); ASSERT(code->kind() == Code::OPTIMIZED_FUNCTION); @@ -1155,9 +1157,10 @@ JavaScriptFrame* StackFrameLocator::FindJavaScriptFrame(int n) { // ------------------------------------------------------------------------- -Code* PcToCodeCache::GcSafeCastToCode(HeapObject* object, Address pc) { +Code* InnerPointerToCodeCache::GcSafeCastToCode(HeapObject* object, + Address inner_pointer) { Code* code = reinterpret_cast(object); - ASSERT(code != NULL && code->contains(pc)); + ASSERT(code != NULL && code->contains(inner_pointer)); return code; } @@ -1170,17 +1173,20 @@ static int GcSafeSizeOfCodeSpaceObject(HeapObject* object) { } -Code* PcToCodeCache::GcSafeFindCodeForPc(Address pc) { +Code* InnerPointerToCodeCache::GcSafeFindCodeForInnerPointer( + Address inner_pointer) { Heap* heap = isolate_->heap(); - // Check if the pc points into a large object chunk. - LargePage* large_page = heap->lo_space()->FindPageContainingPc(pc); - if (large_page != NULL) return GcSafeCastToCode(large_page->GetObject(), pc); + // Check if the inner pointer points into a large object chunk. + LargePage* large_page = heap->lo_space()->FindPageContainingPc(inner_pointer); + if (large_page != NULL) { + return GcSafeCastToCode(large_page->GetObject(), inner_pointer); + } // Iterate through the page until we reach the end or find an object starting - // after the pc. - Page* page = Page::FromAddress(pc); + // after the inner pointer. + Page* page = Page::FromAddress(inner_pointer); - Address addr = page->skip_list()->StartFor(pc); + Address addr = page->skip_list()->StartFor(inner_pointer); Address top = heap->code_space()->top(); Address limit = heap->code_space()->limit(); @@ -1194,30 +1200,31 @@ Code* PcToCodeCache::GcSafeFindCodeForPc(Address pc) { HeapObject* obj = HeapObject::FromAddress(addr); int obj_size = GcSafeSizeOfCodeSpaceObject(obj); Address next_addr = addr + obj_size; - if (next_addr >= pc) return GcSafeCastToCode(obj, pc); + if (next_addr > inner_pointer) return GcSafeCastToCode(obj, inner_pointer); addr = next_addr; } } -PcToCodeCache::PcToCodeCacheEntry* PcToCodeCache::GetCacheEntry(Address pc) { +InnerPointerToCodeCache::InnerPointerToCodeCacheEntry* + InnerPointerToCodeCache::GetCacheEntry(Address inner_pointer) { isolate_->counters()->pc_to_code()->Increment(); - ASSERT(IsPowerOf2(kPcToCodeCacheSize)); + ASSERT(IsPowerOf2(kInnerPointerToCodeCacheSize)); uint32_t hash = ComputeIntegerHash( - static_cast(reinterpret_cast(pc))); - uint32_t index = hash & (kPcToCodeCacheSize - 1); - PcToCodeCacheEntry* entry = cache(index); - if (entry->pc == pc) { + static_cast(reinterpret_cast(inner_pointer))); + uint32_t index = hash & (kInnerPointerToCodeCacheSize - 1); + InnerPointerToCodeCacheEntry* entry = cache(index); + if (entry->inner_pointer == inner_pointer) { isolate_->counters()->pc_to_code_cached()->Increment(); - ASSERT(entry->code == GcSafeFindCodeForPc(pc)); + ASSERT(entry->code == GcSafeFindCodeForInnerPointer(inner_pointer)); } else { // Because this code may be interrupted by a profiling signal that - // also queries the cache, we cannot update pc before the code has - // been set. Otherwise, we risk trying to use a cache entry before + // also queries the cache, we cannot update inner_pointer before the code + // has been set. Otherwise, we risk trying to use a cache entry before // the code has been computed. - entry->code = GcSafeFindCodeForPc(pc); + entry->code = GcSafeFindCodeForInnerPointer(inner_pointer); entry->safepoint_entry.Reset(); - entry->pc = pc; + entry->inner_pointer = inner_pointer; } return entry; } diff --git a/src/frames.h b/src/frames.h index 35471a455..8024fafc3 100644 --- a/src/frames.h +++ b/src/frames.h @@ -49,36 +49,36 @@ class StackFrameIterator; class ThreadLocalTop; class Isolate; -class PcToCodeCache { +class InnerPointerToCodeCache { public: - struct PcToCodeCacheEntry { - Address pc; + struct InnerPointerToCodeCacheEntry { + Address inner_pointer; Code* code; SafepointEntry safepoint_entry; }; - explicit PcToCodeCache(Isolate* isolate) : isolate_(isolate) { + explicit InnerPointerToCodeCache(Isolate* isolate) : isolate_(isolate) { Flush(); } - Code* GcSafeFindCodeForPc(Address pc); - Code* GcSafeCastToCode(HeapObject* object, Address pc); + Code* GcSafeFindCodeForInnerPointer(Address inner_pointer); + Code* GcSafeCastToCode(HeapObject* object, Address inner_pointer); void Flush() { memset(&cache_[0], 0, sizeof(cache_)); } - PcToCodeCacheEntry* GetCacheEntry(Address pc); + InnerPointerToCodeCacheEntry* GetCacheEntry(Address inner_pointer); private: - PcToCodeCacheEntry* cache(int index) { return &cache_[index]; } + InnerPointerToCodeCacheEntry* cache(int index) { return &cache_[index]; } Isolate* isolate_; - static const int kPcToCodeCacheSize = 1024; - PcToCodeCacheEntry cache_[kPcToCodeCacheSize]; + static const int kInnerPointerToCodeCacheSize = 1024; + InnerPointerToCodeCacheEntry cache_[kInnerPointerToCodeCacheSize]; - DISALLOW_COPY_AND_ASSIGN(PcToCodeCache); + DISALLOW_COPY_AND_ASSIGN(InnerPointerToCodeCache); }; diff --git a/src/heap.cc b/src/heap.cc index 1477e16ab..2a2f535b9 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -844,7 +844,8 @@ void Heap::MarkCompactPrologue() { Object* Heap::FindCodeObject(Address a) { - return isolate()->pc_to_code_cache()->GcSafeFindCodeForPc(a); + return isolate()->inner_pointer_to_code_cache()-> + GcSafeFindCodeForInnerPointer(a); } diff --git a/src/incremental-marking.cc b/src/incremental-marking.cc index 9df3bd591..d15a57888 100644 --- a/src/incremental-marking.cc +++ b/src/incremental-marking.cc @@ -87,8 +87,8 @@ void IncrementalMarking::RecordWriteForEvacuationFromCode(HeapObject* obj, void IncrementalMarking::RecordCodeTargetPatch(Address pc, HeapObject* value) { if (IsMarking()) { - Code* host = - heap_->isolate()->pc_to_code_cache()->GcSafeFindCodeForPc(pc); + Code* host = heap_->isolate()->inner_pointer_to_code_cache()-> + GcSafeFindCodeForInnerPointer(pc); RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host); RecordWriteIntoCode(host, &rinfo, value); } diff --git a/src/isolate.cc b/src/isolate.cc index b68f5d52e..311ab4951 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -1403,7 +1403,7 @@ Isolate::Isolate() in_use_list_(0), free_list_(0), preallocated_storage_preallocated_(false), - pc_to_code_cache_(NULL), + inner_pointer_to_code_cache_(NULL), write_input_buffer_(NULL), global_handles_(NULL), context_switcher_(NULL), @@ -1576,8 +1576,8 @@ Isolate::~Isolate() { compilation_cache_ = NULL; delete bootstrapper_; bootstrapper_ = NULL; - delete pc_to_code_cache_; - pc_to_code_cache_ = NULL; + delete inner_pointer_to_code_cache_; + inner_pointer_to_code_cache_ = NULL; delete write_input_buffer_; write_input_buffer_ = NULL; @@ -1701,7 +1701,7 @@ bool Isolate::Init(Deserializer* des) { context_slot_cache_ = new ContextSlotCache(); descriptor_lookup_cache_ = new DescriptorLookupCache(); unicode_cache_ = new UnicodeCache(); - pc_to_code_cache_ = new PcToCodeCache(this); + inner_pointer_to_code_cache_ = new InnerPointerToCodeCache(this); write_input_buffer_ = new StringInputBuffer(); global_handles_ = new GlobalHandles(this); bootstrapper_ = new Bootstrapper(); diff --git a/src/isolate.h b/src/isolate.h index eb0e1c3ad..ec4e8fa54 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -66,7 +66,7 @@ class HandleScopeImplementer; class HeapProfiler; class InlineRuntimeFunctionsTable; class NoAllocationStringAllocator; -class PcToCodeCache; +class InnerPointerToCodeCache; class PreallocatedMemoryThread; class RegExpStack; class SaveContext; @@ -841,7 +841,9 @@ class Isolate { return unicode_cache_; } - PcToCodeCache* pc_to_code_cache() { return pc_to_code_cache_; } + InnerPointerToCodeCache* inner_pointer_to_code_cache() { + return inner_pointer_to_code_cache_; + } StringInputBuffer* write_input_buffer() { return write_input_buffer_; } @@ -1136,7 +1138,7 @@ class Isolate { PreallocatedStorage in_use_list_; PreallocatedStorage free_list_; bool preallocated_storage_preallocated_; - PcToCodeCache* pc_to_code_cache_; + InnerPointerToCodeCache* inner_pointer_to_code_cache_; StringInputBuffer* write_input_buffer_; GlobalHandles* global_handles_; ContextSwitcher* context_switcher_; diff --git a/src/mark-compact.cc b/src/mark-compact.cc index bb594a3aa..cefb008a1 100644 --- a/src/mark-compact.cc +++ b/src/mark-compact.cc @@ -281,7 +281,7 @@ void MarkCompactCollector::CollectGarbage() { if (!collect_maps_) ReattachInitialMaps(); - heap_->isolate()->pc_to_code_cache()->Flush(); + heap_->isolate()->inner_pointer_to_code_cache()->Flush(); Finish(); diff --git a/src/objects-inl.h b/src/objects-inl.h index 8befad568..e7559e4f5 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -3864,9 +3864,8 @@ byte* Code::entry() { } -bool Code::contains(byte* pc) { - return (instruction_start() <= pc) && - (pc <= instruction_start() + instruction_size()); +bool Code::contains(byte* inner_pointer) { + return (address() <= inner_pointer) && (inner_pointer <= address() + Size()); } -- 2.34.1