Commit 931bfd79 authored by yurys@chromium.org's avatar yurys@chromium.org

Always use global indexes for nodes and edges in the heap snapshot representation

- HeapSnapshotNode, HeapSnapshotEdge and HeapSnapshotRetainerEdge now store only reference to HeapSnapshot and global index of corresponding item.
- all index boundaries were moved out of these classes into corresponding iterators

BUG=None

Review URL: https://codereview.chromium.org/207523004

git-svn-id: svn://svn.chromium.org/blink/trunk@169732 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 493a0101
...@@ -33,8 +33,6 @@ Running: heapSnapshotAggregatesTest ...@@ -33,8 +33,6 @@ Running: heapSnapshotAggregatesTest
Running: heapSnapshotFlagsTest Running: heapSnapshotFlagsTest
Running: heapSnapshotArraySliceTest
Running: heapSnapshotNodesProviderTest Running: heapSnapshotNodesProviderTest
Running: heapSnapshotEdgesProviderTest Running: heapSnapshotEdgesProviderTest
......
...@@ -58,12 +58,17 @@ function test() ...@@ -58,12 +58,17 @@ function test()
{ {
var snapshot = InspectorTest.createJSHeapSnapshotMockObject(); var snapshot = InspectorTest.createJSHeapSnapshotMockObject();
var nodeRoot = snapshot.createNode(snapshot._rootNodeIndex); var nodeRoot = snapshot.createNode(snapshot._rootNodeIndex);
var edgesRoot = nodeRoot.rawEdges(); var edgeIterator = new WebInspector.HeapSnapshotEdgeIterator(nodeRoot);
InspectorTest.assertEquals(nodeRoot.edgesCount() * snapshot._edgeFieldsCount, edgesRoot.length, "rawEdges length"); InspectorTest.assertEquals(true, edgeIterator.hasNext(), "has edges");
var edge = snapshot.createEdge(edgesRoot); var edge = edgeIterator.item();
InspectorTest.assertEquals("shortcut", edge.type(), "edge type"); InspectorTest.assertEquals("shortcut", edge.type(), "edge type");
InspectorTest.assertEquals("a", edge.name(), "edge name"); InspectorTest.assertEquals("a", edge.name(), "edge name");
InspectorTest.assertEquals("A", edge.node().name(), "edge node name"); InspectorTest.assertEquals("A", edge.node().name(), "edge node name");
var edgesCount = 0;
for (; edgeIterator.hasNext(); edgeIterator.next())
++edgesCount;
InspectorTest.assertEquals(nodeRoot.edgesCount(), edgesCount, "edges count");
}, },
function heapSnapshotEdgeIteratorTest() function heapSnapshotEdgeIteratorTest()
...@@ -292,19 +297,6 @@ function test() ...@@ -292,19 +297,6 @@ function test()
} }
}, },
function heapSnapshotArraySliceTest()
{
var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.createHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress());
var root = snapshot.rootNode();
var rawEdges = root.rawEdges();
InspectorTest.assertEquals(6, rawEdges.length);
InspectorTest.assertEquals(6, rawEdges.subarray(0).length);
InspectorTest.assertEquals(3, rawEdges.subarray(3).length);
InspectorTest.assertEquals(3, rawEdges.subarray(3, 6).length);
InspectorTest.assertEquals(3, rawEdges.subarray(0, 3).length);
InspectorTest.assertEquals(0, rawEdges.subarray(3, 3).length);
},
function heapSnapshotNodesProviderTest() function heapSnapshotNodesProviderTest()
{ {
var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.createHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress()); var snapshot = new WebInspector.JSHeapSnapshot(InspectorTest.createHeapSnapshotMock(), new WebInspector.HeapSnapshotProgress());
......
...@@ -31,13 +31,12 @@ ...@@ -31,13 +31,12 @@
/** /**
* @constructor * @constructor
* @param {!WebInspector.HeapSnapshot} snapshot * @param {!WebInspector.HeapSnapshot} snapshot
* @param {!Uint32Array} edges
* @param {number=} edgeIndex * @param {number=} edgeIndex
*/ */
WebInspector.HeapSnapshotEdge = function(snapshot, edges, edgeIndex) WebInspector.HeapSnapshotEdge = function(snapshot, edgeIndex)
{ {
this._snapshot = snapshot; this._snapshot = snapshot;
this._edges = edges; this._edges = snapshot._containmentEdges;
this.edgeIndex = edgeIndex || 0; this.edgeIndex = edgeIndex || 0;
} }
...@@ -63,7 +62,7 @@ WebInspector.HeapSnapshotEdge.prototype = { ...@@ -63,7 +62,7 @@ WebInspector.HeapSnapshotEdge.prototype = {
*/ */
clone: function() clone: function()
{ {
return new WebInspector.HeapSnapshotEdge(this._snapshot, this._edges, this.edgeIndex); return new WebInspector.HeapSnapshotEdge(this._snapshot, this.edgeIndex);
}, },
/** /**
...@@ -165,11 +164,12 @@ WebInspector.HeapSnapshotItemIterator.prototype = { ...@@ -165,11 +164,12 @@ WebInspector.HeapSnapshotItemIterator.prototype = {
/** /**
* @constructor * @constructor
* @implements {WebInspector.HeapSnapshotItemIterator} * @implements {WebInspector.HeapSnapshotItemIterator}
* @param {!WebInspector.HeapSnapshotEdge} edge * @param {!WebInspector.HeapSnapshotNode} node
*/ */
WebInspector.HeapSnapshotEdgeIterator = function(edge) WebInspector.HeapSnapshotEdgeIterator = function(node)
{ {
this.edge = edge; this._sourceNode = node;
this.edge = node._snapshot.createEdge(node._edgeIndexesStart());
} }
WebInspector.HeapSnapshotEdgeIterator.prototype = { WebInspector.HeapSnapshotEdgeIterator.prototype = {
...@@ -178,7 +178,7 @@ WebInspector.HeapSnapshotEdgeIterator.prototype = { ...@@ -178,7 +178,7 @@ WebInspector.HeapSnapshotEdgeIterator.prototype = {
*/ */
hasNext: function() hasNext: function()
{ {
return this.edge.edgeIndex < this.edge._edges.length; return this.edge.edgeIndex < this._sourceNode._edgeIndexesEnd();
}, },
/** /**
...@@ -213,16 +213,12 @@ WebInspector.HeapSnapshotEdgeIterator.prototype = { ...@@ -213,16 +213,12 @@ WebInspector.HeapSnapshotEdgeIterator.prototype = {
/** /**
* @constructor * @constructor
* @param {!WebInspector.HeapSnapshot} snapshot
* @param {number} retainerIndex
*/ */
WebInspector.HeapSnapshotRetainerEdge = function(snapshot, retainedNodeIndex, retainerIndex) WebInspector.HeapSnapshotRetainerEdge = function(snapshot, retainerIndex)
{ {
this._snapshot = snapshot; this._snapshot = snapshot;
this._retainedNodeIndex = retainedNodeIndex;
var retainedNodeOrdinal = retainedNodeIndex / snapshot._nodeFieldCount;
this._firstRetainer = snapshot._firstRetainerIndex[retainedNodeOrdinal];
this._retainersCount = snapshot._firstRetainerIndex[retainedNodeOrdinal + 1] - this._firstRetainer;
this.setRetainerIndex(retainerIndex); this.setRetainerIndex(retainerIndex);
} }
...@@ -248,7 +244,7 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = { ...@@ -248,7 +244,7 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = {
*/ */
clone: function() clone: function()
{ {
return new WebInspector.HeapSnapshotRetainerEdge(this._snapshot, this._retainedNodeIndex, this.retainerIndex()); return new WebInspector.HeapSnapshotRetainerEdge(this._snapshot, this.retainerIndex());
}, },
/** /**
...@@ -280,7 +276,7 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = { ...@@ -280,7 +276,7 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = {
*/ */
nodeIndex: function() nodeIndex: function()
{ {
return this._nodeIndex; return this._retainingNodeIndex;
}, },
/** /**
...@@ -292,14 +288,17 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = { ...@@ -292,14 +288,17 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = {
}, },
/** /**
* @param {number} newIndex * @param {number} retainerIndex
*/ */
setRetainerIndex: function(newIndex) setRetainerIndex: function(retainerIndex)
{ {
if (newIndex !== this._retainerIndex) { if (retainerIndex === this._retainerIndex)
this._retainerIndex = newIndex; return;
this.edgeIndex = newIndex; this._retainerIndex = retainerIndex;
} this._globalEdgeIndex = this._snapshot._retainingEdges[retainerIndex];
this._retainingNodeIndex = this._snapshot._retainingNodes[retainerIndex];
this._edgeInstance = null;
this._nodeInstance = null;
}, },
/** /**
...@@ -307,26 +306,20 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = { ...@@ -307,26 +306,20 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = {
*/ */
set edgeIndex(edgeIndex) set edgeIndex(edgeIndex)
{ {
var retainerIndex = this._firstRetainer + edgeIndex; this.setRetainerIndex(edgeIndex);
this._globalEdgeIndex = this._snapshot._retainingEdges[retainerIndex];
this._nodeIndex = this._snapshot._retainingNodes[retainerIndex];
delete this._edgeInstance;
delete this._nodeInstance;
}, },
_node: function() _node: function()
{ {
if (!this._nodeInstance) if (!this._nodeInstance)
this._nodeInstance = this._snapshot.createNode(this._nodeIndex); this._nodeInstance = this._snapshot.createNode(this._retainingNodeIndex);
return this._nodeInstance; return this._nodeInstance;
}, },
_edge: function() _edge: function()
{ {
if (!this._edgeInstance) { if (!this._edgeInstance)
var edgeIndex = this._globalEdgeIndex - this._node()._edgeIndexesStart(); this._edgeInstance = this._snapshot.createEdge(this._globalEdgeIndex);
this._edgeInstance = this._snapshot.createEdge(this._node().rawEdges(), edgeIndex);
}
return this._edgeInstance; return this._edgeInstance;
}, },
...@@ -359,11 +352,15 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = { ...@@ -359,11 +352,15 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = {
/** /**
* @constructor * @constructor
* @implements {WebInspector.HeapSnapshotItemIterator} * @implements {WebInspector.HeapSnapshotItemIterator}
* @param {!WebInspector.HeapSnapshotRetainerEdge} retainer * @param {!WebInspector.HeapSnapshotNode} retainedNode
*/ */
WebInspector.HeapSnapshotRetainerEdgeIterator = function(retainer) WebInspector.HeapSnapshotRetainerEdgeIterator = function(retainedNode)
{ {
this.retainer = retainer; var snapshot = retainedNode._snapshot;
var retainedNodeOrdinal = retainedNode._ordinal();
var retainerIndex = snapshot._firstRetainerIndex[retainedNodeOrdinal];
this._retainersEnd = snapshot._firstRetainerIndex[retainedNodeOrdinal + 1];
this.retainer = snapshot.createRetainingEdge(retainerIndex);
} }
WebInspector.HeapSnapshotRetainerEdgeIterator.prototype = { WebInspector.HeapSnapshotRetainerEdgeIterator.prototype = {
...@@ -372,7 +369,7 @@ WebInspector.HeapSnapshotRetainerEdgeIterator.prototype = { ...@@ -372,7 +369,7 @@ WebInspector.HeapSnapshotRetainerEdgeIterator.prototype = {
*/ */
hasNext: function() hasNext: function()
{ {
return this.retainer.retainerIndex() < this.retainer._retainersCount; return this.retainer.retainerIndex() < this._retainersEnd;
}, },
/** /**
...@@ -475,7 +472,7 @@ WebInspector.HeapSnapshotNode.prototype = { ...@@ -475,7 +472,7 @@ WebInspector.HeapSnapshotNode.prototype = {
*/ */
edges: function() edges: function()
{ {
return new WebInspector.HeapSnapshotEdgeIterator(this._snapshot.createEdge(this.rawEdges(), 0)); return new WebInspector.HeapSnapshotEdgeIterator(this);
}, },
/** /**
...@@ -507,14 +504,6 @@ WebInspector.HeapSnapshotNode.prototype = { ...@@ -507,14 +504,6 @@ WebInspector.HeapSnapshotNode.prototype = {
return this._snapshot._strings[this._name()]; return this._snapshot._strings[this._name()];
}, },
/**
* @return {!Uint32Array}
*/
rawEdges: function()
{
return this._snapshot._containmentEdges.subarray(this._edgeIndexesStart(), this._edgeIndexesEnd());
},
/** /**
* @return {number} * @return {number}
*/ */
...@@ -528,7 +517,7 @@ WebInspector.HeapSnapshotNode.prototype = { ...@@ -528,7 +517,7 @@ WebInspector.HeapSnapshotNode.prototype = {
*/ */
retainers: function() retainers: function()
{ {
return new WebInspector.HeapSnapshotRetainerEdgeIterator(this._snapshot.createRetainingEdge(this.nodeIndex, 0)); return new WebInspector.HeapSnapshotRetainerEdgeIterator(this);
}, },
/** /**
...@@ -1040,12 +1029,20 @@ WebInspector.HeapSnapshot.prototype = { ...@@ -1040,12 +1029,20 @@ WebInspector.HeapSnapshot.prototype = {
throw new Error("Not implemented"); throw new Error("Not implemented");
}, },
createEdge: function(edges, edgeIndex) /**
* @param {number} edgeIndex
* @return {!WebInspector.JSHeapSnapshotEdge}
*/
createEdge: function(edgeIndex)
{ {
throw new Error("Not implemented"); throw new Error("Not implemented");
}, },
createRetainingEdge: function(retainedNodeIndex, retainerIndex) /**
* @param {number} retainerIndex
* @return {!WebInspector.JSHeapSnapshotRetainerEdge}
*/
createRetainingEdge: function(retainerIndex)
{ {
throw new Error("Not implemented"); throw new Error("Not implemented");
}, },
......
...@@ -58,23 +58,23 @@ WebInspector.JSHeapSnapshot.prototype = { ...@@ -58,23 +58,23 @@ WebInspector.JSHeapSnapshot.prototype = {
}, },
/** /**
* @param {!Uint32Array} edges * @override
* @param {number} edgeIndex * @param {number} edgeIndex
* @return {!WebInspector.JSHeapSnapshotEdge} * @return {!WebInspector.JSHeapSnapshotEdge}
*/ */
createEdge: function(edges, edgeIndex) createEdge: function(edgeIndex)
{ {
return new WebInspector.JSHeapSnapshotEdge(this, edges, edgeIndex); return new WebInspector.JSHeapSnapshotEdge(this, edgeIndex);
}, },
/** /**
* @param {number} retainedNodeIndex * @override
* @param {number} retainerIndex * @param {number} retainerIndex
* @return {!WebInspector.JSHeapSnapshotRetainerEdge} * @return {!WebInspector.JSHeapSnapshotRetainerEdge}
*/ */
createRetainingEdge: function(retainedNodeIndex, retainerIndex) createRetainingEdge: function(retainerIndex)
{ {
return new WebInspector.JSHeapSnapshotRetainerEdge(this, retainedNodeIndex, retainerIndex); return new WebInspector.JSHeapSnapshotRetainerEdge(this, retainerIndex);
}, },
/** /**
...@@ -639,12 +639,11 @@ WebInspector.JSHeapSnapshotNode.prototype = { ...@@ -639,12 +639,11 @@ WebInspector.JSHeapSnapshotNode.prototype = {
* @constructor * @constructor
* @extends {WebInspector.HeapSnapshotEdge} * @extends {WebInspector.HeapSnapshotEdge}
* @param {!WebInspector.JSHeapSnapshot} snapshot * @param {!WebInspector.JSHeapSnapshot} snapshot
* @param {!Uint32Array} edges
* @param {number=} edgeIndex * @param {number=} edgeIndex
*/ */
WebInspector.JSHeapSnapshotEdge = function(snapshot, edges, edgeIndex) WebInspector.JSHeapSnapshotEdge = function(snapshot, edgeIndex)
{ {
WebInspector.HeapSnapshotEdge.call(this, snapshot, edges, edgeIndex); WebInspector.HeapSnapshotEdge.call(this, snapshot, edgeIndex);
} }
WebInspector.JSHeapSnapshotEdge.prototype = { WebInspector.JSHeapSnapshotEdge.prototype = {
...@@ -654,7 +653,7 @@ WebInspector.JSHeapSnapshotEdge.prototype = { ...@@ -654,7 +653,7 @@ WebInspector.JSHeapSnapshotEdge.prototype = {
clone: function() clone: function()
{ {
var snapshot = /** @type {!WebInspector.JSHeapSnapshot} */ (this._snapshot); var snapshot = /** @type {!WebInspector.JSHeapSnapshot} */ (this._snapshot);
return new WebInspector.JSHeapSnapshotEdge(snapshot, this._edges, this.edgeIndex); return new WebInspector.JSHeapSnapshotEdge(snapshot, this.edgeIndex);
}, },
/** /**
...@@ -779,10 +778,11 @@ WebInspector.JSHeapSnapshotEdge.prototype = { ...@@ -779,10 +778,11 @@ WebInspector.JSHeapSnapshotEdge.prototype = {
* @constructor * @constructor
* @extends {WebInspector.HeapSnapshotRetainerEdge} * @extends {WebInspector.HeapSnapshotRetainerEdge}
* @param {!WebInspector.JSHeapSnapshot} snapshot * @param {!WebInspector.JSHeapSnapshot} snapshot
* @param {number} retainerIndex
*/ */
WebInspector.JSHeapSnapshotRetainerEdge = function(snapshot, retainedNodeIndex, retainerIndex) WebInspector.JSHeapSnapshotRetainerEdge = function(snapshot, retainerIndex)
{ {
WebInspector.HeapSnapshotRetainerEdge.call(this, snapshot, retainedNodeIndex, retainerIndex); WebInspector.HeapSnapshotRetainerEdge.call(this, snapshot, retainerIndex);
} }
WebInspector.JSHeapSnapshotRetainerEdge.prototype = { WebInspector.JSHeapSnapshotRetainerEdge.prototype = {
...@@ -791,7 +791,8 @@ WebInspector.JSHeapSnapshotRetainerEdge.prototype = { ...@@ -791,7 +791,8 @@ WebInspector.JSHeapSnapshotRetainerEdge.prototype = {
*/ */
clone: function() clone: function()
{ {
return new WebInspector.JSHeapSnapshotRetainerEdge(this._snapshot, this._retainedNodeIndex, this.retainerIndex()); var snapshot = /** @type {!WebInspector.JSHeapSnapshot} */ (this._snapshot);
return new WebInspector.JSHeapSnapshotRetainerEdge(snapshot, this.retainerIndex());
}, },
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment