changeset 51147:d2137bd1e57d

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
author thartmann
date Tue, 21 Aug 2018 17:47:59 +0200
parents 126951ca1462
children 3b3685479784
files src/hotspot/share/compiler/compileBroker.cpp src/hotspot/share/runtime/thread.cpp
diffstat 2 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }