src/share/vm/opto/parse2.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/opto

src/share/vm/opto/parse2.cpp

Print this page
rev 7387 : 8063137: Never-taken branches should be pruned when GWT LambdaForms are shared
Reviewed-by: ?


  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 (method()->ignore_profile()) {
 780     if (btest == BoolTest::eq && test->is_Cmp() && test->in(1)->Opcode() == Op_Opaque4) {
 781       Opaque4Node* opq = (Opaque4Node*)test->in(1);
 782       taken = opq->taken();
 783       not_taken = opq->not_taken();
 784       opq->consume();
 785     } else {
 786       // No profile info. Be conservative.
 787       int cnt = method()->interpreter_invocation_count();
 788       taken = cnt / 2;
 789       not_taken = cnt - taken;
 790     }
 791   } else {
 792     // Use MethodData information if it is available
 793     // FIXME: free the ProfileData structure
 794     ciMethodData* methodData = method()->method_data();
 795     if (!methodData->is_mature())  return PROB_UNKNOWN;
 796     ciProfileData* data = methodData->bci_to_data(bci());
 797     if (!data->is_JumpData())  return PROB_UNKNOWN;
 798 
 799     // get taken and not taken values
 800     taken = data->as_JumpData()->taken();
 801     not_taken = 0;
 802     if (data->is_BranchData()) {
 803       not_taken = data->as_BranchData()->not_taken();
 804     }
 805 
 806     // scale the counts to be commensurate with invocation counts:
 807     taken = method()->scale_count(taken);
 808     not_taken = method()->scale_count(not_taken);
 809   }
 810 
 811   // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful.
 812   // We also check that individual counters are positive first, overwise the sum can become positive.
 813   if (taken < 0 || not_taken < 0 || taken + not_taken < 40) {
 814     if (C->log() != NULL) {
 815       C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d'", iter().get_dest(), taken, not_taken);
 816     }
 817     return PROB_UNKNOWN;
 818   }
 819 
 820   // Compute frequency that we arrive here
 821   float sum = taken + not_taken;
 822   // Adjust, if this block is a cloned private block but the
 823   // Jump counts are shared.  Taken the private counts for
 824   // just this path instead of the shared counts.
 825   if( block()->count() > 0 )
 826     sum = block()->count();
 827   cnt = sum / FreqCountInvocations;
 828 
 829   // Pin probability to sane limits


 842          "Bad frequency assignment in if");
 843 
 844   if (C->log() != NULL) {
 845     const char* prob_str = NULL;
 846     if (prob >= PROB_MAX)  prob_str = (prob == PROB_MAX) ? "max" : "always";
 847     if (prob <= PROB_MIN)  prob_str = (prob == PROB_MIN) ? "min" : "never";
 848     char prob_str_buf[30];
 849     if (prob_str == NULL) {
 850       sprintf(prob_str_buf, "%g", prob);
 851       prob_str = prob_str_buf;
 852     }
 853     C->log()->elem("branch target_bci='%d' taken='%d' not_taken='%d' cnt='%g' prob='%s'",
 854                    iter().get_dest(), taken, not_taken, cnt, prob_str);
 855   }
 856   return prob;
 857 }
 858 
 859 //-----------------------------branch_prediction-------------------------------
 860 float Parse::branch_prediction(float& cnt,
 861                                BoolTest::mask btest,
 862                                int target_bci,
 863                                Node* test) {
 864   float prob = dynamic_branch_prediction(cnt, btest, test);
 865   // If prob is unknown, switch to static prediction
 866   if (prob != PROB_UNKNOWN)  return prob;
 867 
 868   prob = PROB_FAIR;                   // Set default value
 869   if (btest == BoolTest::eq)          // Exactly equal test?
 870     prob = PROB_STATIC_INFREQUENT;    // Assume its relatively infrequent
 871   else if (btest == BoolTest::ne)
 872     prob = PROB_STATIC_FREQUENT;      // Assume its relatively frequent
 873 
 874   // If this is a conditional test guarding a backwards branch,
 875   // assume its a loop-back edge.  Make it a likely taken branch.
 876   if (target_bci < bci()) {
 877     if (is_osr_parse()) {    // Could be a hot OSR'd loop; force deopt
 878       // Since it's an OSR, we probably have profile data, but since
 879       // branch_prediction returned PROB_UNKNOWN, the counts are too small.
 880       // Let's make a special check here for completely zero counts.
 881       ciMethodData* methodData = method()->method_data();
 882       if (!methodData->is_empty()) {
 883         ciProfileData* data = methodData->bci_to_data(bci());
 884         // Only stop for truly zero counts, which mean an unknown part


 934     method()->print_name(); tty->cr();
 935   }
 936 #endif
 937   int bc_depth = - Bytecodes::depth(iter().cur_bc());
 938   assert(bc_depth == 1 || bc_depth == 2, "only two kinds of branches");
 939   DEBUG_ONLY(sync_jvms());   // argument(n) requires a synced jvms
 940   assert(argument(0) != NULL, "must exist");
 941   assert(bc_depth == 1 || argument(1) != NULL, "two must exist");
 942   inc_sp(bc_depth);
 943   return bc_depth;
 944 }
 945 
 946 //----------------------------------do_ifnull----------------------------------
 947 void Parse::do_ifnull(BoolTest::mask btest, Node *c) {
 948   int target_bci = iter().get_dest();
 949 
 950   Block* branch_block = successor_for_bci(target_bci);
 951   Block* next_block   = successor_for_bci(iter().next_bci());
 952 
 953   float cnt;
 954   float prob = branch_prediction(cnt, btest, target_bci, c);
 955   if (prob == PROB_UNKNOWN) {
 956     // (An earlier version of do_ifnull omitted this trap for OSR methods.)
 957 #ifndef PRODUCT
 958     if (PrintOpto && Verbose)
 959       tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
 960 #endif
 961     repush_if_args(); // to gather stats on loop
 962     // We need to mark this branch as taken so that if we recompile we will
 963     // see that it is possible. In the tiered system the interpreter doesn't
 964     // do profiling and by the time we get to the lower tier from the interpreter
 965     // the path may be cold again. Make sure it doesn't look untaken
 966     profile_taken_branch(target_bci, !ProfileInterpreter);
 967     uncommon_trap(Deoptimization::Reason_unreached,
 968                   Deoptimization::Action_reinterpret,
 969                   NULL, "cold");
 970     if (C->eliminate_boxing()) {
 971       // Mark the successor blocks as parsed
 972       branch_block->next_path_num();
 973       next_block->next_path_num();
 974     }


1015     if (C->eliminate_boxing()) {
1016       // Mark the successor block as parsed
1017       next_block->next_path_num();
1018     }
1019   } else  {                     // Path is live.
1020     // Update method data
1021     profile_not_taken_branch();
1022     adjust_map_after_if(BoolTest(btest).negate(), c, 1.0-prob,
1023                         next_block, branch_block);
1024   }
1025 }
1026 
1027 //------------------------------------do_if------------------------------------
1028 void Parse::do_if(BoolTest::mask btest, Node* c) {
1029   int target_bci = iter().get_dest();
1030 
1031   Block* branch_block = successor_for_bci(target_bci);
1032   Block* next_block   = successor_for_bci(iter().next_bci());
1033 
1034   float cnt;
1035   float prob = branch_prediction(cnt, btest, target_bci, c);
1036   float untaken_prob = 1.0 - prob;
1037 
1038   if (prob == PROB_UNKNOWN) {
1039 #ifndef PRODUCT
1040     if (PrintOpto && Verbose)
1041       tty->print_cr("Never-taken edge stops compilation at bci %d",bci());
1042 #endif
1043     repush_if_args(); // to gather stats on loop
1044     // We need to mark this branch as taken so that if we recompile we will
1045     // see that it is possible. In the tiered system the interpreter doesn't
1046     // do profiling and by the time we get to the lower tier from the interpreter
1047     // the path may be cold again. Make sure it doesn't look untaken
1048     profile_taken_branch(target_bci, !ProfileInterpreter);
1049     uncommon_trap(Deoptimization::Reason_unreached,
1050                   Deoptimization::Action_reinterpret,
1051                   NULL, "cold");
1052     if (C->eliminate_boxing()) {
1053       // Mark the successor blocks as parsed
1054       branch_block->next_path_num();
1055       next_block->next_path_num();


src/share/vm/opto/parse2.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File