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

Unified Diff: runtime/vm/dart_api_impl.cc

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 | « no previous file | runtime/vm/lockers.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 5633c72e9756a485809133a2bb9a3ee642caf89e..43467434df40fc471febd5a9eabed3ba77ec4c33 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -480,6 +480,9 @@ Dart_Handle Api::NewError(const char* format, ...) {
CHECK_API_SCOPE(T);
HANDLESCOPE(T);
CHECK_CALLBACK_STATE(T);
+ // Ensure we transition safepoint state to VM if we are not already in
+ // that state.
+ TransitionToVM transition(T);
va_list args;
va_start(args, format);
@@ -847,23 +850,20 @@ DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) {
DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) {
Thread* thread = Thread::Current();
- {
- const Object& obj = Object::Handle(thread->zone(),
- Api::UnwrapHandle(handle));
- if (!obj.IsError()) {
- return Api::NewError(
- "%s expects argument 'handle' to be an error handle. "
- "Did you forget to check Dart_IsError first?",
- CURRENT_FUNC);
- }
+ TransitionNativeToVM transition(thread);
+ const Object& obj = Object::Handle(thread->zone(),
+ Api::UnwrapHandle(handle));
+ if (!obj.IsError()) {
+ return Api::NewError(
+ "%s expects argument 'handle' to be an error handle. "
+ "Did you forget to check Dart_IsError first?",
+ CURRENT_FUNC);
}
if (thread->top_exit_frame_info() == 0) {
// There are no dart frames on the stack so it would be illegal to
// propagate an error here.
return Api::NewError("No Dart frames on stack, cannot propagate error.");
}
-
- TransitionNativeToVM transition(thread);
// Unwind all the API scopes till the exit frame before propagating.
const Error* error;
{
@@ -975,6 +975,7 @@ DART_EXPORT Dart_Handle Dart_HandleFromPersistent(
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
PersistentHandle* ref = PersistentHandle::Cast(object);
@@ -987,6 +988,7 @@ DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent(
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
FinalizablePersistentHandle* weak_ref =
@@ -1061,6 +1063,7 @@ DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle(
DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
PersistentHandle* ref = PersistentHandle::Cast(object);
@@ -1076,6 +1079,7 @@ DART_EXPORT void Dart_DeleteWeakPersistentHandle(
Dart_WeakPersistentHandle object) {
Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate);
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
ASSERT(isolate == Isolate::Current());
ApiState* state = isolate->api_state();
ASSERT(state != NULL);
@@ -1091,8 +1095,10 @@ DART_EXPORT void Dart_DeleteWeakPersistentHandle(
DART_EXPORT Dart_Handle Dart_SetGcCallbacks(
Dart_GcPrologueCallback prologue_callback,
Dart_GcEpilogueCallback epilogue_callback) {
- Isolate* isolate = Isolate::Current();
+ Thread* thread = Thread::Current();
+ Isolate* isolate = thread->isolate();
CHECK_ISOLATE(isolate);
+ DARTSCOPE(thread);
if (prologue_callback != NULL) {
if (isolate->gc_prologue_callback() != NULL) {
return Api::NewError(
@@ -1313,6 +1319,7 @@ DART_EXPORT Dart_Isolate Dart_CurrentIsolate() {
DART_EXPORT void* Dart_CurrentIsolateData() {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
return isolate->init_callback_data();
}
@@ -1322,6 +1329,7 @@ DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) {
FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC);
}
// TODO(16615): Validate isolate parameter.
+ NoSafepointScope no_safepoint_scope;
Isolate* iso = reinterpret_cast<Isolate*>(isolate);
return iso->init_callback_data();
}
@@ -1375,6 +1383,7 @@ DART_EXPORT void Dart_ThreadEnableProfiling() {
DART_EXPORT bool Dart_ShouldPauseOnStart() {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
return isolate->message_handler()->should_pause_on_start();
}
@@ -1382,6 +1391,7 @@ DART_EXPORT bool Dart_ShouldPauseOnStart() {
DART_EXPORT void Dart_SetShouldPauseOnStart(bool should_pause) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
if (isolate->is_runnable()) {
FATAL1("%s expects the current isolate to not be runnable yet.",
CURRENT_FUNC);
@@ -1393,6 +1403,7 @@ DART_EXPORT void Dart_SetShouldPauseOnStart(bool should_pause) {
DART_EXPORT bool Dart_IsPausedOnStart() {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
return isolate->message_handler()->is_paused_on_start();
}
@@ -1400,6 +1411,7 @@ DART_EXPORT bool Dart_IsPausedOnStart() {
DART_EXPORT void Dart_SetPausedOnStart(bool paused) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
if (isolate->message_handler()->is_paused_on_start() != paused) {
isolate->message_handler()->PausedOnStart(paused);
}
@@ -1409,6 +1421,7 @@ DART_EXPORT void Dart_SetPausedOnStart(bool paused) {
DART_EXPORT bool Dart_ShouldPauseOnExit() {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
return isolate->message_handler()->should_pause_on_exit();
}
@@ -1416,6 +1429,7 @@ DART_EXPORT bool Dart_ShouldPauseOnExit() {
DART_EXPORT void Dart_SetShouldPauseOnExit(bool should_pause) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
return isolate->message_handler()->set_should_pause_on_exit(should_pause);
}
@@ -1423,6 +1437,7 @@ DART_EXPORT void Dart_SetShouldPauseOnExit(bool should_pause) {
DART_EXPORT bool Dart_IsPausedOnExit() {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
return isolate->message_handler()->is_paused_on_exit();
}
@@ -1430,6 +1445,7 @@ DART_EXPORT bool Dart_IsPausedOnExit() {
DART_EXPORT void Dart_SetPausedOnExit(bool paused) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
if (isolate->message_handler()->is_paused_on_exit() != paused) {
isolate->message_handler()->PausedOnExit(paused);
}
@@ -1559,6 +1575,7 @@ DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) {
FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC);
}
// TODO(16615): Validate isolate parameter.
+ TransitionNativeToVM transition(Thread::Current());
Isolate* iso = reinterpret_cast<Isolate*>(isolate);
iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability());
}
@@ -1586,6 +1603,7 @@ DART_EXPORT void Dart_SetMessageNotifyCallback(
Dart_MessageNotifyCallback message_notify_callback) {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
isolate->set_message_notify_callback(message_notify_callback);
}
@@ -1593,6 +1611,7 @@ DART_EXPORT void Dart_SetMessageNotifyCallback(
DART_EXPORT Dart_MessageNotifyCallback Dart_GetMessageNotifyCallback() {
Isolate* isolate = Isolate::Current();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
return isolate->message_notify_callback();
}
@@ -1702,6 +1721,7 @@ DART_EXPORT bool Dart_HandleServiceMessages() {
DART_EXPORT bool Dart_HasServiceMessages() {
Isolate* isolate = Isolate::Current();
ASSERT(isolate);
+ NoSafepointScope no_safepoint_scope;
return isolate->message_handler()->HasOOBMessages();
}
@@ -1709,6 +1729,7 @@ DART_EXPORT bool Dart_HasServiceMessages() {
DART_EXPORT bool Dart_HasLivePorts() {
Isolate* isolate = Isolate::Current();
ASSERT(isolate);
+ NoSafepointScope no_safepoint_scope;
return isolate->message_handler()->HasLivePorts();
}
@@ -1786,6 +1807,7 @@ DART_EXPORT void Dart_EnterScope() {
Thread* thread = Thread::Current();
Isolate* isolate = thread->isolate();
CHECK_ISOLATE(isolate);
+ NoSafepointScope no_safepoint_scope;
ApiLocalScope* new_scope = thread->api_reusable_scope();
if (new_scope == NULL) {
new_scope = new ApiLocalScope(thread->api_top_scope(),
@@ -1804,6 +1826,7 @@ DART_EXPORT void Dart_EnterScope() {
DART_EXPORT void Dart_ExitScope() {
Thread* T = Thread::Current();
CHECK_API_SCOPE(T);
+ NoSafepointScope no_safepoint_scope;
ApiLocalScope* scope = T->api_top_scope();
ApiLocalScope* reusable_scope = T->api_reusable_scope();
T->set_api_top_scope(scope->previous()); // Reset top scope to previous.
@@ -4579,20 +4602,16 @@ DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
if (Api::IsError(exception)) {
::Dart_PropagateError(exception);
}
-
- {
- const Instance& excp = Api::UnwrapInstanceHandle(zone, exception);
- if (excp.IsNull()) {
- RETURN_TYPE_ERROR(zone, exception, Instance);
- }
+ TransitionNativeToVM transition(thread);
+ const Instance& excp = Api::UnwrapInstanceHandle(zone, exception);
+ if (excp.IsNull()) {
+ RETURN_TYPE_ERROR(zone, exception, Instance);
}
if (thread->top_exit_frame_info() == 0) {
// There are no dart frames on the stack so it would be illegal to
// throw an exception here.
return Api::NewError("No Dart frames on stack, cannot throw exception");
}
-
- TransitionNativeToVM transition(thread);
// Unwind all the API scopes till the exit frame before throwing an
// exception.
const Instance* saved_exception;
@@ -4615,6 +4634,7 @@ DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
Isolate* isolate = thread->isolate();
CHECK_ISOLATE(isolate);
CHECK_CALLBACK_STATE(thread);
+ TransitionNativeToVM transition(thread);
{
const Instance& excp = Api::UnwrapInstanceHandle(zone, exception);
if (excp.IsNull()) {
@@ -4630,8 +4650,6 @@ DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
// throw an exception here.
return Api::NewError("No Dart frames on stack, cannot throw exception");
}
-
- TransitionNativeToVM transition(thread);
// Unwind all the API scopes till the exit frame before throwing an
// exception.
const Instance* saved_exception;
@@ -5118,6 +5136,7 @@ DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args,
} else {
// Slow path for Mints and Bigints.
ASSERT_CALLBACK_STATE(arguments->thread());
+ TransitionNativeToVM transition(arguments->thread());
Api::SetIntegerReturnValue(arguments, retval);
}
}
@@ -5127,6 +5146,7 @@ DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args,
double retval) {
NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
ASSERT_CALLBACK_STATE(arguments->thread());
+ TransitionNativeToVM transition(arguments->thread());
Api::SetDoubleReturnValue(arguments, retval);
}
« no previous file with comments | « no previous file | runtime/vm/lockers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698