comparison src/share/vm/opto/parse2.cpp @ 1746:4b29a725c43c

6912064: type profiles need to be exploited more for dynamic language support Reviewed-by: kvn
author jrose
date Fri, 20 Aug 2010 23:40:30 -0700
parents 136b78722a08
children f95d63e2154a
comparison
equal deleted inserted replaced
1730:f55c4f82ab9d 1746:4b29a725c43c
890 // counts would keep the program recompiling indefinitely. 890 // counts would keep the program recompiling indefinitely.
891 bool Parse::seems_never_taken(float prob) { 891 bool Parse::seems_never_taken(float prob) {
892 return prob < PROB_MIN; 892 return prob < PROB_MIN;
893 } 893 }
894 894
895 // True if the comparison seems to be the kind that will not change its
896 // statistics from true to false. See comments in adjust_map_after_if.
897 // This question is only asked along paths which are already
898 // classifed as untaken (by seems_never_taken), so really,
899 // if a path is never taken, its controlling comparison is
900 // already acting in a stable fashion. If the comparison
901 // seems stable, we will put an expensive uncommon trap
902 // on the untaken path. To be conservative, and to allow
903 // partially executed counted loops to be compiled fully,
904 // we will plant uncommon traps only after pointer comparisons.
905 bool Parse::seems_stable_comparison(BoolTest::mask btest, Node* cmp) {
906 for (int depth = 4; depth > 0; depth--) {
907 // The following switch can find CmpP here over half the time for
908 // dynamic language code rich with type tests.
909 // Code using counted loops or array manipulations (typical
910 // of benchmarks) will have many (>80%) CmpI instructions.
911 switch (cmp->Opcode()) {
912 case Op_CmpP:
913 // A never-taken null check looks like CmpP/BoolTest::eq.
914 // These certainly should be closed off as uncommon traps.
915 if (btest == BoolTest::eq)
916 return true;
917 // A never-failed type check looks like CmpP/BoolTest::ne.
918 // Let's put traps on those, too, so that we don't have to compile
919 // unused paths with indeterminate dynamic type information.
920 if (ProfileDynamicTypes)
921 return true;
922 return false;
923
924 case Op_CmpI:
925 // A small minority (< 10%) of CmpP are masked as CmpI,
926 // as if by boolean conversion ((p == q? 1: 0) != 0).
927 // Detect that here, even if it hasn't optimized away yet.
928 // Specifically, this covers the 'instanceof' operator.
929 if (btest == BoolTest::ne || btest == BoolTest::eq) {
930 if (_gvn.type(cmp->in(2))->singleton() &&
931 cmp->in(1)->is_Phi()) {
932 PhiNode* phi = cmp->in(1)->as_Phi();
933 int true_path = phi->is_diamond_phi();
934 if (true_path > 0 &&
935 _gvn.type(phi->in(1))->singleton() &&
936 _gvn.type(phi->in(2))->singleton()) {
937 // phi->region->if_proj->ifnode->bool->cmp
938 BoolNode* bol = phi->in(0)->in(1)->in(0)->in(1)->as_Bool();
939 btest = bol->_test._test;
940 cmp = bol->in(1);
941 continue;
942 }
943 }
944 }
945 return false;
946 }
947 }
948 return false;
949 }
950
895 //-------------------------------repush_if_args-------------------------------- 951 //-------------------------------repush_if_args--------------------------------
896 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp. 952 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp.
897 inline int Parse::repush_if_args() { 953 inline int Parse::repush_if_args() {
898 #ifndef PRODUCT 954 #ifndef PRODUCT
899 if (PrintOpto && WizardMode) { 955 if (PrintOpto && WizardMode) {
1135 if (stopped() || !c->is_Cmp() || btest == BoolTest::illegal) 1191 if (stopped() || !c->is_Cmp() || btest == BoolTest::illegal)
1136 return; // nothing to do 1192 return; // nothing to do
1137 1193
1138 bool is_fallthrough = (path == successor_for_bci(iter().next_bci())); 1194 bool is_fallthrough = (path == successor_for_bci(iter().next_bci()));
1139 1195
1140 int cop = c->Opcode(); 1196 if (seems_never_taken(prob) && seems_stable_comparison(btest, c)) {
1141 if (seems_never_taken(prob) && cop == Op_CmpP && btest == BoolTest::eq) {
1142 // (An earlier version of do_if omitted '&& btest == BoolTest::eq'.)
1143 //
1144 // If this might possibly turn into an implicit null check, 1197 // If this might possibly turn into an implicit null check,
1145 // and the null has never yet been seen, we need to generate 1198 // and the null has never yet been seen, we need to generate
1146 // an uncommon trap, so as to recompile instead of suffering 1199 // an uncommon trap, so as to recompile instead of suffering
1147 // with very slow branches. (We'll get the slow branches if 1200 // with very slow branches. (We'll get the slow branches if
1148 // the program ever changes phase and starts seeing nulls here.) 1201 // the program ever changes phase and starts seeing nulls here.)
1149 // 1202 //
1150 // The tests we worry about are of the form (p == null). 1203 // We do not inspect for a null constant, since a node may
1151 // We do not simply inspect for a null constant, since a node may
1152 // optimize to 'null' later on. 1204 // optimize to 'null' later on.
1205 //
1206 // Null checks, and other tests which expect inequality,
1207 // show btest == BoolTest::eq along the non-taken branch.
1208 // On the other hand, type tests, must-be-null tests,
1209 // and other tests which expect pointer equality,
1210 // show btest == BoolTest::ne along the non-taken branch.
1211 // We prune both types of branches if they look unused.
1153 repush_if_args(); 1212 repush_if_args();
1154 // We need to mark this branch as taken so that if we recompile we will 1213 // We need to mark this branch as taken so that if we recompile we will
1155 // see that it is possible. In the tiered system the interpreter doesn't 1214 // see that it is possible. In the tiered system the interpreter doesn't
1156 // do profiling and by the time we get to the lower tier from the interpreter 1215 // do profiling and by the time we get to the lower tier from the interpreter
1157 // the path may be cold again. Make sure it doesn't look untaken 1216 // the path may be cold again. Make sure it doesn't look untaken