# HG changeset patch # User thartmann # Date 1534866479 -7200 # Node ID d2137bd1e57d36cac1d018fa10a4ca7acbd5321d # Parent 126951ca1462d4e89afe32860e56be685c23c0cd 8209670: CompilerThread releasing code buffer in destructor is unsafe Summary: Don't free temporary code buffers in compiler thread destructor to avoid interference with safepoint code. Reviewed-by: kvn, dholmes, zgu diff -r 126951ca1462 -r d2137bd1e57d src/hotspot/share/compiler/compileBroker.cpp --- a/src/hotspot/share/compiler/compileBroker.cpp Tue Aug 21 09:25:06 2018 +0200 +++ b/src/hotspot/share/compiler/compileBroker.cpp Tue Aug 21 17:47:59 2018 +0200 @@ -1637,6 +1637,12 @@ * out to be a problem. */ void CompileBroker::shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread) { + // Free buffer blob, if allocated + if (thread->get_buffer_blob() != NULL) { + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); + CodeCache::free(thread->get_buffer_blob()); + } + if (comp->should_perform_shutdown()) { // There are two reasons for shutting down the compiler // 1) compiler runtime initialization failed @@ -1767,6 +1773,11 @@ tty->print_cr("Removing compiler thread %s after " JLONG_FORMAT " ms idle time", thread->name(), thread->idle_time_millis()); } + // Free buffer blob, if allocated + if (thread->get_buffer_blob() != NULL) { + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); + CodeCache::free(thread->get_buffer_blob()); + } return; // Stop this thread. } } diff -r 126951ca1462 -r d2137bd1e57d src/hotspot/share/runtime/thread.cpp --- a/src/hotspot/share/runtime/thread.cpp Tue Aug 21 09:25:06 2018 +0200 +++ b/src/hotspot/share/runtime/thread.cpp Tue Aug 21 17:47:59 2018 +0200 @@ -3298,11 +3298,6 @@ } CompilerThread::~CompilerThread() { - // Free buffer blob, if allocated - if (get_buffer_blob() != NULL) { - MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); - CodeCache::free(get_buffer_blob()); - } // Delete objects which were allocated on heap. delete _counters; }