Skip to content

Commit 69adb17

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 328db41 commit 69adb17

File tree

4 files changed

+23
-43
lines changed

4 files changed

+23
-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: 10 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,17 @@ 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+
/* first try to sort methods by name, to have a nice sorting when printing types with ptype */
165+
int comparisonResult = javaMethod.getName().compareTo(other.getName());
166+
if (comparisonResult != 0) {
167+
return comparisonResult;
167168
}
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);
169+
return this.javaMethod.hashCode() - other.hashCode();
181170
}
182171

183172
@Override
184173
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());
174+
return compareTo(other.javaMethod);
195175
}
196176
}

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
@@ -651,8 +651,8 @@ public String valueType() {
651651
}
652652

653653
@Override
654-
public String paramSignature() {
655-
return hostedMethod.format("%P");
654+
public ResolvedJavaMethod getJavaMethod() {
655+
return hostedMethod;
656656
}
657657

658658
@Override
@@ -877,8 +877,8 @@ public String symbolNameForMethod() {
877877
}
878878

879879
@Override
880-
public String paramSignature() {
881-
return hostedMethod.format("%P");
880+
public ResolvedJavaMethod getJavaMethod() {
881+
return hostedMethod;
882882
}
883883

884884
@Override
@@ -1101,8 +1101,8 @@ public String valueType() {
11011101
}
11021102

11031103
@Override
1104-
public String paramSignature() {
1105-
return method.format("%P");
1104+
public ResolvedJavaMethod getJavaMethod() {
1105+
return method;
11061106
}
11071107

11081108
@Override

0 commit comments

Comments
 (0)