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
--- 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.
}
}
--- 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;
}