Skip to content
17 changes: 4 additions & 13 deletions src/hotspot/share/code/nmethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class nmethod : public CodeBlob {

public:
// If you change anything in this enum please patch
// vmStructs_jvmci.cpp and HotSpotNmethod.java accordingly.
// vmStructs_jvmci.cpp accordingly.
enum class ChangeReason : u1 {
unknown,
C1_codepatch,
Expand All @@ -483,11 +483,8 @@ class nmethod : public CodeBlob {
GC_unlinking,
GC_unlinking_cold,
JVMCI_invalidate_nmethod,
JVMCI_invalidate_nmethod_mirror,
JVMCI_materialize_virtual_object,
JVMCI_new_installation,
JVMCI_register_method,
JVMCI_replacing_with_new_code,
JVMCI_replaced_with_new_code,
JVMCI_reprofile,
marked_for_deoptimization,
missing_exception_handler,
Expand Down Expand Up @@ -516,16 +513,10 @@ class nmethod : public CodeBlob {
return "CI replay";
case ChangeReason::JVMCI_invalidate_nmethod:
return "JVMCI invalidate nmethod";
case ChangeReason::JVMCI_invalidate_nmethod_mirror:
return "JVMCI invalidate nmethod mirror";
case ChangeReason::JVMCI_materialize_virtual_object:
return "JVMCI materialize virtual object";
case ChangeReason::JVMCI_new_installation:
return "JVMCI new installation";
case ChangeReason::JVMCI_register_method:
return "JVMCI register method";
case ChangeReason::JVMCI_replacing_with_new_code:
return "JVMCI replacing with new code";
case ChangeReason::JVMCI_replaced_with_new_code:
return "JVMCI replaced with new code";
case ChangeReason::JVMCI_reprofile:
return "JVMCI reprofile";
case ChangeReason::marked_for_deoptimization:
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ C2V_VMENTRY_0(jint, installCode0, (JNIEnv *env, jobject,
assert(JVMCIENV->isa_HotSpotNmethod(installed_code_handle), "wrong type");
// Clear the link to an old nmethod first
JVMCIObject nmethod_mirror = installed_code_handle;
JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, true, nmethod::ChangeReason::JVMCI_replacing_with_new_code, JVMCI_CHECK_0);
JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, true, nmethod::ChangeReason::JVMCI_replaced_with_new_code, JVMCI_CHECK_0);
} else {
assert(JVMCIENV->isa_InstalledCode(installed_code_handle), "wrong type");
}
Expand All @@ -1218,10 +1218,10 @@ C2V_VMENTRY_0(jint, installCode0, (JNIEnv *env, jobject,
return result;
C2V_END

C2V_VMENTRY_0(jobject, getChangeReasonDescription, (JNIEnv *env, jobject, jint change_reason))
C2V_VMENTRY_0(jobject, getInvalidationReasonString, (JNIEnv *env, jobject, jint invalidation_reason))
HandleMark hm(THREAD);
JNIHandleMark jni_hm(thread);
nmethod::ChangeReason reason = static_cast<nmethod::ChangeReason>(change_reason);
nmethod::ChangeReason reason = static_cast<nmethod::ChangeReason>(invalidation_reason);
JVMCIObject desc = JVMCIENV->create_string(nmethod::change_reason_to_string(reason), JVMCI_CHECK_NULL);
return JVMCIENV->get_jobject(desc);
C2V_END
Expand Down Expand Up @@ -3360,7 +3360,7 @@ JNINativeMethod CompilerToVM::methods[] = {
{CC "getResolvedJavaType0", CC "(Ljava/lang/Object;JZ)" HS_KLASS, FN_PTR(getResolvedJavaType0)},
{CC "readConfiguration", CC "()[" OBJECT, FN_PTR(readConfiguration)},
{CC "installCode0", CC "(JJZ" HS_COMPILED_CODE "[" OBJECT INSTALLED_CODE "J[B)I", FN_PTR(installCode0)},
{CC "getChangeReasonDescription", CC "(I)" STRING, FN_PTR(getChangeReasonDescription)},
{CC "getInvalidationReasonString", CC "(I)" STRING, FN_PTR(getInvalidationReasonString)},
{CC "getInstallCodeFlags", CC "()I", FN_PTR(getInstallCodeFlags)},
{CC "resetCompilationStatistics", CC "()V", FN_PTR(resetCompilationStatistics)},
{CC "disassembleCodeBlob", CC "(" INSTALLED_CODE ")" STRING, FN_PTR(disassembleCodeBlob)},
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/jvmci/jvmciEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ void JVMCIEnv::initialize_installed_code(JVMCIObject installed_code, CodeBlob* c
set_InstalledCode_entryPoint(installed_code, (jlong) cb->code_begin());
}
set_InstalledCode_address(installed_code, (jlong) cb);
set_InstalledCode_changeReason(installed_code, static_cast<int>(nmethod::ChangeReason::JVMCI_new_installation));
set_HotSpotNmethod_invalidationReason(installed_code, static_cast<int>(nmethod::ChangeReason::unknown));
set_HotSpotInstalledCode_size(installed_code, cb->size());
set_HotSpotInstalledCode_codeStart(installed_code, (jlong) cb->code_begin());
set_HotSpotInstalledCode_codeSize(installed_code, cb->code_size());
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/jvmci/jvmciJavaClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
long_field(InstalledCode, entryPoint) \
long_field(InstalledCode, version) \
object_field(InstalledCode, name, "Ljava/lang/String;") \
int_field(InstalledCode, changeReason) \
end_class \
start_class(HotSpotInstalledCode, jdk_vm_ci_hotspot_HotSpotInstalledCode) \
int_field(HotSpotInstalledCode, size) \
Expand All @@ -103,6 +102,7 @@
boolean_field(HotSpotNmethod, isDefault) \
long_field(HotSpotNmethod, compileIdSnapshot) \
object_field(HotSpotNmethod, method, "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;") \
int_field(HotSpotNmethod, invalidationReason) \
jvmci_constructor(HotSpotNmethod, "(Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;Ljava/lang/String;ZJ)V") \
end_class \
start_class(HotSpotCompiledCode, jdk_vm_ci_hotspot_HotSpotCompiledCode) \
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/jvmci/jvmciRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,14 +815,14 @@ void JVMCINMethodData::invalidate_nmethod_mirror(nmethod* nm, nmethod::ChangeRea
// an InvalidInstalledCodeException.
HotSpotJVMCI::InstalledCode::set_address(jvmciEnv, nmethod_mirror, 0);
HotSpotJVMCI::InstalledCode::set_entryPoint(jvmciEnv, nmethod_mirror, 0);
HotSpotJVMCI::InstalledCode::set_changeReason(jvmciEnv, nmethod_mirror, static_cast<int>(change_reason));
HotSpotJVMCI::HotSpotNmethod::set_invalidationReason(jvmciEnv, nmethod_mirror, static_cast<int>(change_reason));
HotSpotJVMCI::HotSpotInstalledCode::set_codeStart(jvmciEnv, nmethod_mirror, 0);
} else if (nm->is_not_entrant()) {
// Zero the entry point so any new invocation will fail but keep
// the address link around that so that existing activations can
// be deoptimized via the mirror (i.e. JVMCIEnv::invalidate_installed_code).
HotSpotJVMCI::InstalledCode::set_entryPoint(jvmciEnv, nmethod_mirror, 0);
HotSpotJVMCI::InstalledCode::set_changeReason(jvmciEnv, nmethod_mirror, static_cast<int>(change_reason));
HotSpotJVMCI::HotSpotNmethod::set_invalidationReason(jvmciEnv, nmethod_mirror, static_cast<int>(change_reason));
HotSpotJVMCI::HotSpotInstalledCode::set_codeStart(jvmciEnv, nmethod_mirror, 0);
}
}
Expand Down Expand Up @@ -2186,7 +2186,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
tty->print_cr("Replacing method %s", method_name);
}
if (old != nullptr) {
old->make_not_entrant(nmethod::ChangeReason::JVMCI_register_method);
old->make_not_entrant(nmethod::ChangeReason::JVMCI_replaced_with_new_code);
}

LogTarget(Info, nmethod, install) lt;
Expand Down
5 changes: 1 addition & 4 deletions src/hotspot/share/jvmci/vmStructs_jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,8 @@
declare_constant_with_value("nmethod::ChangeReason::GC_UNLINKING", nmethod::ChangeReason::GC_unlinking) \
declare_constant_with_value("nmethod::ChangeReason::GC_UNLINKING_COLD", nmethod::ChangeReason::GC_unlinking_cold) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_INVALIDATE_NMETHOD", nmethod::ChangeReason::JVMCI_invalidate_nmethod) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_INVALIDATE_NMETHOD_MIRROR", nmethod::ChangeReason::JVMCI_invalidate_nmethod_mirror) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_MATERIALIZE_VIRTUAL_OBJECT", nmethod::ChangeReason::JVMCI_materialize_virtual_object) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_NEW_INSTALLATION", nmethod::ChangeReason::JVMCI_new_installation) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_REGISTER_METHOD", nmethod::ChangeReason::JVMCI_register_method) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_REPLACING_WITH_NEW_CODE", nmethod::ChangeReason::JVMCI_replacing_with_new_code) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_REPLACED_WITH_NEW_CODE", nmethod::ChangeReason::JVMCI_replaced_with_new_code) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_REPROFILE", nmethod::ChangeReason::JVMCI_reprofile) \
declare_constant_with_value("nmethod::ChangeReason::MARKED_FOR_DEOPTIMIZATION", nmethod::ChangeReason::marked_for_deoptimization) \
declare_constant_with_value("nmethod::ChangeReason::MISSING_EXCEPTION_HANDLER", nmethod::ChangeReason::missing_exception_handler) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ default InstalledCode setDefaultCode(ResolvedJavaMethod method, CompiledCode com
* raised the next time {@code installedCode} is
* {@linkplain InstalledCode#executeVarargs(Object...) executed}.
*/
void invalidateInstalledCode(InstalledCode installedCode, int changeReason);
void invalidateInstalledCode(InstalledCode installedCode);

/**
* Gets a name for a {@link Mark} mark.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public class InstalledCode {

protected final String name;

/**
* Identify the reason that caused this installed code to change.
*/
protected int changeReason;

/**
* The maximum length of an InstalledCode name. This name is typically installed into
* the code cache so it should have a reasonable limit.
Expand Down Expand Up @@ -124,20 +119,6 @@ public boolean isAlive() {
return address != 0;
}

/**
* @return an integer representing the reason why this InstalledCode changed.
*/
public int getChangeReason() {
return changeReason;
}

/**
* @return a String describing the reason why this InstalledCode changed.
*/
public String getChangeReasonDescription() {
return null;
}

/**
* Returns a copy of this installed code if it is {@linkplain #isValid() valid}, null otherwise.
*/
Expand All @@ -149,7 +130,7 @@ public byte[] getCode() {
* Equivalent to calling {@link #invalidate(boolean, int)} with {@code true} and {@code 0} as arguments.
*/
public void invalidate() {
invalidate(true, 0);
invalidate(true);
}

/**
Expand All @@ -165,9 +146,8 @@ public void invalidate() {
* If {@code false}, any existing invocation will continue until it completes or
* there is a subsequent call to this method with {@code deoptimize == true} before
* the invocation completes.
* @param changeReason an integer code representing the reason why this InstalledCode is being marked as invalidated.
*/
public void invalidate(boolean deoptimize, int statusReason) {
public void invalidate(boolean deoptimize) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ native int installCode0(long compiledCodeBuffer,
long failedSpeculationsAddress,
byte[] speculations);

native String getChangeReasonDescription(int changeReason);
native String getInvalidationReasonString(int invalidationReason);

/**
* Gets flags specifying optional parts of code info. Only if a flag is set, will the
Expand Down Expand Up @@ -844,7 +844,7 @@ void reprofile(HotSpotResolvedJavaMethodImpl method) {
* {@code nmethod} associated with {@code nmethodMirror} is also made non-entrant and if
* {@code deoptimize == true} any current activations of the {@code nmethod} are deoptimized.
*/
native void invalidateHotSpotNmethod(HotSpotNmethod nmethodMirror, boolean deoptimize, int changeReason);
native void invalidateHotSpotNmethod(HotSpotNmethod nmethodMirror, boolean deoptimize, int invalidationReason);

/**
* Collects the current values of all JVMCI benchmark counters, summed up over all threads.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,20 @@ public InstalledCode installCode(ResolvedJavaMethod method, CompiledCode compile
return logOrDump(resultInstalledCode, compiledCode);
}

@Override
public void invalidateInstalledCode(InstalledCode installedCode, int changeReason) {
public void invalidateInstalledCode(InstalledCode installedCode, int invalidationReason) {
if (installedCode instanceof HotSpotNmethod) {
HotSpotNmethod nmethod = (HotSpotNmethod) installedCode;
nmethod.invalidate(true, changeReason);
nmethod.invalidate(true, invalidationReason);
} else {
throw new IllegalArgumentException("Cannot invalidate a " + Objects.requireNonNull(installedCode).getClass().getName());
}
}

@Override
public void invalidateInstalledCode(InstalledCode installedCode) {
invalidateInstalledCode(installedCode, unknownInvalidationReason());
}

@Override
public TargetDescription getTarget() {
return target;
Expand Down Expand Up @@ -201,4 +205,8 @@ public int interpreterFrameSize(BytecodeFrame pos) {
public void resetCompilationStatistics() {
runtime.getCompilerToVM().resetCompilationStatistics();
}

private static int unknownInvalidationReason() {
return HotSpotJVMCIRuntime.runtime().config.getConstant("nmethod::ChangeReason::Unknown", Integer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,4 @@ public long getCodeSize() {
public byte[] getCode() {
return compilerToVM().getCode(this);
}

@Override
public String getChangeReasonDescription() {
return compilerToVM().getChangeReasonDescription(this.getChangeReason());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,52 +78,17 @@ boolean inOopsTable() {
private final long compileIdSnapshot;

/**
* This is a mirror of the ChangeReason enum defined in nmethod.hpp.
* It defines constants representing different reasons why an nmethod
* changed or was invalidated.
* Identify the reason that caused this nmethod to be invalidated.
*/
public enum ChangeReason {
UNKNOWN,
C1_CODEPATCH,
C1_DEOPTIMIZE,
C1_DEOPTIMIZE_FOR_PATCHING,
C1_PREDICATE_FAILED_TRAP,
CI_REPLAY,
GC_UNLINKING,
GC_UNLINKING_COLD,
JVMCI_INVALIDATE_NMETHOD,
JVMCI_INVALIDATE_NMETHOD_MIRROR,
JVMCI_MATERIALIZE_VIRTUAL_OBJECT,
JVMCI_NEW_INSTALLATION,
JVMCI_REGISTER_METHOD,
JVMCI_REPLACING_WITH_NEW_CODE,
JVMCI_REPROFILE,
MARKED_FOR_DEOPTIMIZATION,
MISSING_EXCEPTION_HANDLER,
NOT_USED,
OSR_INVALIDATION_BACK_BRANCH,
OSR_INVALIDATION_FOR_COMPILING_WITH_C1,
OSR_INVALIDATION_OF_LOWER_LEVEL,
SET_NATIVE_FUNCTION,
UNCOMMON_TRAP,
WHITEBOX_DEOPTIMIZATION,
ZOMBIE;

ChangeReason() {
int expect = ordinal();
int actual = nmethodChangeReasonValue(name());
if (expect != actual) {
throw new JVMCIError("%s: expected %d, got %d", name(), expect, actual);
}
}
}
private int invalidationReason;

HotSpotNmethod(HotSpotResolvedJavaMethodImpl method, String name, boolean isDefault, long compileId) {
super(name);
this.method = method;
this.isDefault = isDefault;
boolean inOopsTable = !IS_IN_NATIVE_IMAGE && !isDefault;
this.compileIdSnapshot = inOopsTable ? 0L : compileId;
this.invalidationReason = 0;
assert inOopsTable || compileId != 0L : this;
}

Expand Down Expand Up @@ -164,9 +129,13 @@ public ResolvedJavaMethod getMethod() {
return method;
}

public void invalidate(boolean deoptimize, int invalidationReason) {
compilerToVM().invalidateHotSpotNmethod(this, deoptimize, invalidationReason);
}

@Override
public void invalidate(boolean deoptimize, int changeReason) {
compilerToVM().invalidateHotSpotNmethod(this, deoptimize, changeReason);
public void invalidate(boolean deoptimize) {
invalidate(deoptimize, unknownInvalidationReason());
}

@Override
Expand Down Expand Up @@ -231,7 +200,21 @@ public long getStart() {
return isValid() ? super.getStart() : 0;
}

private static int nmethodChangeReasonValue(String name) {
return HotSpotJVMCIRuntime.runtime().config.getConstant("nmethod::ChangeReason::" + name, Integer.class);
/**
* @return an integer representing the reason why this nmethod was invalidated.
*/
public int getInvalidationReason() {
return invalidationReason;
}

/**
* @return a String describing the reason why this nmethod was invalidated.
*/
public String getInvalidationReasonString() {
return compilerToVM().getInvalidationReasonString(this.getInvalidationReason());
}

private static int unknownInvalidationReason() {
return HotSpotJVMCIRuntime.runtime().config.getConstant("nmethod::ChangeReason::Unknown", Integer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import java.lang.reflect.Method;

/**
* Test if passing InstalledCode changeReason around works.
* Test if setting HotSpotNmethod invalidation reason around works.
*/
public class CodeInvalidationReasonTest extends CodeInstallationTest {

Expand All @@ -69,9 +69,9 @@ public void test() {
Method method = getMethod("add", int.class, int.class);

HotSpotNmethod nmethod = test(CodeInvalidationReasonTest::compileAdd, method, 5, 7);
Asserts.assertEquals(config.JVMCI_new_installation, nmethod.getChangeReason());
Asserts.assertEquals(config.NMETHOD_CHANGE_REASON_UNKNOWN, nmethod.getInvalidationReason());

nmethod.invalidate(true, config.JVMCI_invalidate_nmethod);
Asserts.assertEquals(config.JVMCI_invalidate_nmethod, nmethod.getChangeReason());
nmethod.invalidate(true, config.NMETHOD_CHANGE_REASON_JVMCI_INVALIDATE);
Asserts.assertEquals(config.NMETHOD_CHANGE_REASON_JVMCI_INVALIDATE, nmethod.getInvalidationReason());
}
}
Loading