use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.
the class SnippetRuntime method deoptimize.
/**
* Foreign call: {@link #DEOPTIMIZE}.
*/
@SubstrateForeignCallTarget
private static void deoptimize(long actionAndReason, SpeculationReason speculation) {
Pointer sp = KnownIntrinsics.readCallerStackPointer();
DeoptimizationAction action = Deoptimizer.decodeDeoptAction(actionAndReason);
if (Deoptimizer.Options.TraceDeoptimization.getValue()) {
Log log = Log.log().string("[Deoptimization initiated").newline();
CodePointer ip = KnownIntrinsics.readReturnAddress();
SubstrateInstalledCode installedCode = CodeInfoTable.lookupInstalledCode(ip);
if (installedCode != null) {
log.string(" name: ").string(installedCode.getName()).newline();
}
log.string(" sp: ").hex(sp).string(" ip: ").hex(ip).newline();
DeoptimizationReason reason = Deoptimizer.decodeDeoptReason(actionAndReason);
log.string(" reason: ").string(reason.toString()).string(" action: ").string(action.toString()).newline();
int debugId = Deoptimizer.decodeDebugId(actionAndReason);
log.string(" debugId: ").signed(debugId).string(" speculation: ").string(Objects.toString(speculation)).newline();
CodeInfoQueryResult info = CodeInfoTable.lookupCodeInfoQueryResult(ip);
if (info != null) {
NodeSourcePosition sourcePosition = DeoptimizationSourcePositionDecoder.decode(debugId, info);
if (sourcePosition != null) {
log.string(" stack trace that triggered deoptimization:").newline();
NodeSourcePosition cur = sourcePosition;
while (cur != null) {
log.string(" at ");
if (cur.getMethod() != null) {
StackTraceElement element = cur.getMethod().asStackTraceElement(cur.getBCI());
if (element.getFileName() != null && element.getLineNumber() >= 0) {
log.string(element.toString());
} else {
log.string(cur.getMethod().format("%H.%n(%p)")).string(" bci ").signed(cur.getBCI());
}
} else {
log.string("[unknown method]");
}
log.newline();
cur = cur.getCaller();
}
}
}
}
if (action.doesInvalidateCompilation()) {
Deoptimizer.invalidateMethodOfFrame(sp, speculation);
} else {
Deoptimizer.deoptimizeFrame(sp, false, speculation);
}
if (Deoptimizer.Options.TraceDeoptimization.getValue()) {
Log.log().string("]").newline();
}
}
use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.
the class JavaStackWalker method walkThread.
@AlwaysInline("avoid virtual call to visitor")
public static boolean walkThread(IsolateThread thread, StackFrameVisitor visitor) {
JavaFrameAnchor anchor = JavaFrameAnchors.getFrameAnchor(thread);
Pointer sp = WordFactory.nullPointer();
CodePointer ip = WordFactory.nullPointer();
if (anchor.isNonNull()) {
sp = anchor.getLastJavaSP();
ip = FrameAccess.readReturnAddress(sp);
}
// always call doWalk() to invoke visitor's methods
return doWalk(anchor, sp, ip, visitor);
}
use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.
the class Deoptimizer method invalidateMethodOfFrame.
/**
* Invalidates the {@link InstalledCode} of the method of the given frame. The method must be a
* runtime compiled method, since there is not {@link InstalledCode} for native image methods.
*/
public static void invalidateMethodOfFrame(Pointer sourceSp, SpeculationReason speculation) {
CodePointer returnAddress = FrameAccess.readReturnAddress(sourceSp);
SubstrateInstalledCode installedCode = CodeInfoTable.lookupInstalledCode(returnAddress);
/*
* We look up the installedCode before checking if the frame is deoptimized to avoid race
* conditions. We are not in a VMOperation here. When a deoptimization happens, e.g., at a
* safepoint taken at the method exit of checkDeoptimized, then the result value
* deoptimizedFrame will be null but the return address is already patched to the deoptStub.
* We would not be able to find the installedCode in such a case. Invalidating the same
* installedCode multiple times in case of a race is not a problem because the actual
* invalidation is in a VMOperation.
*/
DeoptimizedFrame deoptimizedFrame = checkDeoptimized(sourceSp);
if (deoptimizedFrame != null) {
installedCode = deoptimizedFrame.getSourceInstalledCode();
if (installedCode == null) {
/* When the method was invalidated before, all the metadata can be gone by now. */
return;
}
} else {
if (installedCode == null) {
CodeInfoTable.getRuntimeCodeCache().logTable();
throw VMError.shouldNotReachHere("Only runtime compiled methods can be invalidated. sp = " + Long.toHexString(sourceSp.rawValue()) + ", returnAddress = " + Long.toHexString(returnAddress.rawValue()));
}
}
registerSpeculationFailure(installedCode, speculation);
VMOperation.guaranteeNotInProgress("invalidateMethodOfFrame: running user code that can block");
installedCode.invalidate();
}
use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.
the class JavaLangSubstitutions method fillInStackTrace.
@Substitute
@NeverInline("Prevent inlining in Truffle compilations")
private Object fillInStackTrace() {
Pointer sp = KnownIntrinsics.readCallerStackPointer();
CodePointer ip = KnownIntrinsics.readReturnAddress();
StackTraceBuilder stackTraceBuilder = new StackTraceBuilder();
JavaStackWalker.walkCurrentThread(sp, ip, stackTraceBuilder);
this.stackTrace = stackTraceBuilder.getTrace();
return this;
}
use of org.graalvm.nativeimage.c.function.CodePointer in project graal by oracle.
the class JavaStackWalker method doWalk.
@AlwaysInline("avoid virtual call to visitor")
private static boolean doWalk(JavaFrameAnchor lastAnchor, Pointer startSP, CodePointer startIP, StackFrameVisitor visitor) {
if (!visitor.prologue()) {
return false;
}
if (startSP.isNonNull() && startIP.isNonNull()) {
JavaFrameAnchor anchor = lastAnchor;
Pointer sp = startSP;
CodePointer ip = startIP;
while (true) {
while (anchor.isNonNull() && anchor.getLastJavaSP().belowOrEqual(sp)) {
/* Skip anchors that are in parts of the stack we are not traversing. */
anchor = anchor.getPreviousAnchor();
}
long totalFrameSize;
DeoptimizedFrame deoptFrame = Deoptimizer.checkDeoptimized(sp);
if (deoptFrame != null) {
totalFrameSize = deoptFrame.getSourceTotalFrameSize();
} else {
totalFrameSize = CodeInfoTable.lookupTotalFrameSize(ip);
}
if (totalFrameSize != -1) {
/* This is a Java frame, visit it. */
if (!visitor.visitFrame(sp, ip, deoptFrame)) {
return false;
}
/* Bump sp *up* over my frame. */
sp = sp.add(WordFactory.unsigned(totalFrameSize));
/* Read the return address to my caller. */
ip = FrameAccess.readReturnAddress(sp);
} else if (anchor.isNonNull()) {
/*
* At the end of a block of Java frames, but we have more Java frames after a
* block of C frames.
*/
assert anchor.getLastJavaSP().aboveThan(sp);
sp = anchor.getLastJavaSP();
ip = FrameAccess.readReturnAddress(sp);
anchor = anchor.getPreviousAnchor();
} else {
/* Really at the end of the stack, we are done with walking. */
break;
}
}
} else {
/*
* It is fine for a thread to have no Java frames, for example in the case of a native
* thread that was attached via JNI, but is currently not executing any Java code.
*/
}
return visitor.epilogue();
}
Aggregations