1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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/compile.hpp"
  29 #include "opto/constnode.hpp"
  30 #include "opto/machnode.hpp"
  31 #include "opto/matcher.hpp"
  32 #include "opto/memnode.hpp"
  33 #include "opto/phaseX.hpp"
  34 #include "opto/subnode.hpp"
  35 #include "runtime/sharedRuntime.hpp"
  36 
  37 // Optimization - Graph Style
  38 
  39 //=============================================================================
  40 //------------------------------hash-------------------------------------------
  41 uint ConNode::hash() const {
  42   return (uintptr_t)in(TypeFunc::Control) + _type->hash();
  43 }
  44 
  45 //------------------------------make-------------------------------------------
  46 ConNode *ConNode::make( Compile* C, const Type *t ) {
  47   switch( t->basic_type() ) {
  48   case T_INT:         return new (C) ConINode( t->is_int() );
  49   case T_LONG:        return new (C) ConLNode( t->is_long() );
  50   case T_FLOAT:       return new (C) ConFNode( t->is_float_constant() );
  51   case T_DOUBLE:      return new (C) ConDNode( t->is_double_constant() );
  52   case T_VOID:        return new (C) ConNode ( Type::TOP );
  53   case T_OBJECT:      return new (C) ConPNode( t->is_ptr() );
  54   case T_ARRAY:       return new (C) ConPNode( t->is_aryptr() );
  55   case T_ADDRESS:     return new (C) ConPNode( t->is_ptr() );
  56   case T_NARROWOOP:   return new (C) ConNNode( t->is_narrowoop() );
  57   case T_NARROWKLASS: return new (C) ConNKlassNode( t->is_narrowklass() );
  58   case T_METADATA:    return new (C) ConPNode( t->is_ptr() );
  59     // Expected cases:  TypePtr::NULL_PTR, any is_rawptr()
  60     // Also seen: AnyPtr(TopPTR *+top); from command line:
  61     //   r -XX:+PrintOpto -XX:CIStart=285 -XX:+CompileTheWorld -XX:CompileTheWorldStartAt=660
  62     // %%%% Stop using TypePtr::NULL_PTR to represent nulls:  use either TypeRawPtr::NULL_PTR
  63     // or else TypeOopPtr::NULL_PTR.  Then set Type::_basic_type[AnyPtr] = T_ILLEGAL
  64   }
  65   ShouldNotReachHere();
  66   return NULL;
  67 }
  68 
  69 //=============================================================================
  70 /*
  71 The major change is for CMoveP and StrComp.  They have related but slightly
  72 different problems.  They both take in TWO oops which are both null-checked
  73 independently before the using Node.  After CCP removes the CastPP's they need
  74 to pick up the guarding test edge - in this case TWO control edges.  I tried
  75 various solutions, all have problems:
  76 
  77 (1) Do nothing.  This leads to a bug where we hoist a Load from a CMoveP or a
  78 StrComp above a guarding null check.  I've seen both cases in normal -Xcomp
  79 testing.
  80 
  81 (2) Plug the control edge from 1 of the 2 oops in.  Apparent problem here is
  82 to figure out which test post-dominates.  The real problem is that it doesn't
  83 matter which one you pick.  After you pick up, the dominating-test elider in
  84 IGVN can remove the test and allow you to hoist up to the dominating test on
  85 the chosen oop bypassing the test on the not-chosen oop.  Seen in testing.
  86 Oops.
  87 
  88 (3) Leave the CastPP's in.  This makes the graph more accurate in some sense;
  89 we get to keep around the knowledge that an oop is not-null after some test.
  90 Alas, the CastPP's interfere with GVN (some values are the regular oop, some
  91 are the CastPP of the oop, all merge at Phi's which cannot collapse, etc).
  92 This cost us 10% on SpecJVM, even when I removed some of the more trivial
  93 cases in the optimizer.  Removing more useless Phi's started allowing Loads to
  94 illegally float above null checks.  I gave up on this approach.
  95 
  96 (4) Add BOTH control edges to both tests.  Alas, too much code knows that
  97 control edges are in slot-zero ONLY.  Many quick asserts fail; no way to do
  98 this one.  Note that I really want to allow the CMoveP to float and add both
  99 control edges to the dependent Load op - meaning I can select early but I
 100 cannot Load until I pass both tests.
 101 
 102 (5) Do not hoist CMoveP and StrComp.  To this end I added the v-call
 103 depends_only_on_test().  No obvious performance loss on Spec, but we are
 104 clearly conservative on CMoveP (also so on StrComp but that's unlikely to
 105 matter ever).
 106 
 107 */
 108 
 109