Skip to content
2 changes: 2 additions & 0 deletions src/hotspot/share/code/nmethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ class nmethod : public CodeBlob {
void oops_do_set_strong_done(nmethod* old_head);

public:
// If you change anything in this enum please patch
// vmStructs_jvmci.cpp and HotSpotNmethod.java accordingly.
enum class ChangeReason : u1 {
unknown,
C1_codepatch,
Expand Down
32 changes: 27 additions & 5 deletions src/hotspot/share/jvmci/vmStructs_jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,33 @@
declare_constant_with_value("LockStack::_end_offset", LockStack::end_offset()) \
declare_constant_with_value("OMCache::oop_to_oop_difference", OMCache::oop_to_oop_difference()) \
declare_constant_with_value("OMCache::oop_to_monitor_difference", OMCache::oop_to_monitor_difference()) \
\
declare_constant_with_value("nmethod::ChangeReason::GC_unlinking_cold", nmethod::ChangeReason::GC_unlinking_cold) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_new_installation", nmethod::ChangeReason::JVMCI_new_installation) \
declare_constant_with_value("nmethod::ChangeReason::JVMCI_invalidate_nmethod", nmethod::ChangeReason::JVMCI_invalidate_nmethod) \
\
\
declare_constant_with_value("nmethod::ChangeReason::UNKNOWN", nmethod::ChangeReason::unknown) \
declare_constant_with_value("nmethod::ChangeReason::C1_CODEPATCH", nmethod::ChangeReason::C1_codepatch) \
declare_constant_with_value("nmethod::ChangeReason::C1_DEOPTIMIZE", nmethod::ChangeReason::C1_deoptimize) \
declare_constant_with_value("nmethod::ChangeReason::C1_DEOPTIMIZE_FOR_PATCHING", nmethod::ChangeReason::C1_deoptimize_for_patching) \
declare_constant_with_value("nmethod::ChangeReason::C1_PREDICATE_FAILED_TRAP", nmethod::ChangeReason::C1_predicate_failed_trap) \
declare_constant_with_value("nmethod::ChangeReason::CI_REPLAY", nmethod::ChangeReason::CI_replay) \
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_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) \
declare_constant_with_value("nmethod::ChangeReason::NOT_USED", nmethod::ChangeReason::not_used) \
declare_constant_with_value("nmethod::ChangeReason::OSR_INVALIDATION_BACK_BRANCH", nmethod::ChangeReason::OSR_invalidation_back_branch) \
declare_constant_with_value("nmethod::ChangeReason::OSR_INVALIDATION_FOR_COMPILING_WITH_C1", nmethod::ChangeReason::OSR_invalidation_for_compiling_with_C1) \
declare_constant_with_value("nmethod::ChangeReason::OSR_INVALIDATION_OF_LOWER_LEVEL", nmethod::ChangeReason::OSR_invalidation_of_lower_level) \
declare_constant_with_value("nmethod::ChangeReason::SET_NATIVE_FUNCTION", nmethod::ChangeReason::set_native_function) \
declare_constant_with_value("nmethod::ChangeReason::UNCOMMON_TRAP", nmethod::ChangeReason::uncommon_trap) \
declare_constant_with_value("nmethod::ChangeReason::WHITEBOX_DEOPTIMIZATION", nmethod::ChangeReason::whitebox_deoptimization) \
declare_constant_with_value("nmethod::ChangeReason::ZOMBIE", nmethod::ChangeReason::zombie) \
\
declare_constant(CodeInstaller::VERIFIED_ENTRY) \
declare_constant(CodeInstaller::UNVERIFIED_ENTRY) \
declare_constant(CodeInstaller::OSR_ENTRY) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,16 @@ 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.code.InvalidInstalledCodeException;
import jdk.vm.ci.common.JVMCIError;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.JavaType;
import jdk.vm.ci.meta.ResolvedJavaMethod;
Expand Down Expand Up @@ -76,6 +77,47 @@ 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.
*/
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);
}
}
}

HotSpotNmethod(HotSpotResolvedJavaMethodImpl method, String name, boolean isDefault, long compileId) {
super(name);
this.method = method;
Expand Down Expand Up @@ -188,4 +230,8 @@ public Object executeVarargs(Object... args) throws InvalidInstalledCodeExceptio
public long getStart() {
return isValid() ? super.getStart() : 0;
}

private static int nmethodChangeReasonValue(String name) {
return HotSpotJVMCIRuntime.runtime().config.getConstant("nmethod::ChangeReason::" + name, Integer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public TestHotSpotVMConfig(HotSpotVMConfigStore config, Architecture arch) {
public final int maxOopMapStackOffset = getFieldValue("CompilerToVM::Data::_max_oop_map_stack_offset", Integer.class, "int");
public final int heapWordSize = getConstant("HeapWordSize", Integer.class);

public final int JVMCI_new_installation = getConstant("nmethod::ChangeReason::JVMCI_new_installation", Integer.class);
public final int JVMCI_invalidate_nmethod = getConstant("nmethod::ChangeReason::JVMCI_invalidate_nmethod", Integer.class);
public final int JVMCI_new_installation = getConstant("nmethod::ChangeReason::JVMCI_NEW_INSTALLATION", Integer.class);
public final int JVMCI_invalidate_nmethod = getConstant("nmethod::ChangeReason::JVMCI_INVALIDATE_NMETHOD", Integer.class);

public final boolean ropProtection;

Expand Down