Skip to content

Commit

Permalink
deps: V8: cherry-pick b95354290941
Browse files Browse the repository at this point in the history
Original commit message:

    [extensions] Fix dcheck failures in getV8Statistics

    HeapObjectIterator creates a SafepointScope which requires the heap to
    allow garbage collection. This collides with the outer
    DisallowGarbageCollection scope. HeapObjectIterator already ensures
    there is no allocation during its lifetime, so there is no need to
    create an outer DisallowGarbageCollection scope.

    Code::source_position_table requires their kind not equals to
    CodeKind::BASELINE.

    This also exposes the statistics extension through flag
    --expose-statistics.

    Bug: v8:12657
    Change-Id: I1bf11cf499285a742dd99ec8c228ebc36152b597
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3496552
    Reviewed-by: Camillo Bruni <cbruni@chromium.org>
    Reviewed-by: Marja Hölttä <marja@chromium.org>
    Commit-Queue: Chengzhong Wu <legendecas@gmail.com>
    Cr-Commit-Position: refs/heads/main@{#79425}

Refs: v8/v8@b953542
PR-URL: #44947
Refs: v8/v8@bbd800c
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
  • Loading branch information
legendecas authored and richardlau committed Nov 24, 2022
1 parent 42e9d80 commit af9d821
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Expand Up @@ -37,7 +37,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.22',
'v8_embedder_string': '-node.23',

##### V8 defaults for Node.js #####

Expand Down
45 changes: 25 additions & 20 deletions deps/v8/src/extensions/statistics-extension.cc
Expand Up @@ -124,36 +124,41 @@ void StatisticsExtension::GetCounters(

AddNumber64(args.GetIsolate(), result, heap->external_memory(),
"amount_of_external_allocated_memory");
args.GetReturnValue().Set(result);

DisallowGarbageCollection no_gc;
HeapObjectIterator iterator(
reinterpret_cast<Isolate*>(args.GetIsolate())->heap());
int reloc_info_total = 0;
int source_position_table_total = 0;
for (HeapObject obj = iterator.Next(); !obj.is_null();
obj = iterator.Next()) {
Object maybe_source_positions;
if (obj.IsCode()) {
Code code = Code::cast(obj);
reloc_info_total += code.relocation_info().Size();
maybe_source_positions = code.source_position_table();
} else if (obj.IsBytecodeArray()) {
maybe_source_positions =
BytecodeArray::cast(obj).source_position_table(kAcquireLoad);
} else {
continue;
{
HeapObjectIterator iterator(
reinterpret_cast<Isolate*>(args.GetIsolate())->heap());
DCHECK(!AllowGarbageCollection::IsAllowed());
for (HeapObject obj = iterator.Next(); !obj.is_null();
obj = iterator.Next()) {
Object maybe_source_positions;
if (obj.IsCode()) {
Code code = Code::cast(obj);
reloc_info_total += code.relocation_info().Size();
// Baseline code doesn't have source positions since it uses
// interpreter code positions.
if (code.kind() == CodeKind::BASELINE) continue;
maybe_source_positions = code.source_position_table();
} else if (obj.IsBytecodeArray()) {
maybe_source_positions =
BytecodeArray::cast(obj).source_position_table(kAcquireLoad);
} else {
continue;
}
if (!maybe_source_positions.IsByteArray()) continue;
ByteArray source_positions = ByteArray::cast(maybe_source_positions);
if (source_positions.length() == 0) continue;
source_position_table_total += source_positions.Size();
}
if (!maybe_source_positions.IsByteArray()) continue;
ByteArray source_positions = ByteArray::cast(maybe_source_positions);
if (source_positions.length() == 0) continue;
source_position_table_total += source_positions.Size();
}

AddNumber(args.GetIsolate(), result, reloc_info_total,
"reloc_info_total_size");
AddNumber(args.GetIsolate(), result, source_position_table_total,
"source_position_table_total_size");
args.GetReturnValue().Set(result);
}

} // namespace internal
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/flags/flag-definitions.h
Expand Up @@ -1390,6 +1390,7 @@ DEFINE_STRING(expose_gc_as, nullptr,
DEFINE_IMPLICATION(expose_gc_as, expose_gc)
DEFINE_BOOL(expose_externalize_string, false,
"expose externalize string extension")
DEFINE_BOOL(expose_statistics, false, "expose statistics extension")
DEFINE_BOOL(expose_trigger_failure, false, "expose trigger-failure extension")
DEFINE_BOOL(expose_ignition_statistics, false,
"expose ignition-statistics extension (requires building with "
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/init/bootstrapper.cc
Expand Up @@ -5089,7 +5089,7 @@ bool Genesis::InstallExtensions(Isolate* isolate,
InstallExtension(isolate, "v8/gc", &extension_states)) &&
(!FLAG_expose_externalize_string ||
InstallExtension(isolate, "v8/externalize", &extension_states)) &&
(!TracingFlags::is_gc_stats_enabled() ||
(!(FLAG_expose_statistics || TracingFlags::is_gc_stats_enabled()) ||
InstallExtension(isolate, "v8/statistics", &extension_states)) &&
(!FLAG_expose_trigger_failure ||
InstallExtension(isolate, "v8/trigger-failure", &extension_states)) &&
Expand Down
12 changes: 12 additions & 0 deletions deps/v8/test/mjsunit/statistics-extension.js
@@ -0,0 +1,12 @@
// 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: --expose-statistics

assertEquals(typeof getV8Statistics, 'function');
var result = getV8Statistics();
assertEquals(typeof result, 'object');
for (let key of Object.keys(result)) {
assertEquals(typeof result[key], 'number');
}

0 comments on commit af9d821

Please sign in to comment.