mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 21:01:50 +00:00
1. Get rid of SwitchIsolateScope as it is not clear when this should be used and there is also a bug in that Thread::ExitIsolate is not called if saved_isolate is not NULL
2. Added Dart::ShutDownIsolate(Isolate* isolate) to take care of ensuring that the isolate is entered before shutting it down and deal with the asymmetry on the way out. R=zra@google.com Review URL: https://codereview.chromium.org/1427583009 .
This commit is contained in:
parent
6566e91f04
commit
10f40ce373
|
@ -395,6 +395,17 @@ void Dart::RunShutdownCallback() {
|
|||
}
|
||||
|
||||
|
||||
void Dart::ShutdownIsolate(Isolate* isolate) {
|
||||
ASSERT(Isolate::Current() == NULL);
|
||||
// We need to enter the isolate in order to shut it down.
|
||||
Thread::EnterIsolate(isolate);
|
||||
ShutdownIsolate();
|
||||
// Since the isolate is shutdown and deleted, there is no need to
|
||||
// exit the isolate here.
|
||||
ASSERT(Isolate::Current() == NULL);
|
||||
}
|
||||
|
||||
|
||||
void Dart::ShutdownIsolate() {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
isolate->Shutdown();
|
||||
|
|
|
@ -39,6 +39,7 @@ class Dart : public AllStatic {
|
|||
const Dart_IsolateFlags& api_flags);
|
||||
static RawError* InitializeIsolate(const uint8_t* snapshot, void* data);
|
||||
static void RunShutdownCallback();
|
||||
static void ShutdownIsolate(Isolate* isolate);
|
||||
static void ShutdownIsolate();
|
||||
|
||||
static Isolate* vm_isolate() { return vm_isolate_; }
|
||||
|
|
|
@ -1660,8 +1660,9 @@ DART_EXPORT Dart_Handle Dart_RunLoop() {
|
|||
Monitor monitor;
|
||||
MonitorLocker ml(&monitor);
|
||||
{
|
||||
SwitchIsolateScope switch_scope(NULL);
|
||||
|
||||
// The message handler run loop does not expect to have a current isolate
|
||||
// so we exit the isolate here and enter it again after the runloop is done.
|
||||
Thread::ExitIsolate();
|
||||
RunLoopData data;
|
||||
data.monitor = &monitor;
|
||||
data.done = false;
|
||||
|
@ -1671,6 +1672,7 @@ DART_EXPORT Dart_Handle Dart_RunLoop() {
|
|||
while (!data.done) {
|
||||
ml.Wait();
|
||||
}
|
||||
Thread::EnterIsolate(I);
|
||||
}
|
||||
if (I->object_store()->sticky_error() != Object::null()) {
|
||||
Dart_Handle error = Api::NewHandle(I, I->object_store()->sticky_error());
|
||||
|
|
|
@ -1454,11 +1454,8 @@ static void ShutdownIsolate(uword parameter) {
|
|||
}
|
||||
Dart::RunShutdownCallback();
|
||||
}
|
||||
{
|
||||
// Shut the isolate down.
|
||||
SwitchIsolateScope switch_scope(isolate);
|
||||
Dart::ShutdownIsolate();
|
||||
}
|
||||
// Shut the isolate down.
|
||||
Dart::ShutdownIsolate(isolate);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1664,6 +1661,9 @@ void Isolate::Shutdown() {
|
|||
|
||||
Thread* thread = Thread::Current();
|
||||
|
||||
// Don't allow anymore dart code to execution on this isolate.
|
||||
ClearStackLimit();
|
||||
|
||||
// First, perform higher-level cleanup that may need to allocate.
|
||||
{
|
||||
// Ensure we have a zone and handle scope so that we can call VM functions.
|
||||
|
|
|
@ -912,48 +912,6 @@ class StartIsolateScope {
|
|||
DISALLOW_COPY_AND_ASSIGN(StartIsolateScope);
|
||||
};
|
||||
|
||||
// When we need to temporarily become another isolate, we use the
|
||||
// SwitchIsolateScope. It is not permitted to run dart code while in
|
||||
// a SwitchIsolateScope.
|
||||
class SwitchIsolateScope {
|
||||
public:
|
||||
explicit SwitchIsolateScope(Isolate* new_isolate)
|
||||
: new_isolate_(new_isolate),
|
||||
saved_isolate_(Isolate::Current()),
|
||||
saved_stack_limit_(saved_isolate_
|
||||
? saved_isolate_->saved_stack_limit() : 0) {
|
||||
// TODO(koda): Audit users; why would these two ever be equal?
|
||||
if (saved_isolate_ != new_isolate_) {
|
||||
if (new_isolate_ == NULL) {
|
||||
Thread::ExitIsolate();
|
||||
} else {
|
||||
Thread::EnterIsolate(new_isolate_);
|
||||
// Don't allow dart code to execute.
|
||||
new_isolate_->SetStackLimit(~static_cast<uword>(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~SwitchIsolateScope() {
|
||||
if (saved_isolate_ != new_isolate_) {
|
||||
if (new_isolate_ != NULL) {
|
||||
Thread::ExitIsolate();
|
||||
}
|
||||
if (saved_isolate_ != NULL) {
|
||||
Thread::EnterIsolate(saved_isolate_);
|
||||
saved_isolate_->SetStackLimit(saved_stack_limit_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Isolate* new_isolate_;
|
||||
Isolate* saved_isolate_;
|
||||
uword saved_stack_limit_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SwitchIsolateScope);
|
||||
};
|
||||
|
||||
|
||||
class IsolateSpawnState {
|
||||
public:
|
||||
|
|
|
@ -360,11 +360,8 @@ class RunServiceTask : public ThreadPool::Task {
|
|||
}
|
||||
Dart::RunShutdownCallback();
|
||||
}
|
||||
{
|
||||
// Shut the isolate down.
|
||||
SwitchIsolateScope switch_scope(I);
|
||||
Dart::ShutdownIsolate();
|
||||
}
|
||||
// Shut the isolate down.
|
||||
Dart::ShutdownIsolate(I);
|
||||
if (FLAG_trace_service) {
|
||||
OS::Print("vm-service: Shutdown.\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue