Skip to content

Commit 8f531db

Browse files
committed
Merge branch 'master' into graal
2 parents 74099a5 + 339ad23 commit 8f531db

File tree

11 files changed

+320
-101
lines changed

11 files changed

+320
-101
lines changed

visualvm/heapviewer/nbproject/project.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<package>org.graalvm.visualvm.heapviewer.model</package>
153153
<package>org.graalvm.visualvm.heapviewer.ui</package>
154154
<package>org.graalvm.visualvm.heapviewer.utils</package>
155+
<package>org.graalvm.visualvm.heapviewer.utils.counters</package>
155156
</friend-packages>
156157
</data>
157158
</configuration>

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/java/InstanceNode.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package org.graalvm.visualvm.heapviewer.java;
2727

28+
import java.util.Objects;
2829
import org.graalvm.visualvm.lib.jfluid.heap.GCRoot;
2930
import org.graalvm.visualvm.lib.jfluid.heap.Heap;
3031
import org.graalvm.visualvm.lib.jfluid.heap.Instance;
@@ -176,4 +177,53 @@ protected void setupCopy(InstanceNode copy) {
176177
copy.logicalValue = logicalValue;
177178
}
178179

180+
181+
public static class IncludingNull extends InstanceNode {
182+
183+
public IncludingNull(Instance instance) {
184+
super(instance);
185+
}
186+
187+
public JavaClass getJavaClass() {
188+
if (getInstance() == null) return null;
189+
else return super.getJavaClass();
190+
}
191+
192+
public String getName(Heap heap) {
193+
if (getInstance() == null) return "null"; // NOI18N
194+
else return super.getName(heap);
195+
}
196+
197+
public String getLogicalValue(Heap heap) {
198+
if (getInstance() == null) return DataType.LOGICAL_VALUE.getNoValue();
199+
else return super.getLogicalValue(heap);
200+
}
201+
202+
public long getOwnSize() {
203+
if (getInstance() == null) return DataType.OWN_SIZE.getNoValue();
204+
else return super.getOwnSize();
205+
}
206+
207+
public long getRetainedSize(Heap heap) {
208+
if (getInstance() == null) return DataType.RETAINED_SIZE.valuesAvailable(heap) ?
209+
DataType.RETAINED_SIZE.getNoValue() : DataType.RETAINED_SIZE.getNotAvailableValue();
210+
else return super.getRetainedSize(heap);
211+
}
212+
213+
public boolean equals(Object o) {
214+
if (o == this) return true;
215+
if (!(o instanceof InstanceNode)) return false;
216+
return Objects.equals(getInstance(), ((InstanceNode)o).getInstance());
217+
}
218+
219+
public int hashCode() {
220+
return getInstance() == null ? 37 : super.hashCode();
221+
}
222+
223+
public boolean isLeaf() {
224+
return getInstance() == null ? true : super.isLeaf();
225+
}
226+
227+
}
228+
179229
}

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/java/InstanceReferenceNode.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@
2626
package org.graalvm.visualvm.heapviewer.java;
2727

2828
import org.graalvm.visualvm.lib.jfluid.heap.ArrayItemValue;
29-
import org.graalvm.visualvm.lib.jfluid.heap.Heap;
3029
import org.graalvm.visualvm.lib.jfluid.heap.Instance;
31-
import org.graalvm.visualvm.lib.jfluid.heap.JavaClass;
3230
import org.graalvm.visualvm.lib.jfluid.heap.ObjectFieldValue;
3331
import org.graalvm.visualvm.lib.jfluid.heap.Value;
34-
import org.graalvm.visualvm.heapviewer.model.DataType;
3532
import org.openide.util.NbBundle;
3633

