Commit 4c4549ee authored by Dominik Inführ's avatar Dominik Inführ Committed by V8 LUCI CQ

[heap] Fix isolate setup with --shared-space

This CL fixes isolate deserialization such that the first test for
concurrent allocation in the shared spaces already succeeds.

* Allows dereferences for the shared heap and not just for the shared
  isolate.
* Updates shared_heap_object_cache() for --shared-space.
* Sets IN_SHARED_HEAP flag on all shared space pages.

Bug: v8:13267
Change-Id: I912630da34f93e15d2ddef77a45a5e875bdceff0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3902523
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83320}
parent bf28ec63
......@@ -4223,8 +4223,9 @@ bool Isolate::Init(SnapshotData* startup_snapshot_data,
// during deserialization.
base::Optional<base::MutexGuard> clients_guard;
if (shared_isolate_) {
clients_guard.emplace(&shared_isolate_->global_safepoint()->clients_mutex_);
if (Isolate* isolate =
shared_isolate_ ? shared_isolate_ : attach_to_shared_space_isolate) {
clients_guard.emplace(&isolate->global_safepoint()->clients_mutex_);
}
// The main thread LocalHeap needs to be set up when attaching to the shared
......
......@@ -1712,7 +1712,9 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
// shared heap object cache holds objects in shared among Isolates. Otherwise
// this object cache is per-Isolate like the startup object cache.
std::vector<Object>* shared_heap_object_cache() {
if (shared_isolate()) return shared_isolate()->shared_heap_object_cache();
if (has_shared_heap()) {
return &shared_heap_isolate()->shared_heap_object_cache_;
}
return &shared_heap_object_cache_;
}
......
......@@ -51,7 +51,7 @@ bool HandleBase::IsDereferenceAllowed() const {
if (!AllowHandleDereference::IsAllowed()) return false;
// Allocations in the shared heap may be dereferenced by multiple threads.
if (isolate->is_shared()) return true;
if (heap_object.InSharedWritableHeap()) return true;
LocalHeap* local_heap = isolate->CurrentLocalHeap();
......
......@@ -5603,7 +5603,7 @@ void Heap::SetUpSpaces(LinearAllocationArea& new_allocation_info,
shared_allocation_space_ = heap->shared_space_;
shared_lo_allocation_space_ = heap->shared_lo_space_;
DCHECK(!v8_flags.use_map_space);
shared_map_allocation_space_ = heap->shared_space_;
DCHECK_NULL(shared_map_allocation_space_);
} else if (isolate()->shared_isolate()) {
Heap* shared_heap = isolate()->shared_isolate()->heap();
......
......@@ -195,7 +195,10 @@ MemoryChunk::MemoryChunk(Heap* heap, BaseSpace* space, size_t chunk_size,
}
// All pages of a shared heap need to be marked with this flag.
if (heap->IsShared()) SetFlag(MemoryChunk::IN_SHARED_HEAP);
if (heap->IsShared() || owner()->identity() == SHARED_SPACE ||
owner()->identity() == SHARED_LO_SPACE) {
SetFlag(MemoryChunk::IN_SHARED_HEAP);
}
#ifdef DEBUG
ValidateOffsets(this);
......
......@@ -306,7 +306,6 @@ void GlobalSafepoint::AppendClient(Isolate* client) {
client->global_safepoint_next_client_isolate_ = clients_head_;
clients_head_ = client;
client->shared_isolate_ = shared_isolate_;
}
void GlobalSafepoint::RemoveClient(Isolate* client) {
......
......@@ -12,9 +12,10 @@ namespace internal {
void SharedHeapDeserializer::DeserializeIntoIsolate() {
// Don't deserialize into client Isolates. If there are client Isolates, the
// shared heap object cache should already be populated.
DCHECK_IMPLIES(isolate()->shared_isolate() != nullptr,
!isolate()->shared_heap_object_cache()->empty());
if (isolate()->shared_isolate() != nullptr) return;
if (isolate()->has_shared_heap() && !isolate()->is_shared_space_isolate()) {
DCHECK(!isolate()->shared_heap_object_cache()->empty());
return;
}
DCHECK(isolate()->shared_heap_object_cache()->empty());
HandleScope scope(isolate());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment