20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciMethodData.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "compiler/compileLog.hpp"
30 #include "interpreter/linkResolver.hpp"
31 #include "memory/universe.inline.hpp"
32 #include "opto/addnode.hpp"
33 #include "opto/castnode.hpp"
34 #include "opto/convertnode.hpp"
35 #include "opto/divnode.hpp"
36 #include "opto/idealGraphPrinter.hpp"
37 #include "opto/matcher.hpp"
38 #include "opto/memnode.hpp"
39 #include "opto/mulnode.hpp"
40 #include "opto/parse.hpp"
41 #include "opto/runtime.hpp"
42 #include "runtime/deoptimization.hpp"
43 #include "runtime/sharedRuntime.hpp"
44
45 extern int explicit_null_checks_inserted,
46 explicit_null_checks_elided;
47
48 //---------------------------------array_load----------------------------------
49 void Parse::array_load(BasicType elem_type) {
50 const Type* elem = Type::TOP;
51 Node* adr = array_addressing(elem_type, 0, &elem);
52 if (stopped()) return; // guaranteed null or range check
53 dec_sp(2); // Pop array and index
54 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type);
55 Node* ld = make_load(control(), adr, elem, elem_type, adr_type, MemNode::unordered);
56 push(ld);
57 }
58
59
750
751 // Flow to the jsr.
752 merge(jsr_bci);
753 }
754
755 // Handle ret bytecode
756 void Parse::do_ret() {
757 // Find to whom we return.
758 assert(block()->num_successors() == 1, "a ret can only go one place now");
759 Block* target = block()->successor_at(0);
760 assert(!target->is_ready(), "our arrival must be expected");
761 profile_ret(target->flow()->start());
762 int pnum = target->next_path_num();
763 merge_common(target, pnum);
764 }
765
766 //--------------------------dynamic_branch_prediction--------------------------
767 // Try to gather dynamic branch prediction behavior. Return a probability
768 // of the branch being taken and set the "cnt" field. Returns a -1.0
769 // if we need to use static prediction for some reason.
770 float Parse::dynamic_branch_prediction(float &cnt) {
771 ResourceMark rm;
772
773 cnt = COUNT_UNKNOWN;
774
775 // Use MethodData information if it is available
776 // FIXME: free the ProfileData structure
777 ciMethodData* methodData = method()->method_data();
778 if (!methodData->is_mature()) return PROB_UNKNOWN;
779 ciProfileData* data = methodData->bci_to_data(bci());
780 if (!data->is_JumpData()) return PROB_UNKNOWN;
781
782 // get taken and not taken values
783 int taken = data->as_JumpData()->taken();
784 int not_taken = 0;
785 if (data->is_BranchData()) {
786 not_taken = data->as_BranchData()->not_taken();
787 }
788
789 // scale the counts to be commensurate with invocation counts:
790 taken = method()->scale_count(taken);
791 not_taken = method()->scale_count(not_taken);
792
793 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful.
794 // We also check that individual counters are positive first, overwise the sum can become positive.
795 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) {
796 if (C->log() != NULL) {
797 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken);
798 }
799 return PROB_UNKNOWN;
800 }
801
802 // Compute frequency that we arrive here
803 float sum = taken + not_taken;
804 // Adjust, if this block is a cloned private block but the
805 // Jump counts are shared. Taken the private counts for
806 // just this path instead of the shared counts.
807 if( block()->count() > 0 )
808 sum = block()->count();
809 cnt = sum / FreqCountInvocations;
810
811 // Pin probability to sane limits
824 "Bad frequency assignment in if");
825
826 if (C->log() != NULL) {
827 const char* prob_str = NULL;
828 if (prob >= PROB_MAX) prob_str = (prob == PROB_MAX) ? "max" : "always";
829 if (prob <= PROB_MIN) prob_str = (prob == PROB_MIN) ? "min" : "never";
830 char prob_str_buf[30];
831 if (prob_str == NULL) {
832 sprintf(prob_str_buf, "%g", prob);
833 prob_str = prob_str_buf;
834 }
835 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%g' prob='%s'",
836 iter().get_dest(), taken, not_taken, cnt, prob_str);
837 }
838 return prob;
839 }
840
841 //-----------------------------branch_prediction-------------------------------
842 float Parse::branch_prediction(float& cnt,
843 BoolTest::mask btest,
844 int target_bci) {
845 float prob = dynamic_branch_prediction(cnt);
846 // If prob is unknown, switch to static prediction
847 if (prob != PROB_UNKNOWN) return prob;
848
849 prob = PROB_FAIR; // Set default value
850 if (btest == BoolTest::eq) // Exactly equal test?
851 prob = PROB_STATIC_INFREQUENT; // Assume its relatively infrequent
852 else if (btest == BoolTest::ne)
853 prob = PROB_STATIC_FREQUENT; // Assume its relatively frequent
854
855 // If this is a conditional test guarding a backwards branch,
856 // assume its a loop-back edge. Make it a likely taken branch.
857 if (target_bci < bci()) {
858 if (is_osr_parse()) { // Could be a hot OSR'd loop; force deopt
859 // Since it's an OSR, we probably have profile data, but since
860 // branch_prediction returned PROB_UNKNOWN, the counts are too small.
861 // Let's make a special check here for completely zero counts.
862 ciMethodData* methodData = method()->method_data();
863 if (!methodData->is_empty()) {
864 ciProfileData* data = methodData->bci_to_data(bci());
865 // Only stop for truly zero counts, which mean an unknown part
915 method()->print_name(); tty->cr();
916 }
917 #endif
918 int bc_depth = - Bytecodes::depth(iter().cur_bc());
919 assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches");
920 DEBUG_ONLY(sync_jvms()); // argument(n) requires a synced jvms
921 assert(argument(0) != NULL, "must exist");
922 assert(bc_depth == 1 || argument(1) != NULL, "two must exist");
923 inc_sp(bc_depth);
924 return bc_depth;
925 }
926
927 //----------------------------------do_ifnull----------------------------------
928 void Parse::do_ifnull(BoolTest::mask btest, Node *c) {
929 int target_bci = iter().get_dest();
930
931 Block* branch_block = successor_for_bci(target_bci);
932 Block* next_block = successor_for_bci(iter().next_bci());
933
934 float cnt;
935 float prob = branch_prediction(cnt, btest, target_bci);
936 if (prob == PROB_UNKNOWN) {
937 // (An earlier version of do_ifnull omitted this trap for OSR methods.)
938 #ifndef PRODUCT
939 if (PrintOpto && Verbose)
940 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
941 #endif
942 repush_if_args(); // to gather stats on loop
943 // We need to mark this branch as taken so that if we recompile we will
944 // see that it is possible. In the tiered system the interpreter doesn't
945 // do profiling and by the time we get to the lower tier from the interpreter
946 // the path may be cold again. Make sure it doesn't look untaken
947 profile_taken_branch(target_bci, !ProfileInterpreter);
948 uncommon_trap(Deoptimization::Reason_unreached,
949 Deoptimization::Action_reinterpret,
950 NULL, "cold");
951 if (C->eliminate_boxing()) {
952 // Mark the successor blocks as parsed
953 branch_block->next_path_num();
954 next_block->next_path_num();
955 }
996 if (C->eliminate_boxing()) {
997 // Mark the successor block as parsed
998 next_block->next_path_num();
999 }
1000 } else { // Path is live.
1001 // Update method data
1002 profile_not_taken_branch();
1003 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob,
1004 next_block, branch_block);
1005 }
1006 }
1007
1008 //------------------------------------do_if------------------------------------
1009 void Parse::do_if(BoolTest::mask btest, Node* c) {
1010 int target_bci = iter().get_dest();
1011
1012 Block* branch_block = successor_for_bci(target_bci);
1013 Block* next_block = successor_for_bci(iter().next_bci());
1014
1015 float cnt;
1016 float prob = branch_prediction(cnt, btest, target_bci);
1017 float untaken_prob = 1.0 - prob;
1018
1019 if (prob == PROB_UNKNOWN) {
1020 #ifndef PRODUCT
1021 if (PrintOpto && Verbose)
1022 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
1023 #endif
1024 repush_if_args(); // to gather stats on loop
1025 // We need to mark this branch as taken so that if we recompile we will
1026 // see that it is possible. In the tiered system the interpreter doesn't
1027 // do profiling and by the time we get to the lower tier from the interpreter
1028 // the path may be cold again. Make sure it doesn't look untaken
1029 profile_taken_branch(target_bci, !ProfileInterpreter);
1030 uncommon_trap(Deoptimization::Reason_unreached,
1031 Deoptimization::Action_reinterpret,
1032 NULL, "cold");
1033 if (C->eliminate_boxing()) {
1034 // Mark the successor blocks as parsed
1035 branch_block->next_path_num();
1036 next_block->next_path_num();
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "ci/ciMethodData.hpp"
27 #include "classfile/systemDictionary.hpp"
28 #include "classfile/vmSymbols.hpp"
29 #include "compiler/compileLog.hpp"
30 #include "interpreter/linkResolver.hpp"
31 #include "memory/universe.inline.hpp"
32 #include "opto/addnode.hpp"
33 #include "opto/castnode.hpp"
34 #include "opto/convertnode.hpp"
35 #include "opto/divnode.hpp"
36 #include "opto/idealGraphPrinter.hpp"
37 #include "opto/matcher.hpp"
38 #include "opto/memnode.hpp"
39 #include "opto/mulnode.hpp"
40 #include "opto/opaquenode.hpp"
41 #include "opto/parse.hpp"
42 #include "opto/runtime.hpp"
43 #include "runtime/deoptimization.hpp"
44 #include "runtime/sharedRuntime.hpp"
45
46 extern int explicit_null_checks_inserted,
47 explicit_null_checks_elided;
48
49 //---------------------------------array_load----------------------------------
50 void Parse::array_load(BasicType elem_type) {
51 const Type* elem = Type::TOP;
52 Node* adr = array_addressing(elem_type, 0, &elem);
53 if (stopped()) return; // guaranteed null or range check
54 dec_sp(2); // Pop array and index
55 const TypeAryPtr* adr_type = TypeAryPtr::get_array_body_type(elem_type);
56 Node* ld = make_load(control(), adr, elem, elem_type, adr_type, MemNode::unordered);
57 push(ld);
58 }
59
60
751
752 // Flow to the jsr.
753 merge(jsr_bci);
754 }
755
756 // Handle ret bytecode
757 void Parse::do_ret() {
758 // Find to whom we return.
759 assert(block()->num_successors() == 1, "a ret can only go one place now");
760 Block* target = block()->successor_at(0);
761 assert(!target->is_ready(), "our arrival must be expected");
762 profile_ret(target->flow()->start());
763 int pnum = target->next_path_num();
764 merge_common(target, pnum);
765 }
766
767 //--------------------------dynamic_branch_prediction--------------------------
768 // Try to gather dynamic branch prediction behavior. Return a probability
769 // of the branch being taken and set the "cnt" field. Returns a -1.0
770 // if we need to use static prediction for some reason.
771 float Parse::dynamic_branch_prediction(float &cnt, BoolTest::mask btest, Node* test) {
772 ResourceMark rm;
773
774 cnt = COUNT_UNKNOWN;
775
776 int taken = 0;
777 int not_taken = 0;
778
779 if (btest == BoolTest::eq && test->is_Cmp() && test->in(1)->Opcode() == Op_ProfileBranch) {
780 ProfileBranchNode* opq = (ProfileBranchNode*)test->in(1);
781 taken = opq->taken();
782 not_taken = opq->not_taken();
783 opq->consume();
784 } else {
785 // Use MethodData information if it is available
786 // FIXME: free the ProfileData structure
787 ciMethodData* methodData = method()->method_data();
788 if (!methodData->is_mature()) return PROB_UNKNOWN;
789 ciProfileData* data = methodData->bci_to_data(bci());
790 if (!data->is_JumpData()) return PROB_UNKNOWN;
791
792 // get taken and not taken values
793 taken = data->as_JumpData()->taken();
794 not_taken = 0;
795 if (data->is_BranchData()) {
796 not_taken = data->as_BranchData()->not_taken();
797 }
798
799 // scale the counts to be commensurate with invocation counts:
800 taken = method()->scale_count(taken);
801 not_taken = method()->scale_count(not_taken);
802 }
803
804 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful.
805 // We also check that individual counters are positive first, overwise the sum can become positive.
806 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) {
807 if (C->log() != NULL) {
808 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken);
809 }
810 return PROB_UNKNOWN;
811 }
812
813 // Compute frequency that we arrive here
814 float sum = taken + not_taken;
815 // Adjust, if this block is a cloned private block but the
816 // Jump counts are shared. Taken the private counts for
817 // just this path instead of the shared counts.
818 if( block()->count() > 0 )
819 sum = block()->count();
820 cnt = sum / FreqCountInvocations;
821
822 // Pin probability to sane limits
835 "Bad frequency assignment in if");
836
837 if (C->log() != NULL) {
838 const char* prob_str = NULL;
839 if (prob >= PROB_MAX) prob_str = (prob == PROB_MAX) ? "max" : "always";
840 if (prob <= PROB_MIN) prob_str = (prob == PROB_MIN) ? "min" : "never";
841 char prob_str_buf[30];
842 if (prob_str == NULL) {
843 sprintf(prob_str_buf, "%g", prob);
844 prob_str = prob_str_buf;
845 }
846 C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%g' prob='%s'",
847 iter().get_dest(), taken, not_taken, cnt, prob_str);
848 }
849 return prob;
850 }
851
852 //-----------------------------branch_prediction-------------------------------
853 float Parse::branch_prediction(float& cnt,
854 BoolTest::mask btest,
855 int target_bci,
856 Node* test) {
857 float prob = dynamic_branch_prediction(cnt, btest, test);
858 // If prob is unknown, switch to static prediction
859 if (prob != PROB_UNKNOWN) return prob;
860
861 prob = PROB_FAIR; // Set default value
862 if (btest == BoolTest::eq) // Exactly equal test?
863 prob = PROB_STATIC_INFREQUENT; // Assume its relatively infrequent
864 else if (btest == BoolTest::ne)
865 prob = PROB_STATIC_FREQUENT; // Assume its relatively frequent
866
867 // If this is a conditional test guarding a backwards branch,
868 // assume its a loop-back edge. Make it a likely taken branch.
869 if (target_bci < bci()) {
870 if (is_osr_parse()) { // Could be a hot OSR'd loop; force deopt
871 // Since it's an OSR, we probably have profile data, but since
872 // branch_prediction returned PROB_UNKNOWN, the counts are too small.
873 // Let's make a special check here for completely zero counts.
874 ciMethodData* methodData = method()->method_data();
875 if (!methodData->is_empty()) {
876 ciProfileData* data = methodData->bci_to_data(bci());
877 // Only stop for truly zero counts, which mean an unknown part
927 method()->print_name(); tty->cr();
928 }
929 #endif
930 int bc_depth = - Bytecodes::depth(iter().cur_bc());
931 assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches");
932 DEBUG_ONLY(sync_jvms()); // argument(n) requires a synced jvms
933 assert(argument(0) != NULL, "must exist");
934 assert(bc_depth == 1 || argument(1) != NULL, "two must exist");
935 inc_sp(bc_depth);
936 return bc_depth;
937 }
938
939 //----------------------------------do_ifnull----------------------------------
940 void Parse::do_ifnull(BoolTest::mask btest, Node *c) {
941 int target_bci = iter().get_dest();
942
943 Block* branch_block = successor_for_bci(target_bci);
944 Block* next_block = successor_for_bci(iter().next_bci());
945
946 float cnt;
947 float prob = branch_prediction(cnt, btest, target_bci, c);
948 if (prob == PROB_UNKNOWN) {
949 // (An earlier version of do_ifnull omitted this trap for OSR methods.)
950 #ifndef PRODUCT
951 if (PrintOpto && Verbose)
952 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
953 #endif
954 repush_if_args(); // to gather stats on loop
955 // We need to mark this branch as taken so that if we recompile we will
956 // see that it is possible. In the tiered system the interpreter doesn't
957 // do profiling and by the time we get to the lower tier from the interpreter
958 // the path may be cold again. Make sure it doesn't look untaken
959 profile_taken_branch(target_bci, !ProfileInterpreter);
960 uncommon_trap(Deoptimization::Reason_unreached,
961 Deoptimization::Action_reinterpret,
962 NULL, "cold");
963 if (C->eliminate_boxing()) {
964 // Mark the successor blocks as parsed
965 branch_block->next_path_num();
966 next_block->next_path_num();
967 }
1008 if (C->eliminate_boxing()) {
1009 // Mark the successor block as parsed
1010 next_block->next_path_num();
1011 }
1012 } else { // Path is live.
1013 // Update method data
1014 profile_not_taken_branch();
1015 adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob,
1016 next_block, branch_block);
1017 }
1018 }
1019
1020 //------------------------------------do_if------------------------------------
1021 void Parse::do_if(BoolTest::mask btest, Node* c) {
1022 int target_bci = iter().get_dest();
1023
1024 Block* branch_block = successor_for_bci(target_bci);
1025 Block* next_block = successor_for_bci(iter().next_bci());
1026
1027 float cnt;
1028 float prob = branch_prediction(cnt, btest, target_bci, c);
1029 float untaken_prob = 1.0 - prob;
1030
1031 if (prob == PROB_UNKNOWN) {
1032 #ifndef PRODUCT
1033 if (PrintOpto && Verbose)
1034 tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
1035 #endif
1036 repush_if_args(); // to gather stats on loop
1037 // We need to mark this branch as taken so that if we recompile we will
1038 // see that it is possible. In the tiered system the interpreter doesn't
1039 // do profiling and by the time we get to the lower tier from the interpreter
1040 // the path may be cold again. Make sure it doesn't look untaken
1041 profile_taken_branch(target_bci, !ProfileInterpreter);
1042 uncommon_trap(Deoptimization::Reason_unreached,
1043 Deoptimization::Action_reinterpret,
1044 NULL, "cold");
1045 if (C->eliminate_boxing()) {
1046 // Mark the successor blocks as parsed
1047 branch_block->next_path_num();
1048 next_block->next_path_num();
|