72
73 if (LogTouchedMethods) {
74 h_m()->log_touched(Thread::current());
75 }
76 // These fields are always filled in in loaded methods.
77 _flags = ciFlags(h_m()->access_flags());
78
79 // Easy to compute, so fill them in now.
80 _max_stack = h_m()->max_stack();
81 _max_locals = h_m()->max_locals();
82 _code_size = h_m()->code_size();
83 _intrinsic_id = h_m()->intrinsic_id();
84 _handler_count = h_m()->exception_table_length();
85 _size_of_parameters = h_m()->size_of_parameters();
86 _uses_monitors = h_m()->access_flags().has_monitor_bytecodes();
87 _balanced_monitors = !_uses_monitors || h_m()->access_flags().is_monitor_matching();
88 _is_c1_compilable = !h_m()->is_not_c1_compilable();
89 _is_c2_compilable = !h_m()->is_not_c2_compilable();
90 _can_be_parsed = true;
91 _has_reserved_stack_access = h_m()->has_reserved_stack_access();
92 // Lazy fields, filled in on demand. Require allocation.
93 _code = NULL;
94 _exception_handlers = NULL;
95 _liveness = NULL;
96 _method_blocks = NULL;
97 #if defined(COMPILER2)
98 _flow = NULL;
99 _bcea = NULL;
100 #endif // COMPILER2
101
102 ciEnv *env = CURRENT_ENV;
103 if (env->jvmti_can_hotswap_or_post_breakpoint()) {
104 // 6328518 check hotswap conditions under the right lock.
105 MutexLocker locker(Compile_lock);
106 if (Dependencies::check_evol_method(h_m()) != NULL) {
107 _is_c1_compilable = false;
108 _is_c2_compilable = false;
109 _can_be_parsed = false;
110 }
111 } else {
701 return root_m;
702 }
703
704 if (actual_recv->is_leaf_type() && actual_recv == root_m->holder()) {
705 // Easy case. There is no other place to put a method, so don't bother
706 // to go through the VM_ENTRY_MARK and all the rest.
707 return root_m;
708 }
709
710 // Array methods (clone, hashCode, etc.) are always statically bound.
711 // If we were to see an array type here, we'd return root_m.
712 // However, this method processes only ciInstanceKlasses. (See 4962591.)
713 // The inline_native_clone intrinsic narrows Object to T[] properly,
714 // so there is no need to do the same job here.
715
716 if (!UseCHA) return NULL;
717
718 VM_ENTRY_MARK;
719
720 // Disable CHA for default methods for now
721 if (root_m->get_Method()->is_default_method()) {
722 return NULL;
723 }
724
725 methodHandle target;
726 {
727 MutexLocker locker(Compile_lock);
728 Klass* context = actual_recv->get_Klass();
729 target = Dependencies::find_unique_concrete_method(context,
730 root_m->get_Method());
731 // %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods.
732 }
733
734 #ifndef PRODUCT
735 if (TraceDependencies && target() != NULL && target() != root_m->get_Method()) {
736 tty->print("found a non-root unique target method");
737 tty->print_cr(" context = %s", actual_recv->get_Klass()->external_name());
738 tty->print(" method = ");
739 target->print_short_name(tty);
740 tty->cr();
741 }
742 #endif //PRODUCT
743
744 if (target() == NULL) {
745 return NULL;
746 }
747 if (target() == root_m->get_Method()) {
748 return root_m;
749 }
750 if (!root_m->is_public() &&
751 !root_m->is_protected()) {
752 // If we are going to reason about inheritance, it's easiest
753 // if the method in question is public, protected, or private.
754 // If the answer is not root_m, it is conservatively correct
755 // to return NULL, even if the CHA encountered irrelevant
756 // methods in other packages.
757 // %%% TO DO: Work out logic for package-private methods
758 // with the same name but different vtable indexes.
759 return NULL;
760 }
761 return CURRENT_THREAD_ENV->get_method(target());
762 }
763
764 // ------------------------------------------------------------------
765 // ciMethod::resolve_invoke
766 //
767 // Given a known receiver klass, find the target for the call.
768 // Return NULL if the call has no target or the target is abstract.
769 ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, bool check_access) {
770 check_is_loaded();
771 VM_ENTRY_MARK;
772
773 Klass* caller_klass = caller->get_Klass();
774 Klass* recv = exact_receiver->get_Klass();
775 Klass* resolved = holder()->get_Klass();
776 Symbol* h_name = name()->get_symbol();
777 Symbol* h_signature = signature()->get_symbol();
778
779 LinkInfo link_info(resolved, h_name, h_signature, caller_klass,
780 check_access ? LinkInfo::needs_access_check : LinkInfo::skip_access_check);
857
858 // ------------------------------------------------------------------
859 // ciMethod::get_field_at_bci
860 ciField* ciMethod::get_field_at_bci(int bci, bool &will_link) {
861 ciBytecodeStream iter(this);
862 iter.reset_to_bci(bci);
863 iter.next();
864 return iter.get_field(will_link);
865 }
866
867 // ------------------------------------------------------------------
868 // ciMethod::get_method_at_bci
869 ciMethod* ciMethod::get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature) {
870 ciBytecodeStream iter(this);
871 iter.reset_to_bci(bci);
872 iter.next();
873 return iter.get_method(will_link, declared_signature);
874 }
875
876 // ------------------------------------------------------------------
877 // Adjust a CounterData count to be commensurate with
878 // interpreter_invocation_count. If the MDO exists for
879 // only 25% of the time the method exists, then the
880 // counts in the MDO should be scaled by 4X, so that
881 // they can be usefully and stably compared against the
882 // invocation counts in methods.
883 int ciMethod::scale_count(int count, float prof_factor) {
884 if (count > 0 && method_data() != NULL) {
885 int counter_life;
886 int method_life = interpreter_invocation_count();
887 if (TieredCompilation) {
888 // In tiered the MDO's life is measured directly, so just use the snapshotted counters
889 counter_life = MAX2(method_data()->invocation_count(), method_data()->backedge_count());
890 } else {
891 int current_mileage = method_data()->current_mileage();
892 int creation_mileage = method_data()->creation_mileage();
893 counter_life = current_mileage - creation_mileage;
894 }
895
896 // counter_life due to backedge_counter could be > method_life
|
72
73 if (LogTouchedMethods) {
74 h_m()->log_touched(Thread::current());
75 }
76 // These fields are always filled in in loaded methods.
77 _flags = ciFlags(h_m()->access_flags());
78
79 // Easy to compute, so fill them in now.
80 _max_stack = h_m()->max_stack();
81 _max_locals = h_m()->max_locals();
82 _code_size = h_m()->code_size();
83 _intrinsic_id = h_m()->intrinsic_id();
84 _handler_count = h_m()->exception_table_length();
85 _size_of_parameters = h_m()->size_of_parameters();
86 _uses_monitors = h_m()->access_flags().has_monitor_bytecodes();
87 _balanced_monitors = !_uses_monitors || h_m()->access_flags().is_monitor_matching();
88 _is_c1_compilable = !h_m()->is_not_c1_compilable();
89 _is_c2_compilable = !h_m()->is_not_c2_compilable();
90 _can_be_parsed = true;
91 _has_reserved_stack_access = h_m()->has_reserved_stack_access();
92 _is_overpass = h_m()->is_overpass();
93 // Lazy fields, filled in on demand. Require allocation.
94 _code = NULL;
95 _exception_handlers = NULL;
96 _liveness = NULL;
97 _method_blocks = NULL;
98 #if defined(COMPILER2)
99 _flow = NULL;
100 _bcea = NULL;
101 #endif // COMPILER2
102
103 ciEnv *env = CURRENT_ENV;
104 if (env->jvmti_can_hotswap_or_post_breakpoint()) {
105 // 6328518 check hotswap conditions under the right lock.
106 MutexLocker locker(Compile_lock);
107 if (Dependencies::check_evol_method(h_m()) != NULL) {
108 _is_c1_compilable = false;
109 _is_c2_compilable = false;
110 _can_be_parsed = false;
111 }
112 } else {
702 return root_m;
703 }
704
705 if (actual_recv->is_leaf_type() && actual_recv == root_m->holder()) {
706 // Easy case. There is no other place to put a method, so don't bother
707 // to go through the VM_ENTRY_MARK and all the rest.
708 return root_m;
709 }
710
711 // Array methods (clone, hashCode, etc.) are always statically bound.
712 // If we were to see an array type here, we'd return root_m.
713 // However, this method processes only ciInstanceKlasses. (See 4962591.)
714 // The inline_native_clone intrinsic narrows Object to T[] properly,
715 // so there is no need to do the same job here.
716
717 if (!UseCHA) return NULL;
718
719 VM_ENTRY_MARK;
720
721 // Disable CHA for default methods for now
722 if (root_m->is_default_method()) {
723 return NULL;
724 }
725
726 methodHandle target;
727 {
728 MutexLocker locker(Compile_lock);
729 Klass* context = actual_recv->get_Klass();
730 target = Dependencies::find_unique_concrete_method(context,
731 root_m->get_Method());
732 // %%% Should upgrade this ciMethod API to look for 1 or 2 concrete methods.
733 }
734
735 #ifndef PRODUCT
736 if (TraceDependencies && target() != NULL && target() != root_m->get_Method()) {
737 tty->print("found a non-root unique target method");
738 tty->print_cr(" context = %s", actual_recv->get_Klass()->external_name());
739 tty->print(" method = ");
740 target->print_short_name(tty);
741 tty->cr();
742 }
743 #endif //PRODUCT
744
745 if (target() == NULL) {
746 return NULL;
747 }
748 if (target() == root_m->get_Method()) {
749 return root_m;
750 }
751 if (!root_m->is_public() &&
752 !root_m->is_protected()) {
753 // If we are going to reason about inheritance, it's easiest
754 // if the method in question is public, protected, or private.
755 // If the answer is not root_m, it is conservatively correct
756 // to return NULL, even if the CHA encountered irrelevant
757 // methods in other packages.
758 // %%% TO DO: Work out logic for package-private methods
759 // with the same name but different vtable indexes.
760 return NULL;
761 }
762 assert(!target()->is_abstract(), "not allowed");
763 return CURRENT_THREAD_ENV->get_method(target());
764 }
765
766 // ------------------------------------------------------------------
767 // ciMethod::resolve_invoke
768 //
769 // Given a known receiver klass, find the target for the call.
770 // Return NULL if the call has no target or the target is abstract.
771 ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver, bool check_access) {
772 check_is_loaded();
773 VM_ENTRY_MARK;
774
775 Klass* caller_klass = caller->get_Klass();
776 Klass* recv = exact_receiver->get_Klass();
777 Klass* resolved = holder()->get_Klass();
778 Symbol* h_name = name()->get_symbol();
779 Symbol* h_signature = signature()->get_symbol();
780
781 LinkInfo link_info(resolved, h_name, h_signature, caller_klass,
782 check_access ? LinkInfo::needs_access_check : LinkInfo::skip_access_check);
859
860 // ------------------------------------------------------------------
861 // ciMethod::get_field_at_bci
862 ciField* ciMethod::get_field_at_bci(int bci, bool &will_link) {
863 ciBytecodeStream iter(this);
864 iter.reset_to_bci(bci);
865 iter.next();
866 return iter.get_field(will_link);
867 }
868
869 // ------------------------------------------------------------------
870 // ciMethod::get_method_at_bci
871 ciMethod* ciMethod::get_method_at_bci(int bci, bool &will_link, ciSignature* *declared_signature) {
872 ciBytecodeStream iter(this);
873 iter.reset_to_bci(bci);
874 iter.next();
875 return iter.get_method(will_link, declared_signature);
876 }
877
878 // ------------------------------------------------------------------
879 ciKlass* ciMethod::get_declared_method_holder_at_bci(int bci) {
880 ciBytecodeStream iter(this);
881 iter.reset_to_bci(bci);
882 iter.next();
883 return iter.get_declared_method_holder();
884 }
885
886 // ------------------------------------------------------------------
887 // Adjust a CounterData count to be commensurate with
888 // interpreter_invocation_count. If the MDO exists for
889 // only 25% of the time the method exists, then the
890 // counts in the MDO should be scaled by 4X, so that
891 // they can be usefully and stably compared against the
892 // invocation counts in methods.
893 int ciMethod::scale_count(int count, float prof_factor) {
894 if (count > 0 && method_data() != NULL) {
895 int counter_life;
896 int method_life = interpreter_invocation_count();
897 if (TieredCompilation) {
898 // In tiered the MDO's life is measured directly, so just use the snapshotted counters
899 counter_life = MAX2(method_data()->invocation_count(), method_data()->backedge_count());
900 } else {
901 int current_mileage = method_data()->current_mileage();
902 int creation_mileage = method_data()->creation_mileage();
903 counter_life = current_mileage - creation_mileage;
904 }
905
906 // counter_life due to backedge_counter could be > method_life
|