comparison src/share/vm/ci/ciEnv.cpp @ 1138:dd57230ba8fe

6893268: additional dynamic language related optimizations in C2 Summary: C2 needs some additional optimizations to be able to handle MethodHandle invokes and invokedynamic instructions at the best performance. Reviewed-by: kvn, never
author twisti
date Tue, 05 Jan 2010 15:21:25 +0100
parents 97125851f396
children 4ce7240d622c
comparison
equal deleted inserted replaced
1137:97125851f396 1138:dd57230ba8fe
441 441
442 // ------------------------------------------------------------------ 442 // ------------------------------------------------------------------
443 // ciEnv::get_klass_by_index_impl 443 // ciEnv::get_klass_by_index_impl
444 // 444 //
445 // Implementation of get_klass_by_index. 445 // Implementation of get_klass_by_index.
446 ciKlass* ciEnv::get_klass_by_index_impl(ciInstanceKlass* accessor, 446 ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool,
447 int index, 447 int index,
448 bool& is_accessible) { 448 bool& is_accessible,
449 assert(accessor->get_instanceKlass()->is_linked(), "must be linked before accessing constant pool"); 449 ciInstanceKlass* accessor) {
450 EXCEPTION_CONTEXT; 450 EXCEPTION_CONTEXT;
451 constantPoolHandle cpool(THREAD, accessor->get_instanceKlass()->constants());
452 KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index)); 451 KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index));
453 symbolHandle klass_name; 452 symbolHandle klass_name;
454 if (klass.is_null()) { 453 if (klass.is_null()) {
455 // The klass has not been inserted into the constant pool. 454 // The klass has not been inserted into the constant pool.
456 // Try to look it up by name. 455 // Try to look it up by name.
508 507
509 // ------------------------------------------------------------------ 508 // ------------------------------------------------------------------
510 // ciEnv::get_klass_by_index 509 // ciEnv::get_klass_by_index
511 // 510 //
512 // Get a klass from the constant pool. 511 // Get a klass from the constant pool.
513 ciKlass* ciEnv::get_klass_by_index(ciInstanceKlass* accessor, 512 ciKlass* ciEnv::get_klass_by_index(constantPoolHandle cpool,
514 int index, 513 int index,
515 bool& is_accessible) { 514 bool& is_accessible,
516 GUARDED_VM_ENTRY(return get_klass_by_index_impl(accessor, index, is_accessible);) 515 ciInstanceKlass* accessor) {
516 GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);)
517 } 517 }
518 518
519 // ------------------------------------------------------------------ 519 // ------------------------------------------------------------------
520 // ciEnv::get_constant_by_index_impl 520 // ciEnv::get_constant_by_index_impl
521 // 521 //
522 // Implementation of get_constant_by_index(). 522 // Implementation of get_constant_by_index().
523 ciConstant ciEnv::get_constant_by_index_impl(ciInstanceKlass* accessor, 523 ciConstant ciEnv::get_constant_by_index_impl(constantPoolHandle cpool,
524 int index) { 524 int index,
525 ciInstanceKlass* accessor) {
525 EXCEPTION_CONTEXT; 526 EXCEPTION_CONTEXT;
526 instanceKlass* ik_accessor = accessor->get_instanceKlass();
527 assert(ik_accessor->is_linked(), "must be linked before accessing constant pool");
528 constantPoolOop cpool = ik_accessor->constants();
529 constantTag tag = cpool->tag_at(index); 527 constantTag tag = cpool->tag_at(index);
530 if (tag.is_int()) { 528 if (tag.is_int()) {
531 return ciConstant(T_INT, (jint)cpool->int_at(index)); 529 return ciConstant(T_INT, (jint)cpool->int_at(index));
532 } else if (tag.is_long()) { 530 } else if (tag.is_long()) {
533 return ciConstant((jlong)cpool->long_at(index)); 531 return ciConstant((jlong)cpool->long_at(index));
551 assert (constant->is_instance(), "must be an instance, or not? "); 549 assert (constant->is_instance(), "must be an instance, or not? ");
552 return ciConstant(T_OBJECT, constant); 550 return ciConstant(T_OBJECT, constant);
553 } else if (tag.is_klass() || tag.is_unresolved_klass()) { 551 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
554 // 4881222: allow ldc to take a class type 552 // 4881222: allow ldc to take a class type
555 bool ignore; 553 bool ignore;
556 ciKlass* klass = get_klass_by_index_impl(accessor, index, ignore); 554 ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore, accessor);
557 if (HAS_PENDING_EXCEPTION) { 555 if (HAS_PENDING_EXCEPTION) {
558 CLEAR_PENDING_EXCEPTION; 556 CLEAR_PENDING_EXCEPTION;
559 record_out_of_memory_failure(); 557 record_out_of_memory_failure();
560 return ciConstant(); 558 return ciConstant();
561 } 559 }
562 assert (klass->is_instance_klass() || klass->is_array_klass(), 560 assert (klass->is_instance_klass() || klass->is_array_klass(),
563 "must be an instance or array klass "); 561 "must be an instance or array klass ");
564 return ciConstant(T_OBJECT, klass); 562 return ciConstant(T_OBJECT, klass);
563 } else if (tag.is_object()) {
564 oop obj = cpool->object_at(index);
565 assert(obj->is_instance(), "must be an instance");
566 ciObject* ciobj = get_object(obj);
567 return ciConstant(T_OBJECT, ciobj);
565 } else { 568 } else {
566 ShouldNotReachHere(); 569 ShouldNotReachHere();
567 return ciConstant(); 570 return ciConstant();
568 } 571 }
569 } 572 }
596 // ciEnv::get_constant_by_index 599 // ciEnv::get_constant_by_index
597 // 600 //
598 // Pull a constant out of the constant pool. How appropriate. 601 // Pull a constant out of the constant pool. How appropriate.
599 // 602 //
600 // Implementation note: this query is currently in no way cached. 603 // Implementation note: this query is currently in no way cached.
601 ciConstant ciEnv::get_constant_by_index(ciInstanceKlass* accessor, 604 ciConstant ciEnv::get_constant_by_index(constantPoolHandle cpool,
602 int index) { 605 int index,
603 GUARDED_VM_ENTRY(return get_constant_by_index_impl(accessor, index); ) 606 ciInstanceKlass* accessor) {
607 GUARDED_VM_ENTRY(return get_constant_by_index_impl(cpool, index, accessor);)
604 } 608 }
605 609
606 // ------------------------------------------------------------------ 610 // ------------------------------------------------------------------
607 // ciEnv::is_unresolved_string 611 // ciEnv::is_unresolved_string
608 // 612 //
609 // Check constant pool 613 // Check constant pool
610 // 614 //
611 // Implementation note: this query is currently in no way cached. 615 // Implementation note: this query is currently in no way cached.
612 bool ciEnv::is_unresolved_string(ciInstanceKlass* accessor, 616 bool ciEnv::is_unresolved_string(ciInstanceKlass* accessor,
613 int index) const { 617 int index) const {
614 GUARDED_VM_ENTRY(return is_unresolved_string_impl(accessor->get_instanceKlass(), index); ) 618 GUARDED_VM_ENTRY(return is_unresolved_string_impl(accessor->get_instanceKlass(), index); )
615 } 619 }
616 620
617 // ------------------------------------------------------------------ 621 // ------------------------------------------------------------------
618 // ciEnv::is_unresolved_klass 622 // ciEnv::is_unresolved_klass
619 // 623 //
620 // Check constant pool 624 // Check constant pool
621 // 625 //
622 // Implementation note: this query is currently in no way cached. 626 // Implementation note: this query is currently in no way cached.
623 bool ciEnv::is_unresolved_klass(ciInstanceKlass* accessor, 627 bool ciEnv::is_unresolved_klass(ciInstanceKlass* accessor,
624 int index) const { 628 int index) const {
625 GUARDED_VM_ENTRY(return is_unresolved_klass_impl(accessor->get_instanceKlass(), index); ) 629 GUARDED_VM_ENTRY(return is_unresolved_klass_impl(accessor->get_instanceKlass(), index); )
626 } 630 }
627 631
628 // ------------------------------------------------------------------ 632 // ------------------------------------------------------------------
629 // ciEnv::get_field_by_index_impl 633 // ciEnv::get_field_by_index_impl
700 } 704 }
701 705
702 706
703 // ------------------------------------------------------------------ 707 // ------------------------------------------------------------------
704 // ciEnv::get_method_by_index_impl 708 // ciEnv::get_method_by_index_impl
705 ciMethod* ciEnv::get_method_by_index_impl(ciInstanceKlass* accessor, 709 ciMethod* ciEnv::get_method_by_index_impl(constantPoolHandle cpool,
706 int index, Bytecodes::Code bc) { 710 int index, Bytecodes::Code bc,
707 // Get the method's declared holder. 711 ciInstanceKlass* accessor) {
708
709 assert(accessor->get_instanceKlass()->is_linked(), "must be linked before accessing constant pool");
710 constantPoolHandle cpool = accessor->get_instanceKlass()->constants();
711 int holder_index = cpool->klass_ref_index_at(index); 712 int holder_index = cpool->klass_ref_index_at(index);
712 bool holder_is_accessible; 713 bool holder_is_accessible;
713 ciKlass* holder = get_klass_by_index_impl(accessor, holder_index, holder_is_accessible); 714 ciKlass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor);
714 ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder); 715 ciInstanceKlass* declared_holder = get_instance_klass_for_declared_method_holder(holder);
715 716
716 // Get the method's name and signature. 717 // Get the method's name and signature.
717 symbolOop name_sym = cpool->name_ref_at(index); 718 symbolOop name_sym = cpool->name_ref_at(index);
718 symbolOop sig_sym = cpool->signature_ref_at(index); 719 symbolOop sig_sym = cpool->signature_ref_at(index);
736 } 737 }
737 738
738 739
739 // ------------------------------------------------------------------ 740 // ------------------------------------------------------------------
740 // ciEnv::get_fake_invokedynamic_method_impl 741 // ciEnv::get_fake_invokedynamic_method_impl
741 ciMethod* ciEnv::get_fake_invokedynamic_method_impl(ciInstanceKlass* accessor, 742 ciMethod* ciEnv::get_fake_invokedynamic_method_impl(constantPoolHandle cpool,
742 int index, Bytecodes::Code bc) { 743 int index, Bytecodes::Code bc) {
743 assert(bc == Bytecodes::_invokedynamic, "must be invokedynamic"); 744 assert(bc == Bytecodes::_invokedynamic, "must be invokedynamic");
744 assert(accessor->get_instanceKlass()->is_linked(), "must be linked before accessing constant pool");
745 constantPoolHandle cpool = accessor->get_instanceKlass()->constants();
746 745
747 // Get the CallSite from the constant pool cache. 746 // Get the CallSite from the constant pool cache.
748 ConstantPoolCacheEntry* cpc_entry = cpool->cache()->secondary_entry_at(index); 747 ConstantPoolCacheEntry* cpc_entry = cpool->cache()->secondary_entry_at(index);
749 assert(cpc_entry != NULL && cpc_entry->is_secondary_entry(), "sanity"); 748 assert(cpc_entry != NULL && cpc_entry->is_secondary_entry(), "sanity");
750 Handle call_site = cpc_entry->f1(); 749 Handle call_site = cpc_entry->f1();
787 } 786 }
788 787
789 788
790 // ------------------------------------------------------------------ 789 // ------------------------------------------------------------------
791 // ciEnv::get_method_by_index 790 // ciEnv::get_method_by_index
792 ciMethod* ciEnv::get_method_by_index(ciInstanceKlass* accessor, 791 ciMethod* ciEnv::get_method_by_index(constantPoolHandle cpool,
793 int index, Bytecodes::Code bc) { 792 int index, Bytecodes::Code bc,
793 ciInstanceKlass* accessor) {
794 if (bc == Bytecodes::_invokedynamic) { 794 if (bc == Bytecodes::_invokedynamic) {
795 GUARDED_VM_ENTRY(return get_fake_invokedynamic_method_impl(accessor, index, bc);) 795 GUARDED_VM_ENTRY(return get_fake_invokedynamic_method_impl(cpool, index, bc);)
796 } else { 796 } else {
797 GUARDED_VM_ENTRY(return get_method_by_index_impl(accessor, index, bc);) 797 GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);)
798 } 798 }
799 } 799 }
800 800
801 801
802 // ------------------------------------------------------------------ 802 // ------------------------------------------------------------------