Skip to content

Commit ea86a20

Browse files
author
Yudi Zheng
committed
8357424: [JVMCI] Avoid incrementing decompilation count for hosted compiled nmethod
Reviewed-by: dnsimon, never, cslucas
1 parent 5e30bf6 commit ea86a20

File tree

5 files changed

+57
-10
lines changed

5 files changed

+57
-10
lines changed

src/hotspot/share/code/nmethod.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,14 @@ bool nmethod::is_maybe_on_stack() {
19351935
void nmethod::inc_decompile_count() {
19361936
if (!is_compiled_by_c2() && !is_compiled_by_jvmci()) return;
19371937
// Could be gated by ProfileTraps, but do not bother...
1938+
#if INCLUDE_JVMCI
1939+
// Deoptimization count is used by the CompileBroker to reason about compilations
1940+
// it requests so do not pollute the count for deoptimizations in non-default (i.e.
1941+
// non-CompilerBroker) compilations.
1942+
if (is_jvmci_hosted()) {
1943+
return;
1944+
}
1945+
#endif
19381946
Method* m = method();
19391947
if (m == nullptr) return;
19401948
MethodData* mdo = m->method_data();
@@ -4056,4 +4064,8 @@ const char* nmethod::jvmci_name() {
40564064
}
40574065
return nullptr;
40584066
}
4067+
4068+
bool nmethod::is_jvmci_hosted() const {
4069+
return jvmci_nmethod_data() != nullptr && !jvmci_nmethod_data()->is_default();
4070+
}
40594071
#endif

src/hotspot/share/code/nmethod.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,10 @@ class nmethod : public CodeBlob {
913913
JVMCINMethodData* jvmci_nmethod_data() const {
914914
return jvmci_data_size() == 0 ? nullptr : (JVMCINMethodData*) jvmci_data_begin();
915915
}
916+
917+
// Returns true if a JVMCI compiled method is non-default,
918+
// i.e., not triggered by CompilerBroker
919+
bool is_jvmci_hosted() const;
916920
#endif
917921

918922
void oops_do(OopClosure* f) { oops_do(f, false); }

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,23 +746,25 @@ JVM_END
746746
void JVMCINMethodData::initialize(int nmethod_mirror_index,
747747
int nmethod_entry_patch_offset,
748748
const char* nmethod_mirror_name,
749+
bool is_default,
749750
FailedSpeculation** failed_speculations)
750751
{
751752
_failed_speculations = failed_speculations;
752753
_nmethod_mirror_index = nmethod_mirror_index;
753754
guarantee(nmethod_entry_patch_offset != -1, "missing entry barrier");
754755
_nmethod_entry_patch_offset = nmethod_entry_patch_offset;
755756
if (nmethod_mirror_name != nullptr) {
756-
_has_name = true;
757+
_properties.bits._has_name = 1;
757758
char* dest = (char*) name();
758759
strcpy(dest, nmethod_mirror_name);
759760
} else {
760-
_has_name = false;
761+
_properties.bits._has_name = 0;
761762
}
763+
_properties.bits._is_default = is_default;
762764
}
763765

764766
void JVMCINMethodData::copy(JVMCINMethodData* data) {
765-
initialize(data->_nmethod_mirror_index, data->_nmethod_entry_patch_offset, data->name(), data->_failed_speculations);
767+
initialize(data->_nmethod_mirror_index, data->_nmethod_entry_patch_offset, data->name(), data->_properties.bits._is_default, data->_failed_speculations);
766768
}
767769

768770
void JVMCINMethodData::add_failed_speculation(nmethod* nm, jlong speculation) {
@@ -2130,7 +2132,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
21302132
JVMCICompileState* compile_state = JVMCIENV->compile_state();
21312133
bool failing_dep_is_call_site;
21322134
result = validate_compile_task_dependencies(dependencies, compile_state, &failure_detail, failing_dep_is_call_site);
2133-
if (result != JVMCI::ok) {
2135+
if (install_default && result != JVMCI::ok) {
21342136
// While not a true deoptimization, it is a preemptive decompile.
21352137
MethodData* mdp = method()->method_data();
21362138
if (mdp != nullptr && !failing_dep_is_call_site) {
@@ -2151,6 +2153,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
21512153
JVMCINMethodData* data = JVMCINMethodData::create(nmethod_mirror_index,
21522154
nmethod_entry_patch_offset,
21532155
nmethod_mirror_name,
2156+
install_default,
21542157
failed_speculations);
21552158
nm = nmethod::new_nmethod(method,
21562159
compile_id,

src/hotspot/share/jvmci/jvmciRuntime.hpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -48,9 +48,19 @@ class MetadataHandles;
4848
class JVMCINMethodData : public ResourceObj {
4949
friend class JVMCIVMStructs;
5050

51-
// Is HotSpotNmethod.name non-null? If so, the value is
52-
// embedded in the end of this object.
53-
bool _has_name;
51+
union JVMCINMethodProperties {
52+
uint8_t value;
53+
struct {
54+
// Is HotSpotNmethod.name non-null? If so, the value is
55+
// embedded in the end of this object.
56+
uint8_t _has_name : 1,
57+
// HotSpotNmethod.isDefault (e.g., compilation scheduled by CompileBroker)
58+
_is_default : 1,
59+
: 6;
60+
} bits;
61+
};
62+
63+
JVMCINMethodProperties _properties;
5464

5565
// Index for the HotSpotNmethod mirror in the nmethod's oops table.
5666
// This is -1 if there is no mirror in the oops table.
@@ -76,6 +86,7 @@ class JVMCINMethodData : public ResourceObj {
7686
void initialize(int nmethod_mirror_index,
7787
int nmethod_entry_patch_offset,
7888
const char* nmethod_mirror_name,
89+
bool is_default,
7990
FailedSpeculation** failed_speculations);
8091

8192
void* operator new(size_t size, const char* nmethod_mirror_name) {
@@ -88,11 +99,13 @@ class JVMCINMethodData : public ResourceObj {
8899
static JVMCINMethodData* create(int nmethod_mirror_index,
89100
int nmethod_entry_patch_offset,
90101
const char* nmethod_mirror_name,
102+
bool is_default,
91103
FailedSpeculation** failed_speculations) {
92104
JVMCINMethodData* result = new (nmethod_mirror_name) JVMCINMethodData();
93105
result->initialize(nmethod_mirror_index,
94106
nmethod_entry_patch_offset,
95107
nmethod_mirror_name,
108+
is_default,
96109
failed_speculations);
97110
return result;
98111
}
@@ -117,7 +130,7 @@ class JVMCINMethodData : public ResourceObj {
117130
void add_failed_speculation(nmethod* nm, jlong speculation);
118131

119132
// Gets the JVMCI name of the nmethod (which may be null).
120-
const char* name() { return _has_name ? (char*)(((address) this) + sizeof(JVMCINMethodData)) : nullptr; }
133+
const char* name() { return has_name() ? (char*)(((address) this) + sizeof(JVMCINMethodData)) : nullptr; }
121134

122135
// Clears the HotSpotNmethod.address field in the mirror. If nm
123136
// is dead, the HotSpotNmethod.entryPoint field is also cleared.
@@ -132,6 +145,14 @@ class JVMCINMethodData : public ResourceObj {
132145
int nmethod_entry_patch_offset() {
133146
return _nmethod_entry_patch_offset;
134147
}
148+
149+
bool has_name() {
150+
return _properties.bits._has_name;
151+
}
152+
153+
bool is_default() {
154+
return _properties.bits._is_default;
155+
}
135156
};
136157

137158
// A top level class that represents an initialized JVMCI runtime.

src/hotspot/share/runtime/deoptimization.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,14 @@ JRT_ENTRY(void, Deoptimization::uncommon_trap_inner(JavaThread* current, jint tr
23632363
ShouldNotReachHere();
23642364
}
23652365

2366+
#if INCLUDE_JVMCI
2367+
// Deoptimization count is used by the CompileBroker to reason about compilations
2368+
// it requests so do not pollute the count for deoptimizations in non-default (i.e.
2369+
// non-CompilerBroker) compilations.
2370+
if (nm->is_jvmci_hosted()) {
2371+
update_trap_state = false;
2372+
}
2373+
#endif
23662374
// Setting +ProfileTraps fixes the following, on all platforms:
23672375
// The result is infinite heroic-opt-uncommon-trap/deopt/recompile cycles, since the
23682376
// recompile relies on a MethodData* to record heroic opt failures.
@@ -2473,7 +2481,6 @@ JRT_ENTRY(void, Deoptimization::uncommon_trap_inner(JavaThread* current, jint tr
24732481
trap_mdo->inc_tenure_traps();
24742482
}
24752483
}
2476-
24772484
if (inc_recompile_count) {
24782485
trap_mdo->inc_overflow_recompile_count();
24792486
if ((uint)trap_mdo->overflow_recompile_count() >

0 commit comments

Comments
 (0)