Skip to content

Commit b5933b1

Browse files
committed
8320805: JFR: Create view for deprecated methods
Reviewed-by: mgronlun
1 parent 29d7a22 commit b5933b1

File tree

7 files changed

+83
-30
lines changed

7 files changed

+83
-30
lines changed

src/jdk.jfr/share/classes/jdk/jfr/internal/query/Aggregator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ enum Aggregator {
5656
* Aggregate values into a comma-separated list, including {@code null}.
5757
*/
5858
LIST("LIST"),
59+
/**
60+
* Aggregate unique values into a comma-separated list, including {@code null}.
61+
*/
62+
SET("SET"),
5963
/**
6064
* The highest numeric value.
6165
*/

src/jdk.jfr/share/classes/jdk/jfr/internal/query/FieldBuilder.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.time.Instant;
2929
import java.util.ArrayDeque;
3030
import java.util.ArrayList;
31-
import java.util.Collections;
3231
import java.util.HashMap;
3332
import java.util.HashSet;
3433
import java.util.List;
@@ -122,7 +121,10 @@ private boolean configureSyntheticFields() {
122121
configureNotInitFrameField();
123122
return true;
124123
}
125-
124+
if (fieldName.equals("stackTrace.topFrame.class")) {
125+
configureTopFrameClassField();
126+
return true;
127+
}
126128
if (fieldName.equals("stackTrace.topFrame")) {
127129
configureTopFrameField();
128130
return true;
@@ -175,6 +177,20 @@ private void configureTopFrameField() {
175177
field.lexicalSort = true;
176178
}
177179

180+
private void configureTopFrameClassField() {
181+
field.alignLeft = true;
182+
field.label = "Class";
183+
field.dataType = "java.lang.Class";
184+
field.valueGetter = e -> {
185+
RecordedStackTrace t = e.getStackTrace();
186+
if (t == null) {
187+
return null;
188+
}
189+
return t.getFrames().getFirst().getMethod().getType();
190+
};
191+
field.lexicalSort = true;
192+
}
193+
178194
private void configureCustomFrame(Predicate<RecordedFrame> condition) {
179195
field.alignLeft = true;
180196
field.dataType = "jdk.types.Frame";
@@ -379,7 +395,7 @@ public static void configureAggregator(Field field) {
379395
field.alignLeft = false;
380396
field.lexicalSort = false;
381397
}
382-
if (aggregator == Aggregator.LIST) {
398+
if (aggregator == Aggregator.LIST || aggregator == Aggregator.SET) {
383399
field.alignLeft = true;
384400
field.lexicalSort = true;
385401
}
@@ -392,6 +408,7 @@ public static void configureAggregator(Field field) {
392408
case SUM -> "Total " + field.label;
393409
case UNIQUE -> "Unique Count " + field.label;
394410
case LIST -> field.label + "s";
411+
case SET -> field.label + "s";
395412
case MISSING -> field.label;
396413
case DIFFERENCE -> "Difference " + field.label;
397414
case MEDIAN -> "Median " + field.label;

src/jdk.jfr/share/classes/jdk/jfr/internal/query/FieldFormatter.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.time.Duration;
2828
import java.time.Instant;
2929
import java.time.temporal.ChronoUnit;
30+
import java.util.Collection;
31+
import java.util.StringJoiner;
3032

3133
import jdk.jfr.consumer.RecordedClass;
3234
import jdk.jfr.consumer.RecordedClassLoader;
@@ -51,6 +53,13 @@ private static String format(Field field, Object object, boolean compact) {
5153
if (object == null) {
5254
return field.missingText;
5355
}
56+
if (object instanceof Collection<?> c) {
57+
StringJoiner sj = new StringJoiner(", ");
58+
for (Object o : c) {
59+
sj.add(format(field, o, compact));
60+
}
61+
return sj.toString();
62+
}
5463
if (object instanceof String s) {
5564
return stripFormatting(s);
5665
}
@@ -71,6 +80,10 @@ private static String format(Field field, Object object, boolean compact) {
7180
return field.missingText;
7281
}
7382

83+
if (object instanceof RecordedFrame f && f.isJavaFrame()) {
84+
object = f.getMethod();
85+
}
86+
7487
if (object instanceof RecordedThread t) {
7588
if (t.getJavaThreadId() > 0) {
7689
return t.getJavaName();

src/jdk.jfr/share/classes/jdk/jfr/internal/query/Function.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import java.time.Instant;
2929
import java.time.temporal.ChronoUnit;
3030
import java.util.ArrayList;
31+
import java.util.Collection;
3132
import java.util.Comparator;
32-
import java.util.HashSet;
33+
import java.util.LinkedHashSet;
3334
import java.util.Set;
34-
import java.util.StringJoiner;
3535

3636
abstract class Function {
3737

@@ -46,7 +46,11 @@ public static Function create(Field field) {
4646
return new FirstNonNull();
4747
}
4848
if (aggregator == Aggregator.LIST) {
49-
return new List();
49+
return new Container(new ArrayList<>());
50+
}
51+
52+
if (aggregator == Aggregator.SET) {
53+
return new Container(new LinkedHashSet<>());
5054
}
5155

5256
if (aggregator == Aggregator.DIFFERENCE) {
@@ -378,7 +382,7 @@ public Object result() {
378382
// **** UNIQUE ****
379383

380384
private static final class Unique extends Function {
381-
private final Set<Object> unique = new HashSet<>();
385+
private final Set<Object> unique = new LinkedHashSet<>();
382386

383387
@Override
384388
public void add(Object value) {
@@ -391,23 +395,22 @@ public Object result() {
391395
}
392396
}
393397

394-
// **** LIST ****
398+
// **** LIST and SET ****
395399

396-
private static final class List extends Function {
397-
private final ArrayList<Object> list = new ArrayList<>();
400+
private static final class Container extends Function {
401+
private final Collection<Object> collection;
398402

403+
private Container(Collection<Object> collection) {
404+
this.collection = collection;
405+
}
399406
@Override
400407
public void add(Object value) {
401-
list.add(value);
408+
collection.add(value);
402409
}
403410

404411
@Override
405412
public Object result() {
406-
StringJoiner sj = new StringJoiner(", ");
407-
for (Object object : list) {
408-
sj.add(String.valueOf(object));
409-
}
410-
return sj.toString();
413+
return collection;
411414
}
412415
}
413416

src/jdk.jfr/share/classes/jdk/jfr/internal/query/TableCell.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package jdk.jfr.internal.query;
2626

2727
import java.util.ArrayList;
28+
import java.util.Collections;
2829
import java.util.List;
2930
import jdk.jfr.internal.query.Configuration.Truncate;
3031

@@ -69,7 +70,7 @@ public int getPreferredWidth() {
6970
}
7071
public void addLine(String text) {
7172
int contentWidth = getContentWidth();
72-
if (text.length() >= contentWidth) {
73+
if (text.length() > contentWidth) {
7374
add(truncate(text, contentWidth));
7475
} else {
7576
addAligned(text);
@@ -143,6 +144,10 @@ private void add(String text) {
143144
}
144145
}
145146

147+
public void sort() {
148+
Collections.sort(lines);
149+
}
150+
146151
public void clear() {
147152
lines.clear();
148153
}

src/jdk.jfr/share/classes/jdk/jfr/internal/query/TableRenderer.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828
import static jdk.jfr.internal.query.Configuration.MIN_PREFERRED_WIDTH;
2929
import static jdk.jfr.internal.query.Configuration.PREFERRED_WIDTH;
3030

31+
import java.util.Collection;
3132
import java.util.List;
3233
import java.util.function.Predicate;
3334

34-
import jdk.jfr.consumer.RecordedFrame;
35-
import jdk.jfr.consumer.RecordedMethod;
3635
import jdk.jfr.consumer.RecordedStackTrace;
3736
import jdk.jfr.internal.query.Configuration.Truncate;
3837
import jdk.jfr.internal.util.Output;
@@ -293,37 +292,39 @@ private void setCellContent(TableCell cell, Row row, int columnIndex) {
293292
if (cell.cellHeight > 1) {
294293
Object o = row.getValue(columnIndex);
295294
if (o instanceof RecordedStackTrace s) {
296-
setStackTrace(cell, s);
295+
o = s.getFrames();
296+
}
297+
if (o instanceof Collection<?> c) {
298+
setMultiline(cell, c);
297299
return;
298300
}
299301
}
300302

301303
if (text.length() > cell.getContentSize()) {
302304
Object o = row.getValue(columnIndex);
303-
304305
cell.setContent(FieldFormatter.formatCompact(cell.field, o));
305306
return;
306307
}
307308
cell.setContent(text);
308309
}
309310

310-
private void setStackTrace(TableCell cell, RecordedStackTrace s) {
311+
private void setMultiline(TableCell cell, Collection<?> objects) {
311312
int row = 0;
312313
cell.clear();
313-
for(RecordedFrame f : s.getFrames()) {
314+
for(Object object : objects) {
314315
if (row == cell.cellHeight) {
315316
return;
316317
}
317-
if (f.isJavaFrame()) {
318-
RecordedMethod method = f.getMethod();
319-
String text = FieldFormatter.format(cell.field, method);
320-
if (text.length() > cell.getContentWidth()) {
321-
text = FieldFormatter.formatCompact(cell.field, method);
322-
}
323-
cell.addLine(text);
318+
String text = FieldFormatter.format(cell.field, object);
319+
if (text.length() > cell.getContentWidth()) {
320+
text = FieldFormatter.formatCompact(cell.field, object);
324321
}
322+
cell.addLine(text);
325323
row++;
326324
}
325+
if (cell.field.lexicalSort) {
326+
cell.sort();
327+
}
327328
}
328329

329330
private void printRow() {

src/jdk.jfr/share/classes/jdk/jfr/internal/query/view.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ table = "COLUMN 'Monitor Address', 'Class', 'Threads', 'Max Duration'
173173
FROM JavaMonitorEnter
174174
GROUP BY monitorClass ORDER BY M"
175175

176+
[application.deprecated-methods-for-removal]
177+
label = "Deprecated Methods for Removal"
178+
table = "COLUMN 'Deprecated Method', 'Called from Class'
179+
FORMAT truncate-beginning, cell-height:10000;truncate-beginning
180+
SELECT method AS m, SET(stackTrace.topFrame.class)
181+
FROM DeprecatedInvocation
182+
WHERE forRemoval = 'true'
183+
GROUP BY m
184+
ORDER BY m"
185+
176186
[environment.cpu-information]
177187
label ="CPU Information"
178188
form = "SELECT cpu, sockets, cores, hwThreads, description FROM CPUInformation"

0 commit comments

Comments
 (0)