Skip to content

Commit af9d821

Browse files
legendecasrichardlau
authored andcommitted
deps: V8: cherry-pick b95354290941
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 <[email protected]> Reviewed-by: Marja Hölttä <[email protected]> Commit-Queue: Chengzhong Wu <[email protected]> Cr-Commit-Position: refs/heads/main@{#79425} Refs: v8/v8@b953542 PR-URL: #44947 Refs: v8/v8@bbd800c Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 42e9d80 commit af9d821

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

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

4242
##### V8 defaults for Node.js #####
4343

deps/v8/src/extensions/statistics-extension.cc

+25-20
Original file line numberDiff line numberDiff line change
@@ -124,36 +124,41 @@ void StatisticsExtension::GetCounters(
124124

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

129-
DisallowGarbageCollection no_gc;
130-
HeapObjectIterator iterator(
131-
reinterpret_cast<Isolate*>(args.GetIsolate())->heap());
132128
int reloc_info_total = 0;
133129
int source_position_table_total = 0;
134-
for (HeapObject obj = iterator.Next(); !obj.is_null();
135-
obj = iterator.Next()) {
136-
Object maybe_source_positions;
137-
if (obj.IsCode()) {
138-
Code code = Code::cast(obj);
139-
reloc_info_total += code.relocation_info().Size();
140-
maybe_source_positions = code.source_position_table();
141-
} else if (obj.IsBytecodeArray()) {
142-
maybe_source_positions =
143-
BytecodeArray::cast(obj).source_position_table(kAcquireLoad);
144-
} else {
145-
continue;
130+
{
131+
HeapObjectIterator iterator(
132+
reinterpret_cast<Isolate*>(args.GetIsolate())->heap());
133+
DCHECK(!AllowGarbageCollection::IsAllowed());
134+
for (HeapObject obj = iterator.Next(); !obj.is_null();
135+
obj = iterator.Next()) {
136+
Object maybe_source_positions;
137+
if (obj.IsCode()) {
138+
Code code = Code::cast(obj);
139+
reloc_info_total += code.relocation_info().Size();
140+
// Baseline code doesn't have source positions since it uses
141+
// interpreter code positions.
142+
if (code.kind() == CodeKind::BASELINE) continue;
143+
maybe_source_positions = code.source_position_table();
144+
} else if (obj.IsBytecodeArray()) {
145+
maybe_source_positions =
146+
BytecodeArray::cast(obj).source_position_table(kAcquireLoad);
147+
} else {
148+
continue;
149+
}
150+
if (!maybe_source_positions.IsByteArray()) continue;
151+
ByteArray source_positions = ByteArray::cast(maybe_source_positions);
152+
if (source_positions.length() == 0) continue;
153+
source_position_table_total += source_positions.Size();
146154
}
147-
if (!maybe_source_positions.IsByteArray()) continue;
148-
ByteArray source_positions = ByteArray::cast(maybe_source_positions);
149-
if (source_positions.length() == 0) continue;
150-
source_position_table_total += source_positions.Size();
151155
}
152156

153157
AddNumber(args.GetIsolate(), result, reloc_info_total,
154158
"reloc_info_total_size");
155159
AddNumber(args.GetIsolate(), result, source_position_table_total,
156160
"source_position_table_total_size");
161+
args.GetReturnValue().Set(result);
157162
}
158163

159164
} // namespace internal

deps/v8/src/flags/flag-definitions.h

+1
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@ DEFINE_STRING(expose_gc_as, nullptr,
13901390
DEFINE_IMPLICATION(expose_gc_as, expose_gc)
13911391
DEFINE_BOOL(expose_externalize_string, false,
13921392
"expose externalize string extension")
1393+
DEFINE_BOOL(expose_statistics, false, "expose statistics extension")
13931394
DEFINE_BOOL(expose_trigger_failure, false, "expose trigger-failure extension")
13941395
DEFINE_BOOL(expose_ignition_statistics, false,
13951396
"expose ignition-statistics extension (requires building with "

deps/v8/src/init/bootstrapper.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5089,7 +5089,7 @@ bool Genesis::InstallExtensions(Isolate* isolate,
50895089
InstallExtension(isolate, "v8/gc", &extension_states)) &&
50905090
(!FLAG_expose_externalize_string ||
50915091
InstallExtension(isolate, "v8/externalize", &extension_states)) &&
5092-
(!TracingFlags::is_gc_stats_enabled() ||
5092+
(!(FLAG_expose_statistics || TracingFlags::is_gc_stats_enabled()) ||
50935093
InstallExtension(isolate, "v8/statistics", &extension_states)) &&
50945094
(!FLAG_expose_trigger_failure ||
50955095
InstallExtension(isolate, "v8/trigger-failure", &extension_states)) &&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2022 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --expose-statistics
6+
7+
assertEquals(typeof getV8Statistics, 'function');
8+
var result = getV8Statistics();
9+
assertEquals(typeof result, 'object');
10+
for (let key of Object.keys(result)) {
11+
assertEquals(typeof result[key], 'number');
12+
}

0 commit comments

Comments
 (0)