Skip to content

Commit 647adc0

Browse files
committed
[GR-31817] Use method entries instead of primary ranges for method DIE generation #3419.
PullRequest: graal/9043
2 parents 4261d4e + 0bfd722 commit 647adc0

17 files changed

+182
-164
lines changed

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/BasicProgbitsSectionImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.oracle.objectfile.ObjectFile.ProgbitsSectionImpl;
3636
import com.oracle.objectfile.ObjectFile.RelocatableSectionImpl;
3737
import com.oracle.objectfile.ObjectFile.RelocationKind;
38-
import com.oracle.objectfile.ObjectFile.RelocationRecord;
3938
import com.oracle.objectfile.ObjectFile.Section;
4039

4140
/**
@@ -114,15 +113,15 @@ public List<Section> getElements() {
114113
}
115114

116115
@Override
117-
public RelocationRecord markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
118-
return ((RelocatableSectionImpl) getElement()).markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend,
116+
public void markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
117+
((RelocatableSectionImpl) getElement()).markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend,
119118
explicitAddend);
120119
}
121120

122121
@Override
123-
public final RelocationRecord markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
122+
public final void markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
124123
assert getContent() == null || bb.array() == getContent();
125-
return ((RelocatableSectionImpl) getElement()).markRelocationSite(offset, bb, k, symbolName, useImplicitAddend, explicitAddend);
124+
((RelocatableSectionImpl) getElement()).markRelocationSite(offset, bb, k, symbolName, useImplicitAddend, explicitAddend);
126125
}
127126

128127
@Override

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/ObjectFile.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,8 @@ public interface RelocatableSectionImpl extends ElementImpl {
408408
* bytes
409409
* @param useImplicitAddend whether the current bytes are to be used as an addend
410410
* @param explicitAddend a full-width addend, or null if useImplicitAddend is true
411-
* @return the relocation record created (or found, if it exists already)
412411
*/
413-
RelocationRecord markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend);
412+
void markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend);
414413

415414
/**
416415
* Force the creation of a relocation section/element for this section, and return it. This
@@ -441,7 +440,7 @@ public interface ProgbitsSectionImpl extends RelocatableSectionImpl {
441440
* passed a buffer. It uses the byte array accessed by {@link #getContent} and
442441
* {@link #setContent}.
443442
*/
444-
RelocationRecord markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend);
443+
void markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend);
445444
}
446445

447446
public interface NobitsSectionImpl extends ElementImpl {

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/StringSectionImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.oracle.objectfile.ObjectFile.Element;
3636
import com.oracle.objectfile.ObjectFile.ProgbitsSectionImpl;
3737
import com.oracle.objectfile.ObjectFile.RelocationKind;
38-
import com.oracle.objectfile.ObjectFile.RelocationRecord;
3938
import com.oracle.objectfile.io.AssemblyBuffer;
4039
import com.oracle.objectfile.io.OutputAssembler;
4140

@@ -125,12 +124,12 @@ public Element getOrCreateRelocationElement(boolean useImplicitAddend) {
125124
}
126125

127126
@Override
128-
public RelocationRecord markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
127+
public void markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
129128
throw new UnsupportedOperationException("can't mark relocaction sites in string section");
130129
}
131130

132131
@Override
133-
public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
132+
public void markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
134133
throw new UnsupportedOperationException("can't mark relocaction sites in string section");
135134
}
136135

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

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.nio.file.Path;
3030
import java.util.ArrayList;
3131
import java.util.HashMap;
32-
import java.util.LinkedList;
3332
import java.util.List;
3433
import java.util.ListIterator;
3534
import java.util.Map;
@@ -40,6 +39,7 @@
4039
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugFrameSizeChange;
4140
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugInstanceTypeInfo;
4241
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugMethodInfo;
42+
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugRangeInfo;
4343
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugTypeInfo;
4444
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugTypeInfo.DebugTypeKind;
4545

@@ -97,10 +97,7 @@ public ClassEntry(String className, FileEntry fileEntry, int size) {
9797
super(className, size);
9898
this.interfaces = new ArrayList<>();
9999
this.fileEntry = fileEntry;
100-
// methods is a sorted list and we want to be able to add more elements to it while keeping
101-
// it sorted,
102-
// so a LinkedList seems more appropriate than an ArrayList. (see getMethodEntry)
103-
this.methods = new LinkedList<>();
100+
this.methods = new ArrayList<>();
104101
this.primaryEntries = new ArrayList<>();
105102
this.primaryIndex = new HashMap<>();
106103
this.localFiles = new ArrayList<>();
@@ -140,7 +137,7 @@ public void addDebugInfo(DebugInfoBase debugInfoBase, DebugTypeInfo debugTypeInf
140137
/* Add details of fields and field types */
141138
debugInstanceTypeInfo.fieldInfoProvider().forEach(debugFieldInfo -> this.processField(debugFieldInfo, debugInfoBase, debugContext));
142139
/* Add details of methods and method types */
143-
debugInstanceTypeInfo.methodInfoProvider().forEach(methodFieldInfo -> this.methods.add(this.processMethod(methodFieldInfo, debugInfoBase, debugContext)));
140+
debugInstanceTypeInfo.methodInfoProvider().forEach(methodFieldInfo -> this.methods.add(this.processMethod(methodFieldInfo, debugInfoBase, debugContext, false)));
144141
/* Sort methods to improve lookup speed */
145142
this.methods.sort(MethodEntry::compareTo);
146143
}
@@ -157,8 +154,9 @@ public void indexPrimary(Range primary, List<DebugFrameSizeChange> frameSizeInfo
157154
assert includesDeoptTarget == false;
158155
}
159156
FileEntry primaryFileEntry = primary.getFileEntry();
160-
assert primaryFileEntry != null;
161-
indexLocalFileEntry(primaryFileEntry);
157+
if (primaryFileEntry != null) {
158+
indexLocalFileEntry(primaryFileEntry);
159+
}
162160
}
163161
}
164162

