Skip to content

Commit

Permalink
Only build full FrameTree when OmitInlinedMethodDebugLineInfo is false
Browse files Browse the repository at this point in the history
  • Loading branch information
olpaw committed May 2, 2023
1 parent d2285ff commit b70c640
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,12 @@ private static void validateStripDebugInfo(HostedOptionKey<Boolean> optionKey) {
@Option(help = "Omit generation of DebugLineInfo originating from inlined methods") //
public static final HostedOptionKey<Boolean> OmitInlinedMethodDebugLineInfo = new HostedOptionKey<>(true);

@Option(help = "Specify maximum inlining depth to consider when building DebugCodeInfo") //
public static final HostedOptionKey<Integer> DebugCodeInfoMaxDepth = new HostedOptionKey<>(Integer.MAX_VALUE);

@Option(help = "Do not use SourceMappings for generating DebugCodeInfo (i.e. only use Infopoints)") //
public static final HostedOptionKey<Boolean> DebugCodeInfoUseSourceMappings = new HostedOptionKey<>(true);

@Option(help = "Emit debuginfo debug.svm.imagebuild.* sections with detailed image-build options.")//
public static final HostedOptionKey<Boolean> UseImagebuildDebugSections = new HostedOptionKey<>(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,35 @@
import java.util.List;
import java.util.function.Consumer;

import jdk.vm.ci.code.BytecodeFrame;
import jdk.vm.ci.meta.JavaValue;
import jdk.vm.ci.meta.Local;
import jdk.vm.ci.meta.LocalVariableTable;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import org.graalvm.compiler.code.CompilationResult;
import org.graalvm.compiler.code.SourceMapping;
import org.graalvm.compiler.debug.DebugContext;

import com.oracle.svm.core.util.VMError;

import jdk.vm.ci.code.BytecodeFrame;
import jdk.vm.ci.code.BytecodePosition;
import jdk.vm.ci.code.site.Call;
import jdk.vm.ci.code.site.Infopoint;
import jdk.vm.ci.code.site.InfopointReason;
import jdk.vm.ci.common.JVMCIError;
import jdk.vm.ci.meta.JavaValue;
import jdk.vm.ci.meta.Local;
import jdk.vm.ci.meta.LocalVariableTable;
import jdk.vm.ci.meta.ResolvedJavaMethod;

public final class CompilationResultFrameTree {

public abstract static class SourcePositionSupplier implements Comparable<SourcePositionSupplier> {

private final BytecodePosition bytecodePosition;
private final int callDepth;

protected SourcePositionSupplier(BytecodePosition bytecodePosition, int callDepth) {
this.bytecodePosition = bytecodePosition;
this.callDepth = callDepth;
}

public abstract int getStartOffset();

public abstract int getSize();
Expand All @@ -59,7 +68,9 @@ public int getEndOffset() {
return getStartOffset() + getSize() - 1;
}

public abstract BytecodePosition getBytecodePosition();
public BytecodePosition getBytecodePosition() {
return bytecodePosition;
}

public static StackTraceElement getStackTraceElement(BytecodePosition pos) {
return pos.getMethod().asStackTraceElement(pos.getBCI());
Expand All @@ -82,9 +93,13 @@ public final String getStackFrameStr() {
}
}

public final int getCallDepth() {
public int getCallDepth() {
return callDepth;
}

protected static int getCallDepth(BytecodePosition startPos) {
int depth = 0;
BytecodePosition pos = getBytecodePosition();
BytecodePosition pos = startPos;
while (pos != null) {
depth += 1;
pos = pos.getCaller();
Expand Down Expand Up @@ -119,14 +134,20 @@ public int compareTo(SourcePositionSupplier o) {
public static final class InfopointSourceWrapper extends SourcePositionSupplier {
public final Infopoint infopoint;

public static InfopointSourceWrapper create(Infopoint infopoint) {
public static InfopointSourceWrapper create(Infopoint infopoint, int maxDepth) {
if (infopoint.debugInfo == null || infopoint.debugInfo.getBytecodePosition() == null) {
return null;
}
return new InfopointSourceWrapper(infopoint);
BytecodePosition pos = infopoint.debugInfo.getBytecodePosition();
int depth = getCallDepth(pos);
if (depth > maxDepth) {
return null;
}
return new InfopointSourceWrapper(pos, depth, infopoint);
}

private InfopointSourceWrapper(Infopoint infopoint) {
private InfopointSourceWrapper(BytecodePosition bytecodePosition, int callDepth, Infopoint infopoint) {
super(bytecodePosition, callDepth);
this.infopoint = infopoint;
}

Expand All @@ -143,11 +164,6 @@ public int getSize() {
return 1;
}

@Override
public BytecodePosition getBytecodePosition() {
return infopoint.debugInfo.getBytecodePosition();
}

@Override
public int compareTo(SourcePositionSupplier o) {
int res = super.compareTo(o);
Expand All @@ -166,22 +182,29 @@ public int compareTo(SourcePositionSupplier o) {
public static final class SourceMappingWrapper extends SourcePositionSupplier {
public final SourceMapping sourceMapping;

public static SourceMappingWrapper create(SourceMapping sourceMapping) {
public static SourceMappingWrapper create(SourceMapping sourceMapping, int maxDepth) {
if (sourceMapping.getSourcePosition() == null) {
return null;
}
BytecodePosition pos = sourceMapping.getSourcePosition();
int depth = getCallDepth(pos);
if (depth > maxDepth) {
return null;
}
if (sourceMapping.getStartOffset() > sourceMapping.getEndOffset()) {
JVMCIError.shouldNotReachHere("Invalid SourceMapping " + getSourceMappingString(sourceMapping));
}
return new SourceMappingWrapper(sourceMapping);
return new SourceMappingWrapper(pos, depth, sourceMapping);
}

static String getSourceMappingString(SourceMapping sourceMapping) {
SourceMappingWrapper tmp = new SourceMappingWrapper(sourceMapping);
BytecodePosition pos = sourceMapping.getSourcePosition();
SourceMappingWrapper tmp = new SourceMappingWrapper(pos, getCallDepth(pos), sourceMapping);
return tmp.getPosStr() + " with " + tmp.getStackFrameStr();
}

private SourceMappingWrapper(SourceMapping sourceMapping) {
private SourceMappingWrapper(BytecodePosition bytecodePosition, int callDepth, SourceMapping sourceMapping) {
super(bytecodePosition, callDepth);
this.sourceMapping = sourceMapping;
}

Expand All @@ -208,11 +231,6 @@ public int getSize() {
return sourceMapping.getEndOffset() - sourceMapping.getStartOffset();
}

@Override
public BytecodePosition getBytecodePosition() {
return sourceMapping.getSourcePosition();
}

@Override
public int compareTo(SourcePositionSupplier o) {
int res = super.compareTo(o);
Expand Down Expand Up @@ -417,7 +435,9 @@ public String toString() {
public static final class Builder {
private Builder.RootNode root = null;
private final int targetCodeSize;
private final int maxDepth;
private final DebugContext debug;
private final boolean useSourceMappings;
private final boolean verify;

int indexLeft;
Expand Down Expand Up @@ -446,8 +466,10 @@ public String toString() {
}
}

public Builder(DebugContext debug, int targetCodeSize, boolean verify) {
public Builder(DebugContext debug, int targetCodeSize, int maxDepth, boolean useSourceMappings, boolean verify) {
this.targetCodeSize = targetCodeSize;
this.maxDepth = maxDepth;
this.useSourceMappings = useSourceMappings;
this.verify = verify;
this.debug = debug;
}
Expand All @@ -462,34 +484,38 @@ public CallNode build(CompilationResult compilationResult) {
List<SourcePositionSupplier> sourcePosData = new ArrayList<>(infopoints.size() + sourceMappings.size());
InfopointSourceWrapper infopointForRoot = null;
for (Infopoint infopoint : infopoints) {
InfopointSourceWrapper wrapper = InfopointSourceWrapper.create(infopoint);
InfopointSourceWrapper wrapper = InfopointSourceWrapper.create(infopoint, maxDepth);
if (wrapper != null) {
sourcePosData.add(wrapper);
infopointForRoot = wrapper;
} else {
debug.log(DebugContext.DETAILED_LEVEL, " Discard Infopoint without BytecodePosition %s", infopoint);
debug.log(DebugContext.DETAILED_LEVEL, " Discard Infopoint %s", infopoint);
}
}
for (SourceMapping sourceMapping : sourceMappings) {
SourceMappingWrapper wrapper = SourceMappingWrapper.create(sourceMapping);
if (wrapper != null) {
if (wrapper.getStartOffset() > targetCodeSize - 1) {
if (useSourceMappings) {
for (SourceMapping sourceMapping : sourceMappings) {
SourceMappingWrapper wrapper = SourceMappingWrapper.create(sourceMapping, maxDepth);
if (wrapper != null) {
if (wrapper.getStartOffset() > targetCodeSize - 1) {
if (debug.isLogEnabled(DebugContext.DETAILED_LEVEL)) {
debug.log(" Discard SourceMapping outside code-range %s", SourceMappingWrapper.getSourceMappingString(sourceMapping));
}
continue;
}
sourcePosData.add(wrapper);
} else {
if (debug.isLogEnabled(DebugContext.DETAILED_LEVEL)) {
debug.log(" Discard SourceMapping outside code-range %s", SourceMappingWrapper.getSourceMappingString(sourceMapping));
debug.log(" Discard SourceMapping %s", SourceMappingWrapper.getSourceMappingString(sourceMapping));
}
continue;
}
sourcePosData.add(wrapper);
} else {
if (debug.isLogEnabled(DebugContext.DETAILED_LEVEL)) {
debug.log(" Discard SourceMapping without NodeSourcePosition %s", SourceMappingWrapper.getSourceMappingString(sourceMapping));
}
}
}

sourcePosData.sort(Comparator.naturalOrder());

nullifyOverlappingSourcePositions(sourcePosData);
if (useSourceMappings) {
nullifyOverlappingSourcePositions(sourcePosData);
}

if (debug.isLogEnabled(DebugContext.DETAILED_LEVEL)) {
debug.log("Sorted input data:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,12 +1246,24 @@ public Stream<DebugLocationInfo> locationInfoProvider() {
if (fileName().length() == 0) {
return Stream.empty();
}
final CallNode root = new Builder(debugContext, compilation.getTargetCodeSize(), true).build(compilation);
boolean omitInline = SubstrateOptions.OmitInlinedMethodDebugLineInfo.getValue();
int maxDepth = SubstrateOptions.DebugCodeInfoMaxDepth.getValue();
boolean useSourceMappings = SubstrateOptions.DebugCodeInfoUseSourceMappings.getValue();
if (omitInline) {
if (!SubstrateOptions.DebugCodeInfoMaxDepth.hasBeenSet()) {
/* TopLevelVisitor will not go deeper than level 2 */
maxDepth = 2;
}
if (!SubstrateOptions.DebugCodeInfoUseSourceMappings.hasBeenSet()) {
/* Skip expensive CompilationResultFrameTree building with SourceMappings */
useSourceMappings = false;
}
}
final CallNode root = new Builder(debugContext, compilation.getTargetCodeSize(), maxDepth, useSourceMappings, true).build(compilation);
if (root == null) {
return Stream.empty();
}
final List<DebugLocationInfo> locationInfos = new ArrayList<>();
final boolean omitInline = SubstrateOptions.OmitInlinedMethodDebugLineInfo.getValue();
int frameSize = getFrameSize();
final Visitor visitor = (omitInline ? new TopLevelVisitor(locationInfos, frameSize) : new MultiLevelVisitor(locationInfos, frameSize));
// arguments passed by visitor to apply are
Expand Down

0 comments on commit b70c640

Please sign in to comment.