Files
sdk/runtime/vm/lockers.cc
T
Martin Kustermann dae308461c [vm/concurrency] Share [Heap] and [SharedClassTable] between all isolates within one isolate group
This CL:

  * Moves [Heap]/[SharedClassTable] from [Isolate] to [IsolateGroup], which
    will make all isolates in the group use the same heap. The GC will use
    the shared class table for object size information.

  * Adds support for entering/leaving an isolate group as a helper thread
    (e.g. via [Thread::EnterIsolateGroupAsHelper]). The current active
    isolate group can be accessed via TLS `IsolateGroup::Current()` or
    `Thread::isolate_group_`. When entering as a helper thread there will be
    no current isolate.

  * Changes the GC to use the above mechanism and ensures GC works without
    a currently active isolate. The GC will use information purely available via
    [IsolateGroup]. The GC will iterate all isolates within an isolate
    group e.g. for scanning roots.

  * Makes spawning of new isolates start in their own isolate group.
    Once the isolate is fully functional it's heap will be merged into
    the original isolate group

  * Moves ApiState, containing persistent and weak persistent handles,
    from [Isolate] to [IsolateGroup], plus adds appropriate locking.

Issue https://github.com/dart-lang/sdk/issues/36097

Change-Id: Ia8e1d8aa78750e8400864200f4825395a182c004
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126646
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-02-20 21:08:35 +00:00

89 lines
2.6 KiB
C++

// Copyright (c) 2016, 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.
#include "vm/lockers.h"
#include "platform/assert.h"
#include "vm/heap/safepoint.h"
#include "vm/isolate.h"
namespace dart {
Monitor::WaitResult MonitorLocker::WaitWithSafepointCheck(Thread* thread,
int64_t millis) {
ASSERT(thread == Thread::Current());
ASSERT(thread->execution_state() == Thread::kThreadInVM);
#if defined(DEBUG)
if (no_safepoint_scope_) {
thread->DecrementNoSafepointScopeDepth();
}
#endif
thread->set_execution_state(Thread::kThreadInBlockedState);
thread->EnterSafepoint();
Monitor::WaitResult result = monitor_->Wait(millis);
// First try a fast update of the thread state to indicate it is not at a
// safepoint anymore.
if (!thread->TryExitSafepoint()) {
// Fast update failed which means we could potentially be in the middle
// of a safepoint operation and need to block for it.
monitor_->Exit();
SafepointHandler* handler = thread->isolate_group()->safepoint_handler();
handler->ExitSafepointUsingLock(thread);
monitor_->Enter();
}
thread->set_execution_state(Thread::kThreadInVM);
#if defined(DEBUG)
if (no_safepoint_scope_) {
thread->IncrementNoSafepointScopeDepth();
}
#endif
return result;
}
SafepointMutexLocker::SafepointMutexLocker(Mutex* mutex) : mutex_(mutex) {
ASSERT(mutex != NULL);
if (!mutex_->TryLock()) {
// We did not get the lock and could potentially block, so transition
// accordingly.
Thread* thread = Thread::Current();
if (thread != NULL) {
TransitionVMToBlocked transition(thread);
mutex->Lock();
} else {
mutex->Lock();
}
}
}
SafepointMonitorLocker::SafepointMonitorLocker(Monitor* monitor)
: monitor_(monitor) {
ASSERT(monitor_ != NULL);
if (!monitor_->TryEnter()) {
// We did not get the lock and could potentially block, so transition
// accordingly.
Thread* thread = Thread::Current();
if (thread != NULL) {
TransitionVMToBlocked transition(thread);
monitor_->Enter();
} else {
monitor_->Enter();
}
}
}
Monitor::WaitResult SafepointMonitorLocker::Wait(int64_t millis) {
Thread* thread = Thread::Current();
if (thread != NULL) {
Monitor::WaitResult result;
{
TransitionVMToBlocked transition(thread);
result = monitor_->Wait(millis);
}
return result;
} else {
return monitor_->Wait(millis);
}
}
} // namespace dart