< prev index next >

src/hotspot/share/opto/memnode.cpp

Print this page

 245       assert(phase->C->get_alias_index(t) == phase->C->get_alias_index(t_adr), "correct memory chain");
 246     }
 247   }
 248   return result;
 249 }
 250 
 251 static Node *step_through_mergemem(PhaseGVN *phase, MergeMemNode *mmem,  const TypePtr *tp, const TypePtr *adr_check, outputStream *st) {
 252   uint alias_idx = phase->C->get_alias_index(tp);
 253   Node *mem = mmem;
 254 #ifdef ASSERT
 255   {
 256     // Check that current type is consistent with the alias index used during graph construction
 257     assert(alias_idx >= Compile::AliasIdxRaw, "must not be a bad alias_idx");
 258     bool consistent =  adr_check == nullptr || adr_check->empty() ||
 259                        phase->C->must_alias(adr_check, alias_idx );
 260     // Sometimes dead array references collapse to a[-1], a[-2], or a[-3]
 261     if( !consistent && adr_check != nullptr && !adr_check->empty() &&
 262                tp->isa_aryptr() &&        tp->offset() == Type::OffsetBot &&
 263         adr_check->isa_aryptr() && adr_check->offset() != Type::OffsetBot &&
 264         ( adr_check->offset() == arrayOopDesc::length_offset_in_bytes() ||
 265           adr_check->offset() == oopDesc::klass_offset_in_bytes() ||
 266           adr_check->offset() == oopDesc::mark_offset_in_bytes() ) ) {
 267       // don't assert if it is dead code.
 268       consistent = true;
 269     }
 270     if( !consistent ) {
 271       st->print("alias_idx==%d, adr_check==", alias_idx);
 272       if( adr_check == nullptr ) {
 273         st->print("null");
 274       } else {
 275         adr_check->dump();
 276       }
 277       st->cr();
 278       print_alias_types();
 279       assert(consistent, "adr_check must match alias idx");
 280     }
 281   }
 282 #endif
 283   // TypeOopPtr::NOTNULL+any is an OOP with unknown offset - generally
 284   // means an array I have not precisely typed yet.  Do not do any
 285   // alias stuff with it any time soon.

 933 
 934     for (size_t i = 0; i < sizeof offsets / sizeof offsets[0]; i++) {
 935       if (offset == offsets[i]) {
 936         return true;
 937       }
 938     }
 939   }
 940 
 941   return false;
 942 }
 943 #endif
 944 
 945 //----------------------------LoadNode::make-----------------------------------
 946 // Polymorphic factory method:
 947 Node* LoadNode::make(PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, BasicType bt, MemOrd mo,
 948                      ControlDependency control_dependency, bool require_atomic_access, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) {
 949   Compile* C = gvn.C;
 950 
 951   // sanity check the alias category against the created node type
 952   assert(!(adr_type->isa_oopptr() &&
 953            adr_type->offset() == oopDesc::klass_offset_in_bytes()),
 954          "use LoadKlassNode instead");
 955   assert(!(adr_type->isa_aryptr() &&
 956            adr_type->offset() == arrayOopDesc::length_offset_in_bytes()),
 957          "use LoadRangeNode instead");
 958   // Check control edge of raw loads
 959   assert( ctl != nullptr || C->get_alias_index(adr_type) != Compile::AliasIdxRaw ||
 960           // oop will be recorded in oop map if load crosses safepoint
 961           rt->isa_oopptr() || is_immutable_value(adr),
 962           "raw memory operations should have control edge");
 963   LoadNode* load = nullptr;
 964   switch (bt) {
 965   case T_BOOLEAN: load = new LoadUBNode(ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 966   case T_BYTE:    load = new LoadBNode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 967   case T_INT:     load = new LoadINode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 968   case T_CHAR:    load = new LoadUSNode(ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 969   case T_SHORT:   load = new LoadSNode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 970   case T_LONG:    load = new LoadLNode (ctl, mem, adr, adr_type, rt->is_long(), mo, control_dependency, require_atomic_access); break;
 971   case T_FLOAT:   load = new LoadFNode (ctl, mem, adr, adr_type, rt,            mo, control_dependency); break;
 972   case T_DOUBLE:  load = new LoadDNode (ctl, mem, adr, adr_type, rt,            mo, control_dependency, require_atomic_access); break;
 973   case T_ADDRESS: load = new LoadPNode (ctl, mem, adr, adr_type, rt->is_ptr(),  mo, control_dependency); break;

2441         // constant oop => constant klass
2442         if (offset == java_lang_Class::array_klass_offset()) {
2443           if (t->is_void()) {
2444             // We cannot create a void array.  Since void is a primitive type return null
2445             // klass.  Users of this result need to do a null check on the returned klass.
2446             return TypePtr::NULL_PTR;
2447           }
2448           return TypeKlassPtr::make(ciArrayKlass::make(t), Type::trust_interfaces);
2449         }
2450         if (!t->is_klass()) {
2451           // a primitive Class (e.g., int.class) has null for a klass field
2452           return TypePtr::NULL_PTR;
2453         }
2454         // Fold up the load of the hidden field
2455         return TypeKlassPtr::make(t->as_klass(), Type::trust_interfaces);
2456       }
2457       // non-constant mirror, so we can't tell what's going on
2458     }
2459     if (!tinst->is_loaded())
2460       return _type;             // Bail out if not loaded
2461     if (offset == oopDesc::klass_offset_in_bytes()) {
2462       return tinst->as_klass_type(true);
2463     }
2464   }
2465 
2466   // Check for loading klass from an array
2467   const TypeAryPtr *tary = tp->isa_aryptr();
2468   if (tary != nullptr &&
2469       tary->offset() == oopDesc::klass_offset_in_bytes()) {
2470     return tary->as_klass_type(true);
2471   }
2472 
2473   // Check for loading klass from an array klass
2474   const TypeKlassPtr *tkls = tp->isa_klassptr();
2475   if (tkls != nullptr && !StressReflectiveCode) {
2476     if (!tkls->is_loaded())
2477      return _type;             // Bail out if not loaded
2478     if (tkls->isa_aryklassptr() && tkls->is_aryklassptr()->elem()->isa_klassptr() &&
2479         tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) {
2480       // // Always returning precise element type is incorrect,
2481       // // e.g., element type could be object and array may contain strings
2482       // return TypeKlassPtr::make(TypePtr::Constant, elem, 0);
2483 
2484       // The array's TypeKlassPtr was declared 'precise' or 'not precise'
2485       // according to the element type's subclassing.
2486       return tkls->is_aryklassptr()->elem()->isa_klassptr()->cast_to_exactness(tkls->klass_is_exact());
2487     }
2488     if (tkls->isa_instklassptr() != nullptr && tkls->klass_is_exact() &&
2489         tkls->offset() == in_bytes(Klass::super_offset())) {

2515   Node* x = LoadNode::Identity(phase);
2516   if (x != this)  return x;
2517 
2518   // Take apart the address into an oop and offset.
2519   // Return 'this' if we cannot.
2520   Node*    adr    = in(MemNode::Address);
2521   intptr_t offset = 0;
2522   Node*    base   = AddPNode::Ideal_base_and_offset(adr, phase, offset);
2523   if (base == nullptr)     return this;
2524   const TypeOopPtr* toop = phase->type(adr)->isa_oopptr();
2525   if (toop == nullptr)     return this;
2526 
2527   // Step over potential GC barrier for OopHandle resolve
2528   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2529   if (bs->is_gc_barrier_node(base)) {
2530     base = bs->step_over_gc_barrier(base);
2531   }
2532 
2533   // We can fetch the klass directly through an AllocateNode.
2534   // This works even if the klass is not constant (clone or newArray).
2535   if (offset == oopDesc::klass_offset_in_bytes()) {
2536     Node* allocated_klass = AllocateNode::Ideal_klass(base, phase);
2537     if (allocated_klass != nullptr) {
2538       return allocated_klass;
2539     }
2540   }
2541 
2542   // Simplify k.java_mirror.as_klass to plain k, where k is a Klass*.
2543   // See inline_native_Class_query for occurrences of these patterns.
2544   // Java Example:  x.getClass().isAssignableFrom(y)
2545   //
2546   // This improves reflective code, often making the Class
2547   // mirror go completely dead.  (Current exception:  Class
2548   // mirrors may appear in debug info, but we could clean them out by
2549   // introducing a new debug info operator for Klass.java_mirror).
2550 
2551   if (toop->isa_instptr() && toop->is_instptr()->instance_klass() == phase->C->env()->Class_klass()
2552       && offset == java_lang_Class::klass_offset()) {
2553     if (base->is_Load()) {
2554       Node* base2 = base->in(MemNode::Address);
2555       if (base2->is_Load()) { /* direct load of a load which is the OopHandle */

 245       assert(phase->C->get_alias_index(t) == phase->C->get_alias_index(t_adr), "correct memory chain");
 246     }
 247   }
 248   return result;
 249 }
 250 
 251 static Node *step_through_mergemem(PhaseGVN *phase, MergeMemNode *mmem,  const TypePtr *tp, const TypePtr *adr_check, outputStream *st) {
 252   uint alias_idx = phase->C->get_alias_index(tp);
 253   Node *mem = mmem;
 254 #ifdef ASSERT
 255   {
 256     // Check that current type is consistent with the alias index used during graph construction
 257     assert(alias_idx >= Compile::AliasIdxRaw, "must not be a bad alias_idx");
 258     bool consistent =  adr_check == nullptr || adr_check->empty() ||
 259                        phase->C->must_alias(adr_check, alias_idx );
 260     // Sometimes dead array references collapse to a[-1], a[-2], or a[-3]
 261     if( !consistent && adr_check != nullptr && !adr_check->empty() &&
 262                tp->isa_aryptr() &&        tp->offset() == Type::OffsetBot &&
 263         adr_check->isa_aryptr() && adr_check->offset() != Type::OffsetBot &&
 264         ( adr_check->offset() == arrayOopDesc::length_offset_in_bytes() ||
 265           adr_check->offset() == Type::klass_offset() ||
 266           adr_check->offset() == oopDesc::mark_offset_in_bytes() ) ) {
 267       // don't assert if it is dead code.
 268       consistent = true;
 269     }
 270     if( !consistent ) {
 271       st->print("alias_idx==%d, adr_check==", alias_idx);
 272       if( adr_check == nullptr ) {
 273         st->print("null");
 274       } else {
 275         adr_check->dump();
 276       }
 277       st->cr();
 278       print_alias_types();
 279       assert(consistent, "adr_check must match alias idx");
 280     }
 281   }
 282 #endif
 283   // TypeOopPtr::NOTNULL+any is an OOP with unknown offset - generally
 284   // means an array I have not precisely typed yet.  Do not do any
 285   // alias stuff with it any time soon.

 933 
 934     for (size_t i = 0; i < sizeof offsets / sizeof offsets[0]; i++) {
 935       if (offset == offsets[i]) {
 936         return true;
 937       }
 938     }
 939   }
 940 
 941   return false;
 942 }
 943 #endif
 944 
 945 //----------------------------LoadNode::make-----------------------------------
 946 // Polymorphic factory method:
 947 Node* LoadNode::make(PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, BasicType bt, MemOrd mo,
 948                      ControlDependency control_dependency, bool require_atomic_access, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) {
 949   Compile* C = gvn.C;
 950 
 951   // sanity check the alias category against the created node type
 952   assert(!(adr_type->isa_oopptr() &&
 953            adr_type->offset() == Type::klass_offset()),
 954          "use LoadKlassNode instead");
 955   assert(!(adr_type->isa_aryptr() &&
 956            adr_type->offset() == arrayOopDesc::length_offset_in_bytes()),
 957          "use LoadRangeNode instead");
 958   // Check control edge of raw loads
 959   assert( ctl != nullptr || C->get_alias_index(adr_type) != Compile::AliasIdxRaw ||
 960           // oop will be recorded in oop map if load crosses safepoint
 961           rt->isa_oopptr() || is_immutable_value(adr),
 962           "raw memory operations should have control edge");
 963   LoadNode* load = nullptr;
 964   switch (bt) {
 965   case T_BOOLEAN: load = new LoadUBNode(ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 966   case T_BYTE:    load = new LoadBNode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 967   case T_INT:     load = new LoadINode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 968   case T_CHAR:    load = new LoadUSNode(ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 969   case T_SHORT:   load = new LoadSNode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
 970   case T_LONG:    load = new LoadLNode (ctl, mem, adr, adr_type, rt->is_long(), mo, control_dependency, require_atomic_access); break;
 971   case T_FLOAT:   load = new LoadFNode (ctl, mem, adr, adr_type, rt,            mo, control_dependency); break;
 972   case T_DOUBLE:  load = new LoadDNode (ctl, mem, adr, adr_type, rt,            mo, control_dependency, require_atomic_access); break;
 973   case T_ADDRESS: load = new LoadPNode (ctl, mem, adr, adr_type, rt->is_ptr(),  mo, control_dependency); break;

2441         // constant oop => constant klass
2442         if (offset == java_lang_Class::array_klass_offset()) {
2443           if (t->is_void()) {
2444             // We cannot create a void array.  Since void is a primitive type return null
2445             // klass.  Users of this result need to do a null check on the returned klass.
2446             return TypePtr::NULL_PTR;
2447           }
2448           return TypeKlassPtr::make(ciArrayKlass::make(t), Type::trust_interfaces);
2449         }
2450         if (!t->is_klass()) {
2451           // a primitive Class (e.g., int.class) has null for a klass field
2452           return TypePtr::NULL_PTR;
2453         }
2454         // Fold up the load of the hidden field
2455         return TypeKlassPtr::make(t->as_klass(), Type::trust_interfaces);
2456       }
2457       // non-constant mirror, so we can't tell what's going on
2458     }
2459     if (!tinst->is_loaded())
2460       return _type;             // Bail out if not loaded
2461     if (offset == Type::klass_offset()) {
2462       return tinst->as_klass_type(true);
2463     }
2464   }
2465 
2466   // Check for loading klass from an array
2467   const TypeAryPtr *tary = tp->isa_aryptr();
2468   if (tary != nullptr &&
2469       tary->offset() == Type::klass_offset()) {
2470     return tary->as_klass_type(true);
2471   }
2472 
2473   // Check for loading klass from an array klass
2474   const TypeKlassPtr *tkls = tp->isa_klassptr();
2475   if (tkls != nullptr && !StressReflectiveCode) {
2476     if (!tkls->is_loaded())
2477      return _type;             // Bail out if not loaded
2478     if (tkls->isa_aryklassptr() && tkls->is_aryklassptr()->elem()->isa_klassptr() &&
2479         tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) {
2480       // // Always returning precise element type is incorrect,
2481       // // e.g., element type could be object and array may contain strings
2482       // return TypeKlassPtr::make(TypePtr::Constant, elem, 0);
2483 
2484       // The array's TypeKlassPtr was declared 'precise' or 'not precise'
2485       // according to the element type's subclassing.
2486       return tkls->is_aryklassptr()->elem()->isa_klassptr()->cast_to_exactness(tkls->klass_is_exact());
2487     }
2488     if (tkls->isa_instklassptr() != nullptr && tkls->klass_is_exact() &&
2489         tkls->offset() == in_bytes(Klass::super_offset())) {

2515   Node* x = LoadNode::Identity(phase);
2516   if (x != this)  return x;
2517 
2518   // Take apart the address into an oop and offset.
2519   // Return 'this' if we cannot.
2520   Node*    adr    = in(MemNode::Address);
2521   intptr_t offset = 0;
2522   Node*    base   = AddPNode::Ideal_base_and_offset(adr, phase, offset);
2523   if (base == nullptr)     return this;
2524   const TypeOopPtr* toop = phase->type(adr)->isa_oopptr();
2525   if (toop == nullptr)     return this;
2526 
2527   // Step over potential GC barrier for OopHandle resolve
2528   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2529   if (bs->is_gc_barrier_node(base)) {
2530     base = bs->step_over_gc_barrier(base);
2531   }
2532 
2533   // We can fetch the klass directly through an AllocateNode.
2534   // This works even if the klass is not constant (clone or newArray).
2535   if (offset == Type::klass_offset()) {
2536     Node* allocated_klass = AllocateNode::Ideal_klass(base, phase);
2537     if (allocated_klass != nullptr) {
2538       return allocated_klass;
2539     }
2540   }
2541 
2542   // Simplify k.java_mirror.as_klass to plain k, where k is a Klass*.
2543   // See inline_native_Class_query for occurrences of these patterns.
2544   // Java Example:  x.getClass().isAssignableFrom(y)
2545   //
2546   // This improves reflective code, often making the Class
2547   // mirror go completely dead.  (Current exception:  Class
2548   // mirrors may appear in debug info, but we could clean them out by
2549   // introducing a new debug info operator for Klass.java_mirror).
2550 
2551   if (toop->isa_instptr() && toop->is_instptr()->instance_klass() == phase->C->env()->Class_klass()
2552       && offset == java_lang_Class::klass_offset()) {
2553     if (base->is_Load()) {
2554       Node* base2 = base->in(MemNode::Address);
2555       if (base2->is_Load()) { /* direct load of a load which is the OopHandle */
< prev index next >