comparison 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
comparison
equal deleted inserted replaced
16003:83433cf49019 16006:66a9286203a2
23 23
24 #include "precompiled.hpp" 24 #include "precompiled.hpp"
25 #include "memory/oopFactory.hpp" 25 #include "memory/oopFactory.hpp"
26 #include "runtime/javaCalls.hpp" 26 #include "runtime/javaCalls.hpp"
27 #include "graal/graalCompiler.hpp" 27 #include "graal/graalCompiler.hpp"
28 #include "graal/graalVMToCompiler.hpp"
29 #include "graal/graalEnv.hpp" 28 #include "graal/graalEnv.hpp"
30 #include "graal/graalRuntime.hpp" 29 #include "graal/graalRuntime.hpp"
31 #include "runtime/compilationPolicy.hpp" 30 #include "runtime/compilationPolicy.hpp"
32 #include "runtime/globals_extension.hpp" 31 #include "runtime/globals_extension.hpp"
33 32
34 GraalCompiler* GraalCompiler::_instance = NULL; 33 GraalCompiler* GraalCompiler::_instance = NULL;
35 34
36 GraalCompiler::GraalCompiler() : AbstractCompiler(graal) { 35 GraalCompiler::GraalCompiler() : AbstractCompiler(graal) {
37 #ifdef COMPILERGRAAL 36 #ifdef COMPILERGRAAL
38 _started = false; 37 _bootstrapping = false;
39 #endif 38 #endif
40 assert(_instance == NULL, "only one instance allowed"); 39 assert(_instance == NULL, "only one instance allowed");
41 _instance = this; 40 _instance = this;
42 } 41 }
43 42
61 } 60 }
62 61
63 { 62 {
64 HandleMark hm; 63 HandleMark hm;
65 64
66 bool bootstrap = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal); 65 _bootstrapping = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal);
67 VMToCompiler::startCompiler(bootstrap); 66
68 _started = true; 67 start_compilation_queue();
69 68
70 // Graal is considered as application code so we need to 69 // Graal is considered as application code so we need to
71 // stop the VM deferring compilation now. 70 // stop the VM deferring compilation now.
72 CompilationPolicy::completed_vm_startup(); 71 CompilationPolicy::completed_vm_startup();
73 72
74 if (bootstrap) { 73 if (_bootstrapping) {
75 // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping. 74 // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping.
76 FlagSetting a(UseInterpreter, true); 75 FlagSetting a(UseInterpreter, true);
77 FlagSetting b(BackgroundCompilation, true); 76 FlagSetting b(BackgroundCompilation, true);
78 #ifndef PRODUCT 77 #ifndef PRODUCT
79 // Turn off CompileTheWorld during bootstrap so that a counter overflow event 78 // Turn off CompileTheWorld during bootstrap so that a counter overflow event
80 // triggers further compilation (see NonTieredCompPolicy::event()) hence 79 // triggers further compilation (see NonTieredCompPolicy::event()) hence
81 // allowing a complete bootstrap 80 // allowing a complete bootstrap
82 FlagSetting c(CompileTheWorld, false); 81 FlagSetting c(CompileTheWorld, false);
83 #endif 82 #endif
84 VMToCompiler::bootstrap(); 83 bootstrap();
85 } 84 }
86 85
87 #ifndef PRODUCT 86 #ifndef PRODUCT
88 if (CompileTheWorld) { 87 if (CompileTheWorld) {
89 VMToCompiler::compileTheWorld(); 88 compile_the_world();
90 } 89 }
91 #endif 90 #endif
92 } 91 }
93 #endif // COMPILERGRAAL 92 #endif // COMPILERGRAAL
94 } 93 }
95 94
96 #ifdef COMPILERGRAAL 95 #ifdef COMPILERGRAAL
96 void GraalCompiler::start_compilation_queue() {
97 JavaThread* THREAD = JavaThread::current();
98 HandleMark hm(THREAD);
99 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD);
100 KlassHandle klass = GraalRuntime::load_required_class(name);
101 NoGraalCompilationScheduling ngcs(THREAD);
102 klass->initialize(THREAD);
103 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling start_compilation_queue");
104 }
105
106
107 void GraalCompiler::shutdown_compilation_queue() {
108 JavaThread* THREAD = JavaThread::current();
109 HandleMark hm(THREAD);
110 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD);
111 KlassHandle klass = GraalRuntime::load_required_class(name);
112 JavaValue result(T_VOID);
113 JavaCallArguments args;
114 JavaCalls::call_static(&result, klass, vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, THREAD);
115 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling shutdown_compilation_queue");
116 }
117
118 void GraalCompiler::bootstrap() {
119 JavaThread* THREAD = JavaThread::current();
120 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD);
121 KlassHandle klass = GraalRuntime::load_required_class(name);
122 JavaValue result(T_VOID);
123 TempNewSymbol bootstrap = SymbolTable::new_symbol("bootstrap", THREAD);
124 NoGraalCompilationScheduling ngcs(THREAD);
125 JavaCalls::call_static(&result, klass, bootstrap, vmSymbols::void_method_signature(), THREAD);
126 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling bootstrap");
127 }
128
97 void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task, jboolean blocking) { 129 void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task, jboolean blocking) {
98 GRAAL_EXCEPTION_CONTEXT 130 GRAAL_EXCEPTION_CONTEXT
99 if (!_started) { 131
100 CompilationPolicy::policy()->delay_compilation(method()); 132 bool is_osr = entry_bci != InvocationEntryBci;
101 return; 133 if (_bootstrapping && is_osr) {
134 // no OSR compilations during bootstrap - the compiler is just too slow at this point,
135 // and we know that there are no endless loops
136 return;
102 } 137 }
103 138
104 assert(_started, "must already be started");
105 ResourceMark rm; 139 ResourceMark rm;
106 thread->set_is_graal_compiling(true); 140 JavaValue result(T_VOID);
107 VMToCompiler::compileMethod(method(), entry_bci, (jlong) (address) task, blocking); 141 JavaCallArguments args;
108 thread->set_is_graal_compiling(false); 142 args.push_long((jlong) (address) method());
143 args.push_int(entry_bci);
144 args.push_long((jlong) (address) task);
145 args.push_int(blocking);
146 JavaCalls::call_static(&result, SystemDictionary::CompilationTask_klass(), vmSymbols::compileMetaspaceMethod_name(), vmSymbols::compileMetaspaceMethod_signature(), &args, THREAD);
147 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling compile_method");
109 } 148 }
110 149
111 150
112 // Compilation entry point for methods 151 // Compilation entry point for methods
113 void GraalCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) { 152 void GraalCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
114 ShouldNotReachHere(); 153 ShouldNotReachHere();
115 } 154 }
116 155
117 void GraalCompiler::shutdown() { 156 void GraalCompiler::shutdown() {
118 if (_started) { 157 shutdown_compilation_queue();
119 VMToCompiler::shutdownCompiler();
120 _started = false;
121 }
122 } 158 }
123 159
124 // Print compilation timers and statistics 160 // Print compilation timers and statistics
125 void GraalCompiler::print_timers() { 161 void GraalCompiler::print_timers() {
126 TRACE_graal_1("GraalCompiler::print_timers"); 162 TRACE_graal_1("GraalCompiler::print_timers");
127 } 163 }
128 164
129 #endif // COMPILERGRAAL 165 #endif // COMPILERGRAAL
166
167 #ifndef PRODUCT
168 void GraalCompiler::compile_the_world() {
169 // We turn off CompileTheWorld so that Graal can
170 // be compiled by C1/C2 when Graal does a CTW.
171 CompileTheWorld = false;
172
173 JavaThread* THREAD = JavaThread::current();
174 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/HotSpotGraalRuntime", THREAD);
175 KlassHandle klass = GraalRuntime::load_required_class(name);
176 TempNewSymbol compileTheWorld = SymbolTable::new_symbol("compileTheWorld", THREAD);
177 JavaValue result(T_VOID);
178 JavaCallArguments args;
179 args.push_oop(GraalRuntime::get_HotSpotGraalRuntime());
180 JavaCalls::call_special(&result, klass, compileTheWorld, vmSymbols::void_method_signature(), &args, THREAD);
181 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling compile_the_world");
182 }
183 #endif