@@ -275,7 +273,7 @@ private void processInterface(String interfaceName, DebugInfoBase debugInfoBase,
275273
interfaceClassEntry.addImplementor(this, debugContext);
276274
}
277275

278-
protected MethodEntry processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
276+
protected MethodEntry processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBase debugInfoBase, DebugContext debugContext, boolean fromRangeInfo) {
279277
String methodName = debugInfoBase.uniqueDebugString(debugMethodInfo.name());
280278
String resultTypeName = TypeEntry.canonicalize(debugMethodInfo.valueType());
281279
int modifiers = debugMethodInfo.modifiers();
@@ -294,15 +292,13 @@ protected MethodEntry processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBa
294292
paramTypeArray[idx++] = paramType;
295293
}
296294
paramNameArray = paramNames.toArray(paramNameArray);
297-
String fileName = debugMethodInfo.fileName();
298-
Path filePath = debugMethodInfo.filePath();
299-
Path cachePath = debugMethodInfo.cachePath();
300295
/*
301296
* n.b. the method file may differ from the owning class file when the method is a
302297
* substitution
303298
*/
304-
FileEntry methodFileEntry = debugInfoBase.ensureFileEntry(fileName, filePath, cachePath);
305-
return new MethodEntry(methodFileEntry, methodName, this, resultType, paramTypeArray, paramNameArray, modifiers, debugMethodInfo.isDeoptTarget());
299+
FileEntry methodFileEntry = debugInfoBase.ensureFileEntry(debugMethodInfo);
300+
return new MethodEntry(methodFileEntry, debugMethodInfo.symbolNameForMethod(), methodName, this, resultType,
301+
paramTypeArray, paramNameArray, modifiers, debugMethodInfo.isDeoptTarget(), fromRangeInfo);
306302
}
307303

308304
@Override
@@ -343,32 +339,28 @@ public ClassEntry getSuperClass() {
343339
return superClass;
344340
}
345341

