< prev index next >

src/hotspot/share/opto/memnode.cpp

Print this page

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

 997     for (size_t i = 0; i < sizeof offsets / sizeof offsets[0]; i++) {
 998       if (offset == offsets[i]) {
 999         return true;
1000       }
1001     }
1002   }
1003 
1004   return false;
1005 }
1006 #endif
1007 
1008 //----------------------------LoadNode::make-----------------------------------
1009 // Polymorphic factory method:
1010 Node* LoadNode::make(PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, BasicType bt, MemOrd mo,
1011                      ControlDependency control_dependency, bool require_atomic_access, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) {
1012   Compile* C = gvn.C;
1013   assert(adr->is_top() || C->get_alias_index(gvn.type(adr)->is_ptr()) == C->get_alias_index(adr_type), "adr and adr_type must agree");
1014 
1015   // sanity check the alias category against the created node type
1016   assert(!(adr_type->isa_oopptr() &&
1017            adr_type->offset() == oopDesc::klass_offset_in_bytes()),
1018          "use LoadKlassNode instead");
1019   assert(!(adr_type->isa_aryptr() &&
1020            adr_type->offset() == arrayOopDesc::length_offset_in_bytes()),
1021          "use LoadRangeNode instead");
1022   // Check control edge of raw loads
1023   assert( ctl != nullptr || C->get_alias_index(adr_type) != Compile::AliasIdxRaw ||
1024           // oop will be recorded in oop map if load crosses safepoint
1025           rt->isa_oopptr() || is_immutable_value(adr),
1026           "raw memory operations should have control edge");
1027   LoadNode* load = nullptr;
1028   switch (bt) {
1029   case T_BOOLEAN: load = new LoadUBNode(ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1030   case T_BYTE:    load = new LoadBNode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1031   case T_INT:     load = new LoadINode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1032   case T_CHAR:    load = new LoadUSNode(ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1033   case T_SHORT:   load = new LoadSNode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1034   case T_LONG:    load = new LoadLNode (ctl, mem, adr, adr_type, rt->is_long(), mo, control_dependency, require_atomic_access); break;
1035   case T_FLOAT:   load = new LoadFNode (ctl, mem, adr, adr_type, rt,            mo, control_dependency); break;
1036   case T_DOUBLE:  load = new LoadDNode (ctl, mem, adr, adr_type, rt,            mo, control_dependency, require_atomic_access); break;
1037   case T_ADDRESS: load = new LoadPNode (ctl, mem, adr, adr_type, rt->is_ptr(),  mo, control_dependency); break;

2527         // constant oop => constant klass
2528         if (offset == java_lang_Class::array_klass_offset()) {
2529           if (t->is_void()) {
2530             // We cannot create a void array.  Since void is a primitive type return null
2531             // klass.  Users of this result need to do a null check on the returned klass.
2532             return TypePtr::NULL_PTR;
2533           }
2534           return TypeKlassPtr::make(ciArrayKlass::make(t), Type::trust_interfaces);
2535         }
2536         if (!t->is_klass()) {
2537           // a primitive Class (e.g., int.class) has null for a klass field
2538           return TypePtr::NULL_PTR;
2539         }
2540         // Fold up the load of the hidden field
2541         return TypeKlassPtr::make(t->as_klass(), Type::trust_interfaces);
2542       }
2543       // non-constant mirror, so we can't tell what's going on
2544     }
2545     if (!tinst->is_loaded())
2546       return _type;             // Bail out if not loaded
2547     if (offset == oopDesc::klass_offset_in_bytes()) {
2548       return tinst->as_klass_type(true);
2549     }
2550   }
2551 
2552   // Check for loading klass from an array
2553   const TypeAryPtr *tary = tp->isa_aryptr();
2554   if (tary != nullptr &&
2555       tary->offset() == oopDesc::klass_offset_in_bytes()) {
2556     return tary->as_klass_type(true);
2557   }
2558 
2559   // Check for loading klass from an array klass
2560   const TypeKlassPtr *tkls = tp->isa_klassptr();
2561   if (tkls != nullptr && !StressReflectiveCode) {
2562     if (!tkls->is_loaded())
2563      return _type;             // Bail out if not loaded
2564     if (tkls->isa_aryklassptr() && tkls->is_aryklassptr()->elem()->isa_klassptr() &&
2565         tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) {
2566       // // Always returning precise element type is incorrect,
2567       // // e.g., element type could be object and array may contain strings
2568       // return TypeKlassPtr::make(TypePtr::Constant, elem, 0);
2569 
2570       // The array's TypeKlassPtr was declared 'precise' or 'not precise'
2571       // according to the element type's subclassing.
2572       return tkls->is_aryklassptr()->elem()->isa_klassptr()->cast_to_exactness(tkls->klass_is_exact());
2573     }
2574     if (tkls->isa_instklassptr() != nullptr && tkls->klass_is_exact() &&
2575         tkls->offset() == in_bytes(Klass::super_offset())) {

2601   Node* x = LoadNode::Identity(phase);
2602   if (x != this)  return x;
2603 
2604   // Take apart the address into an oop and offset.
2605   // Return 'this' if we cannot.
2606   Node*    adr    = in(MemNode::Address);
2607   intptr_t offset = 0;
2608   Node*    base   = AddPNode::Ideal_base_and_offset(adr, phase, offset);
2609   if (base == nullptr)     return this;
2610   const TypeOopPtr* toop = phase->type(adr)->isa_oopptr();
2611   if (toop == nullptr)     return this;
2612 
2613   // Step over potential GC barrier for OopHandle resolve
2614   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2615   if (bs->is_gc_barrier_node(base)) {
2616     base = bs->step_over_gc_barrier(base);
2617   }
2618 
2619   // We can fetch the klass directly through an AllocateNode.
2620   // This works even if the klass is not constant (clone or newArray).
2621   if (offset == oopDesc::klass_offset_in_bytes()) {
2622     Node* allocated_klass = AllocateNode::Ideal_klass(base, phase);
2623     if (allocated_klass != nullptr) {
2624       return allocated_klass;
2625     }
2626   }
2627 
2628   // Simplify k.java_mirror.as_klass to plain k, where k is a Klass*.
2629   // See inline_native_Class_query for occurrences of these patterns.
2630   // Java Example:  x.getClass().isAssignableFrom(y)
2631   //
2632   // This improves reflective code, often making the Class
2633   // mirror go completely dead.  (Current exception:  Class
2634   // mirrors may appear in debug info, but we could clean them out by
2635   // introducing a new debug info operator for Klass.java_mirror).
2636 
2637   if (toop->isa_instptr() && toop->is_instptr()->instance_klass() == phase->C->env()->Class_klass()
2638       && offset == java_lang_Class::klass_offset()) {
2639     if (base->is_Load()) {
2640       Node* base2 = base->in(MemNode::Address);
2641       if (base2->is_Load()) { /* direct load of a load which is the OopHandle */

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

 997     for (size_t i = 0; i < sizeof offsets / sizeof offsets[0]; i++) {
 998       if (offset == offsets[i]) {
 999         return true;
1000       }
1001     }
1002   }
1003 
1004   return false;
1005 }
1006 #endif
1007 
1008 //----------------------------LoadNode::make-----------------------------------
1009 // Polymorphic factory method:
1010 Node* LoadNode::make(PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, BasicType bt, MemOrd mo,
1011                      ControlDependency control_dependency, bool require_atomic_access, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) {
1012   Compile* C = gvn.C;
1013   assert(adr->is_top() || C->get_alias_index(gvn.type(adr)->is_ptr()) == C->get_alias_index(adr_type), "adr and adr_type must agree");
1014 
1015   // sanity check the alias category against the created node type
1016   assert(!(adr_type->isa_oopptr() &&
1017            adr_type->offset() == Type::klass_offset()),
1018          "use LoadKlassNode instead");
1019   assert(!(adr_type->isa_aryptr() &&
1020            adr_type->offset() == arrayOopDesc::length_offset_in_bytes()),
1021          "use LoadRangeNode instead");
1022   // Check control edge of raw loads
1023   assert( ctl != nullptr || C->get_alias_index(adr_type) != Compile::AliasIdxRaw ||
1024           // oop will be recorded in oop map if load crosses safepoint
1025           rt->isa_oopptr() || is_immutable_value(adr),
1026           "raw memory operations should have control edge");
1027   LoadNode* load = nullptr;
1028   switch (bt) {
1029   case T_BOOLEAN: load = new LoadUBNode(ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1030   case T_BYTE:    load = new LoadBNode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1031   case T_INT:     load = new LoadINode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1032   case T_CHAR:    load = new LoadUSNode(ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1033   case T_SHORT:   load = new LoadSNode (ctl, mem, adr, adr_type, rt->is_int(),  mo, control_dependency); break;
1034   case T_LONG:    load = new LoadLNode (ctl, mem, adr, adr_type, rt->is_long(), mo, control_dependency, require_atomic_access); break;
1035   case T_FLOAT:   load = new LoadFNode (ctl, mem, adr, adr_type, rt,            mo, control_dependency); break;
1036   case T_DOUBLE:  load = new LoadDNode (ctl, mem, adr, adr_type, rt,            mo, control_dependency, require_atomic_access); break;
1037   case T_ADDRESS: load = new LoadPNode (ctl, mem, adr, adr_type, rt->is_ptr(),  mo, control_dependency); break;

2527         // constant oop => constant klass
2528         if (offset == java_lang_Class::array_klass_offset()) {
2529           if (t->is_void()) {
2530             // We cannot create a void array.  Since void is a primitive type return null
2531             // klass.  Users of this result need to do a null check on the returned klass.
2532             return TypePtr::NULL_PTR;
2533           }
2534           return TypeKlassPtr::make(ciArrayKlass::make(t), Type::trust_interfaces);
2535         }
2536         if (!t->is_klass()) {
2537           // a primitive Class (e.g., int.class) has null for a klass field
2538           return TypePtr::NULL_PTR;
2539         }
2540         // Fold up the load of the hidden field
2541         return TypeKlassPtr::make(t->as_klass(), Type::trust_interfaces);
2542       }
2543       // non-constant mirror, so we can't tell what's going on
2544     }
2545     if (!tinst->is_loaded())
2546       return _type;             // Bail out if not loaded
2547     if (offset == Type::klass_offset()) {
2548       return tinst->as_klass_type(true);
2549     }
2550   }
2551 
2552   // Check for loading klass from an array
2553   const TypeAryPtr *tary = tp->isa_aryptr();
2554   if (tary != nullptr &&
2555       tary->offset() == Type::klass_offset()) {
2556     return tary->as_klass_type(true);
2557   }
2558 
2559   // Check for loading klass from an array klass
2560   const TypeKlassPtr *tkls = tp->isa_klassptr();
2561   if (tkls != nullptr && !StressReflectiveCode) {
2562     if (!tkls->is_loaded())
2563      return _type;             // Bail out if not loaded
2564     if (tkls->isa_aryklassptr() && tkls->is_aryklassptr()->elem()->isa_klassptr() &&
2565         tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) {
2566       // // Always returning precise element type is incorrect,
2567       // // e.g., element type could be object and array may contain strings
2568       // return TypeKlassPtr::make(TypePtr::Constant, elem, 0);
2569 
2570       // The array's TypeKlassPtr was declared 'precise' or 'not precise'
2571       // according to the element type's subclassing.
2572       return tkls->is_aryklassptr()->elem()->isa_klassptr()->cast_to_exactness(tkls->klass_is_exact());
2573     }
2574     if (tkls->isa_instklassptr() != nullptr && tkls->klass_is_exact() &&
2575         tkls->offset() == in_bytes(Klass::super_offset())) {

2601   Node* x = LoadNode::Identity(phase);
2602   if (x != this)  return x;
2603 
2604   // Take apart the address into an oop and offset.
2605   // Return 'this' if we cannot.
2606   Node*    adr    = in(MemNode::Address);
2607   intptr_t offset = 0;
2608   Node*    base   = AddPNode::Ideal_base_and_offset(adr, phase, offset);
2609   if (base == nullptr)     return this;
2610   const TypeOopPtr* toop = phase->type(adr)->isa_oopptr();
2611   if (toop == nullptr)     return this;
2612 
2613   // Step over potential GC barrier for OopHandle resolve
2614   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2615   if (bs->is_gc_barrier_node(base)) {
2616     base = bs->step_over_gc_barrier(base);
2617   }
2618 
2619   // We can fetch the klass directly through an AllocateNode.
2620   // This works even if the klass is not constant (clone or newArray).
2621   if (offset == Type::klass_offset()) {
2622     Node* allocated_klass = AllocateNode::Ideal_klass(base, phase);
2623     if (allocated_klass != nullptr) {
2624       return allocated_klass;
2625     }
2626   }
2627 
2628   // Simplify k.java_mirror.as_klass to plain k, where k is a Klass*.
2629   // See inline_native_Class_query for occurrences of these patterns.
2630   // Java Example:  x.getClass().isAssignableFrom(y)
2631   //
2632   // This improves reflective code, often making the Class
2633   // mirror go completely dead.  (Current exception:  Class
2634   // mirrors may appear in debug info, but we could clean them out by
2635   // introducing a new debug info operator for Klass.java_mirror).
2636 
2637   if (toop->isa_instptr() && toop->is_instptr()->instance_klass() == phase->C->env()->Class_klass()
2638       && offset == java_lang_Class::klass_offset()) {
2639     if (base->is_Load()) {
2640       Node* base2 = base->in(MemNode::Address);
2641       if (base2->is_Load()) { /* direct load of a load which is the OopHandle */
< prev index next >