< prev index next >

src/hotspot/share/opto/subnode.cpp

Print this page




 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   //   LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
 884   //   or NULL if not matching.
 885   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
 886   if (bs->is_gc_barrier_node(n)) {
 887     n = bs->step_over_gc_barrier(n);
 888   }
 889 
 890   if (n->Opcode() != Op_LoadP) return NULL;
 891 
 892   const TypeInstPtr* tp = phase->type(n)->isa_instptr();
 893   if (!tp || tp->klass() != phase->C->env()->Class_klass()) return NULL;
 894 
 895   Node* adr = n->in(MemNode::Address);
 896   // First load from OopHandle: ((OopHandle)mirror)->resolve(); may need barrier.
 897   if (adr->Opcode() != Op_LoadP || !phase->type(adr)->isa_rawptr()) return NULL;
 898   adr = adr->in(MemNode::Address);
 899 
 900   intptr_t off = 0;
 901   Node* k = AddPNode::Ideal_base_and_offset(adr, phase, off);
 902   if (k == NULL)  return NULL;
 903   const TypeKlassPtr* tkp = phase->type(k)->isa_klassptr();
 904   if (!tkp || off != in_bytes(Klass::java_mirror_offset())) return NULL;
 905 
 906   // We've found the klass node of a Java mirror load.
 907   return k;
 908 }


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






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




 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   //   LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
 884   //   or NULL if not matching.
 885   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();

 886     n = bs->step_over_gc_barrier(n);

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


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


< prev index next >