comparison src/share/vm/graal/graalCompiler.cpp @ 16399:4481cf549cfc

removed (Java based) CompilationQueue
author Doug Simon <doug.simon@oracle.com>
date Thu, 03 Jul 2014 23:28:35 +0200
parents 9b27e69f7cec
children 78ddecd6255f
comparison
equal deleted inserted replaced
16398:c5ab3fbec257 16399:4481cf549cfc
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 _methodsCompiled = 0;
39 #endif 39 #endif
40 assert(_instance == NULL, "only one instance allowed"); 40 assert(_instance == NULL, "only one instance allowed");
41 _instance = this; 41 _instance = this;
42 } 42 }
43 43
47 if (!UseCompiler || !should_perform_init()) { 47 if (!UseCompiler || !should_perform_init()) {
48 return; 48 return;
49 } 49 }
50 50
51 BufferBlob* buffer_blob = GraalRuntime::initialize_buffer_blob(); 51 BufferBlob* buffer_blob = GraalRuntime::initialize_buffer_blob();
52 if (!UseGraalCompilationQueue) { 52 if (buffer_blob == NULL) {
53 // This path is used for initialization both by the native queue and the graal queue 53 set_state(failed);
54 // but set_state acquires a lock which might not be safe during JVM_CreateJavaVM, so 54 } else {
55 // only update the state flag for the native queue. 55 set_state(initialized);
56 if (buffer_blob == NULL) {
57 set_state(failed);
58 } else {
59 set_state(initialized);
60 }
61 } 56 }
62 57
63 { 58 {
64 HandleMark hm; 59 HandleMark hm;
65 60
66 bool bootstrap_now = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal);
67
68 if (UseGraalCompilationQueue) {
69 _bootstrapping = bootstrap_now;
70 start_compilation_queue();
71 }
72
73 // Graal is considered as application code so we need to 61 // Graal is considered as application code so we need to
74 // stop the VM deferring compilation now. 62 // stop the VM deferring compilation now.
75 CompilationPolicy::completed_vm_startup(); 63 CompilationPolicy::completed_vm_startup();
76
77 if (bootstrap_now) {
78 // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping.
79 FlagSetting a(UseInterpreter, true);
80 FlagSetting b(BackgroundCompilation, true);
81 #ifndef PRODUCT
82 // Turn off CompileTheWorld during bootstrap so that a counter overflow event
83 // triggers further compilation (see NonTieredCompPolicy::event()) hence
84 // allowing a complete bootstrap
85 FlagSetting c(CompileTheWorld, false);
86 #endif
87 bootstrap();
88 }
89 64
90 #ifndef PRODUCT 65 #ifndef PRODUCT
91 if (CompileTheWorld) { 66 if (CompileTheWorld) {
92 compile_the_world(); 67 compile_the_world();
93 } 68 }
95 } 70 }
96 #endif // COMPILERGRAAL 71 #endif // COMPILERGRAAL
97 } 72 }
98 73
99 #ifdef COMPILERGRAAL 74 #ifdef COMPILERGRAAL
100 void GraalCompiler::start_compilation_queue() {
101 JavaThread* THREAD = JavaThread::current();
102 HandleMark hm(THREAD);
103 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD);
104 KlassHandle klass = GraalRuntime::load_required_class(name);
105 NoGraalCompilationScheduling ngcs(THREAD);
106 klass->initialize(THREAD);
107 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling start_compilation_queue");
108 }
109
110
111 void GraalCompiler::shutdown_compilation_queue() {
112 JavaThread* THREAD = JavaThread::current();
113 HandleMark hm(THREAD);
114 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD);
115 KlassHandle klass = GraalRuntime::load_required_class(name);
116 JavaValue result(T_VOID);
117 JavaCallArguments args;
118 JavaCalls::call_static(&result, klass, vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, THREAD);
119 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling shutdown_compilation_queue");
120 }
121
122 void GraalCompiler::bootstrap() { 75 void GraalCompiler::bootstrap() {
123 JavaThread* THREAD = JavaThread::current(); 76 JavaThread* THREAD = JavaThread::current();
124 _bootstrapping = true; 77 _bootstrapping = true;
125 if (!UseGraalCompilationQueue) { 78 ResourceMark rm;
126 ResourceMark rm; 79 HandleMark hm;
127 HandleMark hm; 80 if (PrintBootstrap) {
81 tty->print("Bootstrapping Graal");
82 }
83 jlong start = os::javaTimeMillis();
84
85 Array<Method*>* objectMethods = InstanceKlass::cast(SystemDictionary::Object_klass())->methods();
86 // Initialize compile queue with a selected set of methods.
87 int len = objectMethods->length();
88 for (int i = 0; i < len; i++) {
89 methodHandle mh = objectMethods->at(i);
90 if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) {
91 ResourceMark rm;
92 int hot_count = 10; // TODO: what's the appropriate value?
93 CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, "bootstrap", THREAD);
94 }
95 }
96
97 int qsize;
98 jlong sleep_time = 1000;
99 int z = 0;
100 do {
101 os::sleep(THREAD, sleep_time, true);
102 sleep_time = 100;
103 qsize = CompileBroker::queue_size(CompLevel_full_optimization);
128 if (PrintBootstrap) { 104 if (PrintBootstrap) {
129 tty->print("Bootstrapping Graal"); 105 while (z < (_methodsCompiled / 100)) {
130 } 106 ++z;
131 jlong start = os::javaTimeMillis(); 107 tty->print_raw(".");
132
133 Array<Method*>* objectMethods = InstanceKlass::cast(SystemDictionary::Object_klass())->methods();
134 // Initialize compile queue with a selected set of methods.
135 int len = objectMethods->length();
136 for (int i = 0; i < len; i++) {
137 methodHandle mh = objectMethods->at(i);
138 if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) {
139 ResourceMark rm;
140 int hot_count = 10; // TODO: what's the appropriate value?
141 CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, "bootstrap", THREAD);
142 } 108 }
143 } 109 }
110 } while (qsize != 0);
144 111
145 int qsize; 112 if (PrintBootstrap) {
146 jlong sleep_time = 1000; 113 tty->print_cr(" in %d ms (compiled %d methods)", os::javaTimeMillis() - start, _methodsCompiled);
147 int z = 0;
148 do {
149 os::sleep(THREAD, sleep_time, true);
150 sleep_time = 100;
151 qsize = CompileBroker::queue_size(CompLevel_full_optimization);
152 if (PrintBootstrap) {
153 while (z < (_compiled / 100)) {
154 ++z;
155 tty->print_raw(".");
156 }
157 }
158 } while (qsize != 0);
159
160 if (PrintBootstrap) {
161 tty->print_cr(" in %d ms (compiled %d methods)", os::javaTimeMillis() - start, _compiled);
162 }
163 } else {
164
165 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/graal/hotspot/CompilationQueue", THREAD);
166 KlassHandle klass = GraalRuntime::load_required_class(name);
167 JavaValue result(T_VOID);
168 TempNewSymbol bootstrap = SymbolTable::new_symbol("bootstrap", THREAD);
169 NoGraalCompilationScheduling ngcs(THREAD);
170 JavaCalls::call_static(&result, klass, bootstrap, vmSymbols::void_method_signature(), THREAD);
171 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling bootstrap");
172 } 114 }
173 _bootstrapping = false; 115 _bootstrapping = false;
174 } 116 }
175 117
176 void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task, jboolean blocking) { 118 void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task) {
177 GRAAL_EXCEPTION_CONTEXT 119 GRAAL_EXCEPTION_CONTEXT
178 120
179 bool is_osr = entry_bci != InvocationEntryBci; 121 bool is_osr = entry_bci != InvocationEntryBci;
180 if (_bootstrapping && is_osr) { 122 if (_bootstrapping && is_osr) {
181 // no OSR compilations during bootstrap - the compiler is just too slow at this point, 123 // no OSR compilations during bootstrap - the compiler is just too slow at this point,
188 JavaValue result(T_VOID); 130 JavaValue result(T_VOID);
189 JavaCallArguments args; 131 JavaCallArguments args;
190 args.push_long((jlong) (address) method()); 132 args.push_long((jlong) (address) method());
191 args.push_int(entry_bci); 133 args.push_int(entry_bci);
192 args.push_long((jlong) (address) task); 134 args.push_long((jlong) (address) task);
193 args.push_int(blocking); 135 args.push_int(task->compile_id());
194 JavaCalls::call_static(&result, SystemDictionary::CompilationTask_klass(), vmSymbols::compileMetaspaceMethod_name(), vmSymbols::compileMetaspaceMethod_signature(), &args, THREAD); 136 JavaCalls::call_static(&result, SystemDictionary::CompilationTask_klass(), vmSymbols::compileMetaspaceMethod_name(), vmSymbols::compileMetaspaceMethod_signature(), &args, THREAD);
195 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling compile_method"); 137 GUARANTEE_NO_PENDING_EXCEPTION("Error while calling compile_method");
196 138
197 _compiled++; 139 _methodsCompiled++;
198 } 140 }
199 141
200 142
201 // Compilation entry point for methods 143 // Compilation entry point for methods
202 void GraalCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) { 144 void GraalCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
203 ShouldNotReachHere(); 145 ShouldNotReachHere();
204 }
205
206 void GraalCompiler::shutdown() {
207 if (UseGraalCompilationQueue) {
208 shutdown_compilation_queue();
209 }
210 } 146 }
211 147
212 // Print compilation timers and statistics 148 // Print compilation timers and statistics
213 void GraalCompiler::print_timers() { 149 void GraalCompiler::print_timers() {
214 TRACE_graal_1("GraalCompiler::print_timers"); 150 TRACE_graal_1("GraalCompiler::print_timers");