Skip to content

Commit

Permalink
[GR-41116] [GR-40733] Improve Deoptimization and Frame Verification E…
Browse files Browse the repository at this point in the history
…rror Messages.

PullRequest: graal/12804
  • Loading branch information
teshull committed Oct 12, 2022
2 parents e019e71 + 6a10a9a commit ad3a5c6
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,20 @@ protected void fillSourceFields(BytecodeFrame bytecodeFrame, FrameInfoQueryResul
private static final int UNCOMPRESSED_FRAME_SLICE_INDEX = -1;

static class FrameData {
protected DebugInfo debugInfo;
protected int totalFrameSize;
protected ValueInfo[][] virtualObjects;
protected FrameInfoQueryResult frame;
protected final DebugInfo debugInfo;
protected final int totalFrameSize;
protected final ValueInfo[][] virtualObjects;
protected final FrameInfoQueryResult frame;
protected long encodedFrameInfoIndex;
protected int frameSliceIndex = UNCOMPRESSED_FRAME_SLICE_INDEX;

FrameData(DebugInfo debugInfo, int totalFrameSize, ValueInfo[][] virtualObjects, FrameInfoQueryResult frame) {
assert debugInfo != null;
this.debugInfo = debugInfo;
this.totalFrameSize = totalFrameSize;
this.virtualObjects = virtualObjects;
this.frame = frame;
}
}

private static class CompressedFrameData {
Expand Down Expand Up @@ -473,11 +481,8 @@ protected FrameData addDebugInfo(ResolvedJavaMethod method, CompilationResult co
}

final DebugInfo debugInfo = infopoint.debugInfo;
final FrameData data = new FrameData();
data.debugInfo = debugInfo;
data.totalFrameSize = totalFrameSize;
data.virtualObjects = new ValueInfo[countVirtualObjects(debugInfo)][];
data.frame = addFrame(data, debugInfo.frame(), isDeoptEntry, includeLocalValues);
final FrameData data = new FrameData(debugInfo, totalFrameSize, new ValueInfo[countVirtualObjects(debugInfo)][], new FrameInfoQueryResult());
initializeFrameInfo(data.frame, data, debugInfo.frame(), isDeoptEntry, includeLocalValues);

if (encodeSourceReferences) {
List<CompressedFrameData> frameSlice = useCompressedEncoding ? new ArrayList<>() : null;
Expand Down Expand Up @@ -538,33 +543,33 @@ private static void countVirtualObjects(JavaValue[] values, BitSet visitedVirtua
}
}

private FrameInfoQueryResult addFrame(FrameData data, BytecodeFrame frame, boolean isDeoptEntry, boolean needLocalValues) {
FrameInfoQueryResult result = new FrameInfoQueryResult();
private void initializeFrameInfo(FrameInfoQueryResult frameInfo, FrameData data, BytecodeFrame frame, boolean isDeoptEntry, boolean needLocalValues) {
if (frame.caller() != null) {
assert !isDeoptEntry : "Deoptimization entry point information for caller frames is not encoded";
result.caller = addFrame(data, frame.caller(), false, needLocalValues);
frameInfo.caller = new FrameInfoQueryResult();
initializeFrameInfo(frameInfo.caller, data, frame.caller(), false, needLocalValues);
}
result.virtualObjects = data.virtualObjects;
result.encodedBci = encodeBci(frame.getBCI(), frame.duringCall, frame.rethrowException);
result.isDeoptEntry = isDeoptEntry;
frameInfo.virtualObjects = data.virtualObjects;
frameInfo.encodedBci = encodeBci(frame.getBCI(), frame.duringCall, frame.rethrowException);
frameInfo.isDeoptEntry = isDeoptEntry;

ValueInfo[] valueInfos = null;
if (needLocalValues) {
SharedMethod method = (SharedMethod) frame.getMethod();
if (ImageSingletons.contains(CallStackFrameMethodData.class)) {
result.methodId = ImageSingletons.lookup(CallStackFrameMethodData.class).getMethodId(method);
ImageSingletons.lookup(CallStackFrameMethodInfo.class).addMethodInfo(method, result.methodId);
frameInfo.methodId = ImageSingletons.lookup(CallStackFrameMethodData.class).getMethodId(method);
ImageSingletons.lookup(CallStackFrameMethodInfo.class).addMethodInfo(method, frameInfo.methodId);
}

if (customization.storeDeoptTargetMethod()) {
result.deoptMethod = method;
frameInfo.deoptMethod = method;
encoders.objectConstants.addObject(SubstrateObjectConstant.forObject(method));
}
result.deoptMethodOffset = method.getDeoptOffsetInImage();
frameInfo.deoptMethodOffset = method.getDeoptOffsetInImage();

result.numLocals = frame.numLocals;
result.numStack = frame.numStack;
result.numLocks = frame.numLocks;
frameInfo.numLocals = frame.numLocals;
frameInfo.numStack = frame.numStack;
frameInfo.numLocks = frame.numLocks;

JavaValue[] values = frame.values;
int numValues = 0;
Expand All @@ -581,11 +586,9 @@ private FrameInfoQueryResult addFrame(FrameData data, BytecodeFrame frame, boole
valueInfos[i] = makeValueInfo(data, getFrameValueKind(frame, i), values[i], isDeoptEntry);
}
}
result.valueInfos = valueInfos;
frameInfo.valueInfos = valueInfos;

ImageSingletons.lookup(Counters.class).frameCount.inc();

return result;
}

public static JavaKind getFrameValueKind(BytecodeFrame frame, int valueIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public static void setDeoptStubPointer(CFunctionPointer deoptStub) {
*/
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static CFunctionPointer getDeoptStubPointer() {
return get().deoptStubPointer;
CFunctionPointer ptr = get().deoptStubPointer;
assert ptr.rawValue() != 0;
return ptr;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.graalvm.word.WordFactory;

import com.oracle.svm.core.FrameAccess;
import com.oracle.svm.core.NeverInline;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.code.CodeInfo;
import com.oracle.svm.core.code.CodeInfoAccess;
Expand All @@ -47,10 +48,10 @@
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.deopt.Deoptimizer.TargetContent;
import com.oracle.svm.core.graal.stackvalue.UnsafeStackValue;
import com.oracle.svm.core.heap.RestrictHeapAccess;
import com.oracle.svm.core.log.StringBuilderLog;
import com.oracle.svm.core.meta.SubstrateObjectConstant;
import com.oracle.svm.core.monitor.MonitorSupport;
import com.oracle.svm.core.util.VMError;

import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.meta.JavaConstant;
Expand Down Expand Up @@ -158,7 +159,7 @@ abstract static class ConstantEntry extends Entry {

protected final JavaConstant constant;

protected static ConstantEntry factory(int offset, JavaConstant constant) {
protected static ConstantEntry factory(int offset, JavaConstant constant, FrameInfoQueryResult frameInfo) {
switch (constant.getJavaKind()) {
case Boolean:
case Byte:
Expand All @@ -175,7 +176,7 @@ protected static ConstantEntry factory(int offset, JavaConstant constant) {
case Object:
return new ObjectConstantEntry(offset, constant, SubstrateObjectConstant.asObject(constant), SubstrateObjectConstant.isCompressed(constant));
default:
throw VMError.shouldNotReachHere(constant.getJavaKind().toString());
throw Deoptimizer.fatalDeoptimizationError("Unexpected constant type: " + constant, frameInfo);
}
}

Expand Down Expand Up @@ -423,7 +424,19 @@ public void takeException() {
SimpleCodeInfoQueryResult codeInfoQueryResult = UnsafeStackValue.get(SimpleCodeInfoQueryResult.class);
CodeInfoAccess.lookupCodeInfo(info, CodeInfoAccess.relativeIP(info, WordFactory.pointer(firstAddressEntry.returnAddress)), codeInfoQueryResult);
long handler = codeInfoQueryResult.getExceptionOffset();
VMError.guarantee(handler != 0, "no exception handler registered for deopt target");
if (handler == 0) {
throwMissingExceptionHandler(info, firstAddressEntry);
}
firstAddressEntry.returnAddress += handler;
}

@NeverInline("Has more relaxed heap access requirements than caller.")
@RestrictHeapAccess(access = RestrictHeapAccess.Access.UNRESTRICTED, reason = "Printing out error and then crashing.")
private static void throwMissingExceptionHandler(CodeInfo info, ReturnAddress firstAddressEntry) {
CodeInfoQueryResult detailedQueryResult = new CodeInfoQueryResult();
CodeInfoAccess.lookupCodeInfo(info, CodeInfoAccess.relativeIP(info, WordFactory.pointer(firstAddressEntry.returnAddress)), detailedQueryResult);
FrameInfoQueryResult frameInfo = detailedQueryResult.getFrameInfo();
throw Deoptimizer.fatalDeoptimizationError("No exception handler registered for deopt target", frameInfo);
}

}
Loading

0 comments on commit ad3a5c6

Please sign in to comment.