Skip to content

Commit 23c3e3e

Browse files
committed
GH-205 - Enabled Regular Expression filter type in heap viewer: Java Objects, OQL, Truffle Objects
1 parent 7d7b57e commit 23c3e3e

File tree

3 files changed

+55
-84
lines changed

3 files changed

+55
-84
lines changed

visualvm/heapviewer.truffle/src/org/graalvm/visualvm/heapviewer/truffle/ui/FilterUtils.java

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -65,6 +65,7 @@
6565
import org.graalvm.visualvm.heapviewer.model.HeapViewerNodeFilter;
6666
import org.graalvm.visualvm.heapviewer.truffle.TruffleType;
6767
import org.graalvm.visualvm.heapviewer.ui.TreeTableView;
68+
import org.graalvm.visualvm.lib.profiler.api.ProfilerDialogs;
6869
import org.openide.util.NbBundle;
6970

7071
/**
@@ -77,8 +78,10 @@
7778
"TruffleFilterUtils_FilterResults=Filter results ({0})",
7879
"TruffleFilterUtils_MatchCase=Match case",
7980
"TruffleFilterUtils_Close=Close Filter sidebar ({0})",
81+
"TruffleFilterUtils_InvalidRegexp=Entered regular expression is invalid:\n{0}",
8082
"TruffleFilterUtils_FilterContains=Contains",
8183
"TruffleFilterUtils_FilterNotContains=Does Not Contain",
84+
"TruffleFilterUtils_FilterRegExp=Regular Expression",
8285
"TruffleFilterUtils_FilterType=Filter type: {0}",
8386
"TruffleFilterUtils_InsertFilter=Insert Defined Filter"
8487
})
@@ -113,61 +116,13 @@ public static boolean filter(TreeTableView view, final GenericFilter textFilter,
113116

114117
view.setViewFilter(new HeapViewerNodeFilter() {
115118
public boolean passes(HeapViewerNode node, Heap heap) {
116-
// if (!(node instanceof ClassNode)) return true;
117-
//
118-
// JavaClass javaClass = ((ClassNode)node).getJavaClass();
119-
120119
String typeName = HeapViewerNode.getValue(node, TruffleType.TYPE_NAME, heap);
121120
return typeName == null ? true : textFilter.passes(typeName);
122-
// if (javaClass == null) return true;
123-
// if (javaClass.getInstancesCount() == 0) return false;
124-
125-
// String className = javaClass.getName();
126-
// if (textFilter.getType() != TextFilter.TYPE_REGEXP) return textFilter.passes(className);
127-
// else {
128-
// for (String value : textFilter.getValues())
129-
// if (isInstanceOf(javaClass, value)) return true;
130-
// return false;
131-
// }
132121
}
133-
134-
135-
// private boolean isInstanceOf(JavaClass javaClass, String className) {
136-
// if (javaClass != null) {
137-
//// JavaClass superCls = javaClass.getSuperClass();
138-
// JavaClass cls = javaClass;
139-
// for (; cls != null; cls = cls.getSuperClass())
140-
// if (cls.getName().equals(className)) return true;
141-
// }
142-
// return false;
143-
// }
144122
});
145123
return true;
146124
}
147125

148-
// public static void filterSubclasses(String className, JComponent filterPanel) {
149-
// Object filterString = filterPanel.getClientProperty("FILTER_STRING"); // NOI18N
150-
// if (filterString instanceof JTextComponent) {
151-
// ((JTextComponent)filterString).setText(className);
152-
// } else {
153-
// return;
154-
// }
155-
//
156-
// Object filterType = filterPanel.getClientProperty("FILTER_TYPE"); // NOI18N
157-
// if (filterType instanceof FilterType) {
158-
// ((FilterType)filterType).filterImpl(TextFilter.TYPE_REGEXP, Icons.getIcon(LanguageIcons.CLASS), FILTER_REGEXP);
159-
// } else {
160-
// return;
161-
// }
162-
//
163-
// Object filterAction = filterPanel.getClientProperty("FILTER_ACTION"); // NOI18N
164-
// if (filterAction instanceof AbstractAction) {
165-
// ((AbstractAction)filterAction).actionPerformed(null);
166-
// } else {
167-
// return;
168-
// }
169-
// }
170-
171126
public static JComponent createFilterPanel(final TreeTableView view) {
172127
return createFilterPanel(view, null);
173128
}
@@ -238,9 +193,9 @@ protected void fireActionPerformed(ActionEvent event) {
238193
KeyStroke filterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
239194

240195
final TextFilter activeFilter = new TextFilter() {
241-
// protected void handleInvalidFilter(String invalidValue, RuntimeException e) {
242-
// ProfilerDialogs.displayError(MessageFormat.format(MSG_INVALID_REGEXP, invalidValue));
243-
// }
196+
protected void handleInvalidFilter(String invalidValue, RuntimeException e) {
197+
ProfilerDialogs.displayError(Bundle.TruffleFilterUtils_InvalidRegexp(invalidValue));
198+
}
244199
};
245200
final TextFilter currentFilter = new TextFilter();
246201

@@ -314,23 +269,23 @@ protected void fireActionPerformed(ActionEvent e) {
314269
filterImpl(TextFilter.TYPE_EXCLUSIVE, getIcon(), getText());
315270
}
316271
});
317-
// popup.add(new JMenuItem(FILTER_REGEXP, Icons.getIcon(LanguageIcons.CLASS)) {
318-
// protected void fireActionPerformed(ActionEvent e) {
319-
// super.fireActionPerformed(e);
320-
// filterImpl(TextFilter.TYPE_REGEXP, getIcon(), getText());
321-
// }
322-
// });
272+
popup.add(new JMenuItem(Bundle.TruffleFilterUtils_FilterRegExp(), Icons.getIcon(GeneralIcons.FILTER_REG_EXP)) {
273+
protected void fireActionPerformed(ActionEvent e) {
274+
super.fireActionPerformed(e);
275+
filterImpl(TextFilter.TYPE_REGEXP, getIcon(), getText());
276+
}
277+
});
323278
}
324279
protected void filterImpl(final int type, final Icon icon, final String name) {
325-
// if (type == TextFilter.TYPE_REGEXP) {
326-
// matchCase.setEnabled(false);
327-
// matchCase.setSelected(false);
328-
// } else {
280+
if (type == TextFilter.TYPE_REGEXP) {
281+
matchCase.setEnabled(false);
282+
matchCase.setSelected(false);
283+
} else {
329284
if (!matchCase.isEnabled()) {
330285
matchCase.setSelected(currentFilter.isCaseSensitive());
331286
matchCase.setEnabled(true);
332287
}
333-
// }
288+
}
334289
SwingUtilities.invokeLater(new Runnable() {
335290
public void run() {
336291
setIcon(icon);

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -83,6 +83,7 @@
8383
"JavaFilterUtils_InvalidRegexp=Entered regular expression is invalid:\n{0}",
8484
"JavaFilterUtils_FilterContains=Contains",
8585
"JavaFilterUtils_FilterNotContains=Does Not Contain",
86+
"JavaFilterUtils_FilterRegExp=Regular Expression",
8687
"JavaFilterUtils_FilterSubclass=Subclass Of",
8788
"JavaFilterUtils_FilterType=Filter type: {0}",
8889
"JavaFilterUtils_InsertFilter=Insert Defined Filter",
@@ -97,6 +98,9 @@ final class FilterUtils {
9798
private static final Icon ICON_CLASS_NO_INSTANCES = ImageUtilities.image2Icon(ImageUtilities.loadImage(FilterUtils.class.getPackage().getName().replace('.', '/') + "/classWithoutInstances.png", true));
9899

99100

101+
private static final int FILTER_INSTANCEOF = 100;
102+
103+
100104
// public static boolean filterContains(ProfilerTable table, String filter) {
101105
// return filterContains(table, filter, false, null);
102106
// }
@@ -131,7 +135,7 @@ public boolean passes(HeapViewerNode node, Heap heap) {
131135
if (zeroClassesFilter && HeapViewerNode.getValue(node, DataType.COUNT, heap) == 0) return false;
132136

133137
String className = javaClass.getName();
134-
if (textFilter.getType() != TextFilter.TYPE_REGEXP) return textFilter.passes(className);
138+
if (textFilter.getType() != FILTER_INSTANCEOF) return textFilter.passes(className);
135139
else {
136140
for (String value : textFilter.getValues())
137141
if (isInstanceOf(javaClass, value)) return true;
@@ -163,7 +167,7 @@ public static void filterSubclasses(String className, JComponent filterPanel) {
163167

164168
Object filterType = filterPanel.getClientProperty("FILTER_TYPE"); // NOI18N
165169
if (filterType instanceof FilterType) {
166-
((FilterType)filterType).filterImpl(TextFilter.TYPE_REGEXP, Icons.getIcon(LanguageIcons.CLASS), Bundle.JavaFilterUtils_FilterSubclass());
170+
((FilterType)filterType).filterImpl(FILTER_INSTANCEOF, Icons.getIcon(LanguageIcons.CLASS), Bundle.JavaFilterUtils_FilterSubclass());
167171
} else {
168172
return;
169173
}
@@ -335,15 +339,21 @@ protected void fireActionPerformed(ActionEvent e) {
335339
filterImpl(TextFilter.TYPE_EXCLUSIVE, getIcon(), getText());
336340
}
337341
});
338-
popup.add(new JMenuItem(Bundle.JavaFilterUtils_FilterSubclass(), Icons.getIcon(LanguageIcons.CLASS)) {
342+
popup.add(new JMenuItem(Bundle.JavaFilterUtils_FilterRegExp(), Icons.getIcon(GeneralIcons.FILTER_REG_EXP)) {
339343
protected void fireActionPerformed(ActionEvent e) {
340344
super.fireActionPerformed(e);
341345
filterImpl(TextFilter.TYPE_REGEXP, getIcon(), getText());
342346
}
343347
});
348+
popup.add(new JMenuItem(Bundle.JavaFilterUtils_FilterSubclass(), Icons.getIcon(LanguageIcons.CLASS)) {
349+
protected void fireActionPerformed(ActionEvent e) {
350+
super.fireActionPerformed(e);
351+
filterImpl(FILTER_INSTANCEOF, getIcon(), getText());
352+
}
353+
});
344354
}
345355
protected void filterImpl(final int type, final Icon icon, final String name) {
346-
if (type == TextFilter.TYPE_REGEXP) {
356+
if (type == TextFilter.TYPE_REGEXP || type == FILTER_INSTANCEOF) {
347357
matchCase.setEnabled(false);
348358
matchCase.setSelected(false);
349359
} else {

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/oql/FilterUtils.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -82,6 +82,7 @@
8282
"OQLFilterUtils_InvalidRegexp=Entered regular expression is invalid:\n{0}",
8383
"OQLFilterUtils_FilterContains=Contains",
8484
"OQLFilterUtils_FilterNotContains=Does Not Contain",
85+
"OQLFilterUtils_FilterRegExp=Regular Expression",
8586
"OQLFilterUtils_FilterSubclass=Subclass Of",
8687
"OQLFilterUtils_FilterType=Filter type: {0}",
8788
"OQLFilterUtils_InsertFilter=Insert Defined Filter"
@@ -93,6 +94,9 @@ final class FilterUtils {
9394
private static final String FILTER_CHANGED = "filter-changed"; // NOI18N
9495

9596

97+
private static final int FILTER_INSTANCEOF = 100;
98+
99+
96100
// public static boolean filterContains(ProfilerTable table, String filter) {
97101
// return filterContains(table, filter, false, null);
98102
// }
@@ -117,18 +121,14 @@ public static boolean filter(TreeTableView view, final GenericFilter textFilter,
117121

118122
view.setViewFilter(new HeapViewerNodeFilter() {
119123
public boolean passes(HeapViewerNode node, Heap heap) {
120-
// if (!(node instanceof ClassNode)) return true;
121-
//
122-
// JavaClass javaClass = ((ClassNode)node).getJavaClass();
123-
124-
JavaClass javaClass = HeapViewerNode.getValue(node, DataType.CLASS, heap);
125-
if (javaClass == null) return true;
126-
127-
String className = javaClass.getName();
128-
if (textFilter.getType() != TextFilter.TYPE_REGEXP) return textFilter.passes(className);
129-
else {
130-
for (String value : textFilter.getValues())
131-
if (isInstanceOf(javaClass, value)) return true;
124+
if (textFilter.getType() != FILTER_INSTANCEOF) {
125+
String name = HeapViewerNode.getValue(node, DataType.NAME, heap);
126+
return name == null ? false : textFilter.passes(name);
127+
} else {
128+
JavaClass javaClass = HeapViewerNode.getValue(node, DataType.CLASS, heap);
129+
if (javaClass != null)
130+
for (String value : textFilter.getValues())
131+
if (isInstanceOf(javaClass, value)) return true;
132132
return false;
133133
}
134134
}
@@ -157,7 +157,7 @@ public static void filterSubclasses(String className, JComponent filterPanel) {
157157

158158
Object filterType = filterPanel.getClientProperty("FILTER_TYPE"); // NOI18N
159159
if (filterType instanceof FilterType) {
160-
((FilterType)filterType).filterImpl(TextFilter.TYPE_REGEXP, Icons.getIcon(LanguageIcons.CLASS), Bundle.OQLFilterUtils_FilterSubclass());
160+
((FilterType)filterType).filterImpl(FILTER_INSTANCEOF, Icons.getIcon(LanguageIcons.CLASS), Bundle.OQLFilterUtils_FilterSubclass());
161161
} else {
162162
return;
163163
}
@@ -316,15 +316,21 @@ protected void fireActionPerformed(ActionEvent e) {
316316
filterImpl(TextFilter.TYPE_EXCLUSIVE, getIcon(), getText());
317317
}
318318
});
319-
popup.add(new JMenuItem(Bundle.OQLFilterUtils_FilterSubclass(), Icons.getIcon(LanguageIcons.CLASS)) {
319+
popup.add(new JMenuItem(Bundle.OQLFilterUtils_FilterRegExp(), Icons.getIcon(GeneralIcons.FILTER_REG_EXP)) {
320320
protected void fireActionPerformed(ActionEvent e) {
321321
super.fireActionPerformed(e);
322322
filterImpl(TextFilter.TYPE_REGEXP, getIcon(), getText());
323323
}
324324
});
325+
popup.add(new JMenuItem(Bundle.OQLFilterUtils_FilterSubclass(), Icons.getIcon(LanguageIcons.CLASS)) {
326+
protected void fireActionPerformed(ActionEvent e) {
327+
super.fireActionPerformed(e);
328+
filterImpl(FILTER_INSTANCEOF, getIcon(), getText());
329+
}
330+
});
325331
}
326332
protected void filterImpl(final int type, final Icon icon, final String name) {
327-
if (type == TextFilter.TYPE_REGEXP) {
333+
if (type == TextFilter.TYPE_REGEXP || type == FILTER_INSTANCEOF) {
328334
matchCase.setEnabled(false);
329335
matchCase.setSelected(false);
330336
} else {

0 commit comments

Comments
 (0)