Skip to content

Commit da64e03

Browse files
committed
Refactor: Use ResolvedJavaMethod to sort methods in ClassEntry
This way we avoid the expensive calls to "toJavaName". This patch reduces the time spend in debug info generation from ~12s to 5s.
1 parent a3c06b4 commit da64e03

File tree

4 files changed

+25
-43
lines changed

4 files changed

+25
-43
lines changed

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333
import java.util.Map;
3434

35+
import jdk.vm.ci.meta.ResolvedJavaMethod;
3536
import org.graalvm.compiler.debug.DebugContext;
3637

3738
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugFieldInfo;
@@ -272,7 +273,7 @@ private void processInterface(String interfaceName, DebugInfoBase debugInfoBase,
272273
}
273274

274275
protected MethodEntry processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
275-
String methodName = debugInfoBase.uniqueDebugString(debugMethodInfo.name());
276+
String methodName = debugMethodInfo.name();
276277
String resultTypeName = TypeEntry.canonicalize(debugMethodInfo.valueType());
277278
int modifiers = debugMethodInfo.modifiers();
278279
List<String> paramTypes = debugMethodInfo.paramTypes();
@@ -339,17 +340,15 @@ public ClassEntry getSuperClass() {
339340

340341
public MethodEntry ensureMethodEntryForDebugRangeInfo(DebugRangeInfo debugRangeInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
341342
assert listIsSorted(methods);
342-
String methodName = debugInfoBase.uniqueDebugString(debugRangeInfo.name());
343-
String paramSignature = debugRangeInfo.paramSignature();
344-
String returnTypeName = debugRangeInfo.valueType();
343+
ResolvedJavaMethod javaMethod = debugRangeInfo.getJavaMethod();
345344
/* Since the methods list is sorted we perform a binary search */
346345
int start = 0;
347346
int end = methods.size() - 1;
348347
assert end < (Integer.MAX_VALUE / 2);
349348
while (start <= end) {
350349
int middle = (start + end) / 2;
351350
MethodEntry methodEntry = methods.get(middle);
352-
int comparisonResult = methodEntry.compareTo(methodName, paramSignature, returnTypeName);
351+
int comparisonResult = methodEntry.compareTo(javaMethod);
353352
if (comparisonResult == 0) {
354353
methodEntry.updateRangeInfo(debugInfoBase, debugRangeInfo);
355354
if (methodEntry.fileEntry != null) {

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/MethodEntry.java

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,17 @@
2929
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugCodeInfo;
3030
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugLineInfo;
3131
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugMethodInfo;
32-
33-
import java.util.Arrays;
34-
import java.util.stream.Collectors;
32+
import jdk.vm.ci.meta.ResolvedJavaMethod;
3533

3634
public class MethodEntry extends MemberEntry implements Comparable<MethodEntry> {
3735
final TypeEntry[] paramTypes;
3836
final String[] paramNames;
3937
static final int DEOPT = 1 << 0;
4038
static final int IN_RANGE = 1 << 1;
4139
static final int INLINED = 1 << 2;
40+
private final ResolvedJavaMethod javaMethod;
4241
int flags;
4342
final String symbolName;
44-
private String signature;
4543

4644
public MethodEntry(DebugInfoBase debugInfoBase, DebugMethodInfo debugMethodInfo,
4745
FileEntry fileEntry, String methodName, ClassEntry ownerType,
@@ -52,6 +50,7 @@ public MethodEntry(DebugInfoBase debugInfoBase, DebugMethodInfo debugMethodInfo,
5250
this.paramTypes = paramTypes;
5351
this.paramNames = paramNames;
5452
this.symbolName = debugMethodInfo.symbolNameForMethod();
53+
this.javaMethod = debugMethodInfo.getJavaMethod();
5554
this.flags = 0;
5655
if (debugMethodInfo.isDeoptTarget()) {
5756
setIsDeopt();
@@ -161,36 +160,19 @@ public String getSymbolName() {
161160
return symbolName;
162161
}
163162

164-
private String getSignature() {
165-
if (signature == null) {
166-
signature = Arrays.stream(paramTypes).map(TypeEntry::getTypeName).collect(Collectors.joining(", "));
163+
public int compareTo(ResolvedJavaMethod other) {
164+
/*
165+
* first try to sort methods by name, to have a nice sorting when printing types with ptype
166+
*/
167+
int comparisonResult = javaMethod.getName().compareTo(other.getName());
168+
if (comparisonResult != 0) {
169+
return comparisonResult;
167170
}
168-
return signature;
169-
}
170-
171-
public int compareTo(String methodName, String paramSignature, String returnTypeName) {
172-
int nameComparison = memberName.compareTo(methodName);
173-
if (nameComparison != 0) {
174-
return nameComparison;
175-
}
176-
int typeComparison = valueType.getTypeName().compareTo(returnTypeName);
177-
if (typeComparison != 0) {
178-
return typeComparison;
179-
}
180-
return getSignature().compareTo(paramSignature);
171+
return this.javaMethod.hashCode() - other.hashCode();
181172
}
182173

183174
@Override
184175
public int compareTo(MethodEntry other) {
185-
assert other != null;
186-
int nameComparison = methodName().compareTo(other.methodName());
187-
if (nameComparison != 0) {
188-
return nameComparison;
189-
}
190-
int typeComparison = valueType.getTypeName().compareTo(other.valueType.getTypeName());
191-
if (typeComparison != 0) {
192-
return typeComparison;
193-
}
194-
return getSignature().compareTo(other.getSignature());
176+
return compareTo(other.javaMethod);
195177
}
196178
}

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/DebugInfoProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.function.Consumer;
3232
import java.util.stream.Stream;
3333

34+
import jdk.vm.ci.meta.ResolvedJavaMethod;
3435
import jdk.vm.ci.meta.ResolvedJavaType;
3536
import org.graalvm.compiler.debug.DebugContext;
3637

@@ -201,9 +202,9 @@ interface DebugFieldInfo extends DebugMemberInfo {
201202

202203
interface DebugMethodInfo extends DebugMemberInfo {
203204
/**
204-
* @return a string identifying the method parameters.
205+
* @return the JavaMethod of the method associated with this DebugMethodInfo.
205206
*/
206-
String paramSignature();
207+
ResolvedJavaMethod getJavaMethod();
207208

208209
/**
209210
* @return an array of Strings identifying the method parameters.

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,8 @@ public String valueType() {
649649
}
650650

651651
@Override
652-
public String paramSignature() {
653-
return hostedMethod.format("%P");
652+
public ResolvedJavaMethod getJavaMethod() {
653+
return hostedMethod;
654654
}
655655

656656
@Override
@@ -875,8 +875,8 @@ public String symbolNameForMethod() {
875875
}
876876

877877
@Override
878-
public String paramSignature() {
879-
return hostedMethod.format("%P");
878+
public ResolvedJavaMethod getJavaMethod() {
879+
return hostedMethod;
880880
}
881881

882882
@Override
@@ -1099,8 +1099,8 @@ public String valueType() {
10991099
}
11001100

11011101
@Override
1102-
public String paramSignature() {
1103-
return method.format("%P");
1102+
public ResolvedJavaMethod getJavaMethod() {
1103+
return method;
11041104
}
11051105

11061106
@Override

0 commit comments

Comments
 (0)