3734
/**
@@ -42,7 +39,7 @@
4239
"InstanceReferenceNode_NodeNameField={0} {1}",
4340
"InstanceReferenceNode_NodeNameReference={0} in {1}"
4441
})
45-
public abstract class InstanceReferenceNode extends InstanceNode {
42+
public abstract class InstanceReferenceNode extends InstanceNode.IncludingNull {
4643

4744
private final Mode mode;
4845
private final Value value;
@@ -89,29 +86,6 @@ public String getFieldName() {
8986

9087
protected abstract String computeFieldName();
9188

92-
public JavaClass getJavaClass() {
93-
return getInstance() == null ? null : super.getJavaClass();
94-
}
95-
96-
public String getName(Heap heap) {
97-
return getInstance() == null ? "null" : super.getName(heap); // NOI18N
98-
}
99-
100-
public String getLogicalValue(Heap heap) {
101-
return getInstance() == null ? "" : super.getLogicalValue(heap); // NOI18N
102-
}
103-
104-
public long getOwnSize() {
105-
return getInstance() == null ? DataType.OWN_SIZE.getNoValue() : super.getOwnSize();
106-
}
107-
108-
public long getRetainedSize(Heap heap) {
109-
return getInstance() == null ? DataType.RETAINED_SIZE.getNoValue() : super.getRetainedSize(heap);
110-
}
111-
112-
public boolean isLeaf() {
113-
return getInstance() == null ? true : super.isLeaf();
114-
}
11589

11690
public String toString() {
11791
// TODO: should not be called directly when sorting the tree

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/java/impl/JavaFieldsPlugin.java

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.graalvm.visualvm.heapviewer.ui.TreeTableView;
6565
import org.graalvm.visualvm.heapviewer.ui.TreeTableViewColumn;
6666
import org.graalvm.visualvm.heapviewer.ui.UIThresholds;
67+
import org.graalvm.visualvm.heapviewer.utils.ExcludingIterator;
6768
import org.graalvm.visualvm.heapviewer.utils.NodesComputer;
6869
import org.graalvm.visualvm.heapviewer.utils.ProgressIterator;
6970
import org.graalvm.visualvm.heapviewer.utils.counters.InstanceCounter;
@@ -564,7 +565,7 @@ public boolean isLeaf() {
564565
};
565566
}
566567
protected ProgressIterator<Instance> objectsIterator(int index, Progress progress) {
567-
Iterator<Instance> fieldInstanceIterator = new ExcludingInstancesIterator(instancesIterator()) {
568+
Iterator<Instance> fieldInstanceIterator = new ExcludingIterator<Instance>(instancesIterator()) {
568569
@Override
569570
protected boolean exclude(Instance instance) {
570571
FieldValue value = getValueOfField(instance, fieldName);
@@ -670,7 +671,7 @@ public boolean isLeaf() {
670671
}
671672
protected ProgressIterator<Instance> objectsIterator(int index, Progress progress) {
672673
final Instance _instance = getInstance();
673-
Iterator<Instance> fieldInstanceIterator = new ExcludingInstancesIterator(instancesIterator()) {
674+
Iterator<Instance> fieldInstanceIterator = new ExcludingIterator<Instance>(instancesIterator()) {
674675
@Override
675676
protected boolean exclude(Instance instance) {
676677
FieldValue value = getValueOfField(instance, fieldName);
@@ -777,40 +778,6 @@ public String getShortName() {
777778

778779
}
779780

780-
// copied from org.graalvm.visualvm.heapviewer.truffle.TruffleLanguageHeapFragment
781-
// might become a public API in VisualVM-HeapViewer
782-
protected static abstract class ExcludingInstancesIterator implements Iterator<Instance> {
783-
private final Iterator<Instance> instancesIt;
784-
private Instance next;
785-
786-
protected ExcludingInstancesIterator(Iterator<Instance> it) {
787-
instancesIt = it;
788-
computeNext();
789-
}
790-
791-
@Override
792-
public boolean hasNext() {
793-
return next != null;
794-
}
795-
796-
@Override
797-
public Instance next() {
798-
Instance ret = next;
799-
computeNext();
800-
return ret;
801-
}
802-
803-
private void computeNext() {
804-
while (instancesIt.hasNext()) {
805-
next = instancesIt.next();
806-
if (!exclude(next)) return;
807-
}
808-
next = null;
809-
}
810-
811-
protected abstract boolean exclude(Instance instance);
812-
}
813-
814781

815782
@ServiceProvider(service=HeapViewerRenderer.Provider.class)
816783
public static class FieldsHistogramRendererProvider extends HeapViewerRenderer.Provider {

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/java/impl/JavaReferencesPlugin.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.graalvm.visualvm.heapviewer.ui.TreeTableView;
6464
import org.graalvm.visualvm.heapviewer.ui.TreeTableViewColumn;
6565
import org.graalvm.visualvm.heapviewer.ui.UIThresholds;
66+
import org.graalvm.visualvm.heapviewer.utils.ExcludingIterator;
6667
import org.graalvm.visualvm.heapviewer.utils.NodesComputer;
6768
import org.graalvm.visualvm.heapviewer.utils.ProgressIterator;
6869
import org.graalvm.visualvm.lib.jfluid.heap.JavaClass;
@@ -380,7 +381,7 @@ protected HeapViewerNode createNode(Instance object) {
380381
}
381382
protected ProgressIterator<Instance> objectsIterator(int index, Progress _progress) {
382383
final Instance _instance = getInstance();
383-
Iterator<Instance> fieldInstanceIterator = new ExcludingInstancesIterator(instancesIterator()) {
384+
Iterator<Instance> fieldInstanceIterator = new ExcludingIterator<Instance>(instancesIterator()) {
384385
@Override
385386
protected boolean exclude(Instance instance) {
386387
List<Value> references = instance.getReferences();
@@ -505,41 +506,6 @@ private static Value getDirectReferrer(Instance instance) {
505506
}
506507

507508

508-
// copied from org.graalvm.visualvm.heapviewer.truffle.TruffleLanguageHeapFragment
509-
// might become a public API in VisualVM-HeapViewer
510-
protected static abstract class ExcludingInstancesIterator implements Iterator<Instance> {
511-
private final Iterator<Instance> instancesIt;
512-
private Instance next;
513-
514-
protected ExcludingInstancesIterator(Iterator<Instance> it) {
515-
instancesIt = it;
516-
computeNext();
517-
}
518-
519-
@Override
520-
public boolean hasNext() {
521-
return next != null;
522-
}
523-
524-
@Override
525-
public Instance next() {
526-
Instance ret = next;
527-
computeNext();
528-
return ret;
529-
}
530-
531-
private void computeNext() {
532-
while (instancesIt.hasNext()) {
533-
next = instancesIt.next();
534-
if (!exclude(next)) return;
535-
}
536-
next = null;
537-
}
538-
539-
protected abstract boolean exclude(Instance instance);
540-
}
541-
542-
543509
@ServiceProvider(service=HeapViewerRenderer.Provider.class)
544510
public static class JavaReferencesRendererProvider extends HeapViewerRenderer.Provider {
545511

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package org.graalvm.visualvm.heapviewer.model;
26+
27+
import java.util.Objects;
28+
import org.graalvm.visualvm.lib.jfluid.heap.Heap;
29+
30+
/**
31+
*
32+
* @author Jiri Sedlacek
33+
*/
34+
public class HeapViewerNodeWrapper extends HeapViewerNode {
35+
36+
private final HeapViewerNode node;
37+
38+
39+
public HeapViewerNodeWrapper(HeapViewerNode node) {
40+
this.node = node;
41+
}
42+
43+
44+
public final HeapViewerNode getNode() {
45+
return node;
46+
}
47+
48+
49+
@Override
50+
public boolean equals(Object o) {
51+
if (o == this) return true;
52+
if (!(o instanceof HeapViewerNodeWrapper)) return false;
53+
return Objects.equals(node, ((HeapViewerNodeWrapper)o).node);
54+
}
55+
56+
@Override
57+
public int hashCode() {
58+
return node.hashCode();
59+
}
60+
61+
62+
@Override
63+
public String toString() {
64+
return node.toString();
65+
}
66+
67+
68+
@Override
69+
protected <T> T getValue(DataType<T> type, Heap heap) {
70+
return super.getValue(type, heap);
71+
}
72+
73+
}

0 commit comments

Comments
 (0)