OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "lib/stacktrace.h" | 10 #include "lib/stacktrace.h" |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 473 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
474 return reinterpret_cast<Dart_Isolate>(isolate); | 474 return reinterpret_cast<Dart_Isolate>(isolate); |
475 } | 475 } |
476 | 476 |
477 | 477 |
478 Dart_Handle Api::NewError(const char* format, ...) { | 478 Dart_Handle Api::NewError(const char* format, ...) { |
479 Thread* T = Thread::Current(); | 479 Thread* T = Thread::Current(); |
480 CHECK_API_SCOPE(T); | 480 CHECK_API_SCOPE(T); |
481 HANDLESCOPE(T); | 481 HANDLESCOPE(T); |
482 CHECK_CALLBACK_STATE(T); | 482 CHECK_CALLBACK_STATE(T); |
| 483 // Ensure we transition safepoint state to VM if we are not already in |
| 484 // that state. |
| 485 TransitionToVM transition(T); |
483 | 486 |
484 va_list args; | 487 va_list args; |
485 va_start(args, format); | 488 va_start(args, format); |
486 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 489 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
487 va_end(args); | 490 va_end(args); |
488 | 491 |
489 char* buffer = Z->Alloc<char>(len + 1); | 492 char* buffer = Z->Alloc<char>(len + 1); |
490 va_list args2; | 493 va_list args2; |
491 va_start(args2, format); | 494 va_start(args2, format); |
492 OS::VSNPrint(buffer, (len + 1), format, args2); | 495 OS::VSNPrint(buffer, (len + 1), format, args2); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 RETURN_TYPE_ERROR(Z, exception, Instance); | 843 RETURN_TYPE_ERROR(Z, exception, Instance); |
841 } | 844 } |
842 } | 845 } |
843 const Stacktrace& stacktrace = Stacktrace::Handle(Z); | 846 const Stacktrace& stacktrace = Stacktrace::Handle(Z); |
844 return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); | 847 return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); |
845 } | 848 } |
846 | 849 |
847 | 850 |
848 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 851 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
849 Thread* thread = Thread::Current(); | 852 Thread* thread = Thread::Current(); |
850 { | 853 TransitionNativeToVM transition(thread); |
851 const Object& obj = Object::Handle(thread->zone(), | 854 const Object& obj = Object::Handle(thread->zone(), |
852 Api::UnwrapHandle(handle)); | 855 Api::UnwrapHandle(handle)); |
853 if (!obj.IsError()) { | 856 if (!obj.IsError()) { |
854 return Api::NewError( | 857 return Api::NewError( |
855 "%s expects argument 'handle' to be an error handle. " | 858 "%s expects argument 'handle' to be an error handle. " |
856 "Did you forget to check Dart_IsError first?", | 859 "Did you forget to check Dart_IsError first?", |
857 CURRENT_FUNC); | 860 CURRENT_FUNC); |
858 } | |
859 } | 861 } |
860 if (thread->top_exit_frame_info() == 0) { | 862 if (thread->top_exit_frame_info() == 0) { |
861 // There are no dart frames on the stack so it would be illegal to | 863 // There are no dart frames on the stack so it would be illegal to |
862 // propagate an error here. | 864 // propagate an error here. |
863 return Api::NewError("No Dart frames on stack, cannot propagate error."); | 865 return Api::NewError("No Dart frames on stack, cannot propagate error."); |
864 } | 866 } |
865 | |
866 TransitionNativeToVM transition(thread); | |
867 // Unwind all the API scopes till the exit frame before propagating. | 867 // Unwind all the API scopes till the exit frame before propagating. |
868 const Error* error; | 868 const Error* error; |
869 { | 869 { |
870 // We need to preserve the error object across the destruction of zones | 870 // We need to preserve the error object across the destruction of zones |
871 // when the ApiScopes are unwound. By using NoSafepointScope, we can ensure | 871 // when the ApiScopes are unwound. By using NoSafepointScope, we can ensure |
872 // that GC won't touch the raw error object before creating a valid | 872 // that GC won't touch the raw error object before creating a valid |
873 // handle for it in the surviving zone. | 873 // handle for it in the surviving zone. |
874 NoSafepointScope no_safepoint; | 874 NoSafepointScope no_safepoint; |
875 RawError* raw_error = Api::UnwrapErrorHandle(thread->zone(), handle).raw(); | 875 RawError* raw_error = Api::UnwrapErrorHandle(thread->zone(), handle).raw(); |
876 thread->UnwindScopes(thread->top_exit_frame_info()); | 876 thread->UnwindScopes(thread->top_exit_frame_info()); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 } | 968 } |
969 return 0; | 969 return 0; |
970 } | 970 } |
971 | 971 |
972 | 972 |
973 DART_EXPORT Dart_Handle Dart_HandleFromPersistent( | 973 DART_EXPORT Dart_Handle Dart_HandleFromPersistent( |
974 Dart_PersistentHandle object) { | 974 Dart_PersistentHandle object) { |
975 Thread* thread = Thread::Current(); | 975 Thread* thread = Thread::Current(); |
976 Isolate* isolate = thread->isolate(); | 976 Isolate* isolate = thread->isolate(); |
977 CHECK_ISOLATE(isolate); | 977 CHECK_ISOLATE(isolate); |
| 978 NoSafepointScope no_safepoint_scope; |
978 ApiState* state = isolate->api_state(); | 979 ApiState* state = isolate->api_state(); |
979 ASSERT(state != NULL); | 980 ASSERT(state != NULL); |
980 PersistentHandle* ref = PersistentHandle::Cast(object); | 981 PersistentHandle* ref = PersistentHandle::Cast(object); |
981 return Api::NewHandle(thread, ref->raw()); | 982 return Api::NewHandle(thread, ref->raw()); |
982 } | 983 } |
983 | 984 |
984 | 985 |
985 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent( | 986 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent( |
986 Dart_WeakPersistentHandle object) { | 987 Dart_WeakPersistentHandle object) { |
987 Thread* thread = Thread::Current(); | 988 Thread* thread = Thread::Current(); |
988 Isolate* isolate = thread->isolate(); | 989 Isolate* isolate = thread->isolate(); |
989 CHECK_ISOLATE(isolate); | 990 CHECK_ISOLATE(isolate); |
| 991 NoSafepointScope no_safepoint_scope; |
990 ApiState* state = isolate->api_state(); | 992 ApiState* state = isolate->api_state(); |
991 ASSERT(state != NULL); | 993 ASSERT(state != NULL); |
992 FinalizablePersistentHandle* weak_ref = | 994 FinalizablePersistentHandle* weak_ref = |
993 FinalizablePersistentHandle::Cast(object); | 995 FinalizablePersistentHandle::Cast(object); |
994 return Api::NewHandle(thread, weak_ref->raw()); | 996 return Api::NewHandle(thread, weak_ref->raw()); |
995 } | 997 } |
996 | 998 |
997 | 999 |
998 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { | 1000 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { |
999 DARTSCOPE(Thread::Current()); | 1001 DARTSCOPE(Thread::Current()); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 object, | 1056 object, |
1055 peer, | 1057 peer, |
1056 external_allocation_size, | 1058 external_allocation_size, |
1057 callback); | 1059 callback); |
1058 } | 1060 } |
1059 | 1061 |
1060 | 1062 |
1061 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { | 1063 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { |
1062 Isolate* isolate = Isolate::Current(); | 1064 Isolate* isolate = Isolate::Current(); |
1063 CHECK_ISOLATE(isolate); | 1065 CHECK_ISOLATE(isolate); |
| 1066 NoSafepointScope no_safepoint_scope; |
1064 ApiState* state = isolate->api_state(); | 1067 ApiState* state = isolate->api_state(); |
1065 ASSERT(state != NULL); | 1068 ASSERT(state != NULL); |
1066 PersistentHandle* ref = PersistentHandle::Cast(object); | 1069 PersistentHandle* ref = PersistentHandle::Cast(object); |
1067 ASSERT(!state->IsProtectedHandle(ref)); | 1070 ASSERT(!state->IsProtectedHandle(ref)); |
1068 if (!state->IsProtectedHandle(ref)) { | 1071 if (!state->IsProtectedHandle(ref)) { |
1069 state->persistent_handles().FreeHandle(ref); | 1072 state->persistent_handles().FreeHandle(ref); |
1070 } | 1073 } |
1071 } | 1074 } |
1072 | 1075 |
1073 | 1076 |
1074 DART_EXPORT void Dart_DeleteWeakPersistentHandle( | 1077 DART_EXPORT void Dart_DeleteWeakPersistentHandle( |
1075 Dart_Isolate current_isolate, | 1078 Dart_Isolate current_isolate, |
1076 Dart_WeakPersistentHandle object) { | 1079 Dart_WeakPersistentHandle object) { |
1077 Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate); | 1080 Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate); |
1078 CHECK_ISOLATE(isolate); | 1081 CHECK_ISOLATE(isolate); |
| 1082 NoSafepointScope no_safepoint_scope; |
1079 ASSERT(isolate == Isolate::Current()); | 1083 ASSERT(isolate == Isolate::Current()); |
1080 ApiState* state = isolate->api_state(); | 1084 ApiState* state = isolate->api_state(); |
1081 ASSERT(state != NULL); | 1085 ASSERT(state != NULL); |
1082 FinalizablePersistentHandle* weak_ref = | 1086 FinalizablePersistentHandle* weak_ref = |
1083 FinalizablePersistentHandle::Cast(object); | 1087 FinalizablePersistentHandle::Cast(object); |
1084 weak_ref->EnsureFreeExternal(isolate); | 1088 weak_ref->EnsureFreeExternal(isolate); |
1085 state->weak_persistent_handles().FreeHandle(weak_ref); | 1089 state->weak_persistent_handles().FreeHandle(weak_ref); |
1086 } | 1090 } |
1087 | 1091 |
1088 | 1092 |
1089 // --- Garbage Collection Callbacks -- | 1093 // --- Garbage Collection Callbacks -- |
1090 | 1094 |
1091 DART_EXPORT Dart_Handle Dart_SetGcCallbacks( | 1095 DART_EXPORT Dart_Handle Dart_SetGcCallbacks( |
1092 Dart_GcPrologueCallback prologue_callback, | 1096 Dart_GcPrologueCallback prologue_callback, |
1093 Dart_GcEpilogueCallback epilogue_callback) { | 1097 Dart_GcEpilogueCallback epilogue_callback) { |
1094 Isolate* isolate = Isolate::Current(); | 1098 Thread* thread = Thread::Current(); |
| 1099 Isolate* isolate = thread->isolate(); |
1095 CHECK_ISOLATE(isolate); | 1100 CHECK_ISOLATE(isolate); |
| 1101 DARTSCOPE(thread); |
1096 if (prologue_callback != NULL) { | 1102 if (prologue_callback != NULL) { |
1097 if (isolate->gc_prologue_callback() != NULL) { | 1103 if (isolate->gc_prologue_callback() != NULL) { |
1098 return Api::NewError( | 1104 return Api::NewError( |
1099 "%s permits only one gc prologue callback to be registered, please " | 1105 "%s permits only one gc prologue callback to be registered, please " |
1100 "remove the existing callback and then add this callback", | 1106 "remove the existing callback and then add this callback", |
1101 CURRENT_FUNC); | 1107 CURRENT_FUNC); |
1102 } | 1108 } |
1103 } else { | 1109 } else { |
1104 if (isolate->gc_prologue_callback() == NULL) { | 1110 if (isolate->gc_prologue_callback() == NULL) { |
1105 return Api::NewError( | 1111 return Api::NewError( |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 | 1312 |
1307 | 1313 |
1308 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { | 1314 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { |
1309 return Api::CastIsolate(Isolate::Current()); | 1315 return Api::CastIsolate(Isolate::Current()); |
1310 } | 1316 } |
1311 | 1317 |
1312 | 1318 |
1313 DART_EXPORT void* Dart_CurrentIsolateData() { | 1319 DART_EXPORT void* Dart_CurrentIsolateData() { |
1314 Isolate* isolate = Isolate::Current(); | 1320 Isolate* isolate = Isolate::Current(); |
1315 CHECK_ISOLATE(isolate); | 1321 CHECK_ISOLATE(isolate); |
| 1322 NoSafepointScope no_safepoint_scope; |
1316 return isolate->init_callback_data(); | 1323 return isolate->init_callback_data(); |
1317 } | 1324 } |
1318 | 1325 |
1319 | 1326 |
1320 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { | 1327 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { |
1321 if (isolate == NULL) { | 1328 if (isolate == NULL) { |
1322 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1329 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1323 } | 1330 } |
1324 // TODO(16615): Validate isolate parameter. | 1331 // TODO(16615): Validate isolate parameter. |
| 1332 NoSafepointScope no_safepoint_scope; |
1325 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1333 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1326 return iso->init_callback_data(); | 1334 return iso->init_callback_data(); |
1327 } | 1335 } |
1328 | 1336 |
1329 | 1337 |
1330 DART_EXPORT Dart_Handle Dart_DebugName() { | 1338 DART_EXPORT Dart_Handle Dart_DebugName() { |
1331 DARTSCOPE(Thread::Current()); | 1339 DARTSCOPE(Thread::Current()); |
1332 Isolate* I = T->isolate(); | 1340 Isolate* I = T->isolate(); |
1333 return Api::NewHandle(T, String::New(I->name())); | 1341 return Api::NewHandle(T, String::New(I->name())); |
1334 } | 1342 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 if (os_thread == NULL) { | 1376 if (os_thread == NULL) { |
1369 return; | 1377 return; |
1370 } | 1378 } |
1371 os_thread->EnableThreadInterrupts(); | 1379 os_thread->EnableThreadInterrupts(); |
1372 } | 1380 } |
1373 | 1381 |
1374 | 1382 |
1375 DART_EXPORT bool Dart_ShouldPauseOnStart() { | 1383 DART_EXPORT bool Dart_ShouldPauseOnStart() { |
1376 Isolate* isolate = Isolate::Current(); | 1384 Isolate* isolate = Isolate::Current(); |
1377 CHECK_ISOLATE(isolate); | 1385 CHECK_ISOLATE(isolate); |
| 1386 NoSafepointScope no_safepoint_scope; |
1378 return isolate->message_handler()->should_pause_on_start(); | 1387 return isolate->message_handler()->should_pause_on_start(); |
1379 } | 1388 } |
1380 | 1389 |
1381 | 1390 |
1382 DART_EXPORT void Dart_SetShouldPauseOnStart(bool should_pause) { | 1391 DART_EXPORT void Dart_SetShouldPauseOnStart(bool should_pause) { |
1383 Isolate* isolate = Isolate::Current(); | 1392 Isolate* isolate = Isolate::Current(); |
1384 CHECK_ISOLATE(isolate); | 1393 CHECK_ISOLATE(isolate); |
| 1394 NoSafepointScope no_safepoint_scope; |
1385 if (isolate->is_runnable()) { | 1395 if (isolate->is_runnable()) { |
1386 FATAL1("%s expects the current isolate to not be runnable yet.", | 1396 FATAL1("%s expects the current isolate to not be runnable yet.", |
1387 CURRENT_FUNC); | 1397 CURRENT_FUNC); |
1388 } | 1398 } |
1389 return isolate->message_handler()->set_should_pause_on_start(should_pause); | 1399 return isolate->message_handler()->set_should_pause_on_start(should_pause); |
1390 } | 1400 } |
1391 | 1401 |
1392 | 1402 |
1393 DART_EXPORT bool Dart_IsPausedOnStart() { | 1403 DART_EXPORT bool Dart_IsPausedOnStart() { |
1394 Isolate* isolate = Isolate::Current(); | 1404 Isolate* isolate = Isolate::Current(); |
1395 CHECK_ISOLATE(isolate); | 1405 CHECK_ISOLATE(isolate); |
| 1406 NoSafepointScope no_safepoint_scope; |
1396 return isolate->message_handler()->is_paused_on_start(); | 1407 return isolate->message_handler()->is_paused_on_start(); |
1397 } | 1408 } |
1398 | 1409 |
1399 | 1410 |
1400 DART_EXPORT void Dart_SetPausedOnStart(bool paused) { | 1411 DART_EXPORT void Dart_SetPausedOnStart(bool paused) { |
1401 Isolate* isolate = Isolate::Current(); | 1412 Isolate* isolate = Isolate::Current(); |
1402 CHECK_ISOLATE(isolate); | 1413 CHECK_ISOLATE(isolate); |
| 1414 NoSafepointScope no_safepoint_scope; |
1403 if (isolate->message_handler()->is_paused_on_start() != paused) { | 1415 if (isolate->message_handler()->is_paused_on_start() != paused) { |
1404 isolate->message_handler()->PausedOnStart(paused); | 1416 isolate->message_handler()->PausedOnStart(paused); |
1405 } | 1417 } |
1406 } | 1418 } |
1407 | 1419 |
1408 | 1420 |
1409 DART_EXPORT bool Dart_ShouldPauseOnExit() { | 1421 DART_EXPORT bool Dart_ShouldPauseOnExit() { |
1410 Isolate* isolate = Isolate::Current(); | 1422 Isolate* isolate = Isolate::Current(); |
1411 CHECK_ISOLATE(isolate); | 1423 CHECK_ISOLATE(isolate); |
| 1424 NoSafepointScope no_safepoint_scope; |
1412 return isolate->message_handler()->should_pause_on_exit(); | 1425 return isolate->message_handler()->should_pause_on_exit(); |
1413 } | 1426 } |
1414 | 1427 |
1415 | 1428 |
1416 DART_EXPORT void Dart_SetShouldPauseOnExit(bool should_pause) { | 1429 DART_EXPORT void Dart_SetShouldPauseOnExit(bool should_pause) { |
1417 Isolate* isolate = Isolate::Current(); | 1430 Isolate* isolate = Isolate::Current(); |
1418 CHECK_ISOLATE(isolate); | 1431 CHECK_ISOLATE(isolate); |
| 1432 NoSafepointScope no_safepoint_scope; |
1419 return isolate->message_handler()->set_should_pause_on_exit(should_pause); | 1433 return isolate->message_handler()->set_should_pause_on_exit(should_pause); |
1420 } | 1434 } |
1421 | 1435 |
1422 | 1436 |
1423 DART_EXPORT bool Dart_IsPausedOnExit() { | 1437 DART_EXPORT bool Dart_IsPausedOnExit() { |
1424 Isolate* isolate = Isolate::Current(); | 1438 Isolate* isolate = Isolate::Current(); |
1425 CHECK_ISOLATE(isolate); | 1439 CHECK_ISOLATE(isolate); |
| 1440 NoSafepointScope no_safepoint_scope; |
1426 return isolate->message_handler()->is_paused_on_exit(); | 1441 return isolate->message_handler()->is_paused_on_exit(); |
1427 } | 1442 } |
1428 | 1443 |
1429 | 1444 |
1430 DART_EXPORT void Dart_SetPausedOnExit(bool paused) { | 1445 DART_EXPORT void Dart_SetPausedOnExit(bool paused) { |
1431 Isolate* isolate = Isolate::Current(); | 1446 Isolate* isolate = Isolate::Current(); |
1432 CHECK_ISOLATE(isolate); | 1447 CHECK_ISOLATE(isolate); |
| 1448 NoSafepointScope no_safepoint_scope; |
1433 if (isolate->message_handler()->is_paused_on_exit() != paused) { | 1449 if (isolate->message_handler()->is_paused_on_exit() != paused) { |
1434 isolate->message_handler()->PausedOnExit(paused); | 1450 isolate->message_handler()->PausedOnExit(paused); |
1435 } | 1451 } |
1436 } | 1452 } |
1437 | 1453 |
1438 | 1454 |
1439 DART_EXPORT void Dart_ExitIsolate() { | 1455 DART_EXPORT void Dart_ExitIsolate() { |
1440 Thread* T = Thread::Current(); | 1456 Thread* T = Thread::Current(); |
1441 CHECK_ISOLATE(T->isolate()); | 1457 CHECK_ISOLATE(T->isolate()); |
1442 // The Thread structure is disassociated from the isolate, we do the | 1458 // The Thread structure is disassociated from the isolate, we do the |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 API_TIMELINE_DURATION; | 1568 API_TIMELINE_DURATION; |
1553 return createLibrarySnapshot(library, buffer, size); | 1569 return createLibrarySnapshot(library, buffer, size); |
1554 } | 1570 } |
1555 | 1571 |
1556 | 1572 |
1557 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 1573 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
1558 if (isolate == NULL) { | 1574 if (isolate == NULL) { |
1559 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1575 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1560 } | 1576 } |
1561 // TODO(16615): Validate isolate parameter. | 1577 // TODO(16615): Validate isolate parameter. |
| 1578 TransitionNativeToVM transition(Thread::Current()); |
1562 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1579 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1563 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability()); | 1580 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability()); |
1564 } | 1581 } |
1565 | 1582 |
1566 | 1583 |
1567 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { | 1584 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { |
1568 CHECK_NO_ISOLATE(Isolate::Current()); | 1585 CHECK_NO_ISOLATE(Isolate::Current()); |
1569 API_TIMELINE_DURATION; | 1586 API_TIMELINE_DURATION; |
1570 if (isolate == NULL) { | 1587 if (isolate == NULL) { |
1571 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1588 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1572 } | 1589 } |
1573 // TODO(16615): Validate isolate parameter. | 1590 // TODO(16615): Validate isolate parameter. |
1574 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1591 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1575 if (iso->object_store()->root_library() == Library::null()) { | 1592 if (iso->object_store()->root_library() == Library::null()) { |
1576 // The embedder should have called Dart_LoadScript by now. | 1593 // The embedder should have called Dart_LoadScript by now. |
1577 return false; | 1594 return false; |
1578 } | 1595 } |
1579 return iso->MakeRunnable(); | 1596 return iso->MakeRunnable(); |
1580 } | 1597 } |
1581 | 1598 |
1582 | 1599 |
1583 // --- Messages and Ports --- | 1600 // --- Messages and Ports --- |
1584 | 1601 |
1585 DART_EXPORT void Dart_SetMessageNotifyCallback( | 1602 DART_EXPORT void Dart_SetMessageNotifyCallback( |
1586 Dart_MessageNotifyCallback message_notify_callback) { | 1603 Dart_MessageNotifyCallback message_notify_callback) { |
1587 Isolate* isolate = Isolate::Current(); | 1604 Isolate* isolate = Isolate::Current(); |
1588 CHECK_ISOLATE(isolate); | 1605 CHECK_ISOLATE(isolate); |
| 1606 NoSafepointScope no_safepoint_scope; |
1589 isolate->set_message_notify_callback(message_notify_callback); | 1607 isolate->set_message_notify_callback(message_notify_callback); |
1590 } | 1608 } |
1591 | 1609 |
1592 | 1610 |
1593 DART_EXPORT Dart_MessageNotifyCallback Dart_GetMessageNotifyCallback() { | 1611 DART_EXPORT Dart_MessageNotifyCallback Dart_GetMessageNotifyCallback() { |
1594 Isolate* isolate = Isolate::Current(); | 1612 Isolate* isolate = Isolate::Current(); |
1595 CHECK_ISOLATE(isolate); | 1613 CHECK_ISOLATE(isolate); |
| 1614 NoSafepointScope no_safepoint_scope; |
1596 return isolate->message_notify_callback(); | 1615 return isolate->message_notify_callback(); |
1597 } | 1616 } |
1598 | 1617 |
1599 | 1618 |
1600 struct RunLoopData { | 1619 struct RunLoopData { |
1601 Monitor* monitor; | 1620 Monitor* monitor; |
1602 bool done; | 1621 bool done; |
1603 }; | 1622 }; |
1604 | 1623 |
1605 | 1624 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 MessageHandler::MessageStatus status = | 1714 MessageHandler::MessageStatus status = |
1696 I->message_handler()->HandleOOBMessages(); | 1715 I->message_handler()->HandleOOBMessages(); |
1697 bool resume = I->GetAndClearResumeRequest(); | 1716 bool resume = I->GetAndClearResumeRequest(); |
1698 return (status != MessageHandler::kOK) || resume; | 1717 return (status != MessageHandler::kOK) || resume; |
1699 } | 1718 } |
1700 | 1719 |
1701 | 1720 |
1702 DART_EXPORT bool Dart_HasServiceMessages() { | 1721 DART_EXPORT bool Dart_HasServiceMessages() { |
1703 Isolate* isolate = Isolate::Current(); | 1722 Isolate* isolate = Isolate::Current(); |
1704 ASSERT(isolate); | 1723 ASSERT(isolate); |
| 1724 NoSafepointScope no_safepoint_scope; |
1705 return isolate->message_handler()->HasOOBMessages(); | 1725 return isolate->message_handler()->HasOOBMessages(); |
1706 } | 1726 } |
1707 | 1727 |
1708 | 1728 |
1709 DART_EXPORT bool Dart_HasLivePorts() { | 1729 DART_EXPORT bool Dart_HasLivePorts() { |
1710 Isolate* isolate = Isolate::Current(); | 1730 Isolate* isolate = Isolate::Current(); |
1711 ASSERT(isolate); | 1731 ASSERT(isolate); |
| 1732 NoSafepointScope no_safepoint_scope; |
1712 return isolate->message_handler()->HasLivePorts(); | 1733 return isolate->message_handler()->HasLivePorts(); |
1713 } | 1734 } |
1714 | 1735 |
1715 | 1736 |
1716 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 1737 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
1717 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 1738 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
1718 return reinterpret_cast<uint8_t*>(new_ptr); | 1739 return reinterpret_cast<uint8_t*>(new_ptr); |
1719 } | 1740 } |
1720 | 1741 |
1721 | 1742 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1779 return isolate->main_port(); | 1800 return isolate->main_port(); |
1780 } | 1801 } |
1781 | 1802 |
1782 | 1803 |
1783 // --- Scopes ---- | 1804 // --- Scopes ---- |
1784 | 1805 |
1785 DART_EXPORT void Dart_EnterScope() { | 1806 DART_EXPORT void Dart_EnterScope() { |
1786 Thread* thread = Thread::Current(); | 1807 Thread* thread = Thread::Current(); |
1787 Isolate* isolate = thread->isolate(); | 1808 Isolate* isolate = thread->isolate(); |
1788 CHECK_ISOLATE(isolate); | 1809 CHECK_ISOLATE(isolate); |
| 1810 NoSafepointScope no_safepoint_scope; |
1789 ApiLocalScope* new_scope = thread->api_reusable_scope(); | 1811 ApiLocalScope* new_scope = thread->api_reusable_scope(); |
1790 if (new_scope == NULL) { | 1812 if (new_scope == NULL) { |
1791 new_scope = new ApiLocalScope(thread->api_top_scope(), | 1813 new_scope = new ApiLocalScope(thread->api_top_scope(), |
1792 thread->top_exit_frame_info()); | 1814 thread->top_exit_frame_info()); |
1793 ASSERT(new_scope != NULL); | 1815 ASSERT(new_scope != NULL); |
1794 } else { | 1816 } else { |
1795 new_scope->Reinit(thread, | 1817 new_scope->Reinit(thread, |
1796 thread->api_top_scope(), | 1818 thread->api_top_scope(), |
1797 thread->top_exit_frame_info()); | 1819 thread->top_exit_frame_info()); |
1798 thread->set_api_reusable_scope(NULL); | 1820 thread->set_api_reusable_scope(NULL); |
1799 } | 1821 } |
1800 thread->set_api_top_scope(new_scope); // New scope is now the top scope. | 1822 thread->set_api_top_scope(new_scope); // New scope is now the top scope. |
1801 } | 1823 } |
1802 | 1824 |
1803 | 1825 |
1804 DART_EXPORT void Dart_ExitScope() { | 1826 DART_EXPORT void Dart_ExitScope() { |
1805 Thread* T = Thread::Current(); | 1827 Thread* T = Thread::Current(); |
1806 CHECK_API_SCOPE(T); | 1828 CHECK_API_SCOPE(T); |
| 1829 NoSafepointScope no_safepoint_scope; |
1807 ApiLocalScope* scope = T->api_top_scope(); | 1830 ApiLocalScope* scope = T->api_top_scope(); |
1808 ApiLocalScope* reusable_scope = T->api_reusable_scope(); | 1831 ApiLocalScope* reusable_scope = T->api_reusable_scope(); |
1809 T->set_api_top_scope(scope->previous()); // Reset top scope to previous. | 1832 T->set_api_top_scope(scope->previous()); // Reset top scope to previous. |
1810 if (reusable_scope == NULL) { | 1833 if (reusable_scope == NULL) { |
1811 scope->Reset(T); // Reset the old scope which we just exited. | 1834 scope->Reset(T); // Reset the old scope which we just exited. |
1812 T->set_api_reusable_scope(scope); | 1835 T->set_api_reusable_scope(scope); |
1813 } else { | 1836 } else { |
1814 ASSERT(reusable_scope != scope); | 1837 ASSERT(reusable_scope != scope); |
1815 delete scope; | 1838 delete scope; |
1816 } | 1839 } |
(...skipping 2755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4572 | 4595 |
4573 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 4596 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
4574 Thread* thread = Thread::Current(); | 4597 Thread* thread = Thread::Current(); |
4575 Zone* zone = thread->zone(); | 4598 Zone* zone = thread->zone(); |
4576 Isolate* isolate = thread->isolate(); | 4599 Isolate* isolate = thread->isolate(); |
4577 CHECK_ISOLATE(isolate); | 4600 CHECK_ISOLATE(isolate); |
4578 CHECK_CALLBACK_STATE(thread); | 4601 CHECK_CALLBACK_STATE(thread); |
4579 if (Api::IsError(exception)) { | 4602 if (Api::IsError(exception)) { |
4580 ::Dart_PropagateError(exception); | 4603 ::Dart_PropagateError(exception); |
4581 } | 4604 } |
4582 | 4605 TransitionNativeToVM transition(thread); |
4583 { | 4606 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); |
4584 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); | 4607 if (excp.IsNull()) { |
4585 if (excp.IsNull()) { | 4608 RETURN_TYPE_ERROR(zone, exception, Instance); |
4586 RETURN_TYPE_ERROR(zone, exception, Instance); | |
4587 } | |
4588 } | 4609 } |
4589 if (thread->top_exit_frame_info() == 0) { | 4610 if (thread->top_exit_frame_info() == 0) { |
4590 // There are no dart frames on the stack so it would be illegal to | 4611 // There are no dart frames on the stack so it would be illegal to |
4591 // throw an exception here. | 4612 // throw an exception here. |
4592 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 4613 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
4593 } | 4614 } |
4594 | |
4595 TransitionNativeToVM transition(thread); | |
4596 // Unwind all the API scopes till the exit frame before throwing an | 4615 // Unwind all the API scopes till the exit frame before throwing an |
4597 // exception. | 4616 // exception. |
4598 const Instance* saved_exception; | 4617 const Instance* saved_exception; |
4599 { | 4618 { |
4600 NoSafepointScope no_safepoint; | 4619 NoSafepointScope no_safepoint; |
4601 RawInstance* raw_exception = | 4620 RawInstance* raw_exception = |
4602 Api::UnwrapInstanceHandle(zone, exception).raw(); | 4621 Api::UnwrapInstanceHandle(zone, exception).raw(); |
4603 thread->UnwindScopes(thread->top_exit_frame_info()); | 4622 thread->UnwindScopes(thread->top_exit_frame_info()); |
4604 saved_exception = &Instance::Handle(raw_exception); | 4623 saved_exception = &Instance::Handle(raw_exception); |
4605 } | 4624 } |
4606 Exceptions::Throw(thread, *saved_exception); | 4625 Exceptions::Throw(thread, *saved_exception); |
4607 return Api::NewError("Exception was not thrown, internal error"); | 4626 return Api::NewError("Exception was not thrown, internal error"); |
4608 } | 4627 } |
4609 | 4628 |
4610 | 4629 |
4611 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 4630 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
4612 Dart_Handle stacktrace) { | 4631 Dart_Handle stacktrace) { |
4613 Thread* thread = Thread::Current(); | 4632 Thread* thread = Thread::Current(); |
4614 Zone* zone = thread->zone(); | 4633 Zone* zone = thread->zone(); |
4615 Isolate* isolate = thread->isolate(); | 4634 Isolate* isolate = thread->isolate(); |
4616 CHECK_ISOLATE(isolate); | 4635 CHECK_ISOLATE(isolate); |
4617 CHECK_CALLBACK_STATE(thread); | 4636 CHECK_CALLBACK_STATE(thread); |
| 4637 TransitionNativeToVM transition(thread); |
4618 { | 4638 { |
4619 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); | 4639 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); |
4620 if (excp.IsNull()) { | 4640 if (excp.IsNull()) { |
4621 RETURN_TYPE_ERROR(zone, exception, Instance); | 4641 RETURN_TYPE_ERROR(zone, exception, Instance); |
4622 } | 4642 } |
4623 const Instance& stk = Api::UnwrapInstanceHandle(zone, stacktrace); | 4643 const Instance& stk = Api::UnwrapInstanceHandle(zone, stacktrace); |
4624 if (stk.IsNull()) { | 4644 if (stk.IsNull()) { |
4625 RETURN_TYPE_ERROR(zone, stacktrace, Instance); | 4645 RETURN_TYPE_ERROR(zone, stacktrace, Instance); |
4626 } | 4646 } |
4627 } | 4647 } |
4628 if (thread->top_exit_frame_info() == 0) { | 4648 if (thread->top_exit_frame_info() == 0) { |
4629 // There are no dart frames on the stack so it would be illegal to | 4649 // There are no dart frames on the stack so it would be illegal to |
4630 // throw an exception here. | 4650 // throw an exception here. |
4631 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 4651 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
4632 } | 4652 } |
4633 | |
4634 TransitionNativeToVM transition(thread); | |
4635 // Unwind all the API scopes till the exit frame before throwing an | 4653 // Unwind all the API scopes till the exit frame before throwing an |
4636 // exception. | 4654 // exception. |
4637 const Instance* saved_exception; | 4655 const Instance* saved_exception; |
4638 const Stacktrace* saved_stacktrace; | 4656 const Stacktrace* saved_stacktrace; |
4639 { | 4657 { |
4640 NoSafepointScope no_safepoint; | 4658 NoSafepointScope no_safepoint; |
4641 RawInstance* raw_exception = | 4659 RawInstance* raw_exception = |
4642 Api::UnwrapInstanceHandle(zone, exception).raw(); | 4660 Api::UnwrapInstanceHandle(zone, exception).raw(); |
4643 RawStacktrace* raw_stacktrace = | 4661 RawStacktrace* raw_stacktrace = |
4644 Api::UnwrapStacktraceHandle(zone, stacktrace).raw(); | 4662 Api::UnwrapStacktraceHandle(zone, stacktrace).raw(); |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5111 | 5129 |
5112 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, | 5130 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, |
5113 int64_t retval) { | 5131 int64_t retval) { |
5114 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 5132 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5115 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 5133 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
5116 if (Smi::IsValid(retval)) { | 5134 if (Smi::IsValid(retval)) { |
5117 Api::SetSmiReturnValue(arguments, static_cast<intptr_t>(retval)); | 5135 Api::SetSmiReturnValue(arguments, static_cast<intptr_t>(retval)); |
5118 } else { | 5136 } else { |
5119 // Slow path for Mints and Bigints. | 5137 // Slow path for Mints and Bigints. |
5120 ASSERT_CALLBACK_STATE(arguments->thread()); | 5138 ASSERT_CALLBACK_STATE(arguments->thread()); |
| 5139 TransitionNativeToVM transition(arguments->thread()); |
5121 Api::SetIntegerReturnValue(arguments, retval); | 5140 Api::SetIntegerReturnValue(arguments, retval); |
5122 } | 5141 } |
5123 } | 5142 } |
5124 | 5143 |
5125 | 5144 |
5126 DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, | 5145 DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, |
5127 double retval) { | 5146 double retval) { |
5128 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 5147 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5129 ASSERT_CALLBACK_STATE(arguments->thread()); | 5148 ASSERT_CALLBACK_STATE(arguments->thread()); |
| 5149 TransitionNativeToVM transition(arguments->thread()); |
5130 Api::SetDoubleReturnValue(arguments, retval); | 5150 Api::SetDoubleReturnValue(arguments, retval); |
5131 } | 5151 } |
5132 | 5152 |
5133 | 5153 |
5134 // --- Scripts and Libraries --- | 5154 // --- Scripts and Libraries --- |
5135 | 5155 |
5136 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler( | 5156 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler( |
5137 Dart_LibraryTagHandler handler) { | 5157 Dart_LibraryTagHandler handler) { |
5138 Isolate* isolate = Isolate::Current(); | 5158 Isolate* isolate = Isolate::Current(); |
5139 CHECK_ISOLATE(isolate); | 5159 CHECK_ISOLATE(isolate); |
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6360 | 6380 |
6361 DART_EXPORT bool Dart_IsPrecompiledRuntime() { | 6381 DART_EXPORT bool Dart_IsPrecompiledRuntime() { |
6362 #if defined(DART_PRECOMPILED_RUNTIME) | 6382 #if defined(DART_PRECOMPILED_RUNTIME) |
6363 return true; | 6383 return true; |
6364 #else | 6384 #else |
6365 return false; | 6385 return false; |
6366 #endif | 6386 #endif |
6367 } | 6387 } |
6368 | 6388 |
6369 } // namespace dart | 6389 } // namespace dart |
OLD | NEW |