346-
public Range makePrimaryRange(String symbolName, StringTable stringTable, MethodEntry method, int lo, int hi, int primaryLine) {
347-
FileEntry fileEntryToUse = method.fileEntry;
348-
if (fileEntryToUse == null) {
349-
/* Last chance is the class's file entry. */
350-
fileEntryToUse = this.fileEntry;
351-
}
352-
return new Range(symbolName, stringTable, method, fileEntryToUse, lo, hi, primaryLine);
353-
}
354-
355-
public MethodEntry getMethodEntry(DebugMethodInfo debugMethodInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
342+
public MethodEntry ensureMethodEntryForDebugRangeInfo(DebugRangeInfo debugRangeInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
356343
assert listIsSorted(methods);
357-
String methodName = debugInfoBase.uniqueDebugString(debugMethodInfo.name());
358-
String paramSignature = debugMethodInfo.paramSignature();
359-
String returnTypeName = debugMethodInfo.valueType();
360344
ListIterator<MethodEntry> methodIterator = methods.listIterator();
345+
String methodName = debugInfoBase.uniqueDebugString(debugRangeInfo.name());
346+
String paramSignature = debugRangeInfo.paramSignature();
347+
String returnTypeName = debugRangeInfo.valueType();
361348
while (methodIterator.hasNext()) {
362349
MethodEntry methodEntry = methodIterator.next();
363350
int comparisonResult = methodEntry.compareTo(methodName, paramSignature, returnTypeName);
364351
if (comparisonResult == 0) {
352+
methodEntry.setInRangeAndUpdateFileEntry(debugInfoBase, debugRangeInfo);
353+
if (methodEntry.fileEntry != null) {
354+
/* Ensure that the methodEntry's fileEntry is present in the localsFileIndex */
355+
indexLocalFileEntry(methodEntry.fileEntry);
356+
}
365357
return methodEntry;
366358
} else if (comparisonResult > 0) {
367359
methodIterator.previous();
368360
break;
369361
}
370362
}
371-
MethodEntry newMethodEntry = processMethod(debugMethodInfo, debugInfoBase, debugContext);
363+
MethodEntry newMethodEntry = processMethod(debugRangeInfo, debugInfoBase, debugContext, true);
372364
methodIterator.add(newMethodEntry);
373365
return newMethodEntry;
374366
}
@@ -378,4 +370,8 @@ private static boolean listIsSorted(List<MethodEntry> list) {
378370
copy.sort(MethodEntry::compareTo);
379371
return list.equals(copy);
380372
}
373+
374+
public List<MethodEntry> getMethods() {
375+
return methods;
376+
}
381377
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.List;
3535
import java.util.Map;
3636

37+
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugFileInfo;
3738
import org.graalvm.compiler.debug.DebugContext;
3839

3940
import com.oracle.objectfile.debuginfo.DebugInfoProvider;
@@ -239,23 +240,21 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
239240
Path filePath = debugCodeInfo.filePath();
240241
String className = TypeEntry.canonicalize(debugCodeInfo.ownerType());
241242
String methodName = debugCodeInfo.name();
242-
String symbolName = debugCodeInfo.symbolNameForMethod();
243243
int lo = debugCodeInfo.addressLo();
244244
int hi = debugCodeInfo.addressHi();
245245
int primaryLine = debugCodeInfo.line();
246246

247247
/* Search for a method defining this primary range. */
248248
ClassEntry classEntry = ensureClassEntry(className);
249-
MethodEntry methodEntry = classEntry.getMethodEntry(debugCodeInfo, this, debugContext);
250-
Range primaryRange = classEntry.makePrimaryRange(symbolName, stringTable, methodEntry, lo, hi, primaryLine);
249+
MethodEntry methodEntry = classEntry.ensureMethodEntryForDebugRangeInfo(debugCodeInfo, this, debugContext);
250+
Range primaryRange = new Range(stringTable, methodEntry, lo, hi, primaryLine);
251251
debugContext.log(DebugContext.INFO_LEVEL, "PrimaryRange %s.%s %s %s:%d [0x%x, 0x%x]", className, methodName, filePath, fileName, primaryLine, lo, hi);
252252
classEntry.indexPrimary(primaryRange, debugCodeInfo.getFrameSizeChanges(), debugCodeInfo.getFrameSize());
253253
debugCodeInfo.lineInfoProvider().forEach(debugLineInfo -> {
254254
String fileNameAtLine = debugLineInfo.fileName();
255255
Path filePathAtLine = debugLineInfo.filePath();
256256
String classNameAtLine = TypeEntry.canonicalize(debugLineInfo.ownerType());
257257
String methodNameAtLine = debugLineInfo.name();
258-
String symbolNameAtLine = debugLineInfo.symbolNameForMethod();
259258
int loAtLine = lo + debugLineInfo.addressLo();
260259
int hiAtLine = lo + debugLineInfo.addressHi();
261260
int line = debugLineInfo.line();
@@ -264,8 +263,8 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
264263
* symbol for them and don't see a break in the address range.
265264
*/
266265
ClassEntry subClassEntry = ensureClassEntry(classNameAtLine);
267-
MethodEntry subMethodEntry = subClassEntry.getMethodEntry(debugLineInfo, this, debugContext);
268-
Range subRange = new Range(symbolNameAtLine, stringTable, subMethodEntry, loAtLine, hiAtLine, line, primaryRange);
266+
MethodEntry subMethodEntry = subClassEntry.ensureMethodEntryForDebugRangeInfo(debugLineInfo, this, debugContext);
267+
Range subRange = new Range(stringTable, subMethodEntry, loAtLine, hiAtLine, line, primaryRange);
269268
classEntry.indexSubRange(subRange);
270269
try (DebugContext.Scope s = debugContext.scope("Subranges")) {
271270
debugContext.log(DebugContext.VERBOSE_LEVEL, "SubRange %s.%s %s %s:%d 0x%x, 0x%x]", classNameAtLine, methodNameAtLine, filePathAtLine, fileNameAtLine, line, loAtLine, hiAtLine);
@@ -390,10 +389,12 @@ private FileEntry addFileEntry(String fileName, Path filePath, Path cachePath) {
390389
return fileEntry;
391390
}
392391

393-
protected FileEntry ensureFileEntry(String fileName, Path filePath, Path cachePath) {
392+
protected FileEntry ensureFileEntry(DebugFileInfo debugFileInfo) {
393+
String fileName = debugFileInfo.fileName();
394394
if (fileName == null || fileName.length() == 0) {
395395
return null;
396396
}
397+
Path filePath = debugFileInfo.filePath();
397398
Path fileAsPath;
398399
if (filePath == null) {
399400
fileAsPath = Paths.get(fileName);
@@ -403,7 +404,7 @@ protected FileEntry ensureFileEntry(String fileName, Path filePath, Path cachePa
403404
/* Reuse any existing entry. */
404405
FileEntry fileEntry = findFile(fileAsPath);
405406
if (fileEntry == null) {
406-
fileEntry = addFileEntry(fileName, filePath, cachePath);
407+
fileEntry = addFileEntry(fileName, filePath, debugFileInfo.cachePath());
407408
}
408409
return fileEntry;
409410
}

0 commit comments

Comments
 (0)