Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Tests collectGarbage.
Running test: testCollectGarbage
WeakRef state: WeakRef is cleared after GC.

View File

@ -0,0 +1,30 @@
// Copyright 2020 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: --no-stress-incremental-marking
let {session, contextGroup, Protocol} = InspectorTest.start(
'Tests collectGarbage.');
contextGroup.addScript(`
function createWeakRef() {
globalThis.weak_ref = new WeakRef(new Array(1000).fill(0));
}
function getWeakRef() {
if (!globalThis.weak_ref.deref()) return 'WeakRef is cleared after GC.';
return 'WeakRef is not cleared. GC did not happen?'
}
//# sourceURL=test.js`);
Protocol.Debugger.enable();
Protocol.HeapProfiler.enable();
InspectorTest.runAsyncTestSuite([
async function testCollectGarbage() {
await Protocol.Runtime.evaluate({ expression: 'createWeakRef()' });
await Protocol.HeapProfiler.collectGarbage();
let weak_ref = await Protocol.Runtime.evaluate({ expression: 'getWeakRef()' });
InspectorTest.log(`WeakRef state: ${weak_ref.result.result.value}`);
}
]);

View File

@ -0,0 +1,5 @@
Tests edge labels of objects retained by DevTools.
Running test: testConsoleRetainingPath
Edge from (Global handles) to MyClass1: DevTools console
Edge from (Global handles) to MyClass2: DevTools console

View File

@ -0,0 +1,99 @@
// Copyright 2018 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: --no-stress-incremental-marking
let {session, contextGroup, Protocol} = InspectorTest.start(
'Tests edge labels of objects retained by DevTools.');
const kNodeName = 1;
const kNodeEdgeCount = 4;
const kNodeSize = 6;
const kEdgeName = 1;
const kEdgeTarget = 2;
const kEdgeSize = 3;
function EdgeName(snapshot, edgeIndex) {
return snapshot['strings'][snapshot['edges'][edgeIndex + kEdgeName]];
}
function EdgeTarget(snapshot, edgeIndex) {
return snapshot['edges'][edgeIndex + kEdgeTarget];
}
function EdgeCount(snapshot, nodeIndex) {
return snapshot['nodes'][nodeIndex + kNodeEdgeCount];
}
function NodeName(snapshot, nodeIndex) {
return snapshot['strings'][snapshot['nodes'][nodeIndex + kNodeName]];
}
function NodeEdges(snapshot, nodeIndex) {
let startEdgeIndex = 0;
for (let i = 0; i < nodeIndex; i += kNodeSize) {
startEdgeIndex += EdgeCount(snapshot, i);
}
let endEdgeIndex = startEdgeIndex + EdgeCount(snapshot, nodeIndex);
let result = [];
for (let i = startEdgeIndex; i < endEdgeIndex; ++i) {
result.push(i * kEdgeSize);
}
return result;
}
function NodeByName(snapshot, name) {
let count = snapshot['nodes'].length / kNodeSize;
for (let i = 0; i < count; i++) {
if (NodeName(snapshot, i * kNodeSize) == name) return i * kNodeSize;
}
InspectorTest.log(`Cannot node ${name}`);
return 0;
}
function FindEdge(snapshot, sourceName, targetName) {
let sourceIndex = NodeByName(snapshot, sourceName);
let targetIndex = NodeByName(snapshot, targetName);
let edges = NodeEdges(snapshot, sourceIndex);
for (let edge of edges) {
if (EdgeTarget(snapshot, edge) == targetIndex) return edge;
}
InspectorTest.log(`Cannot find edge between ${sourceName} and ${targetName}`);
return 0;
}
function GlobalHandleEdgeName(snapshot, targetName) {
let edge = FindEdge(snapshot, '(Global handles)', targetName);
let edgeName = EdgeName(snapshot, edge);
// Make the test more robust by skipping the edge index prefix and
// a single space.
return edgeName.substring(edgeName.indexOf('/') + 2);
}
contextGroup.addScript(`
class MyClass1 {};
class MyClass2 {};
//# sourceURL=test.js`);
Protocol.Debugger.enable();
Protocol.HeapProfiler.enable();
InspectorTest.runAsyncTestSuite([
async function testConsoleRetainingPath() {
let snapshot_string = '';
function onChunk(message) {
snapshot_string += message['params']['chunk'];
}
Protocol.HeapProfiler.onAddHeapSnapshotChunk(onChunk)
await Protocol.Runtime.evaluate({ expression: 'new MyClass1();' });
await Protocol.Runtime.evaluate(
{ expression: 'console.log(new MyClass2());' });
await Protocol.HeapProfiler.takeHeapSnapshot({ reportProgress: false })
let snapshot = JSON.parse(snapshot_string);
let edge1 = GlobalHandleEdgeName(snapshot, 'MyClass1');
let edge2 = GlobalHandleEdgeName(snapshot, 'MyClass2');
InspectorTest.log(`Edge from (Global handles) to MyClass1: ${edge1}`);
InspectorTest.log(`Edge from (Global handles) to MyClass2: ${edge2}`);
}
]);

