Reland "[heap] Invoke GC callbacks in safepoint for shared GCs"

This is a reland of commit eeed2ebadb

Changes since revert:
- Disable test for builds that don't support shared heap.

Original change's description:
> [heap] Invoke GC callbacks in safepoint for shared GCs
>
> After a shared GC, trigger all registered callbacks while the global
> safepoint is active.
>
> Bug: chromium:1395117
> Change-Id: I16c61533d44fbeddda18414d2256203848420a99
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4079624
> Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
> Commit-Queue: Patrick Thier <pthier@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#84653}

Bug: chromium:1395117
Change-Id: I145dadac39d81342d7fbc2bad8b87f3518b0100e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4081130
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Patrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84687}
This commit is contained in:
pthier 2022-12-06 15:35:20 +01:00 committed by V8 LUCI CQ
parent 4feb9a1c0e
commit c6eb40d762
3 changed files with 28 additions and 0 deletions

View File

@ -1235,6 +1235,19 @@ void Heap::GarbageCollectionEpilogueInSafepoint(GarbageCollector collector) {
GetGCTypeFromGarbageCollector(collector), current_gc_callback_flags_); GetGCTypeFromGarbageCollector(collector), current_gc_callback_flags_);
}); });
if (isolate()->is_shared_heap_isolate()) {
isolate()->global_safepoint()->IterateClientIsolates(
[this, collector](Isolate* client) {
if (client->is_shared_heap_isolate()) return;
client->heap()->safepoint()->IterateLocalHeaps(
[this, collector](LocalHeap* local_heap) {
local_heap->InvokeGCEpilogueCallbacksInSafepoint(
GetGCTypeFromGarbageCollector(collector),
current_gc_callback_flags_);
});
});
}
#define UPDATE_COUNTERS_FOR_SPACE(space) \ #define UPDATE_COUNTERS_FOR_SPACE(space) \
isolate_->counters()->space##_bytes_available()->Set( \ isolate_->counters()->space##_bytes_available()->Set( \
static_cast<int>(space()->Available())); \ static_cast<int>(space()->Available())); \

View File

@ -1821,6 +1821,7 @@
['no_js_shared_memory', { ['no_js_shared_memory', {
'shared-memory/*': [SKIP], 'shared-memory/*': [SKIP],
'regress/regress-crbug-1394741': [SKIP], 'regress/regress-crbug-1394741': [SKIP],
'regress/regress-crbug-1395117': [SKIP],
}], # 'no_js_shared_memory' }], # 'no_js_shared_memory'
############################################################################## ##############################################################################

View File

@ -0,0 +1,14 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --shared-string-table
let o = {}
let json_str = '[{"a": 2.1, "b": 1, "c": "hello"}, {"a": null, "b": 2, "c": {"a": 2.1, "b": 1.1, "c": "hello"}}]';
// Internalize a bunch of strings to trigger a shared GC.
for (let i=0; i<100; i++) {
let str = 'X'.repeat(100) + i;
o[str] = str;
}
JSON.parse('[{"a": 2.1, "b": 1, "c": "hello"}, {"a": null, "b": 2, "c": {"a": 2.1, "b": 1.1, "c": "hello"}}]');