< prev index next >

src/share/vm/opto/ifnode.cpp

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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 "memory/allocation.inline.hpp"
  27 #include "opto/addnode.hpp"
  28 #include "opto/castnode.hpp"
  29 #include "opto/cfgnode.hpp"
  30 #include "opto/connode.hpp"
  31 #include "opto/loopnode.hpp"
  32 #include "opto/phaseX.hpp"
  33 #include "opto/runtime.hpp"
  34 #include "opto/rootnode.hpp"
  35 #include "opto/subnode.hpp"
  36 
  37 // Portions of code courtesy of Clifford Click
  38 
  39 // Optimization - Graph Style
  40 
  41 
  42 extern int explicit_null_checks_elided;
  43 
  44 //=============================================================================
  45 //------------------------------Value------------------------------------------


 751       }
 752     }
 753   }
 754   return success != NULL && fail != NULL;
 755 }
 756 
 757 // Return projection that leads to an uncommon trap if any
 758 ProjNode* IfNode::uncommon_trap_proj(CallStaticJavaNode*& call) const {
 759   for (int i = 0; i < 2; i++) {
 760     call = proj_out(i)->is_uncommon_trap_proj(Deoptimization::Reason_none);
 761     if (call != NULL) {
 762       return proj_out(i);
 763     }
 764   }
 765   return NULL;
 766 }
 767 
 768 // Do this If and the dominating If both branch out to an uncommon trap
 769 bool IfNode::has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNode*& fail, PhaseIterGVN* igvn) {
 770   ProjNode* otherproj = proj->other_if_proj();
 771   CallStaticJavaNode* dom_unc = otherproj->is_uncommon_trap_proj(Deoptimization::Reason_none);






 772 
 773   if (otherproj->outcnt() == 1 && dom_unc != NULL) {
 774     CallStaticJavaNode* unc = NULL;
 775     ProjNode* unc_proj = uncommon_trap_proj(unc);
 776     if (unc_proj != NULL && unc_proj->outcnt() == 1) {
 777       if (dom_unc == unc) {
 778         // Allow the uncommon trap to be shared through a region
 779         RegionNode* r = unc->in(0)->as_Region();
 780         if (r->outcnt() != 2 || r->req() != 3 || r->find_edge(otherproj) == -1 || r->find_edge(unc_proj) == -1) {
 781           return false;
 782         }
 783         assert(r->has_phi() == NULL, "simple region shouldn't have a phi");
 784       } else if (dom_unc->in(0) != otherproj || unc->in(0) != unc_proj) {
 785         return false;
 786       }
















 787       // See merge_uncommon_traps: the reason of the uncommon trap
 788       // will be changed and the state of the dominating If will be
 789       // used. Checked that we didn't apply this transformation in a
 790       // previous compilation and it didn't cause too many traps
 791       if (!igvn->C->too_many_traps(dom_unc->jvms()->method(), dom_unc->jvms()->bci(), Deoptimization::Reason_unstable_fused_if) &&
 792           !igvn->C->too_many_traps(dom_unc->jvms()->method(), dom_unc->jvms()->bci(), Deoptimization::Reason_range_check)) {
 793         success = unc_proj;
 794         fail = unc_proj->other_if_proj();
 795         return true;
 796       }
 797     }
 798   }
 799   return false;
 800 }
 801 
 802 // Check that the 2 CmpI can be folded into as single CmpU and proceed with the folding
 803 bool IfNode::fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn) {
 804   Node* this_cmp = in(1)->in(1);
 805   BoolNode* this_bool = in(1)->as_Bool();
 806   IfNode* dom_iff = proj->in(0)->as_If();
 807   BoolNode* dom_bool = dom_iff->in(1)->as_Bool();
 808   Node* lo = dom_iff->in(1)->in(1)->in(2);
 809   Node* hi = this_cmp->in(2);
 810   Node* n = this_cmp->in(1);
 811   ProjNode* otherproj = proj->other_if_proj();
 812 




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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/ciTypeFlow.hpp"
  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/addnode.hpp"
  29 #include "opto/castnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/connode.hpp"
  32 #include "opto/loopnode.hpp"
  33 #include "opto/phaseX.hpp"
  34 #include "opto/runtime.hpp"
  35 #include "opto/rootnode.hpp"
  36 #include "opto/subnode.hpp"
  37 
  38 // Portions of code courtesy of Clifford Click
  39 
  40 // Optimization - Graph Style
  41 
  42 
  43 extern int explicit_null_checks_elided;
  44 
  45 //=============================================================================
  46 //------------------------------Value------------------------------------------


 752       }
 753     }
 754   }
 755   return success != NULL && fail != NULL;
 756 }
 757 
 758 // Return projection that leads to an uncommon trap if any
 759 ProjNode* IfNode::uncommon_trap_proj(CallStaticJavaNode*& call) const {
 760   for (int i = 0; i < 2; i++) {
 761     call = proj_out(i)->is_uncommon_trap_proj(Deoptimization::Reason_none);
 762     if (call != NULL) {
 763       return proj_out(i);
 764     }
 765   }
 766   return NULL;
 767 }
 768 
 769 // Do this If and the dominating If both branch out to an uncommon trap
 770 bool IfNode::has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNode*& fail, PhaseIterGVN* igvn) {
 771   ProjNode* otherproj = proj->other_if_proj();
 772   // Dominating uncommon trap must have 'Reason_unstable_if' to ensure re-execution of folded Ifs
 773   CallStaticJavaNode* dom_unc = otherproj->is_uncommon_trap_proj(Deoptimization::Reason_unstable_if);
 774 
 775   // We need to re-execute the check after deoptimization
 776   if (!dom_unc->jvms()->should_reexecute()) {
 777     return false;
 778   }
 779 
 780   if (otherproj->outcnt() == 1 && dom_unc != NULL) {
 781     CallStaticJavaNode* unc = NULL;
 782     ProjNode* unc_proj = uncommon_trap_proj(unc);
 783     if (unc_proj != NULL && unc_proj->outcnt() == 1) {
 784       if (dom_unc == unc) {
 785         // Allow the uncommon trap to be shared through a region
 786         RegionNode* r = unc->in(0)->as_Region();
 787         if (r->outcnt() != 2 || r->req() != 3 || r->find_edge(otherproj) == -1 || r->find_edge(unc_proj) == -1) {
 788           return false;
 789         }
 790         assert(r->has_phi() == NULL, "simple region shouldn't have a phi");
 791       } else if (dom_unc->in(0) != otherproj || unc->in(0) != unc_proj) {
 792         return false;
 793       }
 794 
 795       // Check if the bci of the dominating uncommon trap dominates the bci
 796       // of the dominated uncommon trap. Otherwise we may not re-execute
 797       // the dominated check after deoptimization from the merged uncommon trap.
 798       ciMethod* method = unc->jvms()->method();
 799       ciMethod* dom_method = dom_unc->jvms()->method();
 800       if (method != dom_method) {
 801         return false;
 802       }
 803       ciTypeFlow* flow = dom_method->get_flow_analysis();
 804       int bci = unc->jvms()->bci();
 805       int dom_bci = dom_unc->jvms()->bci();
 806       if (!flow->is_dominated_by(bci, dom_bci)) {
 807         return false;
 808       }
 809 
 810       // See merge_uncommon_traps: the reason of the uncommon trap
 811       // will be changed and the state of the dominating If will be
 812       // used. Checked that we didn't apply this transformation in a
 813       // previous compilation and it didn't cause too many traps
 814       if (!igvn->C->too_many_traps(dom_method, dom_bci, Deoptimization::Reason_unstable_fused_if) &&
 815           !igvn->C->too_many_traps(dom_method, dom_bci, Deoptimization::Reason_range_check)) {
 816         success = unc_proj;
 817         fail = unc_proj->other_if_proj();
 818         return true;
 819       }
 820     }
 821   }
 822   return false;
 823 }
 824 
 825 // Check that the 2 CmpI can be folded into as single CmpU and proceed with the folding
 826 bool IfNode::fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn) {
 827   Node* this_cmp = in(1)->in(1);
 828   BoolNode* this_bool = in(1)->as_Bool();
 829   IfNode* dom_iff = proj->in(0)->as_If();
 830   BoolNode* dom_bool = dom_iff->in(1)->as_Bool();
 831   Node* lo = dom_iff->in(1)->in(1)->in(2);
 832   Node* hi = this_cmp->in(2);
 833   Node* n = this_cmp->in(1);
 834   ProjNode* otherproj = proj->other_if_proj();
 835 


< prev index next >