View File

@ -0,0 +1,7 @@
Tests weakness of edges from JSWeakRef and WeakCell.
Running test: testHeapSnapshotJSWeakRefs
WeakRef target edge type: weak
WeakCell target edge type: weak
WeakCell holdings edge type: hidden
WeakCell unregister token edge type: weak

View File

@ -0,0 +1,131 @@
// 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: --no-stress-incremental-marking
let {session, contextGroup, Protocol} = InspectorTest.start(
'Tests weakness of edges from JSWeakRef and WeakCell.');
const kNodeName = 1;
const kNodeEdgeCount = 4;
const kNodeSize = 6;
const kEdgeType = 0;
const kEdgeName = 1;
const kEdgeTarget = 2;
const kEdgeSize = 3;
function EdgeName(snapshot, edgeIndex) {
return snapshot['strings'][snapshot['edges'][edgeIndex + kEdgeName]];
}
function EdgeTarget(snapshot, edgeIndex) {
return snapshot['edges'][edgeIndex + kEdgeTarget];
}
function EdgeType(snapshot, edgeIndex) {
return snapshot['edges'][edgeIndex + kEdgeType];
}
function EdgeCount(snapshot, nodeIndex) {
return snapshot['nodes'][nodeIndex + kNodeEdgeCount];
}
function NodeName(snapshot, nodeIndex) {
return snapshot['strings'][snapshot['nodes'][nodeIndex + kNodeName]];
}
function NodeEdges(snapshot, nodeIndex) {
let startEdgeIndex = 0;
for (let i = 0; i < nodeIndex; i += kNodeSize) {
startEdgeIndex += EdgeCount(snapshot, i);
}
let endEdgeIndex = startEdgeIndex + EdgeCount(snapshot, nodeIndex);
let result = [];
for (let i = startEdgeIndex; i < endEdgeIndex; ++i) {
result.push(i * kEdgeSize);
}
return result;
}
function NodeByName(snapshot, name, start = 0) {
let count = snapshot['nodes'].length / kNodeSize;
for (let i = start; i < count; i++) {
if (NodeName(snapshot, i * kNodeSize) == name) return i * kNodeSize;
}
InspectorTest.log(`Cannot find node ${name}`);
return 0;
}
function FindEdge(snapshot, sourceIndex, targetName) {
let edges = NodeEdges(snapshot, sourceIndex);
for (let edge of edges) {
let target = EdgeTarget(snapshot, edge);
if (NodeName(snapshot, target) == targetName) return edge;
}
InspectorTest.log(
`Cannot find edge between ${sourceIndex} and ${targetName}`);
return 0;
}
function EdgeByName(snapshot, name, start = 0) {
let count = snapshot.edges.length / kEdgeSize;
for (let i = start; i < count; i++) {
if (EdgeName(snapshot, i * kEdgeSize) == name) return i * kEdgeSize;
}
InspectorTest.log(`Cannot find edge ${name}`);
return 0;
}
function EdgeTypeString(snapshot, edgeIndex) {
return snapshot.snapshot.meta.edge_types[0][EdgeType(snapshot, edgeIndex)];
}
contextGroup.addScript(`
class Class1 {}
class Class2 {}
class Class3 {}
class Class4 {}
var class1Instance = new Class1();
var class2Instance = new Class2();
var class3Instance = new Class3();
var class4Instance = new Class4();
var weakRef = new WeakRef(class1Instance);
var finalizationRegistry = new FinalizationRegistry(()=>{});
finalizationRegistry.register(class2Instance, class3Instance, class4Instance);
//# sourceURL=test.js`);
Protocol.HeapProfiler.enable();
InspectorTest.runAsyncTestSuite([
async function testHeapSnapshotJSWeakRefs() {
let snapshot_string = '';
function onChunk(message) {
snapshot_string += message['params']['chunk'];
}
Protocol.HeapProfiler.onAddHeapSnapshotChunk(onChunk)
await Protocol.HeapProfiler.takeHeapSnapshot({ reportProgress: false })
let snapshot = JSON.parse(snapshot_string);
// There should be a single edge named "weakRef", representing the global
// variable of that name. It contains a weak ref to an instance of Class1.
let weakRef = EdgeTarget(snapshot, EdgeByName(snapshot, "weakRef"));
let edge = FindEdge(snapshot, weakRef, "Class1");
let edgeType = EdgeTypeString(snapshot, edge);
InspectorTest.log(`WeakRef target edge type: ${edgeType}`);
// There should be a WeakCell representing the item registered in the
// FinalizationRegistry. It retains the holdings strongly, but has weak
// references to the target and unregister token.
let weakCell = NodeByName(snapshot, "system / WeakCell");
edge = FindEdge(snapshot, weakCell, "Class2");
edgeType = EdgeTypeString(snapshot, edge);
InspectorTest.log(`WeakCell target edge type: ${edgeType}`);
edge = FindEdge(snapshot, weakCell, "Class3");
edgeType = EdgeTypeString(snapshot, edge);
InspectorTest.log(`WeakCell holdings edge type: ${edgeType}`);
edge = FindEdge(snapshot, weakCell, "Class4");
edgeType = EdgeTypeString(snapshot, edge);
InspectorTest.log(`WeakCell unregister token edge type: ${edgeType}`);
}
]);

