Skip to content

Commit 671e7f9

Browse files
committed
Refactor: Avoid toJavaName invocations when getting ranges' class
1 parent 0cf55b5 commit 671e7f9

File tree

3 files changed

+21
-37
lines changed

3 files changed

+21
-37
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Map;
3636

3737
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugFileInfo;
38+
import jdk.vm.ci.meta.ResolvedJavaType;
3839
import org.graalvm.compiler.debug.DebugContext;
3940

4041
import com.oracle.objectfile.debuginfo.DebugInfoProvider;
@@ -103,7 +104,7 @@ public abstract class DebugInfoBase {
103104
/**
104105
* index of already seen classes.
105106
*/
106-
private Map<String, ClassEntry> primaryClassesIndex = new HashMap<>();
107+
private Map<ResolvedJavaType, ClassEntry> primaryClassesIndex = new HashMap<>();
107108
/**
108109
* Index of files which contain primary or secondary ranges.
109110
*/
@@ -238,17 +239,17 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
238239
*/
239240
String fileName = debugCodeInfo.fileName();
240241
Path filePath = debugCodeInfo.filePath();
241-
String className = TypeEntry.canonicalize(debugCodeInfo.ownerType());
242+
ResolvedJavaType ownerType = debugCodeInfo.ownerType();
242243
String methodName = debugCodeInfo.name();
243244
int lo = debugCodeInfo.addressLo();
244245
int hi = debugCodeInfo.addressHi();
245246
int primaryLine = debugCodeInfo.line();
246247

247248
/* Search for a method defining this primary range. */
248-
ClassEntry classEntry = ensureClassEntry(className);
249+
ClassEntry classEntry = ensureClassEntry(ownerType);
249250
MethodEntry methodEntry = classEntry.ensureMethodEntryForDebugRangeInfo(debugCodeInfo, this, debugContext);
250251
Range primaryRange = new Range(stringTable, methodEntry, lo, hi, primaryLine);
251-
debugContext.log(DebugContext.INFO_LEVEL, "PrimaryRange %s.%s %s %s:%d [0x%x, 0x%x]", className, methodName, filePath, fileName, primaryLine, lo, hi);
252+
debugContext.log(DebugContext.INFO_LEVEL, "PrimaryRange %s.%s %s %s:%d [0x%x, 0x%x]", ownerType.toJavaName(), methodName, filePath, fileName, primaryLine, lo, hi);
252253
classEntry.indexPrimary(primaryRange, debugCodeInfo.getFrameSizeChanges(), debugCodeInfo.getFrameSize());
253254
/*
254255
* Record all subranges even if they have no line or file so we at least get a symbol
@@ -349,7 +350,6 @@ ClassEntry lookupClassEntry(String typeName) {
349350
*/
350351
@SuppressWarnings("try")
351352
private Range recursivelyAddSubRanges(DebugInfoProvider.DebugLineInfo lineInfo, Range primaryRange, ClassEntry classEntry, DebugContext debugContext) {
352-
/* Don't process the root method, it is already added as the primary range */
353353
if (lineInfo == null) {
354354
return primaryRange;
355355
}
@@ -359,38 +359,38 @@ private Range recursivelyAddSubRanges(DebugInfoProvider.DebugLineInfo lineInfo,
359359
* number
360360
*/
361361
boolean isInline = lineInfo.getCaller() != null;
362-
assert (isInline || (lineInfo.name().equals(primaryRange.getMethodName()) && lineInfo.ownerType().equals(primaryRange.getClassName())));
362+
assert (isInline || (lineInfo.name().equals(primaryRange.getMethodName()) && TypeEntry.canonicalize(lineInfo.ownerType().toJavaName()).equals(primaryRange.getClassName())));
363363

364364
Range caller = recursivelyAddSubRanges(lineInfo.getCaller(), primaryRange, classEntry, debugContext);
365365
final String fileName = lineInfo.fileName();
366366
final Path filePath = lineInfo.filePath();
367-
final String className = TypeEntry.canonicalize(lineInfo.ownerType());
367+
final ResolvedJavaType ownerType = lineInfo.ownerType();
368368
final String methodName = lineInfo.name();
369369
final int lo = primaryRange.getLo() + lineInfo.addressLo();
370370
final int hi = primaryRange.getLo() + lineInfo.addressHi();
371371
final int line = lineInfo.line();
372-
ClassEntry subRangeClassEntry = ensureClassEntry(className);
372+
ClassEntry subRangeClassEntry = ensureClassEntry(ownerType);
373373
MethodEntry subRangeMethodEntry = subRangeClassEntry.ensureMethodEntryForDebugRangeInfo(lineInfo, this, debugContext);
374374
Range subRange = new Range(stringTable, subRangeMethodEntry, lo, hi, line, primaryRange, isInline, caller);
375375
classEntry.indexSubRange(subRange);
376376
try (DebugContext.Scope s = debugContext.scope("Subranges")) {
377377
debugContext.log(DebugContext.VERBOSE_LEVEL, "SubRange %s.%s %s %s:%d 0x%x, 0x%x]",
378-
className, methodName, filePath, fileName, line, lo, hi);
378+
ownerType.toJavaName(), methodName, filePath, fileName, line, lo, hi);
379379
}
380380
return subRange;
381381
}
382382

383-
private ClassEntry ensureClassEntry(String className) {
383+
private ClassEntry ensureClassEntry(ResolvedJavaType type) {
384384
/* See if we already have an entry. */
385-
ClassEntry classEntry = primaryClassesIndex.get(className);
385+
ClassEntry classEntry = primaryClassesIndex.get(type);
386386
if (classEntry == null) {
387-
TypeEntry typeEntry = typesIndex.get(className);
387+
TypeEntry typeEntry = typesIndex.get(TypeEntry.canonicalize(type.toJavaName()));
388388
assert (typeEntry != null && typeEntry.isClass());
389389
classEntry = (ClassEntry) typeEntry;
390390
primaryClasses.add(classEntry);
391-
primaryClassesIndex.put(className, classEntry);
391+
primaryClassesIndex.put(type, classEntry);
392392
}
393-
assert (classEntry.getTypeName().equals(className));
393+
assert (classEntry.getTypeName().equals(TypeEntry.canonicalize(type.toJavaName())));
394394
return classEntry;
395395
}
396396

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

Lines changed: 2 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.ResolvedJavaType;
3435
import org.graalvm.compiler.debug.DebugContext;
3536

3637
/**
@@ -187,8 +188,6 @@ interface DebugMemberInfo extends DebugFileInfo {
187188

188189
String name();
189190

190-
String ownerType();
191-
192191
String valueType();
193192

194193
int modifiers();
@@ -232,6 +231,7 @@ interface DebugMethodInfo extends DebugMemberInfo {
232231
* {@link com.oracle.objectfile.debugentry.Range}.
233232
*/
234233
interface DebugRangeInfo extends DebugMethodInfo {
234+
ResolvedJavaType ownerType();
235235
}
236236

237237
/**

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,6 @@ public String name() {
436436
return name;
437437
}
438438

439-
@Override
440-
public String ownerType() {
441-
return ownerType;
442-
}
443-
444439
@Override
445440
public String valueType() {
446441
return valueType;
@@ -585,11 +580,6 @@ public String name() {
585580
return field.getName();
586581
}
587582

588-
@Override
589-
public String ownerType() {
590-
return typeName();
591-
}
592-
593583
@Override
594584
public String valueType() {
595585
HostedType valueType = field.getType();
@@ -655,11 +645,6 @@ public String name() {
655645
return name;
656646
}
657647

658-
@Override
659-
public String ownerType() {
660-
return typeName();
661-
}
662-
663648
@Override
664649
public String valueType() {
665650
return hostedMethod.getSignature().getReturnType(null).toJavaName();
@@ -861,8 +846,8 @@ public void debugContext(Consumer<DebugContext> action) {
861846
}
862847

863848
@Override
864-
public String ownerType() {
865-
return getDeclaringClass(hostedMethod, true).toJavaName();
849+
public ResolvedJavaType ownerType() {
850+
return getDeclaringClass(hostedMethod, true);
866851
}
867852

868853
@Override
@@ -1072,12 +1057,11 @@ public Path cachePath() {
10721057
}
10731058

10741059
@Override
1075-
public String ownerType() {
1060+
public ResolvedJavaType ownerType() {
10761061
if (method instanceof HostedMethod) {
1077-
return getDeclaringClass((HostedMethod) method, true).toJavaName();
1078-
} else {
1079-
return method.getDeclaringClass().toJavaName();
1062+
return getDeclaringClass((HostedMethod) method, true);
10801063
}
1064+
return method.getDeclaringClass();
10811065
}
10821066

10831067
@Override

0 commit comments

Comments
 (0)