changeset 4139:feb590a8497f

remove pollJavaQueue and related functionality, minimize diff against HotSpot in the compileBroker.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 18 Dec 2011 00:41:15 +0100
parents 82af018d61db
children 716a2c5c0656
files graal/com.oracle.max.cri/src/com/sun/cri/ri/RiRuntime.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotRuntime.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/VMExits.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/VMExitsNative.java src/share/vm/classfile/vmSymbols.hpp src/share/vm/compiler/compileBroker.cpp src/share/vm/compiler/compileBroker.hpp src/share/vm/graal/graalCompiler.cpp src/share/vm/graal/graalCompiler.hpp src/share/vm/graal/graalVMEntries.cpp src/share/vm/graal/graalVMExits.cpp src/share/vm/graal/graalVMExits.hpp src/share/vm/runtime/fieldDescriptor.hpp
diffstat 13 files changed, 45 insertions(+), 170 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.cri/src/com/sun/cri/ri/RiRuntime.java	Sat Dec 17 22:03:44 2011 +0100
+++ b/graal/com.oracle.max.cri/src/com/sun/cri/ri/RiRuntime.java	Sun Dec 18 00:41:15 2011 +0100
@@ -232,9 +232,4 @@
      * @return a reference to the compiled and ready-to-run code
      */
     RiCompiledMethod addMethod(RiResolvedMethod method, CiTargetMethod code);
-
-    /**
-     * Executes the given runnable on a compiler thread, which means that it can access constant pools, etc.
-     */
-    void executeOnCompilerThread(Runnable r);
 }
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotRuntime.java	Sat Dec 17 22:03:44 2011 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/HotSpotRuntime.java	Sun Dec 18 00:41:15 2011 +0100
@@ -25,7 +25,6 @@
 import java.io.*;
 import java.lang.reflect.*;
 import java.util.*;
-import java.util.concurrent.*;
 
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.cri.*;
@@ -59,8 +58,6 @@
     // TODO(ls) this is not a permanent solution - there should be a more sophisticated compiler oracle
     private HashSet<RiResolvedMethod> notInlineableMethods = new HashSet<RiResolvedMethod>();
 
-    private final ConcurrentLinkedQueue<Runnable> tasks = new ConcurrentLinkedQueue<Runnable>();
-
     public HotSpotRuntime(GraalContext context, HotSpotVMConfig config, Compiler compiler) {
         this.context = context;
         this.config = config;
@@ -466,24 +463,6 @@
     }
 
     @Override
-    public void executeOnCompilerThread(Runnable r) {
-        tasks.add(r);
-        compiler.getVMEntries().notifyJavaQueue();
-    }
-
-    public void pollJavaQueue() {
-        Runnable r = tasks.poll();
-        while (r != null) {
-            try {
-                r.run();
-            } catch (Throwable t) {
-                t.printStackTrace();
-            }
-            r = tasks.poll();
-        }
-    }
-
-    @Override
     public RiCompiledMethod addMethod(RiResolvedMethod method, CiTargetMethod code) {
         Compiler compilerInstance = CompilerImpl.getInstance();
         return HotSpotTargetMethod.installMethod(compilerInstance, (HotSpotMethodResolved) method, code, false);
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/VMExits.java	Sat Dec 17 22:03:44 2011 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/VMExits.java	Sun Dec 18 00:41:15 2011 +0100
@@ -58,6 +58,4 @@
     void startCompiler() throws Throwable;
 
     void bootstrap() throws Throwable;
-
-    void pollJavaQueue();
 }
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/VMExitsNative.java	Sat Dec 17 22:03:44 2011 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/VMExitsNative.java	Sun Dec 18 00:41:15 2011 +0100
@@ -275,9 +275,4 @@
     public CiConstant createCiConstantObject(Object object) {
         return CiConstant.forObject(object);
     }
-
-    @Override
-    public void pollJavaQueue() {
-        ((HotSpotRuntime) compiler.getRuntime()).pollJavaQueue();
-    }
 }
--- a/src/share/vm/classfile/vmSymbols.hpp	Sat Dec 17 22:03:44 2011 +0100
+++ b/src/share/vm/classfile/vmSymbols.hpp	Sun Dec 18 00:41:15 2011 +0100
@@ -317,7 +317,6 @@
   template(bootstrap_name,                            "bootstrap")                                                      \
   template(shutdownCompiler_name,                     "shutdownCompiler")                                               \
   template(compileMethod_name,                        "compileMethod")                                                  \
-  template(pollJavaQueue_name,                        "pollJavaQueue")                                                  \
   template(compileMethod_signature,                   "(Lcom/oracle/max/graal/hotspot/HotSpotMethodResolved;IZ)V")      \
   template(setOption_name,                            "setOption")                                                      \
   template(setDefaultOptions_name,                    "setDefaultOptions")                                              \
--- a/src/share/vm/compiler/compileBroker.cpp	Sat Dec 17 22:03:44 2011 +0100
+++ b/src/share/vm/compiler/compileBroker.cpp	Sun Dec 18 00:41:15 2011 +0100
@@ -189,7 +189,6 @@
 
 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL;
 
-bool CompileBroker::_poll_java_queue = false;
 
 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) {
   CompilerThread* thread = CompilerThread::current();
@@ -574,15 +573,12 @@
 // CompileQueue::get
 //
 // Get the next CompileTask from a CompileQueue
-CompileTask* CompileQueue::get(bool& interrupt) {
+CompileTask* CompileQueue::get() {
   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
@@ -620,7 +616,6 @@
     assert(task == _last, "Sanity");
     _last = task->prev();
   }
-
   --_size;
 }
 
@@ -674,31 +669,6 @@
   }
 }
 
-void CompileBroker::add_method_to_queue(klassOop k, Symbol* name, Symbol* signature) {
-  Thread* THREAD = Thread::current();
-  instanceKlass* klass = instanceKlass::cast(k);
-  methodOop method = klass->find_method(name, signature);
-  CompileBroker::compile_method(method, -1, 0, method, 0, "initial compile of object initializer", THREAD);
-  if (HAS_PENDING_EXCEPTION) {
-    CLEAR_PENDING_EXCEPTION;
-    fatal("error inserting method into compile queue");
-  }
-}
-
-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
 //
@@ -716,9 +686,6 @@
   } else if (c1_count > 0) {
 	  _compilers[0] = new Compiler();
   }
-#ifndef COMPILER2
-  _compilers[1] = _compilers[0];
-#endif
 #endif // COMPILER1
 
 #ifdef COMPILER2
@@ -1548,7 +1515,6 @@
 
   while (true) {
     {
-
       // We need this HandleMark to avoid leaking VM handles.
       HandleMark hm(thread);
 
@@ -1560,58 +1526,49 @@
         NMethodSweeper::handle_full_code_cache(false);
       }
 
-      CompileTask* task = queue->get(_poll_java_queue);
+      CompileTask* task = queue->get();
 
-      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();
+      // 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();
-                }
-                compile_count--;
+      // 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--;
             }
-  #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();
+#endif /* COMPILER1 */
+          invoke_compiler_on_method(task);
+        } else {
+          // After compilation is disabled, remove remaining methods from queue
+          method->clear_queued_for_compilation();
         }
       }
     }
@@ -1701,7 +1658,6 @@
 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
   if (PrintCompilation) {
     ResourceMark rm;
-    tty->print("%s: ", compiler(task->comp_level())->name());
     task->print_line();
   }
   elapsedTimer time;
@@ -1737,17 +1693,15 @@
   // Allocate a new set of JNI handles.
   push_jni_handle_block();
   jobject target_handle = JNIHandles::make_local(thread, JNIHandles::resolve(task->method_handle()));
-  int compilable = ciEnv::MethodCompilable_never;
-  if (MaxCompilationID == -1 || compile_id <= (uint)MaxCompilationID) {
-    compilable = ciEnv::MethodCompilable;
+  int compilable = ciEnv::MethodCompilable;
+  {
     int system_dictionary_modification_counter;
     {
       MutexLocker locker(Compile_lock, thread);
       system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
     }
 
-	// (tw) Check if we may do this?
-    // NoHandleMark  nhm;
+    NoHandleMark  nhm;
     ThreadToNativeFromVM ttn(thread);
 
     ciEnv ci_env(task, system_dictionary_modification_counter);
@@ -1772,13 +1726,12 @@
 
     compiler(task->comp_level())->compile_method(&ci_env, target, osr_bci);
 
-    // TODO (tw): Check if this is OK.
-    /*if (!ci_env.failing() && task->code() == NULL) {
+    if (!ci_env.failing() && task->code() == NULL) {
       //assert(false, "compiler should always document failure");
       // The compiler elected, without comment, not to register a result.
       // Do not attempt further compilations of this method.
       ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
-    }*/
+    }
 
     if (ci_env.failing()) {
       // Copy this bit to the enclosing block:
--- a/src/share/vm/compiler/compileBroker.hpp	Sat Dec 17 22:03:44 2011 +0100
+++ b/src/share/vm/compiler/compileBroker.hpp	Sun Dec 18 00:41:15 2011 +0100
@@ -197,7 +197,7 @@
   CompileTask* first()                           { return _first; }
   CompileTask* last()                            { return _last;  }
 
-  CompileTask* get(bool& interrupt);
+  CompileTask* get();
 
   bool         is_empty() const                  { return _first == NULL; }
   int          size()     const                  { return _size;          }
@@ -407,8 +407,6 @@
   static void print_compiler_threads_on(outputStream* st);
 
   static void add_method_to_queue(klassOop k, Symbol* name, Symbol* signature);
-
-  static void notify_java_queue();
 };
 
 #endif // SHARE_VM_COMPILER_COMPILEBROKER_HPP
--- a/src/share/vm/graal/graalCompiler.cpp	Sat Dec 17 22:03:44 2011 +0100
+++ b/src/share/vm/graal/graalCompiler.cpp	Sun Dec 18 00:41:15 2011 +0100
@@ -294,24 +294,3 @@
   }
   return T_ILLEGAL;
 }
