Skip to content

8351640: Print reason for making method not entrant #23980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
8 changes: 4 additions & 4 deletions src/hotspot/share/c1/c1_Runtime1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ JRT_ENTRY(void, Runtime1::deoptimize(JavaThread* current, jint trap_request))
Deoptimization::DeoptReason reason = Deoptimization::trap_request_reason(trap_request);

if (action == Deoptimization::Action_make_not_entrant) {
if (nm->make_not_entrant()) {
if (nm->make_not_entrant("C1 deoptimize")) {
if (reason == Deoptimization::Reason_tenured) {
MethodData* trap_mdo = Deoptimization::get_method_data(current, method, true /*create_if_missing*/);
if (trap_mdo != nullptr) {
Expand Down Expand Up @@ -1087,7 +1087,7 @@ JRT_ENTRY(void, Runtime1::patch_code(JavaThread* current, C1StubId stub_id ))
// safepoint, but if it's still alive then make it not_entrant.
nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
if (nm != nullptr) {
nm->make_not_entrant();
nm->make_not_entrant("C1 code patch");
}

Deoptimization::deoptimize_frame(current, caller_frame.id());
Expand Down Expand Up @@ -1335,7 +1335,7 @@ void Runtime1::patch_code(JavaThread* current, C1StubId stub_id) {
// Make sure the nmethod is invalidated, i.e. made not entrant.
nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
if (nm != nullptr) {
nm->make_not_entrant();
nm->make_not_entrant("C1 deoptimize for patching");
}
}

Expand Down Expand Up @@ -1463,7 +1463,7 @@ JRT_ENTRY(void, Runtime1::predicate_failed_trap(JavaThread* current))

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

methodHandle m(current, nm->method());
MethodData* mdo = m->method_data();
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/ci/ciReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ class CompileReplay : public StackObj {
// Make sure the existence of a prior compile doesn't stop this one
nmethod* nm = (entry_bci != InvocationEntryBci) ? method->lookup_osr_nmethod_for(entry_bci, comp_level, true) : method->code();
if (nm != nullptr) {
nm->make_not_entrant();
nm->make_not_entrant("CI replay");
}
replay_state = this;
CompileBroker::compile_method(methodHandle(THREAD, method), entry_bci, comp_level,
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/code/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ void CodeCache::make_marked_nmethods_deoptimized() {
while(iter.next()) {
nmethod* nm = iter.method();
if (nm->is_marked_for_deoptimization() && !nm->has_been_deoptimized() && nm->can_be_deoptimized()) {
nm->make_not_entrant();
nm->make_not_entrant("marked for deoptimization");
nm->make_deoptimized();
}
}
Expand Down
22 changes: 15 additions & 7 deletions src/hotspot/share/code/nmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1968,21 +1968,27 @@ void nmethod::invalidate_osr_method() {
}
}

void nmethod::log_state_change() const {
void nmethod::log_state_change(const char* reason) const {
assert(reason != nullptr, "Must provide a reason");

if (LogCompilation) {
if (xtty != nullptr) {
ttyLocker ttyl; // keep the following output all in one block
xtty->begin_elem("make_not_entrant thread='%zu'",
os::current_thread_id());
xtty->begin_elem("make_not_entrant thread='%zu' reason='%s'",
os::current_thread_id(), reason);
log_identity(xtty);
xtty->stamp();
xtty->end_elem();
}
}

CompileTask::print_ul(this, "made not entrant");
ResourceMark rm;
stringStream ss(NEW_RESOURCE_ARRAY(char, 256), 256);
ss.print("made not entrant: %s", reason);

CompileTask::print_ul(this, ss.freeze());
if (PrintCompilation) {
print_on_with_msg(tty, "made not entrant");
print_on_with_msg(tty, ss.freeze());
}
}

Expand All @@ -1993,7 +1999,9 @@ void nmethod::unlink_from_method() {
}

// Invalidate code
bool nmethod::make_not_entrant() {
bool nmethod::make_not_entrant(const char* reason) {
assert(reason != nullptr, "Must provide a reason");

// This can be called while the system is already at a safepoint which is ok
NoSafepointVerifier nsv;

Expand Down Expand Up @@ -2051,7 +2059,7 @@ bool nmethod::make_not_entrant() {
assert(success, "Transition can't fail");

// Log the transition once
log_state_change();
log_state_change(reason);

// Remove nmethod from method.
unlink_from_method();
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/code/nmethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ class nmethod : public CodeBlob {
// alive. It is used when an uncommon trap happens. Returns true
// if this thread changed the state of the nmethod or false if
// another thread performed the transition.
bool make_not_entrant();
bool make_not_used() { return make_not_entrant(); }
bool make_not_entrant(const char* reason);
bool make_not_used() { return make_not_entrant("not used"); }

bool is_marked_for_deoptimization() const { return deoptimization_status() != not_marked; }
bool has_been_deoptimized() const { return deoptimization_status() == deoptimize_done; }
Expand Down Expand Up @@ -945,7 +945,7 @@ class nmethod : public CodeBlob {
// Logging
void log_identity(xmlStream* log) const;
void log_new_nmethod() const;
void log_state_change() const;
void log_state_change(const char* reason) const;

// Prints block-level comments, including nmethod specific block labels:
void print_nmethod_labels(outputStream* stream, address block_begin, bool print_section_labels=true) const;
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/compiler/compilationPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ void CompilationPolicy::compile(const methodHandle& mh, int bci, CompLevel level
nmethod* osr_nm = mh->lookup_osr_nmethod_for(bci, CompLevel_simple, false);
if (osr_nm != nullptr && osr_nm->comp_level() > CompLevel_simple) {
// Invalidate the existing OSR nmethod so that a compile at CompLevel_simple is permitted.
osr_nm->make_not_entrant();
osr_nm->make_not_entrant("OSR invalidation for compiling with C1");
}
compile(mh, bci, CompLevel_simple, THREAD);
}
Expand Down Expand Up @@ -1201,7 +1201,7 @@ void CompilationPolicy::method_back_branch_event(const methodHandle& mh, const m
int osr_bci = nm->is_osr_method() ? nm->osr_entry_bci() : InvocationEntryBci;
print_event(MAKE_NOT_ENTRANT, mh(), mh(), osr_bci, level);
}
nm->make_not_entrant();
nm->make_not_entrant("OSR invalidation, back branch");
}
}
// Fix up next_level if necessary to avoid deopts
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ C2V_VMENTRY(void, reprofile, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))

nmethod* code = method->code();
if (code != nullptr) {
code->make_not_entrant();
code->make_not_entrant("JVMCI reprofile");
}

MethodData* method_data = method->method_data();
Expand Down Expand Up @@ -1809,7 +1809,7 @@ C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv* env, jobject, jobject _hs_
if (!fst.current()->is_compiled_frame()) {
JVMCI_THROW_MSG(IllegalStateException, "compiled stack frame expected");
}
fst.current()->cb()->as_nmethod()->make_not_entrant();
fst.current()->cb()->as_nmethod()->make_not_entrant("JVMCI materialize virtual objects");
}
Deoptimization::deoptimize(thread, *fst.current(), Deoptimization::Reason_none);
// look for the frame again as it has been updated by deopt (pc, deopt state...)
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/jvmci/jvmciEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ void JVMCIEnv::invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimize, JV

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/jvmci/jvmciRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2195,8 +2195,8 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
char *method_name = method->name_and_sig_as_C_string();
tty->print_cr("Replacing method %s", method_name);
}
if (old != nullptr ) {
old->make_not_entrant();
if (old != nullptr) {
old->make_not_entrant("JVMCI register method");
}

LogTarget(Info, nmethod, install) lt;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/oops/instanceKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,7 @@ void InstanceKlass::add_osr_nmethod(nmethod* n) {
for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
if (inv != nullptr && inv->is_in_use()) {
inv->make_not_entrant();
inv->make_not_entrant("OSR invalidation of lower levels");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/oops/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ void Method::set_native_function(address function, bool post_event_flag) {
// If so, we have to make it not_entrant.
nmethod* nm = code(); // Put it into local variable to guard against concurrent updates
if (nm != nullptr) {
nm->make_not_entrant();
nm->make_not_entrant("set native function");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/prims/whitebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ class VM_WhiteBoxDeoptimizeFrames : public VM_WhiteBoxOperation {
if (_make_not_entrant) {
nmethod* nm = CodeCache::find_nmethod(f->pc());
assert(nm != nullptr, "did not find nmethod");
nm->make_not_entrant();
nm->make_not_entrant("Whitebox deoptimization");
}
++_result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/runtime/deoptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ void Deoptimization::deoptimize(JavaThread* thread, frame fr, DeoptReason reason
#if INCLUDE_JVMCI
address Deoptimization::deoptimize_for_missing_exception_handler(nmethod* nm) {
// there is no exception handler for this pc => deoptimize
nm->make_not_entrant();
nm->make_not_entrant("missing exception handler");

// Use Deoptimization::deoptimize for all of its side-effects:
// gathering traps statistics, logging...
Expand Down Expand Up @@ -2436,7 +2436,7 @@ JRT_ENTRY(void, Deoptimization::uncommon_trap_inner(JavaThread* current, jint tr

// Recompile
if (make_not_entrant) {
if (!nm->make_not_entrant()) {
if (!nm->make_not_entrant("uncommon trap")) {
return; // the call did not change nmethod's state
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/runtime/javaThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ void JavaThread::make_zombies() {
// it is a Java nmethod
nmethod* nm = CodeCache::find_nmethod(fst.current()->pc());
assert(nm != nullptr, "did not find nmethod");
nm->make_not_entrant();
nm->make_not_entrant("zombie");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,10 @@ public void startElement(String uri, String localName, String qname, Attributes
e.setCompileKind(compileKind);
String level = atts.getValue("level");
e.setLevel(level);
String reason = atts.getValue("reason");
if (reason != null) {
e.setReason(reason);
}
events.add(e);
} else if (qname.equals("uncommon_trap")) {
String id = atts.getValue("compile_id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class MakeNotEntrantEvent extends BasicLogEvent {
*/
private String level;

/**
* The reason of invalidation.
*/
private String reason;

/**
* The compile kind.
*/
Expand All @@ -64,10 +69,14 @@ public NMethod getNMethod() {

public void print(PrintStream stream, boolean printID) {
if (isZombie()) {
stream.printf("%s make_zombie\n", getId());
stream.printf("%s make_zombie", getId());
} else {
stream.printf("%s make_not_entrant\n", getId());
stream.printf("%s make_not_entrant", getId());
}
if (getReason() != null) {
stream.printf(": %s", getReason());
}
stream.println();
}

public boolean isZombie() {
Expand All @@ -88,7 +97,21 @@ public void setLevel(String level) {
this.level = level;
}

/**
/**
* @return the reason
*/
public String getReason() {
return reason;
}

/**
* @param reason the reason to set
*/
public void setReason(String reason) {
this.reason = reason;
}

/**
* @return the compileKind
*/
public String getCompileKind() {
Expand Down