comparison src/share/vm/graal/graalCompiler.cpp @ 6948:e522a00b91aa

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/ after NPG - C++ build works
author Doug Simon <doug.simon@oracle.com>
date Mon, 12 Nov 2012 23:14:12 +0100
parents d79098b9db3b
children 41938af2b3d8
comparison
equal deleted inserted replaced
6711:ae13cc658b80 6948:e522a00b91aa
29 #include "graal/graalVMToCompiler.hpp" 29 #include "graal/graalVMToCompiler.hpp"
30 #include "graal/graalCompilerToVM.hpp" 30 #include "graal/graalCompilerToVM.hpp"
31 #include "graal/graalVmIds.hpp" 31 #include "graal/graalVmIds.hpp"
32 #include "graal/graalEnv.hpp" 32 #include "graal/graalEnv.hpp"
33 #include "c1/c1_Runtime1.hpp" 33 #include "c1/c1_Runtime1.hpp"
34 #include "compiler/compilerOracle.hpp"
35 #include "runtime/arguments.hpp" 34 #include "runtime/arguments.hpp"
36 #include "runtime/compilationPolicy.hpp" 35 #include "runtime/compilationPolicy.hpp"
37 36
38 GraalCompiler* GraalCompiler::_instance = NULL; 37 GraalCompiler* GraalCompiler::_instance = NULL;
39 38
157 method->clear_queued_for_compilation(); 156 method->clear_queued_for_compilation();
158 method->invocation_counter()->reset(); 157 method->invocation_counter()->reset();
159 method->backedge_counter()->reset(); 158 method->backedge_counter()->reset();
160 return; 159 return;
161 } 160 }
161
162 assert(_initialized, "must already be initialized"); 162 assert(_initialized, "must already be initialized");
163 ResourceMark rm; 163 ResourceMark rm;
164 ciEnv* current_env = JavaThread::current()->env(); 164 ciEnv* current_env = JavaThread::current()->env();
165 JavaThread::current()->set_env(NULL); 165 JavaThread::current()->set_env(NULL);
166 JavaThread::current()->set_compiling(true); 166 JavaThread::current()->set_compiling(true);
167 Handle hotspot_method = GraalCompiler::createHotSpotResolvedJavaMethod(method, CHECK); 167 Handle holder = GraalCompiler::createHotSpotResolvedJavaType(method, CHECK);
168 jboolean success = VMToCompiler::compileMethod(hotspot_method, entry_bci, blocking, method->graal_priority()); 168 jboolean success = VMToCompiler::compileMethod(method(), holder, entry_bci, blocking, method->graal_priority());
169 JavaThread::current()->set_compiling(false); 169 JavaThread::current()->set_compiling(false);
170 JavaThread::current()->set_env(current_env); 170 JavaThread::current()->set_env(current_env);
171 if (success != JNI_TRUE) { 171 if (success != JNI_TRUE) {
172 method->clear_queued_for_compilation(); 172 method->clear_queued_for_compilation();
173 CompilationPolicy::policy()->delay_compilation(method()); 173 CompilationPolicy::policy()->delay_compilation(method());
189 void GraalCompiler::print_timers() { 189 void GraalCompiler::print_timers() {
190 TRACE_graal_1("GraalCompiler::print_timers"); 190 TRACE_graal_1("GraalCompiler::print_timers");
191 } 191 }
192 192
193 Handle GraalCompiler::get_JavaType(Symbol* klass_name, TRAPS) { 193 Handle GraalCompiler::get_JavaType(Symbol* klass_name, TRAPS) {
194 return VMToCompiler::createJavaType(VmIds::toString<Handle>(klass_name, THREAD), THREAD); 194 return VMToCompiler::createUnresolvedJavaType(VmIds::toString<Handle>(klass_name, THREAD), THREAD);
195 } 195 }
196 196
197 Handle GraalCompiler::get_JavaTypeFromSignature(constantPoolHandle cp, int index, KlassHandle loading_klass, TRAPS) { 197 Handle GraalCompiler::get_JavaTypeFromSignature(Symbol* signature, KlassHandle loading_klass, TRAPS) {
198 198
199 Symbol* signature = cp->symbol_at(index);
200 BasicType field_type = FieldType::basic_type(signature); 199 BasicType field_type = FieldType::basic_type(signature);
201 // If the field is a pointer type, get the klass of the 200 // If the field is a pointer type, get the klass of the
202 // field. 201 // field.
203 if (field_type == T_OBJECT || field_type == T_ARRAY) { 202 if (field_type == T_OBJECT || field_type == T_ARRAY) {
204 KlassHandle handle = GraalEnv::get_klass_by_name(loading_klass, signature, false); 203 KlassHandle handle = GraalEnv::get_klass_by_name(loading_klass, signature, false);
216 bool is_accessible = false; 215 bool is_accessible = false;
217 216
218 KlassHandle klass = GraalEnv::get_klass_by_index(cp, index, is_accessible, loading_klass); 217 KlassHandle klass = GraalEnv::get_klass_by_index(cp, index, is_accessible, loading_klass);
219 oop catch_class = NULL; 218 oop catch_class = NULL;
220 if (klass.is_null()) { 219 if (klass.is_null()) {
221 // We have to lock the cpool to keep the oop from being resolved
222 // while we are accessing it.
223 ObjectLocker ol(cp, THREAD);
224
225 Symbol* klass_name = NULL; 220 Symbol* klass_name = NULL;
226 constantTag tag = cp->tag_at(index); 221 {
227 if (tag.is_klass()) { 222 // We have to lock the cpool to keep the oop from being resolved
228 // The klass has been inserted into the constant pool 223 // while we are accessing it. But we must release the lock before
229 // very recently. 224 // calling up into Java.
230 return GraalCompiler::get_JavaType(cp->resolved_klass_at(index), CHECK_NULL); 225 MonitorLockerEx ml(cp->lock());
231 } else if (tag.is_symbol()) { 226 constantTag tag = cp->tag_at(index);
232 klass_name = cp->symbol_at(index); 227 if (tag.is_klass()) {
233 } else { 228 // The klass has been inserted into the constant pool
234 assert(cp->tag_at(index).is_unresolved_klass(), "wrong tag"); 229 // very recently.
235 klass_name = cp->unresolved_klass_at(index); 230 return GraalCompiler::get_JavaType(cp->resolved_klass_at(index), CHECK_NULL);
231 } else if (tag.is_symbol()) {
232 klass_name = cp->symbol_at(index);
233 } else {
234 assert(cp->tag_at(index).is_unresolved_klass(), "wrong tag");
235 klass_name = cp->unresolved_klass_at(index);
236 }
236 } 237 }
237 return GraalCompiler::get_JavaType(klass_name, CHECK_NULL); 238 return GraalCompiler::get_JavaType(klass_name, CHECK_NULL);
238 } else { 239 } else {
239 return GraalCompiler::get_JavaType(klass, CHECK_NULL); 240 return GraalCompiler::get_JavaType(klass, CHECK_NULL);
240 } 241 }
243 Handle GraalCompiler::get_JavaTypeFromClass(Handle javaClassHandle, TRAPS) { 244 Handle GraalCompiler::get_JavaTypeFromClass(Handle javaClassHandle, TRAPS) {
244 if (java_lang_Class::is_primitive(javaClassHandle())) { 245 if (java_lang_Class::is_primitive(javaClassHandle())) {
245 BasicType basicType = java_lang_Class::primitive_type(javaClassHandle()); 246 BasicType basicType = java_lang_Class::primitive_type(javaClassHandle());
246 return VMToCompiler::createPrimitiveJavaType((int) basicType, THREAD); 247 return VMToCompiler::createPrimitiveJavaType((int) basicType, THREAD);
247 } else { 248 } else {
248 KlassHandle klass = java_lang_Class::as_klassOop(javaClassHandle()); 249 KlassHandle klass = java_lang_Class::as_Klass(javaClassHandle());
249 Handle name = java_lang_String::create_from_symbol(klass->name(), CHECK_NULL); 250 Handle name = java_lang_String::create_from_symbol(klass->name(), CHECK_NULL);
250 return GraalCompiler::createHotSpotResolvedJavaType(klass, name, CHECK_NULL); 251 return GraalCompiler::createHotSpotResolvedJavaType(klass, name, CHECK_NULL);
251 } 252 }
252 } 253 }
253 254
256 return createHotSpotResolvedJavaType(klass, name, CHECK_NULL); 257 return createHotSpotResolvedJavaType(klass, name, CHECK_NULL);
257 } 258 }
258 259
259 Handle GraalCompiler::get_JavaField(int offset, int flags, Symbol* field_name, Handle field_holder, Handle field_type, TRAPS) { 260 Handle GraalCompiler::get_JavaField(int offset, int flags, Symbol* field_name, Handle field_holder, Handle field_type, TRAPS) {
260 Handle name = VmIds::toString<Handle>(field_name, CHECK_NULL); 261 Handle name = VmIds::toString<Handle>(field_name, CHECK_NULL);
261 return VMToCompiler::createJavaField(field_holder, name, field_type, offset, flags, CHECK_NULL); 262 return VMToCompiler::createJavaField(field_holder, name, field_type, offset, flags, false, CHECK_NULL);
263 }
264
265 Handle GraalCompiler::createHotSpotResolvedJavaType(methodHandle method, TRAPS) {
266 KlassHandle klass = method->method_holder();
267 oop java_class = klass->java_mirror();
268 oop graal_mirror = java_lang_Class::graal_mirror(java_class);
269 if (graal_mirror != NULL) {
270 assert(graal_mirror->is_a(HotSpotResolvedJavaType::klass()), "unexpected class...");
271 return graal_mirror;
272 }
273 Handle name = java_lang_String::create_from_symbol(klass->name(), CHECK_NULL);
274 return GraalCompiler::createHotSpotResolvedJavaType(klass, name, CHECK_NULL);
262 } 275 }
263 276
264 Handle GraalCompiler::createHotSpotResolvedJavaType(KlassHandle klass, Handle name, TRAPS) { 277 Handle GraalCompiler::createHotSpotResolvedJavaType(KlassHandle klass, Handle name, TRAPS) {
265 ObjectLocker ol(klass, THREAD); 278 oop java_class = klass->java_mirror();
266 279 oop graal_mirror = java_lang_Class::graal_mirror(java_class);
267 if (klass->graal_mirror() != NULL) { 280 if (graal_mirror != NULL) {
268 return klass->graal_mirror(); 281 assert(graal_mirror->is_a(HotSpotResolvedJavaType::klass()), "unexpected class...");
269 } 282 return graal_mirror;
270 283 }
271 instanceKlass::cast(HotSpotResolvedJavaType::klass())->initialize(CHECK_NULL); 284
272 Handle obj = instanceKlass::cast(HotSpotResolvedJavaType::klass())->allocate_instance(CHECK_NULL); 285 Handle simpleName = name;
273 assert(obj() != NULL, "must succeed in allocating instance");
274
275 if (klass->oop_is_instance()) { 286 if (klass->oop_is_instance()) {
276 ResourceMark rm; 287 ResourceMark rm;
277 instanceKlass* ik = (instanceKlass*)klass()->klass_part(); 288 InstanceKlass* ik = (InstanceKlass*) klass();
278 Handle full_name = java_lang_String::create_from_str(ik->signature_name(), CHECK_NULL); 289 name = java_lang_String::create_from_str(ik->signature_name(), CHECK_NULL);
279 HotSpotJavaType::set_name(obj, full_name()); 290 }
291
292 // TODO replace this with the correct value
293 bool hasFinalizableSubclass = false;
294
295 int sizeOrSpecies;
296 if (klass->is_interface()) {
297 sizeOrSpecies = (int) 0x80000000; // see HotSpotResolvedJavaType.INTERFACE_SPECIES_VALUE
298 } else if (klass->oop_is_array()) {
299 sizeOrSpecies = (int) 0x7fffffff; // see HotSpotResolvedJavaType.ARRAY_SPECIES_VALUE
280 } else { 300 } else {
281 HotSpotJavaType::set_name(obj, name()); 301 sizeOrSpecies = InstanceKlass::cast(klass())->size_helper() * HeapWordSize;
282 } 302 if (!InstanceKlass::cast(klass())->can_be_fastpath_allocated()) {
283 303 sizeOrSpecies = -sizeOrSpecies;
284 HotSpotResolvedJavaType::set_javaMirror(obj, klass->java_mirror()); 304 }
285 HotSpotResolvedJavaType::set_simpleName(obj, name()); 305 }
286 HotSpotResolvedJavaType::set_accessFlags(obj, klass->access_flags().as_int()); 306
287 HotSpotResolvedJavaType::set_isInterface(obj, klass->is_interface()); 307 return VMToCompiler::createResolvedJavaType(klass(), name, simpleName, java_class, hasFinalizableSubclass, sizeOrSpecies, CHECK_NULL);
288 HotSpotResolvedJavaType::set_superCheckOffset(obj, klass->super_check_offset());
289 HotSpotResolvedJavaType::set_isInstanceClass(obj, klass->oop_is_instance() && !klass->is_interface());
290
291 if (klass->oop_is_javaArray()) {
292 HotSpotResolvedJavaType::set_isArrayClass(obj, true);
293 } else {
294 int size = instanceKlass::cast(klass())->size_helper() * HeapWordSize;
295 if (!instanceKlass::cast(klass())->can_be_fastpath_allocated()) {
296 size = -size;
297 }
298 HotSpotResolvedJavaType::set_isArrayClass(obj, false);
299 HotSpotResolvedJavaType::set_instanceSize(obj, size);
300 HotSpotResolvedJavaType::set_hasFinalizer(obj, klass->has_finalizer());
301 }
302
303 // TODO replace these with correct values
304 HotSpotResolvedJavaType::set_hasFinalizableSubclass(obj, false);
305
306 klass->set_graal_mirror(obj());
307
308 return obj;
309 }
310
311 Handle GraalCompiler::createHotSpotResolvedJavaMethod(methodHandle method, TRAPS) {
312 if (method->graal_mirror() != NULL) {
313 assert(method->graal_mirror()->is_a(HotSpotResolvedJavaMethod::klass()), "unexpected class...");
314 return method->graal_mirror();
315 }
316 Handle name = VmIds::toString<Handle>(method->name(), CHECK_NULL);
317
318 instanceKlass::cast(HotSpotResolvedJavaMethod::klass())->initialize(CHECK_NULL);
319 Handle obj = instanceKlass::cast(HotSpotResolvedJavaMethod::klass())->allocate_instance(CHECK_NULL);
320 assert(obj() != NULL, "must succeed in allocating instance");
321
322 // (thomaswue) Cannot use reflection here, because the compiler thread could dead lock with the running application.
323 // oop reflected = getReflectedMethod(method(), CHECK_NULL);
324 HotSpotResolvedJavaMethod::set_javaMirror(obj, method());
325 HotSpotResolvedJavaMethod::set_name(obj, name());
326
327 KlassHandle klass = method->method_holder();
328 Handle holder_name = VmIds::toString<Handle>(klass->name(), CHECK_NULL);
329 Handle holder = GraalCompiler::createHotSpotResolvedJavaType(klass, holder_name, CHECK_NULL);
330 HotSpotResolvedJavaMethod::set_holder(obj, holder());
331
332 HotSpotResolvedJavaMethod::set_codeSize(obj, method->code_size());
333 HotSpotResolvedJavaMethod::set_accessFlags(obj, method->access_flags().as_int());
334 HotSpotResolvedJavaMethod::set_maxLocals(obj, method->max_locals());
335 HotSpotResolvedJavaMethod::set_maxStackSize(obj, method->max_stack());
336 HotSpotResolvedJavaMethod::set_canBeInlined(obj, !method->is_not_compilable() && !CompilerOracle::should_not_inline(method));
337
338 method->set_graal_mirror(obj());
339 return obj;
340 }
341
342 Handle GraalCompiler::createHotSpotMethodData(methodDataHandle method_data, TRAPS) {
343 if(method_data->graal_mirror() != NULL) {
344 assert(method_data->graal_mirror()->is_a(HotSpotMethodData::klass()), "unexpected class");
345 return method_data->graal_mirror();
346 }
347
348 instanceKlass::cast(HotSpotMethodData::klass())->initialize(CHECK_NULL);
349 Handle obj = instanceKlass::cast(HotSpotMethodData::klass())->allocate_instance(CHECK_NULL);
350 assert(obj.not_null(), "must succeed in allocating instance");
351
352 HotSpotMethodData::set_hotspotMirror(obj, method_data());
353 HotSpotMethodData::set_normalDataSize(obj, method_data()->data_size());
354 HotSpotMethodData::set_extraDataSize(obj, method_data()->extra_data_size());
355
356 method_data->set_graal_mirror(obj());
357 return obj;
358 } 308 }
359 309
360 BasicType GraalCompiler::kindToBasicType(jchar ch) { 310 BasicType GraalCompiler::kindToBasicType(jchar ch) {
361 switch(ch) { 311 switch(ch) {
362 case 'z': return T_BOOLEAN; 312 case 'z': return T_BOOLEAN;