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