Skip to content

Commit

Permalink
[GR-45654] Single compile unit for Java DWARF debug info.
Browse files Browse the repository at this point in the history
PullRequest: graal/14351
  • Loading branch information
olpaw committed Apr 17, 2023
2 parents e03ab4a + 29fa7c8 commit 6f891ca
Show file tree
Hide file tree
Showing 26 changed files with 1,326 additions and 2,140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class ClassEntry extends StructureTypeEntry {
/**
* Details of the associated file.
*/
private FileEntry fileEntry;
private final FileEntry fileEntry;
/**
* Details of the associated loader.
*/
Expand All @@ -80,50 +80,16 @@ public class ClassEntry extends StructureTypeEntry {
* A list recording details of all normal compiled methods included in this class sorted by
* ascending address range. Note that the associated address ranges are disjoint and contiguous.
*/
private final List<CompiledMethodEntry> normalCompiledEntries = new ArrayList<>();
private final List<CompiledMethodEntry> compiledEntries = new ArrayList<>();
/**
* A list recording details of all deopt fallback compiled methods included in this class sorted
* by ascending address range. Note that the associated address ranges are disjoint, contiguous
* and above all ranges for normal compiled methods.
*/
private List<CompiledMethodEntry> deoptCompiledEntries;
/**
* An index identifying ranges for compiled method which have already been encountered, whether
* normal or deopt fallback methods.
* An index identifying ranges for compiled method which have already been encountered.
*/
private final EconomicMap<Range, CompiledMethodEntry> compiledMethodIndex = EconomicMap.create();
/**
* An index of all primary and secondary files referenced from this class's compilation unit.
*/
private final EconomicMap<FileEntry, Integer> localFilesIndex = EconomicMap.create();
/**
* A list of the same files.
*/
private final List<FileEntry> localFiles = new ArrayList<>();
/**
* An index of all primary and secondary dirs referenced from this class's compilation unit.
*/
private final EconomicMap<DirEntry, Integer> localDirsIndex = EconomicMap.create();
/**
* A list of the same dirs.
*/
private final List<DirEntry> localDirs = new ArrayList<>();

public ClassEntry(String className, FileEntry fileEntry, int size) {
super(className, size);
this.fileEntry = fileEntry;
this.loader = null;
// deopt methods list is created on demand
this.deoptCompiledEntries = null;
if (fileEntry != null) {
localFiles.add(fileEntry);
localFilesIndex.put(fileEntry, localFiles.size());
DirEntry dirEntry = fileEntry.getDirEntry();
if (dirEntry != null) {
localDirs.add(dirEntry);
localDirsIndex.put(dirEntry, localDirs.size());
}
}
}

@Override
Expand Down Expand Up @@ -159,25 +125,12 @@ public void addDebugInfo(DebugInfoBase debugInfoBase, DebugTypeInfo debugTypeInf
debugInstanceTypeInfo.methodInfoProvider().forEach(debugMethodInfo -> this.processMethod(debugMethodInfo, debugInfoBase, debugContext));
}

public void indexPrimary(PrimaryRange primary, List<DebugFrameSizeChange> frameSizeInfos, int frameSize) {
if (compiledMethodIndex.get(primary) == null) {
CompiledMethodEntry compiledEntry = new CompiledMethodEntry(primary, frameSizeInfos, frameSize, this);
compiledMethodIndex.put(primary, compiledEntry);
if (primary.isDeoptTarget()) {
if (deoptCompiledEntries == null) {
deoptCompiledEntries = new ArrayList<>();
}
deoptCompiledEntries.add(compiledEntry);
} else {
normalCompiledEntries.add(compiledEntry);
/* deopt targets should all come after normal methods */
assert deoptCompiledEntries == null;
}
FileEntry primaryFileEntry = primary.getFileEntry();
if (primaryFileEntry != null) {
indexLocalFileEntry(primaryFileEntry);
}
}
public CompiledMethodEntry indexPrimary(PrimaryRange primary, List<DebugFrameSizeChange> frameSizeInfos, int frameSize) {
assert compiledMethodIndex.get(primary) == null : "repeat of primary range [0x%x, 0x%x]!".formatted(primary.getLo(), primary.getHi());
CompiledMethodEntry compiledEntry = new CompiledMethodEntry(primary, frameSizeInfos, frameSize, this);
compiledMethodIndex.put(primary, compiledEntry);
compiledEntries.add(compiledEntry);
return compiledEntry;
}

public void indexSubRange(SubRange subrange) {
Expand All @@ -188,10 +141,6 @@ public void indexSubRange(SubRange subrange) {
/* We should already have seen the primary range. */
assert compiledEntry != null;
assert compiledEntry.getClassEntry() == this;
FileEntry subFileEntry = subrange.getFileEntry();
if (subFileEntry != null) {
indexLocalFileEntry(subFileEntry);
}
}

private void indexMethodEntry(MethodEntry methodEntry, ResolvedJavaMethod idMethod) {
Expand All @@ -200,34 +149,6 @@ private void indexMethodEntry(MethodEntry methodEntry, ResolvedJavaMethod idMeth
methodsIndex.put(idMethod, methodEntry);
}

private void indexLocalFileEntry(FileEntry localFileEntry) {
if (localFilesIndex.get(localFileEntry) == null) {
localFiles.add(localFileEntry);
localFilesIndex.put(localFileEntry, localFiles.size());
DirEntry dirEntry = localFileEntry.getDirEntry();
if (dirEntry != null && localDirsIndex.get(dirEntry) == null) {
localDirs.add(dirEntry);
localDirsIndex.put(dirEntry, localDirs.size());
}
}
}

public int localDirsIdx(DirEntry dirEntry) {
if (dirEntry != null) {
return localDirsIndex.get(dirEntry);
} else {
return 0;
}
}

public int localFilesIdx() {
return localFilesIndex.get(fileEntry);
}

public int localFilesIdx(@SuppressWarnings("hiding") FileEntry fileEntry) {
return localFilesIndex.get(fileEntry);
}

public String getFileName() {
if (fileEntry != null) {
return fileEntry.getFileName();
Expand All @@ -236,7 +157,6 @@ public String getFileName() {
}
}

@SuppressWarnings("unused")
public String getFullFileName() {
if (fileEntry != null) {
return fileEntry.getFullName();
Expand All @@ -258,6 +178,10 @@ public FileEntry getFileEntry() {
return fileEntry;
}

public int getFileIdx() {
return fileEntry.getIdx();
}

public String getLoaderId() {
return (loader != null ? loader.getLoaderId() : "");
}
Expand All @@ -269,11 +193,7 @@ public String getLoaderId() {
* @return a stream of all compiled method entries for this class.
*/
public Stream<CompiledMethodEntry> compiledEntries() {
Stream<CompiledMethodEntry> stream = normalCompiledEntries.stream();
if (deoptCompiledEntries != null) {
stream = Stream.concat(stream, deoptCompiledEntries.stream());
}
return stream;
return compiledEntries.stream();
}

/**
Expand All @@ -283,32 +203,7 @@ public Stream<CompiledMethodEntry> compiledEntries() {
* @return a stream of all normal compiled method entries for this class.
*/
public Stream<CompiledMethodEntry> normalCompiledEntries() {
return normalCompiledEntries.stream();
}

/**
* Retrieve a stream of all deopt fallback compiled method entries for this class.
*
* @return a stream of all deopt fallback compiled method entries for this class.
*/
public Stream<CompiledMethodEntry> deoptCompiledEntries() {
if (hasDeoptCompiledEntries()) {
return deoptCompiledEntries.stream();
} else {
return Stream.empty();
}
}

public List<DirEntry> getLocalDirs() {
return localDirs;
}

public List<FileEntry> getLocalFiles() {
return localFiles;
}

public boolean hasDeoptCompiledEntries() {
return deoptCompiledEntries != null;
return compiledEntries();
}

private void processInterface(ResolvedJavaType interfaceType, DebugInfoBase debugInfoBase, DebugContext debugContext) {
Expand Down Expand Up @@ -352,10 +247,6 @@ protected MethodEntry processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBa
@Override
protected FieldEntry addField(DebugFieldInfo debugFieldInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
FieldEntry fieldEntry = super.addField(debugFieldInfo, debugInfoBase, debugContext);
FileEntry fieldFileEntry = fieldEntry.getFileEntry();
if (fieldFileEntry != null) {
indexLocalFileEntry(fieldFileEntry);
}
return fieldEntry;
}

Expand All @@ -377,7 +268,7 @@ private static String formatParams(DebugLocalInfo[] paramInfo) {
}

public boolean hasCompiledEntries() {
return normalCompiledEntries.size() != 0;
return compiledEntries.size() != 0;
}

public ClassEntry getSuperClass() {
Expand All @@ -391,11 +282,6 @@ public MethodEntry ensureMethodEntryForDebugRangeInfo(DebugRangeInfo debugRangeI
methodEntry = processMethod(debugRangeInfo, debugInfoBase, debugContext);
} else {
methodEntry.updateRangeInfo(debugInfoBase, debugRangeInfo);
/* Ensure that the methodEntry's fileEntry is present in the localsFileIndex */
FileEntry methodFileEntry = methodEntry.fileEntry;
if (methodFileEntry != null) {
indexLocalFileEntry(methodFileEntry);
}
}
return methodEntry;
}
Expand All @@ -417,47 +303,18 @@ public List<MethodEntry> getMethods() {
*/
public int lowpc() {
assert hasCompiledEntries();
return normalCompiledEntries.get(0).getPrimary().getLo();
}

/**
* Retrieve the lowest code section offset for compiled method code belonging to this class that
* belongs to a deoptimization fallback compiled method. It is an error to call this for a class
* entry which has no deoptimization fallback compiled methods.
*
* @return the lowest code section offset for a deoptimization fallback compiled method
* belonging to this class.
*/
public int lowpcDeopt() {
assert hasCompiledEntries();
assert hasDeoptCompiledEntries();
return deoptCompiledEntries.get(0).getPrimary().getLo();
return compiledEntries.get(0).getPrimary().getLo();
}

/**
* Retrieve the highest code section offset for compiled method code belonging to this class
* that does not belong to a deoptimization fallback compiled method. The returned value is the
* offset of the first byte that succeeds the code for that method. It is an error to call this
* for a class entry which has no compiled methods.
* Retrieve the highest code section offset for compiled method code belonging to this class.
* The returned value is the offset of the first byte that succeeds the code for that method. It
* is an error to call this for a class entry which has no compiled methods.
*
* @return the highest code section offset for compiled method code belonging to this class
*/
public int hipc() {
assert hasCompiledEntries();
return normalCompiledEntries.get(normalCompiledEntries.size() - 1).getPrimary().getHi();
}

/**
* Retrieve the highest code section offset for compiled method code belonging to this class
* that belongs to a deoptimization fallback compiled method. It is an error to call this for a
* class entry which has no deoptimization fallback compiled methods.
*
* @return the highest code section offset for a deoptimization fallback compiled method
* belonging to this class.
*/
public int hipcDeopt() {
assert hasCompiledEntries();
assert hasDeoptCompiledEntries();
return deoptCompiledEntries.get(deoptCompiledEntries.size() - 1).getPrimary().getHi();
return compiledEntries.get(compiledEntries.size() - 1).getPrimary().getHi();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ public class CompiledMethodEntry {
/**
* The primary range detailed by this object.
*/
private PrimaryRange primary;
private final PrimaryRange primary;
/**
* Details of the class owning this range.
*/
private ClassEntry classEntry;
private final ClassEntry classEntry;
/**
* Details of of compiled method frame size changes.
*/
private List<DebugFrameSizeChange> frameSizeInfos;
private final List<DebugFrameSizeChange> frameSizeInfos;
/**
* Size of compiled method frame.
*/
private int frameSize;
private final int frameSize;

public CompiledMethodEntry(PrimaryRange primary, List<DebugFrameSizeChange> frameSizeInfos, int frameSize, ClassEntry classEntry) {
this.primary = primary;
Expand Down
Loading

0 comments on commit 6f891ca

Please sign in to comment.