comparison src/share/vm/graal/graalCompiler.cpp @ 15582:063ec2920d21

made Graal runtime initialization in hosted mode lazy
author Doug Simon <doug.simon@oracle.com>
date Fri, 09 May 2014 18:46:41 +0200
parents 9c66a589ef63
children b7fb36e57da8
comparison
equal deleted inserted replaced
15581:0dc0926cf0d8 15582:063ec2920d21
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/graalJavaAccess.hpp"
29 #include "graal/graalVMToCompiler.hpp" 28 #include "graal/graalVMToCompiler.hpp"
30 #include "graal/graalCompilerToVM.hpp"
31 #include "graal/graalEnv.hpp" 29 #include "graal/graalEnv.hpp"
32 #include "graal/graalRuntime.hpp" 30 #include "graal/graalRuntime.hpp"
33 #include "runtime/arguments.hpp"
34 #include "runtime/compilationPolicy.hpp" 31 #include "runtime/compilationPolicy.hpp"
35 #include "runtime/globals_extension.hpp" 32 #include "runtime/globals_extension.hpp"
36 33
37 GraalCompiler* GraalCompiler::_instance = NULL; 34 GraalCompiler* GraalCompiler::_instance = NULL;
38 35
39 GraalCompiler::GraalCompiler() : AbstractCompiler(graal) { 36 GraalCompiler::GraalCompiler() : AbstractCompiler(graal) {
40 _initialized = false; 37 #ifdef COMPILERGRAAL
38 _started = false;
39 #endif
41 assert(_instance == NULL, "only one instance allowed"); 40 assert(_instance == NULL, "only one instance allowed");
42 _instance = this; 41 _instance = this;
43 } 42 }
44 43
45 // Initialization 44 // Initialization
46 void GraalCompiler::initialize() { 45 void GraalCompiler::initialize() {
47 if (!should_perform_init()) { 46 #ifdef COMPILERGRAAL
47 if (!UseCompiler || !should_perform_init()) {
48 return; 48 return;
49 } 49 }
50 50
51 uintptr_t heap_end = (uintptr_t) Universe::heap()->reserved_region().end(); 51 GraalRuntime::initialize();
52 uintptr_t allocation_end = heap_end + ((uintptr_t)16) * 1024 * 1024 * 1024;
53 AMD64_ONLY(guarantee(heap_end < allocation_end, "heap end too close to end of address space (might lead to erroneous TLAB allocations)"));
54 NOT_LP64(error("check TLAB allocation code for address space conflicts"));
55 52
56 BufferBlob* buffer_blob = initialize_buffer_blob(); 53 BufferBlob* buffer_blob = GraalRuntime::initialize_buffer_blob();
57 #ifdef COMPILERGRAAL
58 if (!UseGraalCompilationQueue) { 54 if (!UseGraalCompilationQueue) {
59 // This path is used for initialization both by the native queue and the graal queue 55 // This path is used for initialization both by the native queue and the graal queue
60 // but set_state acquired a lock which might not be safe during JVM_CreateJavaVM, so 56 // but set_state acquires a lock which might not be safe during JVM_CreateJavaVM, so
61 // only update the state flag for the native queue. 57 // only update the state flag for the native queue.
62 if (buffer_blob == NULL) { 58 if (buffer_blob == NULL) {
63 set_state(failed); 59 set_state(failed);
64 } else { 60 } else {
65 set_state(initialized); 61 set_state(initialized);
66 } 62 }
67 } 63 }
68 #endif
69
70 ThreadToNativeFromVM trans(JavaThread::current());
71 JavaThread* THREAD = JavaThread::current();
72 TRACE_graal_1("GraalCompiler::initialize");
73
74 JNIEnv *env = ((JavaThread *) Thread::current())->jni_environment();
75 jclass klass = env->FindClass("com/oracle/graal/hotspot/bridge/CompilerToVMImpl");
76 if (klass == NULL) {
77 tty->print_cr("graal CompilerToVMImpl class not found");
78 vm_abort(false);
79 }
80 env->RegisterNatives(klass, CompilerToVM_methods, CompilerToVM_methods_count());
81
82 ResourceMark rm;
83 HandleMark hm;
84 {
85 GRAAL_VM_ENTRY_MARK;
86 check_pending_exception("Could not register natives");
87 }
88
89 graal_compute_offsets();
90
91 // Ensure _non_oop_bits is initialized
92 Universe::non_oop_word();
93 64
94 { 65 {
95 GRAAL_VM_ENTRY_MARK;
96 HandleMark hm; 66 HandleMark hm;
97 VMToCompiler::initOptions(); 67
98 for (int i = 0; i < Arguments::num_graal_args(); ++i) { 68 bool bootstrap = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal);
99 const char* arg = Arguments::graal_args_array()[i]; 69 VMToCompiler::startCompiler(bootstrap);
100 Handle option = java_lang_String::create_from_str(arg, THREAD); 70 _started = true;
101 jboolean result = VMToCompiler::setOption(option); 71 CompilationPolicy::completed_vm_startup();
102 if (!result) { 72 if (bootstrap) {
103 tty->print_cr("Invalid option for graal: -G:%s", arg); 73 // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping.
104 vm_abort(false); 74 FlagSetting a(UseInterpreter, true);
105 } 75 FlagSetting b(BackgroundCompilation, true);
76 #ifndef PRODUCT
77 // Turn off CompileTheWorld during bootstrap so that a counter overflow event
78 // triggers further compilation (see NonTieredCompPolicy::event()) hence
79 // allowing a complete bootstrap
80 FlagSetting c(CompileTheWorld, false);
81 #endif
82 VMToCompiler::bootstrap();
106 } 83 }
107 VMToCompiler::finalizeOptions(CITime || CITimeEach);
108
109 if (UseCompiler) {
110 _external_deopt_i2c_entry = create_external_deopt_i2c();
111 #ifdef COMPILERGRAAL
112 bool bootstrap = UseGraalCompilationQueue && (FLAG_IS_DEFAULT(BootstrapGraal) ? !TieredCompilation : BootstrapGraal);
113 #else
114 bool bootstrap = false;
115 #endif
116 VMToCompiler::startCompiler(bootstrap);
117 _initialized = true;
118 CompilationPolicy::completed_vm_startup();
119 if (bootstrap) {
120 // Avoid -Xcomp and -Xbatch problems by turning on interpreter and background compilation for bootstrapping.
121 FlagSetting a(UseInterpreter, true);
122 FlagSetting b(BackgroundCompilation, true);
123 #ifndef PRODUCT
124 // Turn off CompileTheWorld during bootstrap so that a counter overflow event
125 // triggers further compilation (see NonTieredCompPolicy::event()) hence
126 // allowing a complete bootstrap
127 FlagSetting c(CompileTheWorld, false);
128 #endif
129 VMToCompiler::bootstrap();
130 }
131 84
132 #ifndef PRODUCT 85 #ifndef PRODUCT
133 if (CompileTheWorld) { 86 if (CompileTheWorld) {
134 // We turn off CompileTheWorld so that Graal can 87 VMToCompiler::compileTheWorld();
135 // be compiled by C1/C2 when Graal does a CTW. 88 }
136 CompileTheWorld = false;
137 VMToCompiler::compileTheWorld();
138 }
139 #endif 89 #endif
140 }
141 } 90 }
91 #endif // COMPILERGRAAL
142 } 92 }
143 93
144 address GraalCompiler::create_external_deopt_i2c() { 94 #ifdef COMPILERGRAAL
145 ResourceMark rm;
146 BufferBlob* buffer = BufferBlob::create("externalDeopt", 1*K);
147 CodeBuffer cb(buffer);
148 short buffer_locs[20];
149 cb.insts()->initialize_shared_locs((relocInfo*)buffer_locs, sizeof(buffer_locs)/sizeof(relocInfo));
150 MacroAssembler masm(&cb);
151
152 int total_args_passed = 5;
153
154 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
155 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
156 int i = 0;
157 sig_bt[i++] = T_INT;
158 sig_bt[i++] = T_LONG;
159 sig_bt[i++] = T_VOID; // long stakes 2 slots
160 sig_bt[i++] = T_INT;
161 sig_bt[i++] = T_OBJECT;
162
163 int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false);
164
165 SharedRuntime::gen_i2c_adapter(&masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
166 masm.flush();
167
168 return AdapterBlob::create(&cb)->content_begin();
169 }
170
171
172 BufferBlob* GraalCompiler::initialize_buffer_blob() {
173 JavaThread* THREAD = JavaThread::current();
174 BufferBlob* buffer_blob = THREAD->get_buffer_blob();
175 if (buffer_blob == NULL) {
176 buffer_blob = BufferBlob::create("Graal thread-local CodeBuffer", GraalNMethodSizeLimit);
177 if (buffer_blob != NULL) {
178 THREAD->set_buffer_blob(buffer_blob);
179 }
180 }
181 return buffer_blob;
182 }
183
184 void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task, jboolean blocking) { 95 void GraalCompiler::compile_method(methodHandle method, int entry_bci, CompileTask* task, jboolean blocking) {
185 GRAAL_EXCEPTION_CONTEXT 96 GRAAL_EXCEPTION_CONTEXT
186 if (!_initialized) { 97 if (!_started) {
187 CompilationPolicy::policy()->delay_compilation(method()); 98 CompilationPolicy::policy()->delay_compilation(method());
188 return; 99 return;
189 } 100 }
190 101
191 assert(_initialized, "must already be initialized"); 102 assert(_started, "must already be started");
192 ResourceMark rm; 103 ResourceMark rm;
193 thread->set_is_graal_compiling(true); 104 thread->set_is_graal_compiling(true);
194 VMToCompiler::compileMethod(method(), entry_bci, (jlong) (address) task, blocking); 105 VMToCompiler::compileMethod(method(), entry_bci, (jlong) (address) task, blocking);
195 thread->set_is_graal_compiling(false); 106 thread->set_is_graal_compiling(false);
196 } 107 }
197 108
109
198 // Compilation entry point for methods 110 // Compilation entry point for methods
199 void GraalCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) { 111 void GraalCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
200 ShouldNotReachHere(); 112 ShouldNotReachHere();
201 } 113 }
202 114
203 void GraalCompiler::exit() { 115 void GraalCompiler::shutdown() {
204 if (_initialized) { 116 if (_started) {
205 VMToCompiler::shutdownCompiler(); 117 VMToCompiler::shutdownCompiler();
118 _started = false;
206 } 119 }
207 } 120 }
208 121
209 // Print compilation timers and statistics 122 // Print compilation timers and statistics
210 void GraalCompiler::print_timers() { 123 void GraalCompiler::print_timers() {
211 TRACE_graal_1("GraalCompiler::print_timers"); 124 TRACE_graal_1("GraalCompiler::print_timers");
212 } 125 }
213 126
214 BasicType GraalCompiler::kindToBasicType(jchar ch) { 127 #endif // COMPILERGRAAL
215 switch(ch) {
216 case 'z': return T_BOOLEAN;
217 case 'b': return T_BYTE;
218 case 's': return T_SHORT;
219 case 'c': return T_CHAR;
220 case 'i': return T_INT;
221 case 'f': return T_FLOAT;
222 case 'j': return T_LONG;
223 case 'd': return T_DOUBLE;
224 case 'a': return T_OBJECT;
225 case 'r': return T_ADDRESS;
226 case '-': return T_ILLEGAL;
227 default:
228 fatal(err_msg("unexpected Kind: %c", ch));
229 break;
230 }
231 return T_ILLEGAL;
232 }