changeset 16136:d32be0297274

support -XX:+BootstrapGraal in conjunction with -XX:-UseGraalCompilationQueue
author Doug Simon <doug.simon@oracle.com>
date Wed, 18 Jun 2014 16:48:59 +0200
parents f3330ba9974c
children 0eb8270ae69d
files src/share/vm/graal/graalCompiler.cpp src/share/vm/graal/graalCompiler.hpp src/share/vm/prims/jni.cpp
diffstat 3 files changed, 58 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/graal/graalCompiler.cpp	Wed Jun 18 14:46:01 2014 +0200
+++ b/src/share/vm/graal/graalCompiler.cpp	Wed Jun 18 16:48:59 2014 +0200
@@ -35,6 +35,7 @@
 GraalCompiler::GraalCompiler() : AbstractCompiler(graal) {
 #ifdef COMPILERGRAAL
   _bootstrapping = false;
+  _compiled = 0;
 #endif
   assert(_instance == NULL, "only one instance allowed");
   _instance = this;
@@ -62,9 +63,10 @@
   {
     HandleMark hm;
 
-    _bootstrapping = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal);
+    bool bootstrap_now = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal);
 
     if (UseGraalCompilationQueue) {
+      _bootstrapping = bootstrap_now;
       start_compilation_queue();
     }
 
@@ -72,7 +74,7 @@
     // stop the VM deferring compilation now.
     CompilationPolicy::completed_vm_startup();
 
-    if (_bootstrapping) {
+    if (bootstrap_now) {
       // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping.
       FlagSetting a(UseInterpreter, true);
       FlagSetting b(BackgroundCompilation, true);
@@ -119,13 +121,51 @@
 
 void GraalCompiler::bootstrap() {
   JavaThread* THREAD = JavaThread::current();
-  TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD);
-  KlassHandle klass = GraalRuntime::load_required_class(name);
-  JavaValue result(T_VOID);
-  TempNewSymbol bootstrap = SymbolTable::new_symbol("bootstrap", THREAD);
-  NoGraalCompilationScheduling ngcs(THREAD);
-  JavaCalls::call_static(&result, klass, bootstrap, vmSymbols::void_method_signature(), THREAD);
-  GUARANTEE_NO_PENDING_EXCEPTION("Error while calling bootstrap");
+  _bootstrapping = true;
+  if (!UseGraalCompilationQueue) {
+    ResourceMark rm;
+    HandleMark hm;
+    tty->print("Bootstrapping Graal");
+    jlong start = os::javaTimeMillis();
+
+    Array<Method*>* objectMethods = InstanceKlass::cast(SystemDictionary::Object_klass())->methods();
+    // Initialize compile queue with a selected set of methods.
+    int len = objectMethods->length();
+    for (int i = 0; i < len; i++) {
+      methodHandle mh = objectMethods->at(i);
+      if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) {
+        ResourceMark rm;
+        int hot_count = 10; // TODO: what's the appropriate value?
+        CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, "bootstrap", THREAD);
+      }
+    }
+
+    int qsize;
+    jlong sleep_time = 1000;
+    int z = 0;
+    do {
+      os::sleep(THREAD, sleep_time, true);
+      sleep_time = 100;
+      qsize = CompileBroker::queue_size(CompLevel_full_optimization);
+      while (z < (_compiled / 100)) {
+          ++z;
+          tty->print_raw(".");
+      }
+
+    } while (qsize != 0);
+
+    tty->print_cr(" in %d ms (compiled %d methods)", os::javaTimeMillis() - start, _compiled);
+  } else {
+
+    TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD);
+    KlassHandle klass = GraalRuntime::load_required_class(name);
+    JavaValue result(T_VOID);
+    TempNewSymbol bootstrap = SymbolTable::new_symbol("bootstrap", THREAD);
+    NoGraalCompilationScheduling ngcs(THREAD);
+    JavaCalls::call_static(&result, klass, bootstrap, vmSymbols::void_method_signature(), THREAD);
+    GUARANTEE_NO_PENDING_EXCEPTION("Error while calling bootstrap");
+  }
+  _bootstrapping = false;
 }
 
 void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task, jboolean blocking) {
@@ -148,6 +188,8 @@
   args.push_int(blocking);
   JavaCalls::call_static(&result, SystemDictionary::CompilationTask_klass(), vmSymbols::compileMetaspaceMethod_name(), vmSymbols::compileMetaspaceMethod_signature(), &args, THREAD);
   GUARANTEE_NO_PENDING_EXCEPTION("Error while calling compile_method");
+
+  _compiled++;
 }
 
 
--- a/src/share/vm/graal/graalCompiler.hpp	Wed Jun 18 14:46:01 2014 +0200
+++ b/src/share/vm/graal/graalCompiler.hpp	Wed Jun 18 16:48:59 2014 +0200
@@ -32,10 +32,10 @@
 
 #ifdef COMPILERGRAAL
   bool _bootstrapping;
+  volatile int  _compiled; // no synchronization so may not be 100% accurate
 
   void start_compilation_queue();
   void shutdown_compilation_queue();
-  void bootstrap();
 #endif
 
   static GraalCompiler* _instance;
@@ -61,6 +61,9 @@
   virtual void initialize();
 
 #ifdef COMPILERGRAAL
+
+  void bootstrap();
+  
   // Compilation entry point for methods
   virtual void compile_method(ciEnv* env, ciMethod* target, int entry_bci);
 
--- a/src/share/vm/prims/jni.cpp	Wed Jun 18 14:46:01 2014 +0200
+++ b/src/share/vm/prims/jni.cpp	Wed Jun 18 16:48:59 2014 +0200
@@ -5188,6 +5188,9 @@
       }
     } else {
       // Graal is initialized on a CompilerThread
+      if (BootstrapGraal) {
+        GraalCompiler::instance()->bootstrap();
+      }
     }
 #endif