[vm] Don't acquire safepoint locks while participating in reload safepoints.

Also disable lint intended to guard against use of std::thread::detach as it has too many false positives against dart::FinalizerEntry::detach.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/60638
Change-Id: I19a0fde743fc5c5658a8dd96cecb5b074481a035
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425324
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak
2025-04-29 16:23:20 -07:00
committed by Commit Queue
parent d1696f890d
commit 077d7c9e89
6 changed files with 8 additions and 2 deletions
-1
View File
@@ -19,7 +19,6 @@ USE_PYTHON3 = True
BANNED_FUNCTIONS = [
['\\bmemcpy\\(', 'memcpy'],
['\\bpthread_detach\\(', 'pthread_detach'],
['\\bdetach\\(', 'std::thread::detach'],
]
+1
View File
@@ -742,6 +742,7 @@ DART_EXPORT bool Dart_IsError(Dart_Handle handle) {
DART_EXPORT void Dart_KillIsolate(Dart_Isolate handle) {
Isolate* isolate = reinterpret_cast<Isolate*>(handle);
CHECK_ISOLATE(isolate);
TransitionNativeToVM transition(Thread::Current());
Isolate::KillIfExists(isolate, Isolate::kKillMsg);
}
+2
View File
@@ -2649,7 +2649,9 @@ static Dart_NativeFunction OptExternalByteDataNativeResolver(
}
TEST_CASE(DartAPI_OptimizedExternalByteDataAccess) {
TransitionNativeToVM transition1(thread);
NoBackgroundCompilerScope no_background_compiler(thread);
TransitionVMToNative transition2(thread);
const char* kScriptChars = R"(
import 'dart:typed_data';
+2
View File
@@ -112,6 +112,7 @@ bool SafepointRwLock::EnterRead() {
//
// Though if the lock was already acquired by this thread before entering a
// safepoint, we do allow the nested acquire (which is a NOP).
ASSERT(thread == nullptr || thread->execution_state() == Thread::kThreadInVM);
DEBUG_ASSERT(thread == nullptr || thread->CanAcquireSafepointLocks() ||
IsCurrentThreadReader());
@@ -178,6 +179,7 @@ void SafepointRwLock::EnterWrite() {
//
// Though if the lock was already acquired by this thread before entering a
// safepoint, we do allow the nested acquire (which is a NOP).
ASSERT(thread == nullptr || thread->execution_state() == Thread::kThreadInVM);
DEBUG_ASSERT(thread == nullptr || thread->CanAcquireSafepointLocks() ||
IsCurrentThreadWriter());
-1
View File
@@ -5811,7 +5811,6 @@ TEST_CASE(DartAPI_BreakpointLockRace) {
&done);
while (!done) {
ReloadParticipationScope allow_reload(thread);
{
TransitionNativeToVM transition(thread);
const String& name = String::Handle(String::New(TestCase::url()));
+3
View File
@@ -1477,6 +1477,9 @@ bool Thread::CanAcquireSafepointLocks() const {
// Example: We own reload safepoint operation, load kernel, which allocates
// symbols, where the symbol implementation acquires the symbol lock (we know
// other mutators at reload safepoint do not hold symbol lock).
if (current_safepoint_level() == SafepointLevel::kGCAndDeoptAndReload) {
return false;
}
return isolate_group()->safepoint_handler()->InnermostSafepointOperation(
this) >= SafepointLevel::kGCAndDeoptAndReload;
}