8063112: Compiler diagnostic commands should have locking instead of safepoint
authorneliasso
Fri, 22 Jan 2016 15:25:40 +0100
changeset 35825 7c7652ee137b
parent 35824 d3958ca72bf9
child 35826 42778c648543
child 35827 24e567453a33
8063112: Compiler diagnostic commands should have locking instead of safepoint Summary: Remove unnecessary vm-ops and add locking instead, improve output Reviewed-by: kvn
hotspot/src/share/vm/code/codeCache.cpp
hotspot/src/share/vm/compiler/compileBroker.cpp
hotspot/src/share/vm/compiler/compileBroker.hpp
hotspot/src/share/vm/runtime/thread.cpp
hotspot/src/share/vm/runtime/thread.hpp
hotspot/src/share/vm/runtime/vm_operations.cpp
hotspot/src/share/vm/runtime/vm_operations.hpp
hotspot/src/share/vm/services/diagnosticCommand.cpp
--- a/hotspot/src/share/vm/code/codeCache.cpp	Wed Feb 03 12:16:44 2016 +0100
+++ b/hotspot/src/share/vm/code/codeCache.cpp	Fri Jan 22 15:25:40 2016 +0100
@@ -1494,7 +1494,7 @@
 }
 
 void CodeCache::print_codelist(outputStream* st) {
-  assert_locked_or_safepoint(CodeCache_lock);
+  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 
   NMethodIterator iter;
   while(iter.next_alive()) {
@@ -1508,9 +1508,8 @@
 }
 
 void CodeCache::print_layout(outputStream* st) {
-  assert_locked_or_safepoint(CodeCache_lock);
+  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
   ResourceMark rm;
-
   print_summary(st, true);
 }
 
--- a/hotspot/src/share/vm/compiler/compileBroker.cpp	Wed Feb 03 12:16:44 2016 +0100
+++ b/hotspot/src/share/vm/compiler/compileBroker.cpp	Fri Jan 22 15:25:40 2016 +0100
@@ -466,9 +466,16 @@
   return NULL;
 }
 
+void CompileBroker::print_compile_queues(outputStream* st) {
+  st->print_cr("Current compiles: ");
+  MutexLocker locker(MethodCompileQueue_lock);
+  MutexLocker locker2(Threads_lock);
 
-void CompileBroker::print_compile_queues(outputStream* st) {
-  MutexLocker locker(MethodCompileQueue_lock);
+  char buf[2000];
+  int buflen = sizeof(buf);
+  Threads::print_threads_compiling(st, buf, buflen);
+
+  st->cr();
   if (_c1_compile_queue != NULL) {
     _c1_compile_queue->print(st);
   }
@@ -479,8 +486,7 @@
 
 void CompileQueue::print(outputStream* st) {
   assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
-  st->print_cr("Contents of %s", name());
-  st->print_cr("----------------------------");
+  st->print_cr("%s:", name());
   CompileTask* task = _first;
   if (task == NULL) {
     st->print_cr("Empty");
@@ -490,7 +496,7 @@
       task = task->next();
     }
   }
-  st->print_cr("----------------------------");
+  st->cr();
 }
 
 void CompileQueue::print_tty() {
@@ -2355,10 +2361,3 @@
   }
 }
 
-
-void CompileBroker::print_compiler_threads_on(outputStream* st) {
-#ifndef PRODUCT
-  st->print_cr("Compiler thread printing unimplemented.");
-  st->cr();
-#endif
-}
--- a/hotspot/src/share/vm/compiler/compileBroker.hpp	Wed Feb 03 12:16:44 2016 +0100
+++ b/hotspot/src/share/vm/compiler/compileBroker.hpp	Fri Jan 22 15:25:40 2016 +0100
@@ -350,8 +350,6 @@
   // Debugging output for failure
   static void print_last_compile();
 
-  static void print_compiler_threads_on(outputStream* st);
-
   // compiler name for debugging
   static const char* compiler_name(int comp_level);
 
--- a/hotspot/src/share/vm/runtime/thread.cpp	Wed Feb 03 12:16:44 2016 +0100
+++ b/hotspot/src/share/vm/runtime/thread.cpp	Fri Jan 22 15:25:40 2016 +0100
@@ -31,6 +31,7 @@
 #include "code/codeCacheExtensions.hpp"
 #include "code/scopeDesc.hpp"
 #include "compiler/compileBroker.hpp"
+#include "compiler/compileTask.hpp"
 #include "gc/shared/gcId.hpp"
 #include "gc/shared/gcLocker.inline.hpp"
 #include "gc/shared/workgroup.hpp"
@@ -2884,6 +2885,20 @@
   print_thread_state_on(st);
   _safepoint_state->print_on(st);
 #endif // PRODUCT
+  if (is_Compiler_thread()) {
+    CompilerThread* ct = (CompilerThread*)this;
+    if (ct->task() != NULL) {
+      st->print("   Compiling: ");
+      ct->task()->print(st, NULL, true, false);
+    } else {
+      st->print("   No compile task");
+    }
+    st->cr();
+  }
+}
+
+void JavaThread::print_name_on_error(outputStream* st, char *buf, int buflen) const {
+  st->print("%s", get_thread_name_string(buf, buflen));
 }
 
 // Called by fatal error handler. The difference between this and
@@ -4386,7 +4401,6 @@
     wt->print_on(st);
     st->cr();
   }
-  CompileBroker::print_compiler_threads_on(st);
   st->flush();
 }
 
@@ -4439,8 +4453,24 @@
     current->print_on_error(st, buf, buflen);
     st->cr();
   }
