Skip to content

Commit

Permalink
Refactor: Improve readability of DwarfInfoSectionImpl#writeMethodLoca…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
zakkak committed Jun 29, 2021
1 parent 19a9d43 commit cc06434
Showing 1 changed file with 55 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -932,50 +932,65 @@ private int writeMethodLocations(DebugContext context, ClassEntry classEntry, bo
if (range.isDeoptTarget() != deoptTargets) {
continue;
}
if (range.withInlinedChildren()) {
/*
* Go through the subranges and generate abstract debug entries for inlined methods.
*/
for (Range subrange : primaryEntry.getSubranges()) {
if (!subrange.isInlined()) {
continue;
}
final String symbolName = subrange.getSymbolName();
if (primaryMap.get(symbolName) == null) {
primaryMap.put(symbolName, pos);
ClassEntry inlinedClassEntry = (ClassEntry) lookupType(subrange.getClassName());
pos = writeMethodLocation(context, inlinedClassEntry, subrange, buffer, pos);
pos = writeAttrNull(buffer, pos);
}
}
}
pos = maybeGenerateAbstractDebugEntriesForInlinedMethods(context, primaryMap, primaryEntry, buffer, pos);
primaryMap.put(range.getSymbolName(), pos);
pos = writeMethodLocation(context, classEntry, range, buffer, pos);
if (range.withInlinedChildren()) {
int depth = 0;
/*
* Go through the subranges and generate concrete debug entries for inlined methods.
*/
for (Range subrange : primaryEntry.getSubranges()) {
if (!subrange.isInlined()) {
continue;
}
Integer subprogramPos = primaryMap.get(subrange.getSymbolName());
assert subprogramPos != null;
int previousPos = pos;
pos = writeInlineSubroutine(context, classEntry, subrange, buffer, pos, subprogramPos - getCUIndex(classEntry), depth);
if (!subrange.withChildren()) {
while (depth > 0) {
pos = writeAttrNull(buffer, pos);
depth--;
}
} else if (previousPos != pos) {
depth++;
}
pos = maybeGenerateConcreteDebugEntriesForInlinedMethods(context, classEntry, primaryMap, primaryEntry, buffer, pos);
pos = writeAttrNull(buffer, pos);
}
return pos;
}

/**
* Go through the subranges and generate concrete debug entries for inlined methods.
*/
private int maybeGenerateConcreteDebugEntriesForInlinedMethods(DebugContext context, ClassEntry classEntry,
HashMap<String, Integer> primaryMap, PrimaryEntry primaryEntry, byte[] buffer, int pos) {
if (!primaryEntry.getPrimary().withInlinedChildren()) {
return pos;
}
int depth = 0;
for (Range subrange : primaryEntry.getSubranges()) {
if (!subrange.isInlined()) {
continue;
}
Integer subprogramPos = primaryMap.get(subrange.getSymbolName());
assert subprogramPos != null;
int previousPos = pos;
int subprogramOffset = subprogramPos - getCUIndex(classEntry);
pos = writeInlineSubroutine(context, classEntry, subrange, buffer, pos, subprogramOffset, depth);
if (!subrange.withChildren()) {
while (depth > 0) {
pos = writeAttrNull(buffer, pos);
depth--;
}
assert depth == 0 : depth;
} else if (previousPos != pos) {
depth++;
}
}
assert depth == 0 : depth;
return pos;
}

/**
* Go through the subranges and generate abstract debug entries for inlined methods.
*/
private int maybeGenerateAbstractDebugEntriesForInlinedMethods(DebugContext context,
HashMap<String, Integer> primaryMap, PrimaryEntry primaryEntry, byte[] buffer, int pos) {
if (!primaryEntry.getPrimary().withInlinedChildren()) {
return pos;
}
for (Range subrange : primaryEntry.getSubranges()) {
if (!subrange.isInlined()) {
continue;
}
final String symbolName = subrange.getSymbolName();
if (primaryMap.get(symbolName) == null) {
primaryMap.put(symbolName, pos);
ClassEntry inlinedClassEntry = (ClassEntry) lookupType(subrange.getClassName());
pos = writeMethodLocation(context, inlinedClassEntry, subrange, buffer, pos);
pos = writeAttrNull(buffer, pos);
}
pos = writeAttrNull(buffer, pos);
}
return pos;
}
Expand Down

0 comments on commit cc06434

Please sign in to comment.