View File

@ -0,0 +1,8 @@
Checks sampling heap profiler methods.
Expected error: V8 sampling heap profiler was not started.
Allocated size is zero in the beginning: true
Allocated size is more than 100KB after a chunk is allocated: true
Allocated size increased after one more chunk is allocated: true
Allocated size did not change after stopping: true
Sample found: true
Successfully finished

View File

@ -0,0 +1,6 @@
Checks sampling heap profiler methods.
Retained size is less than 15KB: true
Including major GC increases size: true
Minor GC collected more: true
Total allocation is greater than 100KB: true
Successfully finished

View File

@ -0,0 +1,67 @@
// Copyright 2017 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: --sampling-heap-profiler-suppress-randomness
// Flags: --no-stress-incremental-marking
// Flags: --allow-natives-syntax
(async function() {
let {contextGroup, Protocol} = InspectorTest.start('Checks sampling heap profiler methods.');
contextGroup.addScript(`
function generateTrash() {
var arr = new Array(100);
for (var i = 0; i < 3000; ++i) {
var s = {a:i, b: new Array(100).fill(42)};
arr[i % 100] = s;
}
return arr[30];
}
%PrepareFunctionForOptimization(generateTrash);
generateTrash();
%OptimizeFunctionOnNextCall(generateTrash);
generateTrash();
//# sourceURL=test.js`);
Protocol.HeapProfiler.enable();
await Protocol.HeapProfiler.startSampling({
samplingInterval: 1e4,
includeObjectsCollectedByMajorGC: false,
includeObjectsCollectedByMinorGC: false,
});
await Protocol.Runtime.evaluate({ expression: 'generateTrash()' });
const profile1 = await Protocol.HeapProfiler.stopSampling();
const size1 = nodeSize(profile1.result.profile.head);
InspectorTest.log('Retained size is less than 15KB:', size1 < 15000);
await Protocol.HeapProfiler.startSampling({
samplingInterval: 100,
includeObjectsCollectedByMajorGC: true,
includeObjectsCollectedByMinorGC: false,
});
await Protocol.Runtime.evaluate({ expression: 'generateTrash()' });
const profile2 = await Protocol.HeapProfiler.stopSampling();
const size2 = nodeSize(profile2.result.profile.head);
InspectorTest.log('Including major GC increases size:', size1 < size2);
await Protocol.HeapProfiler.startSampling({
samplingInterval: 100,
includeObjectsCollectedByMajorGC: true,
includeObjectsCollectedByMinorGC: true,
});
await Protocol.Runtime.evaluate({ expression: 'generateTrash()' });
const profile3 = await Protocol.HeapProfiler.stopSampling();
const size3 = nodeSize(profile3.result.profile.head);
InspectorTest.log('Minor GC collected more:', size3 > size2);
InspectorTest.log('Total allocation is greater than 100KB:', size3 > 100000);
InspectorTest.log('Successfully finished');
InspectorTest.completeTest();
function nodeSize(node) {
return node.children.reduce((res, child) => res + nodeSize(child),
node.callFrame.functionName === 'generateTrash' ? node.selfSize : 0);
}
})();

