From 2d388b751fc104ca52884934f519b35876476afb Mon Sep 17 00:00:00 2001 From: "asiva@google.com" Date: Thu, 10 Nov 2011 21:08:18 +0000 Subject: [PATCH] Cache isolate in the StackTrace object to that we don't call Isolate::Current in the destructor, HandleScope and Zone. TBR=iposva (already reviewed change on other client). Review URL: http://codereview.chromium.org//8523013 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@1427 260f80e4-7a28-3924-810f-c04153c831b5 --- runtime/vm/allocation.cc | 11 +++++------ runtime/vm/allocation.h | 6 ++++++ runtime/vm/handles.cc | 24 ++++++++++-------------- runtime/vm/zone.cc | 10 ++++------ 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/runtime/vm/allocation.cc b/runtime/vm/allocation.cc index 592a48bf28b..c366759ec5c 100644 --- a/runtime/vm/allocation.cc +++ b/runtime/vm/allocation.cc @@ -11,17 +11,16 @@ namespace dart { StackResource::StackResource() { - Isolate* isolate = Isolate::Current(); - previous_ = isolate->top_resource(); - isolate->set_top_resource(this); + isolate_ = Isolate::Current(); + previous_ = isolate_->top_resource(); + isolate_->set_top_resource(this); } StackResource::~StackResource() { - Isolate* isolate = Isolate::Current(); - StackResource* top = isolate->top_resource(); + StackResource* top = isolate_->top_resource(); ASSERT(top == this); - isolate->set_top_resource(previous_); + isolate_->set_top_resource(previous_); } ZoneAllocated::~ZoneAllocated() { diff --git a/runtime/vm/allocation.h b/runtime/vm/allocation.h index 4c7b5fca2ff..89afc7c169b 100644 --- a/runtime/vm/allocation.h +++ b/runtime/vm/allocation.h @@ -9,6 +9,9 @@ namespace dart { +// Forward declarations. +class Isolate; + // Stack allocated objects subclass from this base class. Objects of this type // cannot be allocated on either the C or object heaps. Destructors for objects // of this type will not be run unless the stack is unwound through normal @@ -35,11 +38,14 @@ class StackResource { StackResource(); virtual ~StackResource(); + Isolate* isolate() const { return isolate_; } + // The delete operator should be private instead of public, but unfortunately // the compiler complains when compiling the destructors for subclasses. void operator delete(void* pointer) { UNREACHABLE(); } private: + Isolate* isolate_; // Current isolate for this stack resource. StackResource* previous_; void* operator new(uword size); diff --git a/runtime/vm/handles.cc b/runtime/vm/handles.cc index db83bc1d5bd..77527c281c8 100644 --- a/runtime/vm/handles.cc +++ b/runtime/vm/handles.cc @@ -70,45 +70,41 @@ int VMHandles::ZoneHandleCount() { HandleScope::HandleScope() : StackResource() { - Isolate* isolate = Isolate::Current(); - ASSERT(isolate->no_handle_scope_depth() == 0); - VMHandles* handles = isolate->current_zone()->handles(); + ASSERT(isolate()->no_handle_scope_depth() == 0); + VMHandles* handles = isolate()->current_zone()->handles(); ASSERT(handles != NULL); saved_handle_block_ = handles->scoped_blocks_; saved_handle_slot_ = handles->scoped_blocks_->next_handle_slot(); #if defined(DEBUG) - link_ = isolate->top_handle_scope(); - isolate->set_top_handle_scope(this); + link_ = isolate()->top_handle_scope(); + isolate()->set_top_handle_scope(this); #endif } HandleScope::~HandleScope() { - Isolate* isolate = Isolate::Current(); - ASSERT(isolate->current_zone() != NULL); - VMHandles* handles = isolate->current_zone()->handles(); + ASSERT(isolate()->current_zone() != NULL); + VMHandles* handles = isolate()->current_zone()->handles(); ASSERT(handles != NULL); handles->scoped_blocks_ = saved_handle_block_; handles->scoped_blocks_->set_next_handle_slot(saved_handle_slot_); #if defined(DEBUG) handles->VerifyScopedHandleState(); handles->ZapFreeScopedHandles(); - ASSERT(isolate->top_handle_scope() == this); - isolate->set_top_handle_scope(link_); + ASSERT(isolate()->top_handle_scope() == this); + isolate()->set_top_handle_scope(link_); #endif } #if defined(DEBUG) NoHandleScope::NoHandleScope() : StackResource() { - Isolate* isolate = Isolate::Current(); - isolate->IncrementNoHandleScopeDepth(); + isolate()->IncrementNoHandleScopeDepth(); } NoHandleScope::~NoHandleScope() { - Isolate* isolate = Isolate::Current(); - isolate->DecrementNoHandleScopeDepth(); + isolate()->DecrementNoHandleScopeDepth(); } #endif // defined(DEBUG) diff --git a/runtime/vm/zone.cc b/runtime/vm/zone.cc index 5b5fada7f9b..261f6614961 100644 --- a/runtime/vm/zone.cc +++ b/runtime/vm/zone.cc @@ -223,16 +223,14 @@ Zone::Zone() // Assert that there is no current zone as we only want to scope // zones when transitioning from generated dart code to dart VM // runtime code. - Isolate* isolate = Isolate::Current(); - previous_ = isolate->current_zone(); - Isolate::Current()->set_current_zone(this); + previous_ = isolate()->current_zone(); + isolate()->set_current_zone(this); } Zone::~Zone() { - Isolate* isolate = Isolate::Current(); - ASSERT(isolate->current_zone() == this); - isolate->set_current_zone(previous_); + ASSERT(isolate()->current_zone() == this); + isolate()->set_current_zone(previous_); }