diff src/share/vm/graal/graalCompiler.cpp @ 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 e54507c88a93
children 9b27e69f7cec
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++;
 }