+  st->cr();
+  st->print_cr("Threads with active compile tasks:");
+  print_threads_compiling(st, buf, buflen);
 }
 
+void Threads::print_threads_compiling(outputStream* st, char* buf, int buflen) {
+  ALL_JAVA_THREADS(thread) {
+    if (thread->is_Compiler_thread()) {
+      CompilerThread* ct = (CompilerThread*) thread;
+      if (ct->task() != NULL) {
+        thread->print_name_on_error(st, buf, buflen);
+        ct->task()->print(st, NULL, true, true);
+      }
+    }
+  }
+}
+
+
 // Internal SpinLock and Mutex
 // Based on ParkEvent
 
--- a/hotspot/src/share/vm/runtime/thread.hpp	Wed Feb 03 12:16:44 2016 +0100
+++ b/hotspot/src/share/vm/runtime/thread.hpp	Fri Jan 22 15:25:40 2016 +0100
@@ -1660,6 +1660,7 @@
   void print_thread_state_on(outputStream*) const      PRODUCT_RETURN;
   void print_thread_state() const                      PRODUCT_RETURN;
   void print_on_error(outputStream* st, char* buf, int buflen) const;
+  void print_name_on_error(outputStream* st, char* buf, int buflen) const;
   void verify();
   const char* get_thread_name() const;
  private:
@@ -2158,6 +2159,7 @@
     print_on(tty, print_stacks, internal_format, false /* no concurrent lock printed */);
   }
   static void print_on_error(outputStream* st, Thread* current, char* buf, int buflen);
+  static void print_threads_compiling(outputStream* st, char* buf, int buflen);
 
   // Get Java threads that are waiting to enter a monitor. If doLock
   // is true, then Threads_lock is grabbed as needed. Otherwise, the
--- a/hotspot/src/share/vm/runtime/vm_operations.cpp	Wed Feb 03 12:16:44 2016 +0100
+++ b/hotspot/src/share/vm/runtime/vm_operations.cpp	Fri Jan 22 15:25:40 2016 +0100
@@ -485,18 +485,6 @@
   }
 }
 
-void VM_PrintCompileQueue::doit() {
-  CompileBroker::print_compile_queues(_out);
-}
-
-void VM_PrintCodeList::doit() {
-  CodeCache::print_codelist(_out);
-}
-
-void VM_PrintCodeCache::doit() {
-  CodeCache::print_layout(_out);
-}
-
 #if INCLUDE_SERVICES
 void VM_PrintClassHierarchy::doit() {
   KlassHierarchy::print_class_hierarchy(_out, _print_interfaces, _print_subclasses, _classname);
--- a/hotspot/src/share/vm/runtime/vm_operations.hpp	Wed Feb 03 12:16:44 2016 +0100
+++ b/hotspot/src/share/vm/runtime/vm_operations.hpp	Fri Jan 22 15:25:40 2016 +0100
@@ -105,9 +105,6 @@
   template(DumpHashtable)                         \
   template(DumpTouchedMethods)                    \
   template(MarkActiveNMethods)                    \
-  template(PrintCompileQueue)                     \
-  template(PrintCodeList)                         \
-  template(PrintCodeCache)                        \
   template(PrintClassHierarchy)                   \
 
 class VM_Operation: public CHeapObj<mtInternal> {
@@ -424,37 +421,6 @@
   void doit();
 };
 
-class VM_PrintCompileQueue: public VM_Operation {
- private:
-  outputStream* _out;
-
- public:
-  VM_PrintCompileQueue(outputStream* st) : _out(st) {}
-  VMOp_Type type() const { return VMOp_PrintCompileQueue; }
-  Mode evaluation_mode() const { return _no_safepoint; }
-  void doit();
-};
-
-class VM_PrintCodeList: public VM_Operation {
- private:
-  outputStream* _out;
-
- public:
-  VM_PrintCodeList(outputStream* st) : _out(st) {}
-  VMOp_Type type() const { return VMOp_PrintCodeList; }
-  void doit();
-};
-
-class VM_PrintCodeCache: public VM_Operation {
- private:
-  outputStream* _out;
-
- public:
-  VM_PrintCodeCache(outputStream* st) : _out(st) {}
-  VMOp_Type type() const { return VMOp_PrintCodeCache; }
-  void doit();
-};
-
 #if INCLUDE_SERVICES
 class VM_PrintClassHierarchy: public VM_Operation {
  private:
--- a/hotspot/src/share/vm/services/diagnosticCommand.cpp	Wed Feb 03 12:16:44 2016 +0100
+++ b/hotspot/src/share/vm/services/diagnosticCommand.cpp	Fri Jan 22 15:25:40 2016 +0100
@@ -832,18 +832,15 @@
 }
 
 void CompileQueueDCmd::execute(DCmdSource source, TRAPS) {
-  VM_PrintCompileQueue printCompileQueueOp(output());
-  VMThread::execute(&printCompileQueueOp);
+  CompileBroker::print_compile_queues(output());
 }
 
 void CodeListDCmd::execute(DCmdSource source, TRAPS) {
-  VM_PrintCodeList printCodeListOp(output());
-  VMThread::execute(&printCodeListOp);
+  CodeCache::print_codelist(output());
 }
 
 void CodeCacheDCmd::execute(DCmdSource source, TRAPS) {
-  VM_PrintCodeCache printCodeCacheOp(output());
-  VMThread::execute(&printCodeCacheOp);
+  CodeCache::print_layout(output());
 }
 
 void CompilerDirectivesPrintDCmd::execute(DCmdSource source, TRAPS) {