| Index: runtime/vm/safepoint.h
|
| diff --git a/runtime/vm/safepoint.h b/runtime/vm/safepoint.h
|
| index 947742512ddad6f6991d01c183f526de79217968..58afb493f2b90e4d3e3f66df653e4dcf3afed1b4 100644
|
| --- a/runtime/vm/safepoint.h
|
| +++ b/runtime/vm/safepoint.h
|
| @@ -313,10 +313,45 @@ class TransitionToGenerated : public TransitionSafepointState {
|
| }
|
|
|
| private:
|
| - int16_t execution_state_;
|
| + uint32_t execution_state_;
|
| DISALLOW_COPY_AND_ASSIGN(TransitionToGenerated);
|
| };
|
|
|
| +
|
| +// TransitionToVM is used to transition the safepoint state of a
|
| +// thread from "running native code" to "running vm code"
|
| +// and ensures that the state is reverted back to "running native code"
|
| +// when exiting the scope/frame.
|
| +// This transition helper is mainly used in the error path of the
|
| +// Dart API implementations where we sometimes do not have an explicit
|
| +// transition set up.
|
| +class TransitionToVM : public TransitionSafepointState {
|
| + public:
|
| + explicit TransitionToVM(Thread* T) : TransitionSafepointState(T),
|
| + execution_state_(T->execution_state()) {
|
| + ASSERT(T == Thread::Current());
|
| + ASSERT((execution_state_ == Thread::kThreadInVM) ||
|
| + (execution_state_ == Thread::kThreadInNative));
|
| + if (execution_state_ == Thread::kThreadInNative) {
|
| + T->ExitSafepoint();
|
| + T->set_execution_state(Thread::kThreadInVM);
|
| + }
|
| + ASSERT(T->execution_state() == Thread::kThreadInVM);
|
| + }
|
| +
|
| + ~TransitionToVM() {
|
| + ASSERT(thread()->execution_state() == Thread::kThreadInVM);
|
| + if (execution_state_ == Thread::kThreadInNative) {
|
| + thread()->set_execution_state(Thread::kThreadInNative);
|
| + thread()->EnterSafepoint();
|
| + }
|
| + }
|
| +
|
| + private:
|
| + uint32_t execution_state_;
|
| + DISALLOW_COPY_AND_ASSIGN(TransitionToVM);
|
| +};
|
| +
|
| } // namespace dart
|
|
|
| #endif // VM_SAFEPOINT_H_
|
|
|