Skip to content

Commit db45ff0

Browse files
author
Tom Rodriguez
committed
8268052: [JVMCI] non-default installed code must be marked as in_use
Reviewed-by: kvn, dnsimon
1 parent bb3d226 commit db45ff0

File tree

9 files changed

+46
-20
lines changed

9 files changed

+46
-20
lines changed

src/hotspot/share/jvmci/jvmci.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ class JVMCI : public AllStatic {
8989
ok,
9090
dependencies_failed,
9191
cache_full,
92-
code_too_large
92+
nmethod_reclaimed, // code cache sweeper reclaimed nmethod in between its creation and being marked "in_use"
93+
code_too_large,
94+
first_permanent_bailout = code_too_large
9395
};
9496

9597
// Gets the handle to the loaded JVMCI shared library, loading it

src/hotspot/share/jvmci/jvmciCodeInstaller.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
480480
JVMCIObject target,
481481
JVMCIObject compiled_code,
482482
CodeBlob*& cb,
483+
nmethodLocker& nmethod_handle,
483484
JVMCIObject installed_code,
484485
FailedSpeculation** failed_speculations,
485486
char* speculations,
@@ -537,18 +538,20 @@ JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
537538
}
538539

539540
JVMCIObject mirror = installed_code;
540-
nmethod* nm = NULL;
541-
result = runtime()->register_method(jvmci_env(), method, nm, entry_bci, &_offsets, _orig_pc_offset, &buffer,
541+
result = runtime()->register_method(jvmci_env(), method, nmethod_handle, entry_bci, &_offsets, _orig_pc_offset, &buffer,
542542
stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, &_implicit_exception_table,
543543
compiler, _debug_recorder, _dependencies, id,
544544
has_unsafe_access, _has_wide_vector, compiled_code, mirror,
545545
failed_speculations, speculations, speculations_len);
546-
cb = nm->as_codeblob_or_null();
547-
if (nm != NULL && compile_state == NULL) {
548-
// This compile didn't come through the CompileBroker so perform the printing here
549-
DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, compiler);
550-
nm->maybe_print_nmethod(directive);
551-
DirectivesStack::release(directive);
546+
if (result == JVMCI::ok) {
547+
nmethod* nm = nmethod_handle.code()->as_nmethod_or_null();
548+
cb = nm;
549+
if (compile_state == NULL) {
550+
// This compile didn't come through the CompileBroker so perform the printing here
551+
DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, compiler);
552+
nm->maybe_print_nmethod(directive);
553+
DirectivesStack::release(directive);
554+
}
552555
}
553556
}
554557

src/hotspot/share/jvmci/jvmciCodeInstaller.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class CodeInstaller : public StackObj {
187187
JVMCIObject target,
188188
JVMCIObject compiled_code,
189189
CodeBlob*& cb,
190+
nmethodLocker& nmethod_handle,
190191
JVMCIObject installed_code,
191192
FailedSpeculation** failed_speculations,
192193
char* speculations,

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,13 @@ C2V_VMENTRY_0(jint, installCode, (JNIEnv *env, jobject, jobject target, jobject
881881

882882
TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer(!thread->is_Compiler_thread()));
883883

884+
nmethodLocker nmethod_handle;
884885
CodeInstaller installer(JVMCIENV);
885886
JVMCI::CodeInstallResult result = installer.install(compiler,
886887
target_handle,
887888
compiled_code_handle,
888889
cb,
890+
nmethod_handle,
889891
installed_code_handle,
890892
(FailedSpeculation**)(address) failed_speculations_address,
891893
speculations,

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ bool JVMCIRuntime::is_gc_supported(JVMCIEnv* JVMCIENV, CollectedHeap::Name name)
16411641
// ------------------------------------------------------------------
16421642
JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
16431643
const methodHandle& method,
1644-
nmethod*& nm,
1644+
nmethodLocker& code_handle,
16451645
int entry_bci,
16461646
CodeOffsets* offsets,
16471647
int orig_pc_offset,
@@ -1662,7 +1662,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
16621662
char* speculations,
16631663
int speculations_len) {
16641664
JVMCI_EXCEPTION_CONTEXT;
1665-
nm = NULL;
1665+
nmethod* nm = NULL;
16661666
int comp_level = CompLevel_full_optimization;
16671667
char* failure_detail = NULL;
16681668

@@ -1747,6 +1747,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
17471747
MutexUnlocker locker(MethodCompileQueue_lock);
17481748
CompileBroker::handle_full_code_cache(CodeCache::get_code_blob_type(comp_level));
17491749
}
1750+
result = JVMCI::cache_full;
17501751
} else {
17511752
nm->set_has_unsafe_access(has_unsafe_access);
17521753
nm->set_has_wide_vectors(has_wide_vector);
@@ -1784,6 +1785,8 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
17841785
MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
17851786
if (nm->make_in_use()) {
17861787
method->set_code(method, nm);
1788+
} else {
1789+
result = JVMCI::nmethod_reclaimed;
17871790
}
17881791
} else {
17891792
LogTarget(Info, nmethod, install) lt;
@@ -1796,13 +1799,20 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
17961799
MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
17971800
if (nm->make_in_use()) {
17981801
InstanceKlass::cast(method->method_holder())->add_osr_nmethod(nm);
1802+
} else {
1803+
result = JVMCI::nmethod_reclaimed;
17991804
}
18001805
}
18011806
} else {
18021807
assert(!nmethod_mirror.is_hotspot() || data->get_nmethod_mirror(nm, /* phantom_ref */ false) == HotSpotJVMCI::resolve(nmethod_mirror), "must be");
1808+
if (!nm->make_in_use()) {
1809+
result = JVMCI::nmethod_reclaimed;
1810+
}
18031811
}
18041812
}
1805-
result = nm != NULL ? JVMCI::ok :JVMCI::cache_full;
1813+
}
1814+
if (result == JVMCI::ok) {
1815+
code_handle.set_code(nm);
18061816
}
18071817
}
18081818

