Skip to content

Commit

Permalink
8310561: JFR: Unify decodeDescriptors(String, String)
Browse files Browse the repository at this point in the history
Reviewed-by: mgronlun
  • Loading branch information
egahlin committed Jun 22, 2023
1 parent 7da3f19 commit 8976ebf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 53 deletions.
55 changes: 3 additions & 52 deletions src/jdk.jfr/share/classes/jdk/jfr/internal/tool/PrettyWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void printObject(RecordedObject object, long arraySize) {
if (clazz != null) {
String className = clazz.getName();
if (className!= null && className.startsWith("[")) {
className = decodeDescriptors(className, arraySize > 0 ? Long.toString(arraySize) : "").getFirst();
className = ValueFormatter.decodeDescriptors(className, arraySize > 0 ? Long.toString(arraySize) : "").getFirst();
}
print(className);
String description = object.getString("description");
Expand Down Expand Up @@ -463,7 +463,7 @@ private String formatMethod(RecordedMethod m) {
StringJoiner sj = new StringJoiner(", ");
String md = m.getDescriptor().replace("/", ".");
String parameter = md.substring(1, md.lastIndexOf(")"));
for (String qualifiedName : decodeDescriptors(parameter, "")) {
for (String qualifiedName : ValueFormatter.decodeDescriptors(parameter, "")) {
String typeName = qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1);
sj.add(typeName);
}
Expand All @@ -484,60 +484,11 @@ private void printClass(RecordedClass clazz, String postFix) {
}
String className = clazz.getName();
if (className.startsWith("[")) {
className = decodeDescriptors(className, "").getFirst();
className = ValueFormatter.decodeDescriptors(className, "").getFirst();
}
println(className + " (classLoader = " + classLoaderName + ")" + postFix);
}

List<String> decodeDescriptors(String descriptor, String arraySize) {
List<String> descriptors = new ArrayList<>();
for (int index = 0; index < descriptor.length(); index++) {
String arrayBrackets = "";
while (descriptor.charAt(index) == '[') {
arrayBrackets = arrayBrackets + "[" + arraySize + "]" ;
arraySize = "";
index++;
}
char c = descriptor.charAt(index);
String type;
switch (c) {
case 'L':
int endIndex = descriptor.indexOf(';', index);
type = descriptor.substring(index + 1, endIndex);
index = endIndex;
break;
case 'I':
type = "int";
break;
case 'J':
type = "long";
break;
case 'Z':
type = "boolean";
break;
case 'D':
type = "double";
break;
case 'F':
type = "float";
break;
case 'S':
type = "short";
break;
case 'C':
type = "char";
break;
case 'B':
type = "byte";
break;
default:
type = "<unknown-descriptor-type>";
}
descriptors.add(type + arrayBrackets);
}
return descriptors;
}

private void printThread(RecordedThread thread, String postFix) {
long javaThreadId = thread.getJavaThreadId();
if (javaThreadId > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public static String formatMethod(RecordedMethod m, boolean compact) {
return sb.toString();
}

private static List<String> decodeDescriptors(String descriptor, String arraySize) {
public static List<String> decodeDescriptors(String descriptor, String arraySize) {
List<String> descriptors = new ArrayList<>();
for (int index = 0; index < descriptor.length(); index++) {
String arrayBrackets = "";
Expand Down

1 comment on commit 8976ebf

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.