Bug 107425 - Web Inspector: heap profiler shows nodes with distance 0
Summary: Web Inspector: heap profiler shows nodes with distance 0
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (Deprecated) (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Yury Semikhatsky
URL:
Keywords:
Depends on: 100140
Blocks:
  Show dependency treegraph
 
Reported: 2013-01-21 00:17 PST by Yury Semikhatsky
Modified: 2019-11-13 14:21 PST (History)
10 users (show)

See Also:


Attachments
Patch (5.73 KB, patch)
2013-01-23 06:25 PST, Yury Semikhatsky
no flags Details | Formatted Diff | Diff
Patch (5.60 KB, patch)
2013-01-23 06:56 PST, Yury Semikhatsky
pfeldman: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yury Semikhatsky 2013-01-21 00:17:11 PST
In some cases we see nodes with distance 0 retaining nodes with distance e.g. 7 All retainers of nodes with distance N should have distance >=N-1.
Comment 1 Yury Semikhatsky 2013-01-22 23:43:36 PST
It was likely broken in https://bugs.webkit.org/show_bug.cgi?id=100140 where 
v8::V8::SetGlobalGCPrologueCallback(&V8GCController::gcPrologue) call was replaced with v8::V8::AddGCPrologueCallback(&V8GCController::gcPrologue). Now heap profiler is not aware of the implicit references between DOM node wrappers and event listener functions. Such functions end up as having only weak handle to them and break heap profiler which doesn't expect any alive objects without strong references. The functions appear as having no retainers.
Comment 2 Yury Semikhatsky 2013-01-23 01:51:06 PST
Patch sent to v8: https://codereview.chromium.org/11953043/
Comment 3 Yury Semikhatsky 2013-01-23 06:25:07 PST
Created attachment 184217 [details]
Patch
Comment 4 Ilya Tikhonovsky 2013-01-23 06:41:26 PST
Comment on attachment 184217 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=184217&action=review

> Source/WebCore/inspector/front-end/JSHeapSnapshot.js:240
> +            var edgeType = containmentEdges[edgeIndex + edgeTypeOffset];
> +            var nodeOrdinal;
> +            if (edgeType === edgeShortcutType)
> +                nodeOrdinal = containmentEdges[edgeIndex + edgeToNodeOffset] / nodeFieldCount;
> +            else if (edgeType === edgeElementType) {
> +                node.nodeIndex = containmentEdges[edgeIndex + edgeToNodeOffset];
> +                if (node.isDocumentDOMTreesRoot())
> +                    nodeOrdinal = node.nodeIndex / nodeFieldCount;
> +                else
> +                    continue;
> +            } else
> +                continue;
> +            nodesToVisit[nodesToVisitLength++] = nodeOrdinal;
> +            flags[nodeOrdinal] |= visitedMarker;

I'd invert the conditions:

var edgeType = containmentEdges[edgeIndex + edgeTypeOffset];
var nodeIndex = containmentEdges[edgeIndex + edgeToNodeOffset];
if (edgeType === edgeElementType) {
    if (!node.isDocumentDOMTreesRoot())
        continue;
} else if (edgeType !== edgeShortcutType)
    continue;
var nodeOrdinal = nodeIndex / nodeFieldCount;
nodesToVisit[nodesToVisitLength++] = nodeOrdinal;
flags[nodeOrdinal] |= visitedMarker;
Comment 5 Alexei Filippov 2013-01-23 06:46:33 PST
Comment on attachment 184217 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=184217&action=review

> Source/WebCore/inspector/front-end/HeapSnapshot.js:781
> +    distanceForUserRoot: function(node)

How about initialDistance?
Comment 6 Yury Semikhatsky 2013-01-23 06:56:01 PST
Created attachment 184224 [details]
Patch
Comment 7 Yury Semikhatsky 2013-01-23 06:57:10 PST
Comment on attachment 184217 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=184217&action=review

>> Source/WebCore/inspector/front-end/HeapSnapshot.js:781
>> +    distanceForUserRoot: function(node)
> 
> How about initialDistance?

I'd like the method name to reflect that is supposed to be called only on potential user roots. If node is not a user root it should return -1.

>> Source/WebCore/inspector/front-end/JSHeapSnapshot.js:240
>> +            flags[nodeOrdinal] |= visitedMarker;
> 
> I'd invert the conditions:
> 
> var edgeType = containmentEdges[edgeIndex + edgeTypeOffset];
> var nodeIndex = containmentEdges[edgeIndex + edgeToNodeOffset];
> if (edgeType === edgeElementType) {
>     if (!node.isDocumentDOMTreesRoot())
>         continue;
> } else if (edgeType !== edgeShortcutType)
>     continue;
> var nodeOrdinal = nodeIndex / nodeFieldCount;
> nodesToVisit[nodesToVisitLength++] = nodeOrdinal;
> flags[nodeOrdinal] |= visitedMarker;

done.
Comment 8 Yury Semikhatsky 2013-01-23 07:03:33 PST
Committed r140535: <http://trac.webkit.org/changeset/140535>
Comment 9 Yury Semikhatsky 2013-01-24 01:09:27 PST
V8 fix was committed https://code.google.com/p/v8/source/detail?r=13486, we should wait until it is rolled to Chromium and see if the problems disappears.
Comment 10 Brian Burg 2014-12-12 13:29:17 PST
Closing as invalid, as this bug pertains to the old inspector UI and/or its tests.
Please file a new bug (https://www.webkit.org/new-inspector-bug) if the bug/feature/issue is still relevant to WebKit trunk.