-
-void GraalCompiler::poll_java_queue() {
-  int system_dictionary_modification_counter;
-  {
-    MutexLocker locker(Compile_lock, Thread::current());
-    system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
-  }
-
-  {
-    ThreadToNativeFromVM ttn(JavaThread::current());
-    ciEnv ci_env(NULL, system_dictionary_modification_counter);
-    {
-      VM_ENTRY_MARK;
-      ResourceMark rm;
-      HandleMark hm;
-
-      VMExits::pollJavaQueue();
-    }
-  }
-}
-
--- a/src/share/vm/graal/graalCompiler.hpp	Sat Dec 17 22:03:44 2011 +0100
+++ b/src/share/vm/graal/graalCompiler.hpp	Sun Dec 18 00:41:15 2011 +0100
@@ -83,8 +83,6 @@
   }
 
   static void initialize_buffer_blob();
-
-  void poll_java_queue();
 };
 
 // Tracing macros
--- a/src/share/vm/graal/graalVMEntries.cpp	Sat Dec 17 22:03:44 2011 +0100
+++ b/src/share/vm/graal/graalVMEntries.cpp	Sun Dec 18 00:41:15 2011 +0100
@@ -974,12 +974,6 @@
   return id;
 }
 
-// public void notifyJavaQueue();
-JNIEXPORT void JNICALL Java_com_oracle_graal_hotspot_VMEntries_notifyJavaQueue(JNIEnv *jniEnv, jobject) {
-  CompileBroker::notify_java_queue();
-}
-
-
 
 
 #define CC (char*)  /*cast a literal from (const char*)*/
@@ -1040,8 +1034,7 @@
   {CC"getType",                           CC"("CLASS")"TYPE,                          FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_getType)},
   {CC"getConfiguration",                  CC"()"CONFIG,                               FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_getConfiguration)},
   {CC"installMethod",                     CC"("TARGET_METHOD"Z)"HS_COMP_METHOD,       FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_installMethod)},
-  {CC"installStub",                       CC"("TARGET_METHOD")"PROXY,                 FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_installStub)},
-  {CC"notifyJavaQueue",                   CC"()V",                                    FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_notifyJavaQueue)}
+  {CC"installStub",                       CC"("TARGET_METHOD")"PROXY,                 FN_PTR(Java_com_oracle_graal_hotspot_VMEntries_installStub)}
 };
 
 int VMEntries_methods_count() {
--- a/src/share/vm/graal/graalVMExits.cpp	Sat Dec 17 22:03:44 2011 +0100
+++ b/src/share/vm/graal/graalVMExits.cpp	Sun Dec 18 00:41:15 2011 +0100
@@ -148,15 +148,6 @@
   check_pending_exception("Error while calling boostrap");
 }
 
-void VMExits::pollJavaQueue() {
-  JavaThread* THREAD = JavaThread::current();
-  JavaValue result(T_VOID);
-  JavaCallArguments args;
-  args.push_oop(instance());
-  JavaCalls::call_interface(&result, vmExitsKlass(), vmSymbols::pollJavaQueue_name(), vmSymbols::void_method_signature(), &args, THREAD);
-  check_pending_exception("Error while calling pollJavaQueue");
-}
-
 oop VMExits::createRiMethodResolved(jlong vmId, Handle name, TRAPS) {
   assert(!name.is_null(), "just checking");
   JavaValue result(T_OBJECT);
--- a/src/share/vm/graal/graalVMExits.hpp	Sat Dec 17 22:03:44 2011 +0100
+++ b/src/share/vm/graal/graalVMExits.hpp	Sun Dec 18 00:41:15 2011 +0100
@@ -62,9 +62,6 @@
   // public abstract void bootstrap();
   static void bootstrap();
 
-  // public abstract void pollJavaQueue();
-  static void pollJavaQueue();
-
   // public abstract RiMethod createRiMethodResolved(long vmId, String name);
   static oop createRiMethodResolved(jlong vmId, Handle name, TRAPS);
 
--- a/src/share/vm/runtime/fieldDescriptor.hpp	Sat Dec 17 22:03:44 2011 +0100
+++ b/src/share/vm/runtime/fieldDescriptor.hpp	Sun Dec 18 00:41:15 2011 +0100
@@ -61,7 +61,7 @@
   Symbol* signature() const {
     return field()->signature(_cp);
   }
-  int signature_index() const            { return field()->signature_index(); }
+  int signature_index() const          { return field()->signature_index(); }
   klassOop field_holder() const        { return _cp->pool_holder(); }
   constantPoolOop constants() const    { return _cp(); }
   AccessFlags access_flags() const     { return _access_flags; }