diff src/share/vm/compiler/compileBroker.cpp @ 3619:5e9645341ec3

support for new RiRuntime features: add code without making it the default for the method, executing Java tasks on the compile thread, communicate nmethod reference to Java code as HotSpotCompiledMethod
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 09 Nov 2011 11:27:38 +0100
parents 22d11b3bc561
children 9c2c0a182f13
line wrap: on
line diff
--- a/src/share/vm/compiler/compileBroker.cpp	Tue Oct 25 14:44:32 2011 +0200
+++ b/src/share/vm/compiler/compileBroker.cpp	Wed Nov 09 11:27:38 2011 +0100
@@ -159,6 +159,7 @@
 
 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL;
 
+bool CompileBroker::_poll_java_queue = false;
 
 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) {
   CompilerThread* thread = CompilerThread::current();
@@ -543,12 +544,15 @@
 // CompileQueue::get
 //
 // Get the next CompileTask from a CompileQueue
-CompileTask* CompileQueue::get() {
+CompileTask* CompileQueue::get(bool& interrupt) {
   NMethodSweeper::possibly_sweep();
 
   MutexLocker locker(lock());
   // Wait for an available CompileTask.
   while (_first == NULL) {
+    if (interrupt) {
+      return NULL;
+    }
     // There is no work to be done right now.  Wait.
     if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) {
       // During the emergency sweeping periods, wake up and sweep occasionally
@@ -717,6 +721,20 @@
 }
 
 
+void CompileBroker::notify_java_queue() {
+  HandleMark hm;
+  ResourceMark rm;
+
+  _poll_java_queue = true;
+  {
+    ThreadInVMfromNative tivm(JavaThread::current());
+    MutexLocker locker(_c1_method_queue->lock(), Thread::current());
+
+    _c1_method_queue->lock()->notify_all();
+  }
+}
+
+
 // ------------------------------------------------------------------
 // CompileBroker::compilation_init
 //
@@ -1579,49 +1597,58 @@
         NMethodSweeper::handle_full_code_cache(false);
       }
 
-      CompileTask* task = queue->get();
+      CompileTask* task = queue->get(_poll_java_queue);
 
-      // Give compiler threads an extra quanta.  They tend to be bursty and
-      // this helps the compiler to finish up the job.
-      if( CompilerThreadHintNoPreempt )
-        os::hint_no_preempt();
+      if (task != NULL) {
+        // Give compiler threads an extra quanta.  They tend to be bursty and
+        // this helps the compiler to finish up the job.
+        if( CompilerThreadHintNoPreempt )
+          os::hint_no_preempt();
 
-      // trace per thread time and compile statistics
-      CompilerCounters* counters = ((CompilerThread*)thread)->counters();
-      PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
+        // trace per thread time and compile statistics
+        CompilerCounters* counters = ((CompilerThread*)thread)->counters();
+        PerfTraceTimedEvent(counters->time_counter(), counters->compile_counter());
 
-      // Assign the task to the current thread.  Mark this compilation
-      // thread as active for the profiler.
-      CompileTaskWrapper ctw(task);
-      nmethodLocker result_handle;  // (handle for the nmethod produced by this task)
-      task->set_code_handle(&result_handle);
-      methodHandle method(thread,
-                     (methodOop)JNIHandles::resolve(task->method_handle()));
+        // Assign the task to the current thread.  Mark this compilation
+        // thread as active for the profiler.
+        CompileTaskWrapper ctw(task);
+        nmethodLocker result_handle;  // (handle for the nmethod produced by this task)
+        task->set_code_handle(&result_handle);
+        methodHandle method(thread,
+                       (methodOop)JNIHandles::resolve(task->method_handle()));
 
-      // Never compile a method if breakpoints are present in it
-      if (method()->number_of_breakpoints() == 0) {
-        // Compile the method.
-        if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
-#ifdef COMPILER1
-          // Allow repeating compilations for the purpose of benchmarking
-          // compile speed. This is not useful for customers.
-          if (CompilationRepeat != 0) {
-            int compile_count = CompilationRepeat;
-            while (compile_count > 0) {
-              invoke_compiler_on_method(task);
-              nmethod* nm = method->code();
-              if (nm != NULL) {
-                nm->make_zombie();
-                method->clear_code();
+        // Never compile a method if breakpoints are present in it
+        if (method()->number_of_breakpoints() == 0) {
+          // Compile the method.
+          if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
+  #ifdef COMPILER1
+            // Allow repeating compilations for the purpose of benchmarking
+            // compile speed. This is not useful for customers.
+            if (CompilationRepeat != 0) {
+              int compile_count = CompilationRepeat;
+              while (compile_count > 0) {
+                invoke_compiler_on_method(task);
+                nmethod* nm = method->code();
+                if (nm != NULL) {
+                  nm->make_zombie();
+                  method->clear_code();
+                }
+                compile_count--;
               }
-              compile_count--;
             }
+  #endif /* COMPILER1 */
+            invoke_compiler_on_method(task);
+          } else {
+            // After compilation is disabled, remove remaining methods from queue
+            method->clear_queued_for_compilation();
           }
-#endif /* COMPILER1 */
-          invoke_compiler_on_method(task);
-        } else {
-          // After compilation is disabled, remove remaining methods from queue
-          method->clear_queued_for_compilation();
+        }
+      }
+
+      if (_poll_java_queue) {
+        _poll_java_queue = false;
+        if (UseGraal) {
+          GraalCompiler::instance()->poll_java_queue();
         }
       }
     }