@@ -1813,8 +1823,8 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
18131823
JVMCIENV->set_HotSpotCompiledNmethod_installationFailureMessage(compiled_code, message);
18141824
}
18151825

1816-
// JVMTI -- compiled method notification (must be done outside lock)
1817-
if (nm != NULL) {
1826+
if (result == JVMCI::ok) {
1827+
// JVMTI -- compiled method notification (must be done outside lock)
18181828
nm->post_compiled_method_load_event();
18191829
}
18201830

src/hotspot/share/jvmci/jvmciRuntime.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class JVMCIRuntime: public CHeapObj<mtJVMCI> {
290290
// Register the result of a compilation.
291291
JVMCI::CodeInstallResult register_method(JVMCIEnv* JVMCIENV,
292292
const methodHandle& target,
293-
nmethod*& nm,
293+
nmethodLocker& code_handle,
294294
int entry_bci,
295295
CodeOffsets* offsets,
296296
int orig_pc_offset,

src/hotspot/share/jvmci/vmStructs_jvmci.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,13 @@
590590
declare_constant(JumpData::taken_off_set) \
591591
declare_constant(JumpData::displacement_off_set) \
592592
\
593-
declare_preprocessor_constant("JVMCI::ok", JVMCI::ok) \
594-
declare_preprocessor_constant("JVMCI::dependencies_failed", JVMCI::dependencies_failed) \
595-
declare_preprocessor_constant("JVMCI::cache_full", JVMCI::cache_full) \
596-
declare_preprocessor_constant("JVMCI::code_too_large", JVMCI::code_too_large) \
593+
declare_preprocessor_constant("JVMCI::ok", JVMCI::ok) \
594+
declare_preprocessor_constant("JVMCI::dependencies_failed", JVMCI::dependencies_failed) \
595+
declare_preprocessor_constant("JVMCI::cache_full", JVMCI::cache_full) \
596+
declare_preprocessor_constant("JVMCI::code_too_large", JVMCI::code_too_large) \
597+
declare_preprocessor_constant("JVMCI::nmethod_reclaimed", JVMCI::nmethod_reclaimed) \
598+
declare_preprocessor_constant("JVMCI::first_permanent_bailout", JVMCI::first_permanent_bailout) \
599+
\
597600
declare_constant(JVMCIRuntime::none) \
598601
declare_constant(JVMCIRuntime::by_holder) \
599602
declare_constant(JVMCIRuntime::by_full_signature) \

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotCodeCacheProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public InstalledCode installCode(ResolvedJavaMethod method, CompiledCode compile
144144
} else {
145145
msg = String.format("Code installation failed: %s", resultDesc);
146146
}
147-
throw new BailoutException(result != config.codeInstallResultDependenciesFailed, msg);
147+
throw new BailoutException(result >= config.codeInstallResultFirstPermanentBailout, msg);
148148
} else {
149149
throw new BailoutException("Error installing %s: %s", ((HotSpotCompiledCode) compiledCode).getName(), resultDesc);
150150
}

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ final int baseVtableLength() {
362362
final int codeInstallResultDependenciesFailed = getConstant("JVMCI::dependencies_failed", Integer.class);
363363
final int codeInstallResultCacheFull = getConstant("JVMCI::cache_full", Integer.class);
364364
final int codeInstallResultCodeTooLarge = getConstant("JVMCI::code_too_large", Integer.class);
365+
final int codeInstallResultNMethodReclaimed = getConstant("JVMCI::nmethod_reclaimed", Integer.class);
366+
final int codeInstallResultFirstPermanentBailout = getConstant("JVMCI::first_permanent_bailout", Integer.class);
365367

366368
String getCodeInstallResultDescription(int codeInstallResult) {
367369
if (codeInstallResult == codeInstallResultOk) {
@@ -376,6 +378,9 @@ String getCodeInstallResultDescription(int codeInstallResult) {
376378
if (codeInstallResult == codeInstallResultCodeTooLarge) {
377379
return "code is too large";
378380
}
381+
if (codeInstallResult == codeInstallResultNMethodReclaimed) {
382+
return "nmethod reclaimed";
383+
}
379384
assert false : codeInstallResult;
380385
return "unknown";
381386
}

0 commit comments

Comments
 (0)