[cppgc-js] Allow overriding marking support

Adds flags to allow overriding marking support. This adds
compatibility with EmbedderHeapTracer which allows for disabling
incremental marking support with `--no-incremental-marking-wrappers`.

The corresponding CppHeap flags are
* `--cppheap-incremental-marking`
* `--cppheap-concurrent-marking`

This allows embedders that use types that do not support incremental
and concurrent marking to switch from EmbedderHeapTracer to CppHeap.

Bug: v8:13207
Change-Id: I74bdf8ef4be3f6aed8d4d587ea4399546ba2fda4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3840939
Reviewed-by: Dominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82652}
This commit is contained in:
Michael Lippautz 2022-08-23 11:04:58 +02:00 committed by V8 LUCI CQ
parent 545ebe4a82
commit 2115ba5053
6 changed files with 35 additions and 19 deletions

View File

@ -1479,6 +1479,15 @@ DEFINE_BOOL(clear_free_memory, false, "initialize free memory with 0")
DEFINE_BOOL(crash_on_aborted_evacuation, false,
"crash when evacuation of page fails")
// v8::CppHeap flags that allow fine-grained control of how C++ memory is
// reclaimed in the garbage collector.
DEFINE_BOOL(cppheap_incremental_marking, false,
"use incremental marking for CppHeap")
DEFINE_WEAK_IMPLICATION(incremental_marking, cppheap_incremental_marking)
DEFINE_BOOL(cppheap_concurrent_marking, false,
"use concurrent marking for CppHeap")
DEFINE_WEAK_IMPLICATION(concurrent_marking, cppheap_concurrent_marking)
// assembler-ia32.cc / assembler-arm.cc / assembler-arm64.cc / assembler-x64.cc
#ifdef V8_ENABLE_DEBUG_CODE
DEFINE_BOOL(debug_code, DEBUG_BOOL,
@ -2296,6 +2305,7 @@ DEFINE_NEG_IMPLICATION(single_threaded_gc, parallel_pointer_update)
DEFINE_NEG_IMPLICATION(single_threaded_gc, parallel_scavenge)
DEFINE_NEG_IMPLICATION(single_threaded_gc, concurrent_array_buffer_sweeping)
DEFINE_NEG_IMPLICATION(single_threaded_gc, stress_concurrent_allocation)
DEFINE_NEG_IMPLICATION(single_threaded_gc, cppheap_concurrent_marking)
// Web snapshots: 1) expose WebSnapshot.* API 2) interpret scripts as web
// snapshots if they start with a magic number.

View File

@ -478,10 +478,10 @@ CppHeap::CppHeap(
std::make_shared<CppgcPlatformAdapter>(platform), custom_spaces,
cppgc::internal::HeapBase::StackSupport::
kSupportsConservativeStackScan,
// Default marking and sweeping types are only incremental. The types
// Default marking and sweeping types are only atomic. The types
// are updated respecting flags only on GC as the flags are not set
// properly during heap setup.
MarkingType::kIncremental, SweepingType::kIncremental),
MarkingType::kAtomic, SweepingType::kAtomic),
wrapper_descriptor_(wrapper_descriptor) {
CHECK_NE(WrapperDescriptor::kUnknownEmbedderId,
wrapper_descriptor_.embedder_id_for_garbage_collected);
@ -579,12 +579,14 @@ CppHeap::SweepingType CppHeap::SelectSweepingType() const {
}
void CppHeap::UpdateSupportedGCTypesFromFlags() {
// Keep the selection simple for now as production configurations do not turn
// off parallel and/or concurrent marking independently.
if (!FLAG_parallel_marking || !FLAG_concurrent_marking) {
CHECK_IMPLIES(FLAG_cppheap_concurrent_marking,
FLAG_cppheap_incremental_marking);
if (FLAG_cppheap_concurrent_marking) {
marking_support_ = MarkingType::kIncrementalAndConcurrent;
} else if (FLAG_cppheap_incremental_marking) {
marking_support_ = MarkingType::kIncremental;
} else {
marking_support_ = MarkingType::kIncrementalAndConcurrent;
marking_support_ = MarkingType::kAtomic;
}
sweeping_support_ = FLAG_single_threaded_gc

View File

@ -101,10 +101,8 @@ void LocalEmbedderHeapTracer::EnterFinalPause() {
bool LocalEmbedderHeapTracer::Trace(double max_duration) {
if (!InUse()) return true;
if (cpp_heap_)
return cpp_heap()->AdvanceTracing(max_duration);
else
return remote_tracer_->AdvanceTracing(max_duration);
return cpp_heap_ ? cpp_heap_->AdvanceTracing(max_duration)
: remote_tracer_->AdvanceTracing(max_duration);
}
bool LocalEmbedderHeapTracer::IsRemoteTracingDone() {

View File

@ -108,8 +108,18 @@ class V8_EXPORT_PRIVATE LocalEmbedderHeapTracer final {
bool IsRemoteTracingDone();
bool ShouldFinalizeIncrementalMarking() {
return !FLAG_incremental_marking_wrappers || !InUse() ||
(IsRemoteTracingDone() && embedder_worklist_empty_);
// Covers cases where no remote tracer is in use or the flags for
// incremental marking have been disabled.
if (!SupportsIncrementalEmbedderSteps()) return true;
return IsRemoteTracingDone() && embedder_worklist_empty_;
}
bool SupportsIncrementalEmbedderSteps() const {
if (!InUse()) return false;
return cpp_heap_ ? FLAG_cppheap_incremental_marking
: FLAG_incremental_marking_wrappers;
}
void SetEmbedderWorklistEmpty(bool is_empty) {

View File

@ -452,7 +452,9 @@ void IncrementalMarking::UpdateMarkedBytesAfterScavenge(
void IncrementalMarking::EmbedderStep(double expected_duration_ms,
double* duration_ms) {
if (!ShouldDoEmbedderStep()) {
DCHECK(IsMarking());
if (!heap_->local_embedder_heap_tracer()
->SupportsIncrementalEmbedderSteps()) {
*duration_ms = 0.0;
return;
}
@ -607,11 +609,6 @@ bool IncrementalMarking::TryInitializeTaskTimeout() {
}
}
bool IncrementalMarking::ShouldDoEmbedderStep() {
return IsRunning() && FLAG_incremental_marking_wrappers &&
heap_->local_embedder_heap_tracer()->InUse();
}
void IncrementalMarking::FastForwardSchedule() {
if (scheduled_bytes_to_mark_ < bytes_marked_) {
scheduled_bytes_to_mark_ = bytes_marked_;

View File

@ -173,7 +173,6 @@ class V8_EXPORT_PRIVATE IncrementalMarking final {
void StartMarking();
bool ShouldDoEmbedderStep();
void EmbedderStep(double expected_duration_ms, double* duration_ms);
void StartBlackAllocation();