Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: runtime/vm/safepoint.h

Issue 2018673003: Fix for issue 26511 (VM hangs waiting for all threads that are not already at (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code-review-comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/lockers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« no previous file with comments | « runtime/vm/lockers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698