50e0e0d99d
This method allows for synchronous execution of dart callbacks from native code. The execution happens on dart mutator thread, from which dart code can only access isolate-group variables - those which are tagged with . Bug: https://github.com/dart-lang/sdk/issues/54530 Bug: https://github.com/dart-lang/sdk/issues/56841 Change-Id: Ia1a6b01327be493f003f1eea82e558bb6b147dd3 CoreLibraryReviewExempt: only internal library change TEST=isolate_group_shared_callback_test Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422920 Reviewed-by: Slava Egorov <vegorov@google.com> Commit-Queue: Alexander Aprelev <aam@google.com>
44 lines
1.8 KiB
C++
44 lines
1.8 KiB
C++
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "vm/bss_relocs.h"
|
|
#include "vm/native_symbol.h"
|
|
#include "vm/runtime_entry.h"
|
|
#include "vm/thread.h"
|
|
|
|
namespace dart {
|
|
|
|
void BSS::InitializeBSSEntry(BSS::Relocation relocation,
|
|
uword new_value,
|
|
uword* bss_start) {
|
|
std::atomic<uword>* slot = reinterpret_cast<std::atomic<uword>*>(
|
|
&bss_start[BSS::RelocationIndex(relocation)]);
|
|
uword old_value = slot->load(std::memory_order_relaxed);
|
|
// FullSnapshotReader::ReadProgramSnapshot, and thus BSS::Initialize, can
|
|
// get called multiple times for the same isolate in different threads, though
|
|
// the initialized value will be consistent and thus change only once. Avoid
|
|
// calling compare_exchange_strong unless we actually need to change the
|
|
// value, to avoid spurious read/write races by TSAN.
|
|
if (old_value == new_value) return;
|
|
if (!slot->compare_exchange_strong(old_value, new_value,
|
|
std::memory_order_relaxed)) {
|
|
RELEASE_ASSERT(old_value == new_value);
|
|
}
|
|
}
|
|
|
|
void BSS::Initialize(Thread* current, uword* bss_start, bool vm) {
|
|
// TODO(https://dartbug.com/52579): Remove.
|
|
InitializeBSSEntry(Relocation::DLRT_GetFfiCallbackMetadata,
|
|
reinterpret_cast<uword>(DLRT_GetFfiCallbackMetadata),
|
|
bss_start);
|
|
InitializeBSSEntry(Relocation::DLRT_ExitTemporaryIsolate,
|
|
reinterpret_cast<uword>(DLRT_ExitTemporaryIsolate),
|
|
bss_start);
|
|
InitializeBSSEntry(
|
|
Relocation::DLRT_ExitIsolateGroupSharedIsolate,
|
|
reinterpret_cast<uword>(DLRT_ExitIsolateGroupSharedIsolate), bss_start);
|
|
}
|
|
|
|
} // namespace dart
|