Skip to content

Commit 990384f

Browse files
committed
deps: V8: cherry-pick 0f024d4e66e0
Original commit message: [heap profiler] Add is_live field to AllocationProfile::Sample When using kSamplingIncludeObjectsCollectedByMajorGC/MinorGC flag, samples for collected objects are retained but callers had no way to distinguish live from dead objects. Add is_live to expose this information. Change-Id: I2e930644348ff942caa4b192a127c5baa05bbfef Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7603535 Reviewed-by: Dominik Inführ <dinfuehr@chromium.org> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Cr-Commit-Position: refs/heads/main@{#105698} Refs: v8/v8@0f024d4
1 parent 4579957 commit 990384f

5 files changed

Lines changed: 86 additions & 2 deletions

File tree

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.13',
41+
'v8_embedder_string': '-node.14',
4242

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

deps/v8/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Huáng Jùnliàng <jlhwung@gmail.com>
155155
HyeockJin Kim <kherootz@gmail.com>
156156
Iain Ireland <iireland@mozilla.com>
157157
Ilya Gavrilin <ilya.gavrilin@syntacore.com>
158+
Ilyas Shabi <ilyasshabi94@gmail.com>
158159
Ingvar Stepanyan <me@rreverser.com>
159160
Ioseb Dzmanashvili <ioseb.dzmanashvili@gmail.com>
160161
Isiah Meadows <impinball@gmail.com>

deps/v8/include/v8-profiler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,12 @@ class V8_EXPORT AllocationProfile {
811811
* what samples were added or removed between two snapshots.
812812
*/
813813
uint64_t sample_id;
814+
815+
/**
816+
* Indicates whether the sampled allocation is still live or has already
817+
* been collected by GC.
818+
*/
819+
bool is_live;
814820
};
815821

816822
/**

deps/v8/src/profiler/sampling-heap-profiler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,10 @@ SamplingHeapProfiler::BuildSamples() const {
312312
samples.reserve(samples_.size());
313313
for (const auto& it : samples_) {
314314
const Sample* sample = it.second.get();
315+
const bool is_live = !sample->global.IsEmpty();
315316
samples.emplace_back(v8::AllocationProfile::Sample{
316317
sample->owner->id_, sample->size, ScaleSample(sample->size, 1).count,
317-
sample->sample_id});
318+
sample->sample_id, is_live});
318319
}
319320
return samples;
320321
}

deps/v8/test/cctest/test-heap-profiler.cc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4442,6 +4442,82 @@ TEST(SamplingHeapProfilerLargeInterval) {
44424442
heap_profiler->StopSamplingHeapProfiler();
44434443
}
44444444

4445+
TEST(SamplingHeapProfilerSampleWithoutGCFlags) {
4446+
v8::HandleScope scope(CcTest::isolate());
4447+
LocalContext env;
4448+
v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
4449+
4450+
// Suppress randomness to avoid flakiness in tests.
4451+
i::v8_flags.sampling_heap_profiler_suppress_randomness = true;
4452+
4453+
heap_profiler->StartSamplingHeapProfiler(1024);
4454+
4455+
// Allocate objects that will be retained
4456+
CompileRun(
4457+
"var retained = [];\n"
4458+
"for (var i = 0; i < 500; i++) retained.push(new Array(10));\n");
4459+
4460+
CompileRun("for (var i = 0; i < 500; i++) new Array(10);\n");
4461+
4462+
std::unique_ptr<v8::AllocationProfile> profile(
4463+
heap_profiler->GetAllocationProfile());
4464+
CHECK(profile);
4465+
4466+
const auto& samples = profile->GetSamples();
4467+
CHECK(!samples.empty());
4468+
4469+
for (const auto& sample : samples) {
4470+
CHECK(sample.is_live);
4471+
}
4472+
4473+
heap_profiler->StopSamplingHeapProfiler();
4474+
}
4475+
4476+
TEST(SamplingHeapProfilerSampleIsLive) {
4477+
v8::HandleScope scope(CcTest::isolate());
4478+
LocalContext env;
4479+
v8::HeapProfiler* heap_profiler = env.isolate()->GetHeapProfiler();
4480+
4481+
// Suppress randomness to avoid flakiness in tests.
4482+
i::v8_flags.sampling_heap_profiler_suppress_randomness = true;
4483+
4484+
heap_profiler->StartSamplingHeapProfiler(
4485+
64, 16,
4486+
static_cast<v8::HeapProfiler::SamplingFlags>(
4487+
v8::HeapProfiler::kSamplingForceGC |
4488+
v8::HeapProfiler::kSamplingIncludeObjectsCollectedByMajorGC));
4489+
4490+
// Allocate objects that will be retained
4491+
CompileRun(
4492+
"var retained = [];\n"
4493+
"for (var i = 0; i < 500; i++) retained.push(new Array(10));\n");
4494+
4495+
CompileRun("for (var i = 0; i < 500; i++) new Array(10);\n");
4496+
4497+
std::unique_ptr<v8::AllocationProfile> profile(
4498+
heap_profiler->GetAllocationProfile());
4499+
CHECK(profile);
4500+
4501+
const auto& samples = profile->GetSamples();
4502+
CHECK(!samples.empty());
4503+
4504+
int live_samples = 0;
4505+
int dead_samples = 0;
4506+
for (const auto& sample : samples) {
4507+
if (sample.is_live) {
4508+
++live_samples;
4509+
} else {
4510+
++dead_samples;
4511+
}
4512+
}
4513+
4514+
// We expect both retained and collected allocations in this profile.
4515+
CHECK_GT(live_samples, 0);
4516+
CHECK_GT(dead_samples, 0);
4517+
4518+
heap_profiler->StopSamplingHeapProfiler();
4519+
}
4520+
44454521
TEST(HeapSnapshotPrototypeNotJSReceiver) {
44464522
LocalContext env;
44474523
v8::HandleScope scope(env.isolate());

0 commit comments

Comments
 (0)