# HG changeset patch # User Doug Simon # Date 1403102939 -7200 # Node ID d32be0297274e509d3a91efc36aee6328229e0ca # Parent f3330ba9974c2beb335a7c22884c2fc28aed716e support -XX:+BootstrapGraal in conjunction with -XX:-UseGraalCompilationQueue diff -r f3330ba9974c -r d32be0297274 src/share/vm/graal/graalCompiler.cpp --- 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* 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++; } diff -r f3330ba9974c -r d32be0297274 src/share/vm/graal/graalCompiler.hpp --- 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); diff -r f3330ba9974c -r d32be0297274 src/share/vm/prims/jni.cpp --- 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