changeset 23303:633cf7bea01d

thread waiting for blocking JVMCI compilation should not wait on compiler queue forever (JDK-8148507) [part 2]
author Doug Simon <doug.simon@oracle.com>
date Thu, 04 Feb 2016 19:18:52 +0100
parents 90f7b4c21cfb
children 3dab35122bce
files src/share/vm/compiler/compileBroker.cpp src/share/vm/compiler/compileBroker.hpp src/share/vm/jvmci/jvmciCompiler.cpp src/share/vm/jvmci/jvmciCompiler.hpp
diffstat 4 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/compiler/compileBroker.cpp	Thu Feb 04 15:21:43 2016 +0100
+++ b/src/share/vm/compiler/compileBroker.cpp	Thu Feb 04 19:18:52 2016 +0100
@@ -50,7 +50,6 @@
 #include "c1/c1_Compiler.hpp"
 #endif
 #if INCLUDE_JVMCI
-#include "jvmci/jvmciCompiler.hpp"
 #include "jvmci/jvmciJavaClasses.hpp"
 #ifdef COMPILERJVMCI
 #include "jvmci/jvmciRuntime.hpp"
@@ -1741,12 +1740,10 @@
  *
  * @return true if this thread needs to free/recycle the task
  */
-bool CompileBroker::wait_for_jvmci_completion(AbstractCompiler* comp, CompileTask* task, JavaThread* thread) {
+bool CompileBroker::wait_for_jvmci_completion(JVMCICompiler* jvmci, CompileTask* task, JavaThread* thread) {
   MutexLocker waiter(task->lock(), thread);
-  assert(comp->is_jvmci(), "must be");
-  JVMCICompiler* jvmci = (JVMCICompiler*) comp;
   int progress_wait_attempts = 0;
-  int methods_compiled = jvmci->approx_num_methods_compiled();
+  int methods_compiled = jvmci->methods_compiled();
   while (!task->is_complete() && !is_compilation_disabled_forever() &&
          task->lock()->wait(!Mutex::_no_safepoint_check_flag, JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE)) {
     CompilerThread* jvmci_compiler_thread = task->jvmci_compiler_thread();
@@ -1760,7 +1757,7 @@
       // that all JVMCI compiler threads are blocked on. We use the counter for
       // successful JVMCI compilations to determine whether JVMCI compilation
       // is still making progress through the JVMCI compiler queue.
-      progress = jvmci->approx_num_methods_compiled() != methods_compiled;
+      progress = jvmci->methods_compiled() != methods_compiled;
     }
 
     if (!progress) {
@@ -1773,7 +1770,7 @@
     } else {
       progress_wait_attempts = 0;
       if (jvmci_compiler_thread == NULL) {
-        methods_compiled = jvmci->approx_num_methods_compiled();
+        methods_compiled = jvmci->methods_compiled();
       }
     }
   }
@@ -1801,7 +1798,7 @@
 #ifdef COMPILERJVMCI
   AbstractCompiler* comp = compiler(task->comp_level());
   if (comp->is_jvmci()) {
-    free_task = wait_for_jvmci_completion(comp, task, thread);
+    free_task = wait_for_jvmci_completion((JVMCICompiler*) comp, task, thread);
   } else
 #endif
   {
--- a/src/share/vm/compiler/compileBroker.hpp	Thu Feb 04 15:21:43 2016 +0100
+++ b/src/share/vm/compiler/compileBroker.hpp	Thu Feb 04 19:18:52 2016 +0100
@@ -29,6 +29,9 @@
 #include "compiler/abstractCompiler.hpp"
 #include "runtime/perfData.hpp"
 #include "trace/tracing.hpp"
+#if INCLUDE_JVMCI
+#include "jvmci/jvmciCompiler.hpp"
+#endif
 
 class nmethod;
 class nmethodLocker;
@@ -372,7 +375,7 @@
                                           bool          blocking);
   static void wait_for_completion(CompileTask* task);
 #ifdef COMPILERJVMCI
-  static bool wait_for_jvmci_completion(AbstractCompiler* comp, CompileTask* task, JavaThread* thread);
+  static bool wait_for_jvmci_completion(JVMCICompiler* comp, CompileTask* task, JavaThread* thread);
 #endif
 
   static void invoke_compiler_on_method(CompileTask* task);
--- a/src/share/vm/jvmci/jvmciCompiler.cpp	Thu Feb 04 15:21:43 2016 +0100
+++ b/src/share/vm/jvmci/jvmciCompiler.cpp	Thu Feb 04 19:18:52 2016 +0100
@@ -37,7 +37,7 @@
 JVMCICompiler::JVMCICompiler() : AbstractCompiler(jvmci) {
 #ifdef COMPILERJVMCI
   _bootstrapping = false;
-  _methodsCompiled = 0;
+  _methods_compiled = 0;
 #endif
   assert(_instance == NULL, "only one instance allowed");
   _instance = this;
@@ -103,7 +103,7 @@
     } while (first_round && qsize == 0);
     first_round = false;
     if (PrintBootstrap) {
-      while (z < (_methodsCompiled / 100)) {
+      while (z < (_methods_compiled / 100)) {
         ++z;
         tty->print_raw(".");
       }
@@ -111,7 +111,7 @@
   } while (qsize != 0);
 
   if (PrintBootstrap) {
-    tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methodsCompiled);
+    tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methods_compiled);
   }
   _bootstrapping = false;
 }
@@ -172,7 +172,7 @@
           env->set_failure("no nmethod produced", true);
         } else {
           env->task()->set_num_inlined_bytecodes(CompilationRequestResult::inlinedBytecodes(result_object));
-          _methodsCompiled++;
+          Atomic::inc(&_methods_compiled);
         }
       }
     } else {
--- a/src/share/vm/jvmci/jvmciCompiler.hpp	Thu Feb 04 15:21:43 2016 +0100
+++ b/src/share/vm/jvmci/jvmciCompiler.hpp	Thu Feb 04 19:18:52 2016 +0100
@@ -35,10 +35,10 @@
   bool _bootstrapping;
 
   /**
-   * Number of methods compiled by JVMCI. This is not synchronized
-   * so may not be 100% accurate.
+   * Number of methods successfully compiled by a call to
+   * JVMCICompiler::compile_method().
    */
-  volatile int  _methodsCompiled;
+  volatile int  _methods_compiled;
 
 #endif
 
@@ -81,10 +81,10 @@
   virtual void print_timers();
 
   /**
-   * Get the number of methods that have been successfully compiled.
-   * This is an approximation as updating the counter is not atomic.
+   * Gets the number of methods that have been successfully compiled by
+   * a call to JVMCICompiler::compile_method().
    */
-  int approx_num_methods_compiled() { return _methodsCompiled; }
+  int methods_compiled() { return _methods_compiled; }
 
 #endif // COMPILERJVMCI