Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected DeoptInvalidateListener(OptimizedTruffleRuntime runtime, OptimizedCall
}

@Override
public void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame) {
public void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame, String reason) {
if (target == focus) {
deoptimized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public SnippetResolvedJavaMethod(SnippetResolvedJavaType type, ResolvedJavaMetho
assert format("%h.%n").equals(method.format("%h.%n"));
}

@Override
public boolean isDeclared() {
return false;
}

@Override
public byte[] getCode() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Objects;
import java.util.List;

import jdk.graal.compiler.core.common.LibGraalSupport;
import jdk.graal.compiler.debug.GraalError;
Expand Down Expand Up @@ -58,6 +59,11 @@ public final class SnippetResolvedJavaType implements ResolvedJavaType {
private SnippetResolvedJavaMethod[] methods;
private SnippetResolvedJavaType arrayOfType;

@Override
public List<ResolvedJavaMethod> getAllMethods(boolean forceLink) {
return null;
}

public SnippetResolvedJavaType(Class<?> javaClass) {
this.javaClass = javaClass;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.io.DataInputStream;
import java.io.IOException;
import java.util.List;

import jdk.graal.compiler.core.common.LibGraalSupport;
import jdk.graal.compiler.debug.GraalError;
Expand Down Expand Up @@ -73,6 +74,11 @@ public static class Bytecodes {
public static final int MULTIANEWARRAY = 197; // 0xC5
}

@Override
public List<BootstrapMethodInvocation> lookupBootstrapMethodInvocations(boolean invokeDynamic) {
return null;
}

ClassfileConstantPool(DataInputStream stream, ClassfileBytecodeProvider context) throws IOException {
this.context = context;
byte tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.oracle.truffle.compiler.TruffleCompilerRuntime;

import jdk.graal.compiler.debug.GraalError;
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.vm.ci.meta.ConstantReflectionProvider;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
Expand Down Expand Up @@ -221,11 +222,12 @@ private static ResolvedJavaField getThrowableJFRTracingField(MetaAccessProvider
ResolvedJavaType throwableType = metaAccess.lookupJavaType(Throwable.class);
for (ResolvedJavaField staticField : throwableType.getStaticFields()) {
if (staticField.getName().equals("jfrTracing") &&
staticField.getType().equals(metaAccess.lookupJavaType(boolean.class)) && staticField.isVolatile()) {
staticField.getType().equals(metaAccess.lookupJavaType(boolean.class)) &&
(JavaVersionUtil.JAVA_SPEC > 25 || staticField.isVolatile())) {
return staticField;
}
}
throw GraalError.shouldNotReachHere("Field Throwable.jfrTracing not found. This field was added in JDK-22+24 and must be present. " +
throw GraalError.shouldNotReachHere("Field Throwable.jfrTracing not found. This field was added in JDK-22+24 (as volatile and later changed in JDK26 to not volatile) and must be present." +
"This either means this field was removed in which case this code needs to be adapted or the meta access lookup above failed which should never happen.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public SharedCodeCacheProvider(TargetDescription target, RegisterConfig register
}

@Override
public void invalidateInstalledCode(InstalledCode installedCode) {
public void invalidateInstalledCode(InstalledCode installedCode, int statusReason) {
throw intentionallyUnimplemented(); // ExcludeFromJacocoGeneratedReport
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ private RuntimeException handleException(VirtualFrame frame, Throwable t) {
throw rethrow(profiledT);
}

private void notifyDeoptimized(VirtualFrame frame) {
runtime().getListener().onCompilationDeoptimized(this, frame);
protected void notifyDeoptimized(VirtualFrame frame) {
runtime().getListener().onCompilationDeoptimized(this, frame, null);
}

protected static OptimizedTruffleRuntime runtime() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,17 @@ default void onCompilationInvalidated(OptimizedCallTarget target, Object source,
*
* @param target the call target whose compiled code was just deoptimized
* @param frame
* @param reason optional reason why the deoptimization happened
*/
default void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame) {
default void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame, String reason) {
}

/**
* Notifies this object when {@code target} has its execution profile reset.
*
* @param target the call target whose profile was just reset.
*/
default void onProfileReset(OptimizedCallTarget target) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ public void onCompilationInvalidated(OptimizedCallTarget target, Object source,
}

@Override
public void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame) {
invokeListeners((l) -> l.onCompilationDeoptimized(target, frame));
public void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame, String reason) {
invokeListeners((l) -> l.onCompilationDeoptimized(target, frame, reason));
}

@Override
public void onProfileReset(OptimizedCallTarget target) {
invokeListeners((l) -> l.onProfileReset(target));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void onCompilationStarted(OptimizedCallTarget target, AbstractCompilation
}

@Override
public void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame) {
public void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame, String reason) {
DeoptimizationEvent event = factory.createDeoptimizationEvent();
if (event.isEnabled()) {
event.setRootFunction(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public static void install(OptimizedTruffleRuntime runtime) {
private static final String FAILED_FORMAT = "opt failed " + TARGET_FORMAT + "|" + TIER_FORMAT + "|Time %18s|Reason: %s|UTC %s|Src %s";
private static final String PADDING = " ";
private static final String INV_FORMAT = "opt inval. " + TARGET_FORMAT + " " + PADDING + "|UTC %s|Src %s|Reason %s";
private static final String DEOPT_FORMAT = "opt deopt " + TARGET_FORMAT + "|" + PADDING + "|UTC %s|Src %s";
private static final String DEOPT_FORMAT = "opt deopt " + TARGET_FORMAT + "|" + PADDING + "|UTC %s|Src %s|Reason %s";
private static final String REPROF_FORMAT = "opt reprofile " + TARGET_FORMAT + "|" + PADDING + "|UTC %s|Src %s";
// @formatter:on

@Override
Expand Down Expand Up @@ -222,14 +223,27 @@ private void log(OptimizedCallTarget target, String message) {
}

@Override
public void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame) {
public void onCompilationDeoptimized(OptimizedCallTarget target, Frame frame, String reason) {
if (target.engine.traceCompilation || target.engine.traceCompilationDetails) {
log(target, String.format(DEOPT_FORMAT,
target.engineId(),
target.id,
safeTargetName(target),
TIME_FORMATTER.format(ZonedDateTime.now()),
formatSourceSection(safeSourceSection(target))));
formatSourceSection(safeSourceSection(target)),
reason != null ? reason : "unknown"));
}
}

@Override
public void onProfileReset(OptimizedCallTarget target) {
if (target.engine.traceCompilation || target.engine.traceCompilationDetails) {
log(target, String.format(REPROF_FORMAT,
target.engineId(),
target.id,
safeTargetName(target),
TIME_FORMATTER.format(ZonedDateTime.now()),
formatSourceSection(safeSourceSection(target))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import java.lang.reflect.Method;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.compiler.TruffleCompiler;
import com.oracle.truffle.runtime.EngineData;
Expand Down Expand Up @@ -111,7 +112,7 @@ public HotSpotOptimizedCallTarget(EngineData engine) {
setSpeculationLog = method;
method = null;
try {
method = InstalledCode.class.getDeclaredMethod("invalidate", boolean.class);
method = InstalledCode.class.getDeclaredMethod("invalidate", boolean.class, int.class);
} catch (NoSuchMethodException e) {
}
invalidateInstalledCode = method;
Expand All @@ -122,20 +123,10 @@ public HotSpotOptimizedCallTarget(EngineData engine) {
*/
public void setInstalledCode(InstalledCode code) {
assert code != null : "code must never become null";
InstalledCode oldCode = this.installedCode;
if (oldCode == code) {
if (this.installedCode == code) {
return;
}

if (oldCode != INVALID_CODE && invalidateInstalledCode != null) {
try {
invalidateInstalledCode.invoke(oldCode, false);
} catch (Error e) {
throw e;
} catch (Throwable throwable) {
throw new InternalError(throwable);
}
}
invalidateExistingCode();

// A default nmethod can be called from entry points in the VM (e.g., Method::_code)
// and so allowing it to be installed here would invalidate the truth of
Expand All @@ -151,6 +142,19 @@ public void setInstalledCode(InstalledCode code) {
this.installedCode = code;
}

private void invalidateExistingCode() {
if (this.installedCode != INVALID_CODE && invalidateInstalledCode != null) {
try {
invalidateInstalledCode.invoke(this.installedCode, false, HotSpotNmethod.ChangeReason.GC_UNLINKING_COLD.ordinal());
this.installedCode = INVALID_CODE;
} catch (Error e) {
throw e;
} catch (Throwable throwable) {
throw new InternalError(throwable);
}
}
}

/**
* Tethers this object's speculation log with {@code nmethod} if the log has speculations and
* manages its failed speculation list. This maintains the invariant described by
Expand All @@ -174,9 +178,20 @@ private void tetherSpeculationLog(HotSpotNmethod nmethod) throws Error, Internal
}
}

/**
* This method will reset the execution profile counters of this call target if the
* installed code was invalidated because it became cold.
* @return whether the currently installed code is valid/executable.
*/
@Override
public boolean isValid() {
return installedCode.isValid();
boolean isValid = installedCode.isValid();
if (!isValid && installedCode != INVALID_CODE && installedCode.getChangeReason() == HotSpotNmethod.ChangeReason.GC_UNLINKING_COLD.ordinal()) {
invalidateExistingCode();
resetCompilationProfile();
runtime().getListener().onProfileReset(this);
}
return isValid;
}

@Override
Expand All @@ -195,4 +210,8 @@ public SpeculationLog getCompilationSpeculationLog() {
return HotSpotTruffleRuntimeServices.getCompilationSpeculationLog(this);
}

protected void notifyDeoptimized(VirtualFrame frame) {
runtime().getListener().onCompilationDeoptimized(this, frame,
installedCode.getChangeReasonDescription());
}
}