Mercurial > hg > graal-compiler
diff src/share/vm/graal/graalCompiler.cpp @ 16006:66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 03 Jun 2014 11:51:27 +0200 |
parents | b7fb36e57da8 |
children | c1a47bf45b66 |
line wrap: on
line diff
--- a/src/share/vm/graal/graalCompiler.cpp Tue Jun 03 11:01:58 2014 +0200 +++ b/src/share/vm/graal/graalCompiler.cpp Tue Jun 03 11:51:27 2014 +0200 @@ -25,7 +25,6 @@ #include "memory/oopFactory.hpp" #include "runtime/javaCalls.hpp" #include "graal/graalCompiler.hpp" -#include "graal/graalVMToCompiler.hpp" #include "graal/graalEnv.hpp" #include "graal/graalRuntime.hpp" #include "runtime/compilationPolicy.hpp" @@ -35,7 +34,7 @@ GraalCompiler::GraalCompiler() : AbstractCompiler(graal) { #ifdef COMPILERGRAAL - _started = false; + _bootstrapping = false; #endif assert(_instance == NULL, "only one instance allowed"); _instance = this; @@ -63,15 +62,15 @@ { HandleMark hm; - bool bootstrap = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal); - VMToCompiler::startCompiler(bootstrap); - _started = true; + _bootstrapping = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal); + + start_compilation_queue(); // Graal is considered as application code so we need to // stop the VM deferring compilation now. CompilationPolicy::completed_vm_startup(); - if (bootstrap) { + if (_bootstrapping) { // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping. FlagSetting a(UseInterpreter, true); FlagSetting b(BackgroundCompilation, true); @@ -81,12 +80,12 @@ // allowing a complete bootstrap FlagSetting c(CompileTheWorld, false); #endif - VMToCompiler::bootstrap(); + bootstrap(); } #ifndef PRODUCT if (CompileTheWorld) { - VMToCompiler::compileTheWorld(); + compile_the_world(); } #endif } @@ -94,18 +93,58 @@ } #ifdef COMPILERGRAAL +void GraalCompiler::start_compilation_queue() { + JavaThread* THREAD = JavaThread::current(); + HandleMark hm(THREAD); + TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD); + KlassHandle klass = GraalRuntime::load_required_class(name); + NoGraalCompilationScheduling ngcs(THREAD); + klass->initialize(THREAD); + GUARANTEE_NO_PENDING_EXCEPTION("Error while calling start_compilation_queue"); +} + + +void GraalCompiler::shutdown_compilation_queue() { + JavaThread* THREAD = JavaThread::current(); + HandleMark hm(THREAD); + TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD); + KlassHandle klass = GraalRuntime::load_required_class(name); + JavaValue result(T_VOID); + JavaCallArguments args; + JavaCalls::call_static(&result, klass, vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, THREAD); + GUARANTEE_NO_PENDING_EXCEPTION("Error while calling shutdown_compilation_queue"); +} + +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"); +} + void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task, jboolean blocking) { GRAAL_EXCEPTION_CONTEXT - if (!_started) { - CompilationPolicy::policy()->delay_compilation(method()); - return; + + bool is_osr = entry_bci != InvocationEntryBci; + if (_bootstrapping && is_osr) { + // no OSR compilations during bootstrap - the compiler is just too slow at this point, + // and we know that there are no endless loops + return; } - assert(_started, "must already be started"); ResourceMark rm; - thread->set_is_graal_compiling(true); - VMToCompiler::compileMethod(method(), entry_bci, (jlong) (address) task, blocking); - thread->set_is_graal_compiling(false); + JavaValue result(T_VOID); + JavaCallArguments args; + args.push_long((jlong) (address) method()); + args.push_int(entry_bci); + args.push_long((jlong) (address) task); + 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"); } @@ -115,10 +154,7 @@ } void GraalCompiler::shutdown() { - if (_started) { - VMToCompiler::shutdownCompiler(); - _started = false; - } + shutdown_compilation_queue(); } // Print compilation timers and statistics @@ -127,3 +163,21 @@ } #endif // COMPILERGRAAL + +#ifndef PRODUCT +void GraalCompiler::compile_the_world() { + // We turn off CompileTheWorld so that Graal can + // be compiled by C1/C2 when Graal does a CTW. + CompileTheWorld = false; + + JavaThread* THREAD = JavaThread::current(); + TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/HotSpotGraalRuntime", THREAD); + KlassHandle klass = GraalRuntime::load_required_class(name); + TempNewSymbol compileTheWorld = SymbolTable::new_symbol("compileTheWorld", THREAD); + JavaValue result(T_VOID); + JavaCallArguments args; + args.push_oop(GraalRuntime::get_HotSpotGraalRuntime()); + JavaCalls::call_special(&result, klass, compileTheWorld, vmSymbols::void_method_signature(), &args, THREAD); + GUARANTEE_NO_PENDING_EXCEPTION("Error while calling compile_the_world"); +} +#endif