Skip to content

Commit 241aecc

Browse files
committed
Installed code change reason
1 parent a2d7f44 commit 241aecc

File tree

15 files changed

+56
-44
lines changed

15 files changed

+56
-44
lines changed

src/hotspot/share/c1/c1_Runtime1.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ JRT_ENTRY(void, Runtime1::deoptimize(JavaThread* current, jint trap_request))
800800
Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(trap_request);
801801

802802
if (action == Deoptimization::Action_make_not_entrant) {
803-
if (nm->make_not_entrant("C1 deoptimize")) {
803+
if (nm->make_not_entrant(nmethod::C1_deoptimize)) {
804804
if (reason == Deoptimization::Reason_tenured) {
805805
MethodData* trap_mdo = Deoptimization::get_method_data(current, method, true /*create_if_missing*/);
806806
if (trap_mdo != nullptr) {
@@ -1092,7 +1092,7 @@ JRT_ENTRY(void, Runtime1::patch_code(JavaThread* current, C1StubId stub_id ))
10921092
// safepoint, but if it's still alive then make it not_entrant.
10931093
nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
10941094
if (nm != nullptr) {
1095-
nm->make_not_entrant("C1 code patch");
1095+
nm->make_not_entrant(nmethod::C1_codepatch);
10961096
}
10971097

10981098
Deoptimization::deoptimize_frame(current, caller_frame.id());
@@ -1340,7 +1340,7 @@ void Runtime1::patch_code(JavaThread* current, C1StubId stub_id) {
13401340
// Make sure the nmethod is invalidated, i.e. made not entrant.
13411341
nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
13421342
if (nm != nullptr) {
1343-
nm->make_not_entrant("C1 deoptimize for patching");
1343+
nm->make_not_entrant(nmethod::C1_deoptimize_for_patching);
13441344
}
13451345
}
13461346

@@ -1468,7 +1468,7 @@ JRT_ENTRY(void, Runtime1::predicate_failed_trap(JavaThread* current))
14681468

14691469
nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
14701470
assert (nm != nullptr, "no more nmethod?");
1471-
nm->make_not_entrant("C1 predicate failed trap");
1471+
nm->make_not_entrant(nmethod::C1_predicate_failed_trap);
14721472

14731473
methodHandle m(current, nm->method());
14741474
MethodData* mdo = m->method_data();

src/hotspot/share/ci/ciReplay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ class CompileReplay : public StackObj {
802802
// Make sure the existence of a prior compile doesn't stop this one
803803
nmethod* nm = (entry_bci != InvocationEntryBci) ? method->lookup_osr_nmethod_for(entry_bci, comp_level, true) : method->code();
804804
if (nm != nullptr) {
805-
nm->make_not_entrant("CI replay");
805+
nm->make_not_entrant(nmethod::CI_replay);
806806
}
807807
replay_state = this;
808808
CompileBroker::compile_method(methodHandle(THREAD, method), entry_bci, comp_level,

src/hotspot/share/code/codeCache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ void CodeCache::make_marked_nmethods_deoptimized() {
13611361
while(iter.next()) {
13621362
nmethod* nm = iter.method();
13631363
if (nm->is_marked_for_deoptimization() && !nm->has_been_deoptimized() && nm->can_be_deoptimized()) {
1364-
nm->make_not_entrant("marked for deoptimization");
1364+
nm->make_not_entrant(nmethod::marked_for_deoptimization);
13651365
nm->make_deoptimized();
13661366
}
13671367
}

src/hotspot/share/code/nmethod.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,13 +1964,11 @@ void nmethod::invalidate_osr_method() {
19641964
}
19651965
}
19661966

1967-
void nmethod::log_state_change(const char* reason) const {
1968-
assert(reason != nullptr, "Must provide a reason");
1969-
1967+
void nmethod::log_state_change(NMethodChangeReason reason) const {
19701968
if (LogCompilation) {
19711969
if (xtty != nullptr) {
19721970
ttyLocker ttyl; // keep the following output all in one block
1973-
xtty->begin_elem("make_not_entrant thread='%zu' reason='%s'",
1971+
xtty->begin_elem("make_not_entrant thread='%zu' reason='%d'",
19741972
os::current_thread_id(), reason);
19751973
log_identity(xtty);
19761974
xtty->stamp();
@@ -1980,7 +1978,7 @@ void nmethod::log_state_change(const char* reason) const {
19801978

19811979
ResourceMark rm;
19821980
stringStream ss(NEW_RESOURCE_ARRAY(char, 256), 256);
1983-
ss.print("made not entrant: %s", reason);
1981+
ss.print("made not entrant: %d", reason);
19841982

19851983
CompileTask::print_ul(this, ss.freeze());
19861984
if (PrintCompilation) {
@@ -1995,9 +1993,7 @@ void nmethod::unlink_from_method() {
19951993
}
19961994

19971995
// Invalidate code
1998-
bool nmethod::make_not_entrant(const char* reason) {
1999-
assert(reason != nullptr, "Must provide a reason");
2000-
1996+
bool nmethod::make_not_entrant(NMethodChangeReason reason) {
20011997
// This can be called while the system is already at a safepoint which is ok
20021998
NoSafepointVerifier nsv;
20031999

src/hotspot/share/code/nmethod.hpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,31 @@ class nmethod : public CodeBlob {
469469
void oops_do_set_strong_done(nmethod* old_head);
470470

471471
public:
472+
enum NMethodChangeReason : s4 {
473+
C1_deoptimize = 0,
474+
C1_codepatch,
475+
C1_predicate_failed_trap,
476+
C1_deoptimize_for_patching,
477+
CI_replay,
478+
marked_for_deoptimization,
479+
not_used,
480+
OSR_invalidation_for_compiling_with_C1,
481+
OSR_invalidation_back_branch,
482+
JVMCI_reprofile,
483+
JVMCI_materialize_virtual_object,
484+
JVMCI_invalidate_nmethod_mirror,
485+
JVMCI_register_method,
486+
OSR_invalidation_of_lower_level,
487+
set_native_function,
488+
whitebox_deoptimization,
489+
missing_exception_handler,
490+
uncommon_trap,
491+
zombie,
492+
JVMCI_invalidate_nmethod,
493+
JVMCI_new_installation,
494+
JVMCI_replacing_with_new_code,
495+
};
496+
472497
// create nmethod with entry_bci
473498
static nmethod* new_nmethod(const methodHandle& method,
474499
int compile_id,
@@ -631,8 +656,8 @@ class nmethod : public CodeBlob {
631656
// alive. It is used when an uncommon trap happens. Returns true
632657
// if this thread changed the state of the nmethod or false if
633658
// another thread performed the transition.
634-
bool make_not_entrant(const char* reason);
635-
bool make_not_used() { return make_not_entrant("not used"); }
659+
bool make_not_entrant(NMethodChangeReason reason);
660+
bool make_not_used() { return make_not_entrant(nmethod::not_used); }
636661

637662
bool is_marked_for_deoptimization() const { return deoptimization_status() != not_marked; }
638663
bool has_been_deoptimized() const { return deoptimization_status() == deoptimize_done; }
@@ -945,7 +970,7 @@ class nmethod : public CodeBlob {
945970
// Logging
946971
void log_identity(xmlStream* log) const;
947972
void log_new_nmethod() const;
948-
void log_state_change(const char* reason) const;
973+
void log_state_change(NMethodChangeReason reason) const;
949974

950975
// Prints block-level comments, including nmethod specific block labels:
951976
void print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels=true) const;

src/hotspot/share/compiler/compilationPolicy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ void CompilationPolicy::compile(const methodHandle& mh, int bci, CompLevel level
796796
nmethod* osr_nm = mh->lookup_osr_nmethod_for(bci, CompLevel_simple, false);
797797
if (osr_nm != nullptr && osr_nm->comp_level() > CompLevel_simple) {
798798
// Invalidate the existing OSR nmethod so that a compile at CompLevel_simple is permitted.
799-
osr_nm->make_not_entrant("OSR invalidation for compiling with C1");
799+
osr_nm->make_not_entrant(nmethod::OSR_invalidation_for_compiling_with_C1);
800800
}
801801
compile(mh, bci, CompLevel_simple, THREAD);
802802
}
@@ -1201,7 +1201,7 @@ void CompilationPolicy::method_back_branch_event(const methodHandle& mh, const m
12011201
int osr_bci = nm->is_osr_method() ? nm->osr_entry_bci() : InvocationEntryBci;
12021202
print_event(MAKE_NOT_ENTRANT, mh(), mh(), osr_bci, level);
12031203
}
1204-
nm->make_not_entrant("OSR invalidation, back branch");
1204+
nm->make_not_entrant(nmethod::OSR_invalidation_back_branch);
12051205
}
12061206
}
12071207
// Fix up next_level if necessary to avoid deopts

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "classfile/systemDictionary.hpp"
2929
#include "classfile/vmClasses.hpp"
3030
#include "code/scopeDesc.hpp"
31+
#include "code/nmethod.hpp"
3132
#include "compiler/compileBroker.hpp"
3233
#include "compiler/compilerEvent.hpp"
3334
#include "compiler/compilerOracle.hpp"
@@ -1193,7 +1194,7 @@ C2V_VMENTRY_0(jint, installCode0, (JNIEnv *env, jobject,
11931194
assert(JVMCIENV->isa_HotSpotNmethod(installed_code_handle), "wrong type");
11941195
// Clear the link to an old nmethod first
11951196
JVMCIObject nmethod_mirror = installed_code_handle;
1196-
JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, true, JVMCI_CHECK_0);
1197+
JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, true, nmethod::JVMCI_replacing_with_new_code, JVMCI_CHECK_0);
11971198
} else {
11981199
assert(JVMCIENV->isa_InstalledCode(installed_code_handle), "wrong type");
11991200
}
@@ -1369,7 +1370,7 @@ C2V_VMENTRY(void, reprofile, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
13691370

13701371
nmethod* code = method->code();
13711372
if (code != nullptr) {
1372-
code->make_not_entrant("JVMCI reprofile");
1373+
code->make_not_entrant(nmethod::JVMCI_reprofile);
13731374
}
13741375

13751376
MethodData* method_data = method->method_data();
@@ -1384,7 +1385,7 @@ C2V_END
13841385

13851386
C2V_VMENTRY(void, invalidateHotSpotNmethod, (JNIEnv* env, jobject, jobject hs_nmethod, jboolean deoptimize))
13861387
JVMCIObject nmethod_mirror = JVMCIENV->wrap(hs_nmethod);
1387-
JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, deoptimize, JVMCI_CHECK);
1388+
JVMCIENV->invalidate_nmethod_mirror(nmethod_mirror, deoptimize, nmethod::NMethodChangeReason::JVMCI_invalidate_nmethod, JVMCI_CHECK);
13881389
C2V_END
13891390

13901391
C2V_VMENTRY_NULL(jlongArray, collectCounters, (JNIEnv* env, jobject))
@@ -1809,7 +1810,7 @@ C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv* env, jobject, jobject _hs_
18091810
if (!fst.current()->is_compiled_frame()) {
18101811
JVMCI_THROW_MSG(IllegalStateException, "compiled stack frame expected");
18111812
}
1812-
fst.current()->cb()->as_nmethod()->make_not_entrant("JVMCI materialize virtual objects");
1813+
fst.current()->cb()->as_nmethod()->make_not_entrant(nmethod::JVMCI_materialize_virtual_object);
18131814
}
18141815
Deoptimization::deoptimize(thread, *fst.current(), Deoptimization::Reason_none);
18151816
// look for the frame again as it has been updated by deopt (pc, deopt state...)
@@ -2253,16 +2254,6 @@ static jobject read_field_value(Handle obj, long displacement, jchar type_char,
22532254
if (!aligned) {
22542255
JVMCI_THROW_MSG_NULL(IllegalArgumentException, "read is unaligned");
22552256
}
2256-
if (obj->is_array()) {
2257-
// Disallow reading after the last element of an array
2258-
size_t array_length = arrayOop(obj())->length();
2259-
int lh = obj->klass()->layout_helper();
2260-
size_t size_in_bytes = array_length << Klass::layout_helper_log2_element_size(lh);
2261-
size_in_bytes += Klass::layout_helper_header_size(lh);
2262-
if ((size_t) displacement + basic_type_elemsize > size_in_bytes) {
2263-
JVMCI_THROW_MSG_NULL(IllegalArgumentException, "reading after last array element");
2264-
}
2265-
}
22662257
if (basic_type == T_OBJECT) {
22672258
if (obj->is_objArray()) {
22682259
if (displacement < arrayOopDesc::base_offset_in_bytes(T_OBJECT)) {

src/hotspot/share/jvmci/jvmciEnv.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ void JVMCIEnv::initialize_installed_code(JVMCIObject installed_code, CodeBlob* c
17521752
}
17531753

17541754

1755-
void JVMCIEnv::invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimize, JVMCI_TRAPS) {
1755+
void JVMCIEnv::invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimize, nmethod::NMethodChangeReason statusReason, JVMCI_TRAPS) {
17561756
if (mirror.is_null()) {
17571757
JVMCI_THROW(NullPointerException);
17581758
}
@@ -1775,7 +1775,7 @@ void JVMCIEnv::invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimize, JV
17751775

17761776
if (!deoptimize) {
17771777
// Prevent future executions of the nmethod but let current executions complete.
1778-
nm->make_not_entrant("JVMCI invalidate nmethod mirror");
1778+
nm->make_not_entrant(statusReason);
17791779

17801780
// Do not clear the address field here as the Java code may still
17811781
// want to later call this method with deoptimize == true. That requires
@@ -1784,7 +1784,7 @@ void JVMCIEnv::invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimize, JV
17841784
// Deoptimize the nmethod immediately.
17851785
DeoptimizationScope deopt_scope;
17861786
deopt_scope.mark(nm);
1787-
nm->make_not_entrant("JVMCI invalidate nmethod mirror");
1787+
nm->make_not_entrant(statusReason);
17881788
nm->make_deoptimized();
17891789
deopt_scope.deoptimize_marked();
17901790

src/hotspot/share/jvmci/jvmciEnv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ class JVMCIEnv : public ResourceObj {
462462
// field of `mirror` to prevent it from being called.
463463
// If `deoptimize` is true, the nmethod is immediately deoptimized.
464464
// The HotSpotNmethod.address field is zero upon returning.
465-
void invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimze, JVMCI_TRAPS);
465+
void invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimze, nmethod::NMethodChangeReason statusReason, JVMCI_TRAPS);
466466

467467
void initialize_installed_code(JVMCIObject installed_code, CodeBlob* cb, JVMCI_TRAPS);
468468

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
21962196
tty->print_cr("Replacing method %s", method_name);
21972197
}
21982198
if (old != nullptr) {
2199-
old->make_not_entrant("JVMCI register method");
2199+
old->make_not_entrant(nmethod::JVMCI_register_method);
22002200
}
22012201

22022202
LogTarget(Info, nmethod, install) lt;

0 commit comments

Comments
 (0)