8254104: MethodCounters must exist before nmethod is installed

Reviewed-by: dnsimon, kvn
This commit is contained in:
Igor Veresov 2020-10-08 06:53:24 +00:00
parent fd0cb98ed0
commit 4e5ef30303
2 changed files with 21 additions and 5 deletions
src/hotspot/share

@ -972,6 +972,18 @@ void ciEnv::register_method(ciMethod* target,
VM_ENTRY_MARK;
nmethod* nm = NULL;
{
methodHandle method(THREAD, target->get_Method());
// We require method counters to store some method state (max compilation levels) required by the compilation policy.
if (method->get_method_counters(THREAD) == NULL) {
record_failure("can't create method counters");
// All buffers in the CodeBuffer are allocated in the CodeCache.
// If the code buffer is created on each compile attempt
// as in C2, then it must be freed.
code_buffer->free_blob();
return;
}
// To prevent compile queue updates.
MutexLocker locker(THREAD, MethodCompileQueue_lock);
@ -1011,9 +1023,6 @@ void ciEnv::register_method(ciMethod* target,
// Check for {class loads, evolution, breakpoints, ...} during compilation
validate_compile_task_dependencies(target);
}
methodHandle method(THREAD, target->get_Method());
#if INCLUDE_RTM_OPT
if (!failing() && (rtm_state != NoRTM) &&
(method()->method_data() != NULL) &&

@ -1577,8 +1577,15 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
nmethod_mirror_index = -1;
}
JVMCI::CodeInstallResult result;
{
JVMCI::CodeInstallResult result(JVMCI::ok);
// We require method counters to store some method state (max compilation levels) required by the compilation policy.
if (method->get_method_counters(THREAD) == NULL) {
result = JVMCI::cache_full;
failure_detail = (char*) "can't create method counters";
}
if (result == JVMCI::ok) {
// To prevent compile queue updates.
MutexLocker locker(THREAD, MethodCompileQueue_lock);