Mercurial > hg > truffle
comparison src/share/vm/opto/parse2.cpp @ 20439:f6f9aec27858
8030976: Untaken paths should be more vigorously pruned at highest optimization level
Reviewed-by: roland, vlivanov
author | rbackman |
---|---|
date | Wed, 10 Sep 2014 12:39:11 +0200 |
parents | 78bbf4d43a14 |
children | 42460b71ba70 |
comparison
equal
deleted
inserted
replaced
20438:166d744df0de | 20439:f6f9aec27858 |
---|---|
893 // This question is only asked along paths which are already | 893 // This question is only asked along paths which are already |
894 // classifed as untaken (by seems_never_taken), so really, | 894 // classifed as untaken (by seems_never_taken), so really, |
895 // if a path is never taken, its controlling comparison is | 895 // if a path is never taken, its controlling comparison is |
896 // already acting in a stable fashion. If the comparison | 896 // already acting in a stable fashion. If the comparison |
897 // seems stable, we will put an expensive uncommon trap | 897 // seems stable, we will put an expensive uncommon trap |
898 // on the untaken path. To be conservative, and to allow | 898 // on the untaken path. |
899 // partially executed counted loops to be compiled fully, | |
900 // we will plant uncommon traps only after pointer comparisons. | |
901 bool Parse::seems_stable_comparison(BoolTest::mask btest, Node* cmp) { | 899 bool Parse::seems_stable_comparison(BoolTest::mask btest, Node* cmp) { |
902 for (int depth = 4; depth > 0; depth--) { | 900 if (C->too_many_traps(method(), bci(), Deoptimization::Reason_unstable_if)) { |
903 // The following switch can find CmpP here over half the time for | 901 return false; |
904 // dynamic language code rich with type tests. | 902 } |
905 // Code using counted loops or array manipulations (typical | 903 return true; |
906 // of benchmarks) will have many (>80%) CmpI instructions. | |
907 switch (cmp->Opcode()) { | |
908 case Op_CmpP: | |
909 // A never-taken null check looks like CmpP/BoolTest::eq. | |
910 // These certainly should be closed off as uncommon traps. | |
911 if (btest == BoolTest::eq) | |
912 return true; | |
913 // A never-failed type check looks like CmpP/BoolTest::ne. | |
914 // Let's put traps on those, too, so that we don't have to compile | |
915 // unused paths with indeterminate dynamic type information. | |
916 if (ProfileDynamicTypes) | |
917 return true; | |
918 return false; | |
919 | |
920 case Op_CmpI: | |
921 // A small minority (< 10%) of CmpP are masked as CmpI, | |
922 // as if by boolean conversion ((p == q? 1: 0) != 0). | |
923 // Detect that here, even if it hasn't optimized away yet. | |
924 // Specifically, this covers the 'instanceof' operator. | |
925 if (btest == BoolTest::ne || btest == BoolTest::eq) { | |
926 if (_gvn.type(cmp->in(2))->singleton() && | |
927 cmp->in(1)->is_Phi()) { | |
928 PhiNode* phi = cmp->in(1)->as_Phi(); | |
929 int true_path = phi->is_diamond_phi(); | |
930 if (true_path > 0 && | |
931 _gvn.type(phi->in(1))->singleton() && | |
932 _gvn.type(phi->in(2))->singleton()) { | |
933 // phi->region->if_proj->ifnode->bool->cmp | |
934 BoolNode* bol = phi->in(0)->in(1)->in(0)->in(1)->as_Bool(); | |
935 btest = bol->_test._test; | |
936 cmp = bol->in(1); | |
937 continue; | |
938 } | |
939 } | |
940 } | |
941 return false; | |
942 } | |
943 } | |
944 return false; | |
945 } | 904 } |
946 | 905 |
947 //-------------------------------repush_if_args-------------------------------- | 906 //-------------------------------repush_if_args-------------------------------- |
948 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp. | 907 // Push arguments of an "if" bytecode back onto the stack by adjusting _sp. |
949 inline int Parse::repush_if_args() { | 908 inline int Parse::repush_if_args() { |
1178 return; // nothing to do | 1137 return; // nothing to do |
1179 | 1138 |
1180 bool is_fallthrough = (path == successor_for_bci(iter().next_bci())); | 1139 bool is_fallthrough = (path == successor_for_bci(iter().next_bci())); |
1181 | 1140 |
1182 if (seems_never_taken(prob) && seems_stable_comparison(btest, c)) { | 1141 if (seems_never_taken(prob) && seems_stable_comparison(btest, c)) { |
1183 // If this might possibly turn into an implicit null check, | |
1184 // and the null has never yet been seen, we need to generate | |
1185 // an uncommon trap, so as to recompile instead of suffering | |
1186 // with very slow branches. (We'll get the slow branches if | |
1187 // the program ever changes phase and starts seeing nulls here.) | |
1188 // | |
1189 // We do not inspect for a null constant, since a node may | |
1190 // optimize to 'null' later on. | |
1191 // | |
1192 // Null checks, and other tests which expect inequality, | |
1193 // show btest == BoolTest::eq along the non-taken branch. | |
1194 // On the other hand, type tests, must-be-null tests, | |
1195 // and other tests which expect pointer equality, | |
1196 // show btest == BoolTest::ne along the non-taken branch. | |
1197 // We prune both types of branches if they look unused. | |
1198 repush_if_args(); | 1142 repush_if_args(); |
1199 // We need to mark this branch as taken so that if we recompile we will | 1143 uncommon_trap(Deoptimization::Reason_unstable_if, |
1200 // see that it is possible. In the tiered system the interpreter doesn't | |
1201 // do profiling and by the time we get to the lower tier from the interpreter | |
1202 // the path may be cold again. Make sure it doesn't look untaken | |
1203 if (is_fallthrough) { | |
1204 profile_not_taken_branch(!ProfileInterpreter); | |
1205 } else { | |
1206 profile_taken_branch(iter().get_dest(), !ProfileInterpreter); | |
1207 } | |
1208 uncommon_trap(Deoptimization::Reason_unreached, | |
1209 Deoptimization::Action_reinterpret, | 1144 Deoptimization::Action_reinterpret, |
1210 NULL, | 1145 NULL, |
1211 (is_fallthrough ? "taken always" : "taken never")); | 1146 (is_fallthrough ? "taken always" : "taken never")); |
1212 return; | 1147 return; |
1213 } | 1148 } |