Files
sdk/runtime/vm/base_isolate.h
T
koda@google.com 89daba5454 Split Thread/Isolate instances, but still maintain 1:1 relationship.
The life cycle of Thread is still coupled with the life cycle of Isolate, but the added indirection allows the migration work to proceed, at negligible performance impact.

This is a small step towards making Thread different from Isolate and allow a many-to-one relationship. In particular, in prepares for being able to have the sweeper have some minimal separate state from the main thread (eliminating the current fake-isolate hack).

Concretely, it moves the thread-local storage key into the Thread class, but for now, keeps a "main_thread" in Isolate for quick access in native/runtime_entry.
Also moves cha_ field to Thread (the first of many fields that will move).

To summarize, this CL enables the next steps:
- moving other fields from Isolate to Thread without circular include-dependencies
- replacing sweeper's fake Isolate with a helper Thread (referencing the original Isolate)

Also add 'volatile' to local variables that clang thinks could be clobbered.

R=asiva@google.com

Review URL: https://codereview.chromium.org//1037453002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@44703 260f80e4-7a28-3924-810f-c04153c831b5
2015-03-25 22:41:33 +00:00

140 lines
3.1 KiB
C++

// 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_
#include "platform/assert.h"
#include "vm/globals.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; }
static intptr_t top_resource_offset() {
return OFFSET_OF(BaseIsolate, top_resource_);
}
// DEPRECATED: Use Thread::current_zone.
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_safepoint_scope_depth() const {
#if defined(DEBUG)
return no_safepoint_scope_depth_;
#else
return 0;
#endif
}
void IncrementNoSafepointScopeDepth() {
#if defined(DEBUG)
ASSERT(no_safepoint_scope_depth_ < INT_MAX);
no_safepoint_scope_depth_ += 1;
#endif
}
void DecrementNoSafepointScopeDepth() {
#if defined(DEBUG)
ASSERT(no_safepoint_scope_depth_ > 0);
no_safepoint_scope_depth_ -= 1;
#endif
}
int32_t no_callback_scope_depth() const {
return no_callback_scope_depth_;
}
void IncrementNoCallbackScopeDepth() {
ASSERT(no_callback_scope_depth_ < INT_MAX);
no_callback_scope_depth_ += 1;
}
void DecrementNoCallbackScopeDepth() {
ASSERT(no_callback_scope_depth_ > 0);
no_callback_scope_depth_ -= 1;
}
#if defined(DEBUG)
static void AssertCurrent(BaseIsolate* isolate);
#endif
protected:
BaseIsolate()
: top_resource_(NULL),
current_zone_(NULL),
#if defined(DEBUG)
top_handle_scope_(NULL),
no_handle_scope_depth_(0),
no_safepoint_scope_depth_(0),
#endif
no_callback_scope_depth_(0)
{}
~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_safepoint_scope_depth_;
#endif
int32_t no_callback_scope_depth_;
private:
DISALLOW_COPY_AND_ASSIGN(BaseIsolate);
};
} // namespace dart
#endif // VM_BASE_ISOLATE_H_