View File

@ -0,0 +1,57 @@
// Copyright 2017 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: --sampling-heap-profiler-suppress-randomness
(async function() {
let {contextGroup, Protocol} = InspectorTest.start('Checks sampling heap profiler methods.');
contextGroup.addScript(`
var holder = [];
function allocateChunk() {
holder.push(new Array(100000).fill(42));
}
//# sourceURL=test.js`);
Protocol.HeapProfiler.enable();
const profile0 = await Protocol.HeapProfiler.getSamplingProfile();
InspectorTest.log('Expected error: ' + profile0.error.message);
await Protocol.HeapProfiler.startSampling();
const profile1 = await Protocol.HeapProfiler.getSamplingProfile();
const size1 = nodeSize(profile1.result.profile.head);
InspectorTest.log('Allocated size is zero in the beginning:', size1 === 0);
await Protocol.Runtime.evaluate({ expression: 'allocateChunk()' });
const profile2 = await Protocol.HeapProfiler.getSamplingProfile();
const size2 = nodeSize(profile2.result.profile.head);
InspectorTest.log('Allocated size is more than 100KB after a chunk is allocated:', size2 > 100000);
await Protocol.Runtime.evaluate({ expression: 'allocateChunk()' });
const profile3 = await Protocol.HeapProfiler.getSamplingProfile();
const size3 = nodeSize(profile3.result.profile.head);
InspectorTest.log('Allocated size increased after one more chunk is allocated:', size3 > size2);
const profile4 = await Protocol.HeapProfiler.stopSampling();
const size4 = nodeSize(profile4.result.profile.head);
InspectorTest.log('Allocated size did not change after stopping:', size4 === size3);
const sample = profile4.result.profile.samples.find(s => s.size > 400000);
const hasSample = hasNode(n => n.id === sample.nodeId && n.callFrame.functionName === 'allocateChunk',
profile4.result.profile.head);
InspectorTest.log('Sample found: ' + hasSample);
InspectorTest.log('Successfully finished');
InspectorTest.completeTest();
function nodeSize(node) {
return node.children.reduce((res, child) => res + nodeSize(child),
node.callFrame.functionName === 'allocateChunk' ? node.selfSize : 0);
}
function hasNode(predicate, node) {
return predicate(node) || node.children.some(hasNode.bind(null, predicate));
}
})();

View File

@ -0,0 +1,2 @@
Checks that takeHeapSnapshot uses empty accessing_context for access checks.
Successfully finished

View File

@ -0,0 +1,24 @@
// Copyright 2017 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.
let {session, contextGroup, Protocol} = InspectorTest.start('Checks that takeHeapSnapshot uses empty accessing_context for access \
checks.');
contextGroup.addScript(`
function testFunction() {
var array = [ inspector.createObjectWithStrictCheck() ];
debugger;
}
//# sourceURL=test.js`);
Protocol.Debugger.onScriptParsed(message => {
Protocol.HeapProfiler.takeHeapSnapshot({ reportProgress: false })
.then(() => Protocol.Debugger.resume());
});
Protocol.Debugger.enable();
Protocol.HeapProfiler.enable();
Protocol.Runtime.evaluate({ expression: 'testFunction()' })
.then(() => InspectorTest.log('Successfully finished'))
.then(InspectorTest.completeTest);