Inline the StackResource constructor/destructor.

This yields a 29% improvement on the Benchmark_UseDartApi microbenchmark.

To do this, I had to split a few fields from Isolate into a
BaseIsolate class.  Sort of yucky.
Review URL: https://chromiumcodereview.appspot.com//10008030

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@6288 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
turnidge@google.com
2012-04-06 18:00:51 +00:00
parent c5338dc38c
commit 5f30febb45
10 changed files with 160 additions and 112 deletions
-21
View File
@@ -10,27 +10,6 @@
namespace dart {
StackResource::StackResource(Isolate* isolate)
: isolate_(isolate), previous_(NULL) {
// We can only have longjumps and exceptions when there is a current
// isolate. If there is no current isolate, we don't need to
// protect this case.
if (isolate) {
previous_ = isolate->top_resource();
isolate->set_top_resource(this);
}
}
StackResource::~StackResource() {
if (isolate()) {
StackResource* top = isolate()->top_resource();
ASSERT(top == this);
isolate()->set_top_resource(previous_);
}
ASSERT(Isolate::Current() == isolate());
}
ZoneAllocated::~ZoneAllocated() {
UNREACHABLE();
}
+24 -4
View File
@@ -6,6 +6,7 @@
#define VM_ALLOCATION_H_
#include "platform/assert.h"
#include "vm/base_isolate.h"
#include "vm/globals.h"
namespace dart {
@@ -36,17 +37,36 @@ class ValueObject {
// to a stack frame above the frame where these objects were allocated.
class StackResource {
public:
explicit StackResource(Isolate* isolate);
virtual ~StackResource();
explicit StackResource(BaseIsolate* isolate)
: isolate_(isolate), previous_(NULL) {
// We can only have longjumps and exceptions when there is a current
// isolate. If there is no current isolate, we don't need to
// protect this case.
if (isolate) {
previous_ = isolate->top_resource();
isolate->set_top_resource(this);
}
}
Isolate* isolate() const { return isolate_; }
virtual ~StackResource() {
if (isolate()) {
StackResource* top = isolate()->top_resource();
ASSERT(top == this);
isolate()->set_top_resource(previous_);
}
#if defined(DEBUG)
BaseIsolate::AssertCurrent(isolate());
#endif
}
BaseIsolate* 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.
BaseIsolate* isolate_; // Current isolate for this stack resource.
StackResource* previous_;
void* operator new(uword size);
+117
View File
@@ -0,0 +1,117 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef VM_BASE_ISOLATE_H_
#define VM_BASE_ISOLATE_H_
namespace dart {
class HandleScope;
class StackResource;
class Zone;
// A BaseIsolate contains just enough functionality to allocate
// StackResources. This allows us to inline the StackResource
// constructor/destructor for performance.
class BaseIsolate {
public:
StackResource* top_resource() const { return top_resource_; }
void set_top_resource(StackResource* value) { top_resource_ = value; }
Zone* current_zone() const { return current_zone_; }
void set_current_zone(Zone* zone) { current_zone_ = zone; }
HandleScope* top_handle_scope() const {
#if defined(DEBUG)
return top_handle_scope_;
#else
return 0;
#endif
}
void set_top_handle_scope(HandleScope* handle_scope) {
#if defined(DEBUG)
top_handle_scope_ = handle_scope;
#endif
}
int32_t no_handle_scope_depth() const {
#if defined(DEBUG)
return no_handle_scope_depth_;
#else
return 0;
#endif
}
void IncrementNoHandleScopeDepth() {
#if defined(DEBUG)
ASSERT(no_handle_scope_depth_ < INT_MAX);
no_handle_scope_depth_ += 1;
#endif
}
void DecrementNoHandleScopeDepth() {
#if defined(DEBUG)
ASSERT(no_handle_scope_depth_ > 0);
no_handle_scope_depth_ -= 1;
#endif
}
int32_t no_gc_scope_depth() const {
#if defined(DEBUG)
return no_gc_scope_depth_;
#else
return 0;
#endif
}
void IncrementNoGCScopeDepth() {
#if defined(DEBUG)
ASSERT(no_gc_scope_depth_ < INT_MAX);
no_gc_scope_depth_ += 1;
#endif
}
void DecrementNoGCScopeDepth() {
#if defined(DEBUG)
ASSERT(no_gc_scope_depth_ > 0);
no_gc_scope_depth_ -= 1;
#endif
}
#if defined(DEBUG)
static void AssertCurrent(BaseIsolate* isolate);
#endif
protected:
BaseIsolate()
: top_resource_(NULL),
#if defined(DEBUG)
current_zone_(NULL),
top_handle_scope_(NULL),
no_handle_scope_depth_(0),
no_gc_scope_depth_(0)
#else
current_zone_(NULL)
#endif
{}
~BaseIsolate() {
// Do not delete stack resources: top_resource_ and current_zone_.
}
StackResource* top_resource_;
Zone* current_zone_;
#if defined(DEBUG)
HandleScope* top_handle_scope_;
int32_t no_handle_scope_depth_;
int32_t no_gc_scope_depth_;
#endif
DISALLOW_COPY_AND_ASSIGN(BaseIsolate);
};
} // namespace dart
#endif // VM_BASE_ISOLATE_H_
+2 -2
View File
@@ -69,7 +69,7 @@ int VMHandles::ZoneHandleCount() {
}
HandleScope::HandleScope(Isolate* isolate) : StackResource(isolate) {
HandleScope::HandleScope(BaseIsolate* isolate) : StackResource(isolate) {
ASSERT(isolate->no_handle_scope_depth() == 0);
VMHandles* handles = isolate->current_zone()->handles();
ASSERT(handles != NULL);
@@ -98,7 +98,7 @@ HandleScope::~HandleScope() {
#if defined(DEBUG)
NoHandleScope::NoHandleScope(Isolate* isolate) : StackResource(isolate) {
NoHandleScope::NoHandleScope(BaseIsolate* isolate) : StackResource(isolate) {
isolate->IncrementNoHandleScopeDepth();
}
+3 -3
View File
@@ -266,7 +266,7 @@ class VMHandles : public Handles<kVMHandleSizeInWords,
// }
class HandleScope : public StackResource {
public:
explicit HandleScope(Isolate* isolate);
explicit HandleScope(BaseIsolate* isolate);
~HandleScope();
private:
@@ -298,7 +298,7 @@ class HandleScope : public StackResource {
#if defined(DEBUG)
class NoHandleScope : public StackResource {
public:
explicit NoHandleScope(Isolate* isolate);
explicit NoHandleScope(BaseIsolate* isolate);
~NoHandleScope();
private:
@@ -307,7 +307,7 @@ class NoHandleScope : public StackResource {
#else // defined(DEBUG)
class NoHandleScope : public ValueObject {
public:
explicit NoHandleScope(Isolate* isolate) { }
explicit NoHandleScope(BaseIsolate* isolate) { }
~NoHandleScope() { }
private:
+9 -9
View File
@@ -83,6 +83,14 @@ void IsolateMessageHandler::CheckAccess() {
#endif
#if defined(DEBUG)
// static
void BaseIsolate::AssertCurrent(BaseIsolate* isolate) {
ASSERT(isolate == Isolate::Current());
}
#endif
Isolate::Isolate()
: store_buffer_(),
message_notify_callback_(NULL),
@@ -90,14 +98,7 @@ Isolate::Isolate()
main_port_(0),
heap_(NULL),
object_store_(NULL),
top_resource_(NULL),
top_context_(Context::null()),
current_zone_(NULL),
#if defined(DEBUG)
no_gc_scope_depth_(0),
no_handle_scope_depth_(0),
top_handle_scope_(NULL),
#endif
random_seed_(Random::kDefaultRandomSeed),
top_exit_frame_info_(0),
init_callback_data_(NULL),
@@ -119,7 +120,6 @@ Isolate::~Isolate() {
delete [] name_;
delete heap_;
delete object_store_;
// Do not delete stack resources: top_resource_ and current_zone_.
delete api_state_;
delete stub_code_;
delete code_index_table_;
@@ -308,7 +308,7 @@ void Isolate::PrintInvokedFunctions() {
void Isolate::Shutdown() {
ASSERT(this == Isolate::Current());
ASSERT(top_resource_ == NULL);
ASSERT(top_resource() == NULL);
ASSERT((heap_ == NULL) || heap_->Verify());
// Clean up debugger resources. Shutting down the debugger
+2 -71
View File
@@ -8,6 +8,7 @@
#include "include/dart_api.h"
#include "platform/assert.h"
#include "platform/thread.h"
#include "vm/base_isolate.h"
#include "vm/gc_callbacks.h"
#include "vm/store_buffer.h"
#include "vm/timer.h"
@@ -33,7 +34,7 @@ class StubCode;
class Zone;
class Isolate {
class Isolate : public BaseIsolate {
public:
~Isolate();
@@ -83,9 +84,6 @@ class Isolate {
return OFFSET_OF(Isolate, object_store_);
}
StackResource* top_resource() const { return top_resource_; }
void set_top_resource(StackResource* value) { top_resource_ = value; }
RawContext* top_context() const { return top_context_; }
void set_top_context(RawContext* value) { top_context_ = value; }
static intptr_t top_context_offset() {
@@ -117,70 +115,10 @@ class Isolate {
TimerList& timer_list() { return timer_list_; }
Zone* current_zone() const { return current_zone_; }
void set_current_zone(Zone* zone) { current_zone_ = zone; }
static intptr_t current_zone_offset() {
return OFFSET_OF(Isolate, current_zone_);
}
int32_t no_gc_scope_depth() const {
#if defined(DEBUG)
return no_gc_scope_depth_;
#else
return 0;
#endif
}
void IncrementNoGCScopeDepth() {
#if defined(DEBUG)
ASSERT(no_gc_scope_depth_ < INT_MAX);
no_gc_scope_depth_ += 1;
#endif
}
void DecrementNoGCScopeDepth() {
#if defined(DEBUG)
ASSERT(no_gc_scope_depth_ > 0);
no_gc_scope_depth_ -= 1;
#endif
}
int32_t no_handle_scope_depth() const {
#if defined(DEBUG)
return no_handle_scope_depth_;
#else
return 0;
#endif
}
void IncrementNoHandleScopeDepth() {
#if defined(DEBUG)
ASSERT(no_handle_scope_depth_ < INT_MAX);
no_handle_scope_depth_ += 1;
#endif
}
void DecrementNoHandleScopeDepth() {
#if defined(DEBUG)
ASSERT(no_handle_scope_depth_ > 0);
no_handle_scope_depth_ -= 1;
#endif
}
HandleScope* top_handle_scope() const {
#if defined(DEBUG)
return top_handle_scope_;
#else
return 0;
#endif
}
void set_top_handle_scope(HandleScope* handle_scope) {
#if defined(DEBUG)
top_handle_scope_ = handle_scope;
#endif
}
void set_init_callback_data(void* value) {
init_callback_data_ = value;
}
@@ -263,14 +201,7 @@ class Isolate {
Dart_Port main_port_;
Heap* heap_;
ObjectStore* object_store_;
StackResource* top_resource_;
RawContext* top_context_;
Zone* current_zone_;
#if defined(DEBUG)
int32_t no_gc_scope_depth_;
int32_t no_handle_scope_depth_;
HandleScope* top_handle_scope_;
#endif
int32_t random_seed_;
uword top_exit_frame_info_;
void* init_callback_data_;
+1
View File
@@ -30,6 +30,7 @@
'ast_printer.h',
'ast_printer.cc',
'ast_printer_test.cc',
'base_isolate.h',
'bigint_operations.cc',
'bigint_operations.h',
'bigint_operations_test.cc',
+1 -1
View File
@@ -216,7 +216,7 @@ void BaseZone::DumpZoneSizes() {
#endif
Zone::Zone(Isolate* isolate)
Zone::Zone(BaseIsolate* isolate)
: StackResource(isolate),
zone_(),
handles_(),
+1 -1
View File
@@ -99,7 +99,7 @@ class BaseZone {
class Zone : public StackResource {
public:
// Create an empty zone and set is at the current zone for the Isolate.
explicit Zone(Isolate* isolate);
explicit Zone(BaseIsolate* isolate);
// Delete all memory associated with the zone.
~Zone();