8194482: Fix SIGSEGV in print_threads_compiling. jdk-10+38
authorgoetz
Wed, 03 Jan 2018 14:41:17 -0800
changeset 48428 e569e83139fd
parent 48427 b08405cc467a
child 48429 e9a564028f2f
child 48446 fe391f235400
8194482: Fix SIGSEGV in print_threads_compiling. Reviewed-by: kvn
src/hotspot/share/runtime/thread.cpp
src/hotspot/share/runtime/thread.hpp
--- a/src/hotspot/share/runtime/thread.cpp	Wed Jan 03 11:10:56 2018 -0800
+++ b/src/hotspot/share/runtime/thread.cpp	Wed Jan 03 14:41:17 2018 -0800
@@ -2946,8 +2946,9 @@
     if (ct->env() != NULL) {
       ct->env()->metadata_do(f);
     }
-    if (ct->task() != NULL) {
-      ct->task()->metadata_do(f);
+    CompileTask* task = ct->task();
+    if (task != NULL) {
+      task->metadata_do(f);
     }
   }
 }
@@ -3001,10 +3002,10 @@
   _safepoint_state->print_on(st);
 #endif // PRODUCT
   if (is_Compiler_thread()) {
-    CompilerThread* ct = (CompilerThread*)this;
-    if (ct->task() != NULL) {
+    CompileTask *task = ((CompilerThread*)this)->task();
+    if (task != NULL) {
       st->print("   Compiling: ");
-      ct->task()->print(st, NULL, true, false);
+      task->print(st, NULL, true, false);
     } else {
       st->print("   No compile task");
     }
@@ -4712,9 +4713,15 @@
   ALL_JAVA_THREADS(thread) {
     if (thread->is_Compiler_thread()) {
       CompilerThread* ct = (CompilerThread*) thread;
-      if (ct->task() != NULL) {
+
+      // Keep task in local variable for NULL check.
+      // ct->_task might be set to NULL by concurring compiler thread
+      // because it completed the compilation. The task is never freed,
+      // though, just returned to a free list.
+      CompileTask* task = ct->task();
+      if (task != NULL) {
         thread->print_name_on_error(st, buf, buflen);
-        ct->task()->print(st, NULL, true, true);
+        task->print(st, NULL, true, true);
       }
     }
   }
--- a/src/hotspot/share/runtime/thread.hpp	Wed Jan 03 11:10:56 2018 -0800
+++ b/src/hotspot/share/runtime/thread.hpp	Wed Jan 03 14:41:17 2018 -0800
@@ -2064,13 +2064,13 @@
  private:
   CompilerCounters* _counters;
 
-  ciEnv*            _env;
-  CompileLog*       _log;
-  CompileTask*      _task;
-  CompileQueue*     _queue;
-  BufferBlob*       _buffer_blob;
+  ciEnv*                _env;
+  CompileLog*           _log;
+  CompileTask* volatile _task;  // print_threads_compiling can read this concurrently.
+  CompileQueue*         _queue;
+  BufferBlob*           _buffer_blob;
 
-  AbstractCompiler* _compiler;
+  AbstractCompiler*     _compiler;
 
  public: