< prev index next >

src/hotspot/share/opto/subnode.cpp

Print this page




   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 "compiler/compileLog.hpp"


  27 #include "memory/allocation.inline.hpp"
  28 #include "opto/addnode.hpp"
  29 #include "opto/callnode.hpp"
  30 #include "opto/cfgnode.hpp"
  31 #include "opto/loopnode.hpp"
  32 #include "opto/matcher.hpp"
  33 #include "opto/movenode.hpp"
  34 #include "opto/mulnode.hpp"
  35 #include "opto/opcodes.hpp"
  36 #include "opto/phaseX.hpp"
  37 #include "opto/subnode.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 
  40 // Portions of code courtesy of Clifford Click
  41 
  42 // Optimization - Graph Style
  43 
  44 #include "math.h"
  45 
  46 //=============================================================================


 863 
 864   // Known constants can be compared exactly
 865   // Null can be distinguished from any NotNull pointers
 866   // Unknown inputs makes an unknown result
 867   if( r0->singleton() ) {
 868     intptr_t bits0 = r0->get_con();
 869     if( r1->singleton() )
 870       return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
 871     return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
 872   } else if( r1->singleton() ) {
 873     intptr_t bits1 = r1->get_con();
 874     return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
 875   } else
 876     return TypeInt::CC;
 877 }
 878 
 879 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
 880   // Return the klass node for (indirect load from OopHandle)
 881   //   LoadP(LoadP(AddP(foo:Klass, #java_mirror)))
 882   //   or NULL if not matching.








 883   if (n->Opcode() != Op_LoadP) return NULL;
 884 
 885   const TypeInstPtr* tp = phase->type(n)->isa_instptr();
 886   if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
 887 
 888   Node* adr = n->in(MemNode::Address);
 889   // First load from OopHandle: ((OopHandle)mirror)->resolve(); may need barrier.
 890   if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return NULL;
 891   adr = adr->in(MemNode::Address);
 892 
 893   intptr_t off = 0;
 894   Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
 895   if (k == NULL)  return NULL;
 896   const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
 897   if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
 898 
 899   // We've found the klass node of a Java mirror load.
 900   return k;
 901 }
 902 


 935   // Normalize comparisons between Java mirrors into comparisons of the low-
 936   // level klass, where a dependent load could be shortened.
 937   //
 938   // The new pattern has a nice effect of matching the same pattern used in the
 939   // fast path of instanceof/checkcast/Class.isInstance(), which allows
 940   // redundant exact type check be optimized away by GVN.
 941   // For example, in
 942   //   if (x.getClass() == Foo.class) {
 943   //     Foo foo = (Foo) x;
 944   //     // ... use a ...
 945   //   }
 946   // a CmpPNode could be shared between if_acmpne and checkcast
 947   {
 948     Node* k1 = isa_java_mirror_load(phase, in(1));
 949     Node* k2 = isa_java_mirror_load(phase, in(2));
 950     Node* conk2 = isa_const_java_mirror(phase, in(2));
 951 
 952     if (k1 && (k2 || conk2)) {
 953       Node* lhs = k1;
 954       Node* rhs = (k2 != NULL) ? k2 : conk2;
 955       this->set_req(1, lhs);
 956       this->set_req(2, rhs);









 957       return this;
 958     }
 959   }
 960 
 961   // Constant pointer on right?
 962   const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
 963   if (t2 == NULL || !t2->klass_is_exact())
 964     return NULL;
 965   // Get the constant klass we are comparing to.
 966   ciKlass* superklass = t2->klass();
 967 
 968   // Now check for LoadKlass on left.
 969   Node* ldk1 = in(1);
 970   if (ldk1->is_DecodeNKlass()) {
 971     ldk1 = ldk1->in(1);
 972     if (ldk1->Opcode() != Op_LoadNKlass )
 973       return NULL;
 974   } else if (ldk1->Opcode() != Op_LoadKlass )
 975     return NULL;
 976   // Take apart the address of the LoadKlass:




   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 "compiler/compileLog.hpp"
  27 #include "gc/shared/barrierSet.hpp"
  28 #include "gc/shared/c2/barrierSetC2.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "opto/addnode.hpp"
  31 #include "opto/callnode.hpp"
  32 #include "opto/cfgnode.hpp"
  33 #include "opto/loopnode.hpp"
  34 #include "opto/matcher.hpp"
  35 #include "opto/movenode.hpp"
  36 #include "opto/mulnode.hpp"
  37 #include "opto/opcodes.hpp"
  38 #include "opto/phaseX.hpp"
  39 #include "opto/subnode.hpp"
  40 #include "runtime/sharedRuntime.hpp"
  41 
  42 // Portions of code courtesy of Clifford Click
  43 
  44 // Optimization - Graph Style
  45 
  46 #include "math.h"
  47 
  48 //=============================================================================


 865 
 866   // Known constants can be compared exactly
 867   // Null can be distinguished from any NotNull pointers
 868   // Unknown inputs makes an unknown result
 869   if( r0->singleton() ) {
 870     intptr_t bits0 = r0->get_con();
 871     if( r1->singleton() )
 872       return bits0 == r1->get_con() ? TypeInt::CC_EQ : TypeInt::CC_GT;
 873     return ( r1->_ptr == TypePtr::NotNull && bits0==0 ) ? TypeInt::CC_GT : TypeInt::CC;
 874   } else if( r1->singleton() ) {
 875     intptr_t bits1 = r1->get_con();
 876     return ( r0->_ptr == TypePtr::NotNull && bits1==0 ) ? TypeInt::CC_GT : TypeInt::CC;
 877   } else
 878     return TypeInt::CC;
 879 }
 880 
 881 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
 882   // Return the klass node for (indirect load from OopHandle)
 883   //   LoadP(LoadP(AddP(foo:Klass, #java_mirror)))
 884   //   or NULL if not matching.
 885 
 886 #if INCLUDE_SHENANDOAHGC
 887   if (UseShenandoahGC) {
 888     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 889     n = bs->step_over_gc_barrier(n);
 890   }
 891 #endif
 892 
 893   if (n->Opcode() != Op_LoadP) return NULL;
 894 
 895   const TypeInstPtr* tp = phase->type(n)->isa_instptr();
 896   if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
 897 
 898   Node* adr = n->in(MemNode::Address);
 899   // First load from OopHandle: ((OopHandle)mirror)->resolve(); may need barrier.
 900   if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return NULL;
 901   adr = adr->in(MemNode::Address);
 902 
 903   intptr_t off = 0;
 904   Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
 905   if (k == NULL)  return NULL;
 906   const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
 907   if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
 908 
 909   // We've found the klass node of a Java mirror load.
 910   return k;
 911 }
 912 


 945   // Normalize comparisons between Java mirrors into comparisons of the low-
 946   // level klass, where a dependent load could be shortened.
 947   //
 948   // The new pattern has a nice effect of matching the same pattern used in the
 949   // fast path of instanceof/checkcast/Class.isInstance(), which allows
 950   // redundant exact type check be optimized away by GVN.
 951   // For example, in
 952   //   if (x.getClass() == Foo.class) {
 953   //     Foo foo = (Foo) x;
 954   //     // ... use a ...
 955   //   }
 956   // a CmpPNode could be shared between if_acmpne and checkcast
 957   {
 958     Node* k1 = isa_java_mirror_load(phase, in(1));
 959     Node* k2 = isa_java_mirror_load(phase, in(2));
 960     Node* conk2 = isa_const_java_mirror(phase, in(2));
 961 
 962     if (k1 && (k2 || conk2)) {
 963       Node* lhs = k1;
 964       Node* rhs = (k2 != NULL) ? k2 : conk2;
 965 #if INCLUDE_SHENANDOAHGC
 966       PhaseIterGVN* igvn = phase->is_IterGVN();
 967       if (UseShenandoahGC && igvn != NULL) {
 968         set_req_X(1, lhs, igvn);
 969         set_req_X(2, rhs, igvn);
 970       } else
 971 #endif
 972       {
 973         set_req(1, lhs);
 974         set_req(2, rhs);
 975       }
 976       return this;
 977     }
 978   }
 979 
 980   // Constant pointer on right?
 981   const TypeKlassPtr* t2 = phase->type(in(2))->isa_klassptr();
 982   if (t2 == NULL || !t2->klass_is_exact())
 983     return NULL;
 984   // Get the constant klass we are comparing to.
 985   ciKlass* superklass = t2->klass();
 986 
 987   // Now check for LoadKlass on left.
 988   Node* ldk1 = in(1);
 989   if (ldk1->is_DecodeNKlass()) {
 990     ldk1 = ldk1->in(1);
 991     if (ldk1->Opcode() != Op_LoadNKlass )
 992       return NULL;
 993   } else if (ldk1->Opcode() != Op_LoadKlass )
 994     return NULL;
 995   // Take apart the address of the LoadKlass:


< prev index next >