comparison src/share/vm/ci/ciEnv.cpp @ 2181:d25d4ca69222

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Wed, 16 Feb 2011 13:47:20 +0100
parents 06f017f7daa7 3582bf76420e
children 2ab52cda08e5
comparison
equal deleted inserted replaced
2108:50b45e2d9725 2181:d25d4ca69222
66 // This class is the top level broker for requests from the compiler 66 // This class is the top level broker for requests from the compiler
67 // to the VM. 67 // to the VM.
68 68
69 ciObject* ciEnv::_null_object_instance; 69 ciObject* ciEnv::_null_object_instance;
70 ciMethodKlass* ciEnv::_method_klass_instance; 70 ciMethodKlass* ciEnv::_method_klass_instance;
71 ciSymbolKlass* ciEnv::_symbol_klass_instance;
72 ciKlassKlass* ciEnv::_klass_klass_instance; 71 ciKlassKlass* ciEnv::_klass_klass_instance;
73 ciInstanceKlassKlass* ciEnv::_instance_klass_klass_instance; 72 ciInstanceKlassKlass* ciEnv::_instance_klass_klass_instance;
74 ciTypeArrayKlassKlass* ciEnv::_type_array_klass_klass_instance; 73 ciTypeArrayKlassKlass* ciEnv::_type_array_klass_klass_instance;
75 ciObjArrayKlassKlass* ciEnv::_obj_array_klass_klass_instance; 74 ciObjArrayKlassKlass* ciEnv::_obj_array_klass_klass_instance;
76 75
201 } 200 }
202 201
203 ciEnv::~ciEnv() { 202 ciEnv::~ciEnv() {
204 _factory->cleanup(); 203 _factory->cleanup();
205 CompilerThread* current_thread = CompilerThread::current(); 204 CompilerThread* current_thread = CompilerThread::current();
205 _factory->remove_symbols();
206 current_thread->set_env(NULL); 206 current_thread->set_env(NULL);
207 } 207 }
208 208
209 // ------------------------------------------------------------------ 209 // ------------------------------------------------------------------
210 // Cache Jvmti state 210 // Cache Jvmti state
233 } 233 }
234 } 234 }
235 235
236 // ------------------------------------------------------------------ 236 // ------------------------------------------------------------------
237 // helper for lazy exception creation 237 // helper for lazy exception creation
238 ciInstance* ciEnv::get_or_create_exception(jobject& handle, symbolHandle name) { 238 ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) {
239 VM_ENTRY_MARK; 239 VM_ENTRY_MARK;
240 if (handle == NULL) { 240 if (handle == NULL) {
241 // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance. 241 // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance.
242 klassOop k = SystemDictionary::find(name, Handle(), Handle(), THREAD); 242 klassOop k = SystemDictionary::find(name, Handle(), Handle(), THREAD);
243 jobject objh = NULL; 243 jobject objh = NULL;
260 // ciEnv::ArrayIndexOutOfBoundsException_instance, etc. 260 // ciEnv::ArrayIndexOutOfBoundsException_instance, etc.
261 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() { 261 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() {
262 if (_ArrayIndexOutOfBoundsException_instance == NULL) { 262 if (_ArrayIndexOutOfBoundsException_instance == NULL) {
263 _ArrayIndexOutOfBoundsException_instance 263 _ArrayIndexOutOfBoundsException_instance
264 = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle, 264 = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle,
265 vmSymbolHandles::java_lang_ArrayIndexOutOfBoundsException()); 265 vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
266 } 266 }
267 return _ArrayIndexOutOfBoundsException_instance; 267 return _ArrayIndexOutOfBoundsException_instance;
268 } 268 }
269 ciInstance* ciEnv::ArrayStoreException_instance() { 269 ciInstance* ciEnv::ArrayStoreException_instance() {
270 if (_ArrayStoreException_instance == NULL) { 270 if (_ArrayStoreException_instance == NULL) {
271 _ArrayStoreException_instance 271 _ArrayStoreException_instance
272 = get_or_create_exception(_ArrayStoreException_handle, 272 = get_or_create_exception(_ArrayStoreException_handle,
273 vmSymbolHandles::java_lang_ArrayStoreException()); 273 vmSymbols::java_lang_ArrayStoreException());
274 } 274 }
275 return _ArrayStoreException_instance; 275 return _ArrayStoreException_instance;
276 } 276 }
277 ciInstance* ciEnv::ClassCastException_instance() { 277 ciInstance* ciEnv::ClassCastException_instance() {
278 if (_ClassCastException_instance == NULL) { 278 if (_ClassCastException_instance == NULL) {
279 _ClassCastException_instance 279 _ClassCastException_instance
280 = get_or_create_exception(_ClassCastException_handle, 280 = get_or_create_exception(_ClassCastException_handle,
281 vmSymbolHandles::java_lang_ClassCastException()); 281 vmSymbols::java_lang_ClassCastException());
282 } 282 }
283 return _ClassCastException_instance; 283 return _ClassCastException_instance;
284 } 284 }
285 285
286 ciInstance* ciEnv::the_null_string() { 286 ciInstance* ciEnv::the_null_string() {
376 bool require_local) { 376 bool require_local) {
377 ASSERT_IN_VM; 377 ASSERT_IN_VM;
378 EXCEPTION_CONTEXT; 378 EXCEPTION_CONTEXT;
379 379
380 // Now we need to check the SystemDictionary 380 // Now we need to check the SystemDictionary
381 symbolHandle sym(THREAD, name->get_symbolOop()); 381 Symbol* sym = name->get_symbol();
382 if (sym->byte_at(0) == 'L' && 382 if (sym->byte_at(0) == 'L' &&
383 sym->byte_at(sym->utf8_length()-1) == ';') { 383 sym->byte_at(sym->utf8_length()-1) == ';') {
384 // This is a name from a signature. Strip off the trimmings. 384 // This is a name from a signature. Strip off the trimmings.
385 sym = oopFactory::new_symbol_handle(sym->as_utf8()+1, 385 // Call recursive to keep scope of strippedsym.
386 sym->utf8_length()-2, 386 TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1,
387 KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass)); 387 sym->utf8_length()-2,
388 name = get_object(sym())->as_symbol(); 388 KILL_COMPILE_ON_FATAL_(_unloaded_ciinstance_klass));
389 ciSymbol* strippedname = get_symbol(strippedsym);
390 return get_klass_by_name_impl(accessing_klass, strippedname, require_local);
389 } 391 }
390 392
391 // Check for prior unloaded klass. The SystemDictionary's answers 393 // Check for prior unloaded klass. The SystemDictionary's answers
392 // can vary over time but the compiler needs consistency. 394 // can vary over time but the compiler needs consistency.
393 ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name); 395 ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name);
408 if (sym->byte_at(0) == '[') { 410 if (sym->byte_at(0) == '[') {
409 fail_type = _unloaded_ciobjarrayklass; 411 fail_type = _unloaded_ciobjarrayklass;
410 } else { 412 } else {
411 fail_type = _unloaded_ciinstance_klass; 413 fail_type = _unloaded_ciinstance_klass;
412 } 414 }
413 klassOop found_klass; 415 KlassHandle found_klass;
414 if (!require_local) { 416 if (!require_local) {
415 found_klass = 417 klassOop kls = SystemDictionary::find_constrained_instance_or_array_klass(
416 SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, 418 sym, loader, KILL_COMPILE_ON_FATAL_(fail_type));
417 KILL_COMPILE_ON_FATAL_(fail_type)); 419 found_klass = KlassHandle(THREAD, kls);
418 } else { 420 } else {
419 found_klass = 421 klassOop kls = SystemDictionary::find_instance_or_array_klass(
420 SystemDictionary::find_instance_or_array_klass(sym, loader, domain, 422 sym, loader, domain, KILL_COMPILE_ON_FATAL_(fail_type));
421 KILL_COMPILE_ON_FATAL_(fail_type)); 423 found_klass = KlassHandle(THREAD, kls);
422 } 424 }
423 425
424 // If we fail to find an array klass, look again for its element type. 426 // If we fail to find an array klass, look again for its element type.
425 // The element type may be available either locally or via constraints. 427 // The element type may be available either locally or via constraints.
426 // In either case, if we can find the element type in the system dictionary, 428 // In either case, if we can find the element type in the system dictionary,
429 // is exhausted. 431 // is exhausted.
430 if (sym->byte_at(0) == '[' && 432 if (sym->byte_at(0) == '[' &&
431 (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { 433 (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) {
432 // We have an unloaded array. 434 // We have an unloaded array.
433 // Build it on the fly if the element class exists. 435 // Build it on the fly if the element class exists.
434 symbolOop elem_sym = oopFactory::new_symbol(sym->as_utf8()+1, 436 TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1,
435 sym->utf8_length()-1, 437 sym->utf8_length()-1,
436 KILL_COMPILE_ON_FATAL_(fail_type)); 438 KILL_COMPILE_ON_FATAL_(fail_type));
439
437 // Get element ciKlass recursively. 440 // Get element ciKlass recursively.
438 ciKlass* elem_klass = 441 ciKlass* elem_klass =
439 get_klass_by_name_impl(accessing_klass, 442 get_klass_by_name_impl(accessing_klass,
440 get_object(elem_sym)->as_symbol(), 443 get_symbol(elem_sym),
441 require_local); 444 require_local);
442 if (elem_klass != NULL && elem_klass->is_loaded()) { 445 if (elem_klass != NULL && elem_klass->is_loaded()) {
443 // Now make an array for it 446 // Now make an array for it
444 return ciObjArrayKlass::make_impl(elem_klass); 447 return ciObjArrayKlass::make_impl(elem_klass);
445 } 448 }
446 } 449 }
447 450
448 if (found_klass != NULL) { 451 if (found_klass() != NULL) {
449 // Found it. Build a CI handle. 452 // Found it. Build a CI handle.
450 return get_object(found_klass)->as_klass(); 453 return get_object(found_klass())->as_klass();
451 } 454 }
452 455
453 if (require_local) return NULL; 456 if (require_local) return NULL;
454 // Not yet loaded into the VM, or not governed by loader constraints. 457 // Not yet loaded into the VM, or not governed by loader constraints.
455 // Make a CI representative for it. 458 // Make a CI representative for it.
474 int index, 477 int index,
475 bool& is_accessible, 478 bool& is_accessible,
476 ciInstanceKlass* accessor) { 479 ciInstanceKlass* accessor) {
477 EXCEPTION_CONTEXT; 480 EXCEPTION_CONTEXT;
478 KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index)); 481 KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index));
479 symbolHandle klass_name; 482 Symbol* klass_name = NULL;
480 if (klass.is_null()) { 483 if (klass.is_null()) {
481 // The klass has not been inserted into the constant pool. 484 // The klass has not been inserted into the constant pool.
482 // Try to look it up by name. 485 // Try to look it up by name.
483 { 486 {
484 // We have to lock the cpool to keep the oop from being resolved 487 // We have to lock the cpool to keep the oop from being resolved
489 if (tag.is_klass()) { 492 if (tag.is_klass()) {
490 // The klass has been inserted into the constant pool 493 // The klass has been inserted into the constant pool
491 // very recently. 494 // very recently.
492 klass = KlassHandle(THREAD, cpool->resolved_klass_at(index)); 495 klass = KlassHandle(THREAD, cpool->resolved_klass_at(index));
493 } else if (tag.is_symbol()) { 496 } else if (tag.is_symbol()) {
494 klass_name = symbolHandle(THREAD, cpool->symbol_at(index)); 497 klass_name = cpool->symbol_at(index);
495 } else { 498 } else {
496 assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag"); 499 assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag");
497 klass_name = symbolHandle(THREAD, cpool->unresolved_klass_at(index)); 500 klass_name = cpool->unresolved_klass_at(index);
498 } 501 }
499 } 502 }
500 } 503 }
501 504
502 if (klass.is_null()) { 505 if (klass.is_null()) {
503 // Not found in constant pool. Use the name to do the lookup. 506 // Not found in constant pool. Use the name to do the lookup.
504 ciKlass* k = get_klass_by_name_impl(accessor, 507 ciKlass* k = get_klass_by_name_impl(accessor,
505 get_object(klass_name())->as_symbol(), 508 get_symbol(klass_name),
506 false); 509 false);
507 // Calculate accessibility the hard way. 510 // Calculate accessibility the hard way.
508 if (!k->is_loaded()) { 511 if (!k->is_loaded()) {
509 is_accessible = false; 512 is_accessible = false;
510 } else if (k->loader() != accessor->loader() && 513 } else if (k->loader() != accessor->loader() &&
518 return k; 521 return k;
519 } 522 }
520 523
521 // Check for prior unloaded klass. The SystemDictionary's answers 524 // Check for prior unloaded klass. The SystemDictionary's answers
522 // can vary over time but the compiler needs consistency. 525 // can vary over time but the compiler needs consistency.
523 ciSymbol* name = get_object(klass()->klass_part()->name())->as_symbol(); 526 ciSymbol* name = get_symbol(klass()->klass_part()->name());
524 ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name); 527 ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name);
525 if (unloaded_klass != NULL) { 528 if (unloaded_klass != NULL) {
526 is_accessible = false; 529 is_accessible = false;
527 return unloaded_klass; 530 return unloaded_klass;
528 } 531 }
604 assert(obj->is_instance(), "must be an instance"); 607 assert(obj->is_instance(), "must be an instance");
605 ciObject* ciobj = get_object(obj); 608 ciObject* ciobj = get_object(obj);
606 return ciConstant(T_OBJECT, ciobj); 609 return ciConstant(T_OBJECT, ciobj);
607 } else if (tag.is_method_type()) { 610 } else if (tag.is_method_type()) {
608 // must execute Java code to link this CP entry into cache[i].f1 611 // must execute Java code to link this CP entry into cache[i].f1
609 ciSymbol* signature = get_object(cpool->method_type_signature_at(index))->as_symbol(); 612 ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
610 ciObject* ciobj = get_unloaded_method_type_constant(signature); 613 ciObject* ciobj = get_unloaded_method_type_constant(signature);
611 return ciConstant(T_OBJECT, ciobj); 614 return ciConstant(T_OBJECT, ciobj);
612 } else if (tag.is_method_handle()) { 615 } else if (tag.is_method_handle()) {
613 // must execute Java code to link this CP entry into cache[i].f1 616 // must execute Java code to link this CP entry into cache[i].f1
614 int ref_kind = cpool->method_handle_ref_kind_at(index); 617 int ref_kind = cpool->method_handle_ref_kind_at(index);
615 int callee_index = cpool->method_handle_klass_index_at(index); 618 int callee_index = cpool->method_handle_klass_index_at(index);
616 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor); 619 ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
617 ciSymbol* name = get_object(cpool->method_handle_name_ref_at(index))->as_symbol(); 620 ciSymbol* name = get_symbol(cpool->method_handle_name_ref_at(index));
618 ciSymbol* signature = get_object(cpool->method_handle_signature_ref_at(index))->as_symbol(); 621 ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
619 ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind); 622 ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
620 return ciConstant(T_OBJECT, ciobj); 623 return ciConstant(T_OBJECT, ciobj);
621 } else { 624 } else {
622 ShouldNotReachHere(); 625 ShouldNotReachHere();
623 return ciConstant(); 626 return ciConstant();
673 // 676 //
674 // Perform an appropriate method lookup based on accessor, holder, 677 // Perform an appropriate method lookup based on accessor, holder,
675 // name, signature, and bytecode. 678 // name, signature, and bytecode.
676 methodOop ciEnv::lookup_method(instanceKlass* accessor, 679 methodOop ciEnv::lookup_method(instanceKlass* accessor,
677 instanceKlass* holder, 680 instanceKlass* holder,
678 symbolOop name, 681 Symbol* name,
679 symbolOop sig, 682 Symbol* sig,
680 Bytecodes::Code bc) { 683 Bytecodes::Code bc) {
681 EXCEPTION_CONTEXT; 684 EXCEPTION_CONTEXT;
682 KlassHandle h_accessor(THREAD, accessor); 685 KlassHandle h_accessor(THREAD, accessor);
683 KlassHandle h_holder(THREAD, holder); 686 KlassHandle h_holder(THREAD, holder);
684 symbolHandle h_name(THREAD, name);
685 symbolHandle h_sig(THREAD, sig);
686 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); 687 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL));
687 methodHandle dest_method; 688 methodHandle dest_method;
688 switch (bc) { 689 switch (bc) {
689 case Bytecodes::_invokestatic: 690 case Bytecodes::_invokestatic:
690 dest_method = 691 dest_method =
691 LinkResolver::resolve_static_call_or_null(h_holder, h_name, h_sig, h_accessor); 692 LinkResolver::resolve_static_call_or_null(h_holder, name, sig, h_accessor);
692 break; 693 break;
693 case Bytecodes::_invokespecial: 694 case Bytecodes::_invokespecial:
694 dest_method = 695 dest_method =
695 LinkResolver::resolve_special_call_or_null(h_holder, h_name, h_sig, h_accessor); 696 LinkResolver::resolve_special_call_or_null(h_holder, name, sig, h_accessor);
696 break; 697 break;
697 case Bytecodes::_invokeinterface: 698 case Bytecodes::_invokeinterface:
698 dest_method = 699 dest_method =
699 LinkResolver::linktime_resolve_interface_method_or_null(h_holder, h_name, h_sig, 700 LinkResolver::linktime_resolve_interface_method_or_null(h_holder, name, sig,
700 h_accessor, true); 701 h_accessor, true);
701 break; 702 break;
702 case Bytecodes::_invokevirtual: 703 case Bytecodes::_invokevirtual:
703 dest_method = 704 dest_method =
704 LinkResolver::linktime_resolve_virtual_method_or_null(h_holder, h_name, h_sig, 705 LinkResolver::linktime_resolve_virtual_method_or_null(h_holder, name, sig,
705 h_accessor, true); 706 h_accessor, true);
706 break; 707 break;
707 default: ShouldNotReachHere(); 708 default: ShouldNotReachHere();
708 } 709 }
709 710
720 bool holder_is_accessible; 721 bool holder_is_accessible;
721 ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); 722 ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
722 ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder); 723 ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder);
723 724
724 // Get the method's name and signature. 725 // Get the method's name and signature.
725 symbolOop name_sym = cpool->name_ref_at(index); 726 Symbol* name_sym = cpool->name_ref_at(index);
726 symbolOop sig_sym = cpool->signature_ref_at(index); 727 Symbol* sig_sym = cpool->signature_ref_at(index);
727 728
728 if (holder_is_accessible) { // Our declared holder is loaded. 729 if (holder_is_accessible) { // Our declared holder is loaded.
729 instanceKlass* lookup = declared_holder->get_instanceKlass(); 730 instanceKlass* lookup = declared_holder->get_instanceKlass();
730 methodOop m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc); 731 methodOop m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc);
731 if (m != NULL) { 732 if (m != NULL) {
737 // Either the declared holder was not loaded, or the method could 738 // Either the declared holder was not loaded, or the method could
738 // not be found. Create a dummy ciMethod to represent the failed 739 // not be found. Create a dummy ciMethod to represent the failed
739 // lookup. 740 // lookup.
740 741
741 return get_unloaded_method(declared_holder, 742 return get_unloaded_method(declared_holder,
742 get_object(name_sym)->as_symbol(), 743 get_symbol(name_sym),
743 get_object(sig_sym)->as_symbol()); 744 get_symbol(sig_sym));
744 } 745 }
745 746
746 747
747 // ------------------------------------------------------------------ 748 // ------------------------------------------------------------------
748 // ciEnv::get_fake_invokedynamic_method_impl 749 // ciEnv::get_fake_invokedynamic_method_impl
758 759
759 // Call site might not be resolved yet. We could create a real invoker method from the 760 // Call site might not be resolved yet. We could create a real invoker method from the
760 // compiler, but it is simpler to stop the code path here with an unlinked method. 761 // compiler, but it is simpler to stop the code path here with an unlinked method.
761 if (!is_resolved) { 762 if (!is_resolved) {
762 ciInstanceKlass* mh_klass = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass(); 763 ciInstanceKlass* mh_klass = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass();
763 ciSymbol* sig_sym = get_object(cpool->signature_ref_at(index))->as_symbol(); 764 ciSymbol* sig_sym = get_symbol(cpool->signature_ref_at(index));
764 return get_unloaded_method(mh_klass, ciSymbol::invokeExact_name(), sig_sym); 765 return get_unloaded_method(mh_klass, ciSymbol::invokeExact_name(), sig_sym);
765 } 766 }
766 767
767 // Get the invoker methodOop from the constant pool. 768 // Get the invoker methodOop from the constant pool.
768 oop f1_value = cpool->cache()->main_entry_at(index)->f1(); 769 oop f1_value = cpool->cache()->main_entry_at(index)->f1();