comparison 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
comparison
equal deleted inserted replaced
16135:f3330ba9974c 16136:d32be0297274
33 GraalCompiler* GraalCompiler::_instance = NULL; 33 GraalCompiler* GraalCompiler::_instance = NULL;
34 34
35 GraalCompiler::GraalCompiler() : AbstractCompiler(graal) { 35 GraalCompiler::GraalCompiler() : AbstractCompiler(graal) {
36 #ifdef COMPILERGRAAL 36 #ifdef COMPILERGRAAL
37 _bootstrapping = false; 37 _bootstrapping = false;
38 _compiled = 0;
38 #endif 39 #endif
39 assert(_instance == NULL, "only one instance allowed"); 40 assert(_instance == NULL, "only one instance allowed");
40 _instance = this; 41 _instance = this;
41 } 42 }
42 43
60 } 61 }
61 62
62 { 63 {
63 HandleMark hm; 64 HandleMark hm;
64 65
65 _bootstrapping = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal); 66 bool bootstrap_now = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal);
66 67
67 if (UseGraalCompilationQueue) { 68 if (UseGraalCompilationQueue) {
69 _bootstrapping = bootstrap_now;
68 start_compilation_queue(); 70 start_compilation_queue();
69 } 71 }
70 72
71 // Graal is considered as application code so we need to 73 // Graal is considered as application code so we need to
72 // stop the VM deferring compilation now. 74 // stop the VM deferring compilation now.
73 CompilationPolicy::completed_vm_startup(); 75 CompilationPolicy::completed_vm_startup();
74 76
75 if (_bootstrapping) { 77 if (bootstrap_now) {
76 // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping. 78 // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping.
77 FlagSetting a(UseInterpreter, true); 79 FlagSetting a(UseInterpreter, true);
78 FlagSetting b(BackgroundCompilation, true); 80 FlagSetting b(BackgroundCompilation, true);
79 #ifndef PRODUCT 81 #ifndef PRODUCT
80 // Turn off CompileTheWorld during bootstrap so that a counter overflow event 82 // Turn off CompileTheWorld during bootstrap so that a counter overflow event
117 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling shutdown_compilation_queue"); 119 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling shutdown_compilation_queue");
118 } 120 }
119 121
120 void GraalCompiler::bootstrap() { 122 void GraalCompiler::bootstrap() {
121 JavaThread* THREAD = JavaThread::current(); 123 JavaThread* THREAD = JavaThread::current();
122 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD); 124 _bootstrapping = true;
123 KlassHandle klass = GraalRuntime::load_required_class(name); 125 if (!UseGraalCompilationQueue) {
124 JavaValue result(T_VOID); 126 ResourceMark rm;
125 TempNewSymbol bootstrap = SymbolTable::new_symbol("bootstrap", THREAD); 127 HandleMark hm;
126 NoGraalCompilationScheduling ngcs(THREAD); 128 tty->print("Bootstrapping Graal");
127 JavaCalls::call_static(&result, klass, bootstrap, vmSymbols::void_method_signature(), THREAD); 129 jlong start = os::javaTimeMillis();
128 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling bootstrap"); 130
131 Array<Method*>* objectMethods = InstanceKlass::cast(SystemDictionary::Object_klass())->methods();
132 // Initialize compile queue with a selected set of methods.
133 int len = objectMethods->length();
134 for (int i = 0; i < len; i++) {
135 methodHandle mh = objectMethods->at(i);
136 if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) {
137 ResourceMark rm;
138 int hot_count = 10; // TODO: what's the appropriate value?
139 CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, "bootstrap", THREAD);
140 }
141 }
142
143 int qsize;
144 jlong sleep_time = 1000;
145 int z = 0;
146 do {
147 os::sleep(THREAD, sleep_time, true);
148 sleep_time = 100;
149 qsize = CompileBroker::queue_size(CompLevel_full_optimization);
150 while (z < (_compiled / 100)) {
151 ++z;
152 tty->print_raw(".");
153 }
154
155 } while (qsize != 0);
156
157 tty->print_cr(" in %d ms (compiled %d methods)", os::javaTimeMillis() - start, _compiled);
158 } else {
159
160 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD);
161 KlassHandle klass = GraalRuntime::load_required_class(name);
162 JavaValue result(T_VOID);
163 TempNewSymbol bootstrap = SymbolTable::new_symbol("bootstrap", THREAD);
164 NoGraalCompilationScheduling ngcs(THREAD);
165 JavaCalls::call_static(&result, klass, bootstrap, vmSymbols::void_method_signature(), THREAD);
166 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling bootstrap");
167 }
168 _bootstrapping = false;
129 } 169 }
130 170
131 void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task, jboolean blocking) { 171 void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task, jboolean blocking) {
132 GRAAL_EXCEPTION_CONTEXT 172 GRAAL_EXCEPTION_CONTEXT
133 173
146 args.push_int(entry_bci); 186 args.push_int(entry_bci);
147 args.push_long((jlong) (address) task); 187 args.push_long((jlong) (address) task);
148 args.push_int(blocking); 188 args.push_int(blocking);
149 JavaCalls::call_static(&result, SystemDictionary::CompilationTask_klass(), vmSymbols::compileMetaspaceMethod_name(), vmSymbols::compileMetaspaceMethod_signature(), &args, THREAD); 189 JavaCalls::call_static(&result, SystemDictionary::CompilationTask_klass(), vmSymbols::compileMetaspaceMethod_name(), vmSymbols::compileMetaspaceMethod_signature(), &args, THREAD);
150 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling compile_method"); 190 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling compile_method");
191
192 _compiled++;
151 } 193 }
152 194
153 195
154 // Compilation entry point for methods 196 // Compilation entry point for methods
155 void GraalCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) { 197 void GraalCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {