< prev index next >

src/hotspot/share/opto/memnode.cpp

Print this page




2241     if( !ik->is_loaded() )
2242       return _type;             // Bail out if not loaded
2243     if (offset == oopDesc::klass_offset_in_bytes()) {
2244       if (tinst->klass_is_exact()) {
2245         return TypeKlassPtr::make(ik);
2246       }
2247       // See if we can become precise: no subklasses and no interface
2248       // (Note:  We need to support verified interfaces.)
2249       if (!ik->is_interface() && !ik->has_subklass()) {
2250         //assert(!UseExactTypes, "this code should be useless with exact types");
2251         // Add a dependence; if any subclass added we need to recompile
2252         if (!ik->is_final()) {
2253           // %%% should use stronger assert_unique_concrete_subtype instead
2254           phase->C->dependencies()->assert_leaf_type(ik);
2255         }
2256         // Return precise klass
2257         return TypeKlassPtr::make(ik);
2258       }
2259 
2260       // Return root of possible klass
2261       return TypeKlassPtr::make(TypePtr::NotNull, ik, Type::Offset(0));
2262     }
2263   }
2264 
2265   // Check for loading klass from an array
2266   const TypeAryPtr *tary = tp->isa_aryptr();
2267   if (tary != NULL) {
2268     ciKlass *tary_klass = tary->klass();
2269     if (tary_klass != NULL   // can be NULL when at BOTTOM or TOP
2270         && tary->offset() == oopDesc::klass_offset_in_bytes()) {
2271       ciArrayKlass* ak = tary_klass->as_array_klass();
2272       // Do not fold klass loads from [V?. The runtime type might be [V due to [V <: [V?
2273       // and the klass for [V is not equal to the klass for [V?.
2274       if (tary->klass_is_exact()) {
2275         return TypeKlassPtr::make(tary_klass);
2276       }
2277 
2278       // If the klass is an object array, we defer the question to the
2279       // array component klass.
2280       if (ak->is_obj_array_klass()) {
2281         assert(ak->is_loaded(), "");
2282         ciKlass *base_k = ak->as_obj_array_klass()->base_element_klass();
2283         if (base_k->is_loaded() && base_k->is_instance_klass()) {
2284           ciInstanceKlass *ik = base_k->as_instance_klass();
2285           // See if we can become precise: no subklasses and no interface
2286           if (!ik->is_interface() && !ik->has_subklass() && (!ik->is_valuetype() || ak->storage_properties().is_null_free())) {
2287             //assert(!UseExactTypes, "this code should be useless with exact types");
2288             // Add a dependence; if any subclass added we need to recompile
2289             if (!ik->is_final()) {
2290               phase->C->dependencies()->assert_leaf_type(ik);
2291             }
2292             // Return precise array klass
2293             return TypeKlassPtr::make(ak);
2294           }
2295         }
2296         return TypeKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0));
2297       } else if (ak->is_type_array_klass()) {
2298         //assert(!UseExactTypes, "this code should be useless with exact types");
2299         return TypeKlassPtr::make(ak); // These are always precise
2300       }
2301     }
2302   }
2303 
2304   // Check for loading klass from an array klass
2305   const TypeKlassPtr *tkls = tp->isa_klassptr();
2306   if (tkls != NULL && !StressReflectiveCode) {
2307     if (!tkls->is_loaded()) {
2308       return _type;             // Bail out if not loaded
2309     }
2310     ciKlass* klass = tkls->klass();
2311     if( klass->is_obj_array_klass() &&
2312         tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) {
2313       ciKlass* elem = klass->as_obj_array_klass()->element_klass();
2314       // // Always returning precise element type is incorrect,
2315       // // e.g., element type could be object and array may contain strings
2316       // return TypeKlassPtr::make(TypePtr::Constant, elem, 0);
2317 
2318       // The array's TypeKlassPtr was declared 'precise' or 'not precise'
2319       // according to the element type's subclassing.
2320       return TypeKlassPtr::make(tkls->ptr(), elem, Type::Offset(0));
2321     } else if (klass->is_value_array_klass() &&
2322                tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) {
2323       ciKlass* elem = klass->as_value_array_klass()->element_klass();
2324       return TypeKlassPtr::make(tkls->ptr(), elem, Type::Offset(0));
2325     }
2326     if( klass->is_instance_klass() && tkls->klass_is_exact() &&
2327         tkls->offset() == in_bytes(Klass::super_offset())) {
2328       ciKlass* sup = klass->as_instance_klass()->super();
2329       // The field is Klass::_super.  Return its (constant) value.
2330       // (Folds up the 2nd indirection in aClassConstant.getSuperClass().)
2331       return sup ? TypeKlassPtr::make(sup) : TypePtr::NULL_PTR;
2332     }
2333   }
2334 
2335   // Bailout case
2336   return LoadNode::Value(phase);
2337 }
2338 
2339 //------------------------------Identity---------------------------------------
2340 // To clean up reflective code, simplify k.java_mirror.as_klass to plain k.
2341 // Also feed through the klass in Allocate(...klass...)._klass.
2342 Node* LoadKlassNode::Identity(PhaseGVN* phase) {
2343   return klass_identity_common(phase);
2344 }
2345 
2346 const Type* GetNullFreePropertyNode::Value(PhaseGVN* phase) const {
2347   if (in(1) != NULL) {
2348     const Type* in1_t = phase->type(in(1));
2349     if (in1_t == Type::TOP) {
2350       return Type::TOP;
2351     }
2352     const TypeKlassPtr* tk = in1_t->make_ptr()->is_klassptr();
2353     ciArrayKlass* ak = tk->klass()->as_array_klass();
2354     ciKlass* elem = ak->element_klass();
2355     if (tk->klass_is_exact() || (!elem->is_java_lang_Object() && !elem->is_interface() && !elem->is_valuetype())) {
2356       int props_shift = in1_t->isa_narrowklass() ? oopDesc::narrow_storage_props_shift : oopDesc::wide_storage_props_shift;
2357       ArrayStorageProperties props = ak->storage_properties();
2358       intptr_t storage_properties = props.encode<intptr_t>(props_shift);




2359       if (in1_t->isa_narrowklass()) {
2360         return TypeInt::make((int)storage_properties);
2361       }
2362       return TypeX::make(storage_properties);
2363     }
2364   }
2365   return bottom_type();
2366 }
2367 
2368 Node* GetNullFreePropertyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2369   if (!can_reshape) {
2370     return NULL;
2371   }
2372   if (in(1) != NULL && in(1)->is_Phi()) {
2373     Node* phi = in(1);
2374     Node* r = phi->in(0);
2375     Node* new_phi = new PhiNode(r, bottom_type());
2376     for (uint i = 1; i < r->req(); i++) {
2377       Node* in = phi->in(i);
2378       if (in == NULL) continue;
2379       new_phi->init_req(i, phase->transform(new GetNullFreePropertyNode(in)));


2380     }
2381     return new_phi;
2382   }
2383   return NULL;
2384 }
2385 
2386 Node* LoadNode::klass_identity_common(PhaseGVN* phase) {
2387   Node* x = LoadNode::Identity(phase);
2388   if (x != this)  return x;
2389 
2390   // Take apart the address into an oop and and offset.
2391   // Return 'this' if we cannot.
2392   Node*    adr    = in(MemNode::Address);
2393   intptr_t offset = 0;
2394   Node*    base   = AddPNode::Ideal_base_and_offset(adr, phase, offset);
2395   if (base == NULL)     return this;
2396   const TypeOopPtr* toop = phase->type(adr)->isa_oopptr();
2397   if (toop == NULL)     return this;
2398 
2399   // Step over potential GC barrier for OopHandle resolve




2241     if( !ik->is_loaded() )
2242       return _type;             // Bail out if not loaded
2243     if (offset == oopDesc::klass_offset_in_bytes()) {
2244       if (tinst->klass_is_exact()) {
2245         return TypeKlassPtr::make(ik);
2246       }
2247       // See if we can become precise: no subklasses and no interface
2248       // (Note:  We need to support verified interfaces.)
2249       if (!ik->is_interface() && !ik->has_subklass()) {
2250         //assert(!UseExactTypes, "this code should be useless with exact types");
2251         // Add a dependence; if any subclass added we need to recompile
2252         if (!ik->is_final()) {
2253           // %%% should use stronger assert_unique_concrete_subtype instead
2254           phase->C->dependencies()->assert_leaf_type(ik);
2255         }
2256         // Return precise klass
2257         return TypeKlassPtr::make(ik);
2258       }
2259 
2260       // Return root of possible klass
2261       return TypeKlassPtr::make(TypePtr::NotNull, ik, Type::Offset(0), tinst->flat_array());
2262     }
2263   }
2264 
2265   // Check for loading klass from an array
2266   const TypeAryPtr *tary = tp->isa_aryptr();
2267   if (tary != NULL) {
2268     ciKlass *tary_klass = tary->klass();
2269     if (tary_klass != NULL   // can be NULL when at BOTTOM or TOP
2270         && tary->offset() == oopDesc::klass_offset_in_bytes()) {
2271       ciArrayKlass* ak = tary_klass->as_array_klass();
2272       // Do not fold klass loads from [V?. The runtime type might be [V due to [V <: [V?
2273       // and the klass for [V is not equal to the klass for [V?.
2274       if (tary->klass_is_exact()) {
2275         return TypeKlassPtr::make(tary_klass);
2276       }
2277 
2278       // If the klass is an object array, we defer the question to the
2279       // array component klass.
2280       if (ak->is_obj_array_klass()) {
2281         assert(ak->is_loaded(), "");
2282         ciKlass *base_k = ak->as_obj_array_klass()->base_element_klass();
2283         if (base_k->is_loaded() && base_k->is_instance_klass()) {
2284           ciInstanceKlass *ik = base_k->as_instance_klass();
2285           // See if we can become precise: no subklasses and no interface
2286           if (!ik->is_interface() && !ik->has_subklass() && (!ik->is_valuetype() || ak->storage_properties().is_null_free())) {
2287             //assert(!UseExactTypes, "this code should be useless with exact types");
2288             // Add a dependence; if any subclass added we need to recompile
2289             if (!ik->is_final()) {
2290               phase->C->dependencies()->assert_leaf_type(ik);
2291             }
2292             // Return precise array klass
2293             return TypeKlassPtr::make(ak);
2294           }
2295         }
2296         return TypeKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0), false);
2297       } else if (ak->is_type_array_klass()) {
2298         //assert(!UseExactTypes, "this code should be useless with exact types");
2299         return TypeKlassPtr::make(ak); // These are always precise
2300       }
2301     }
2302   }
2303 
2304   // Check for loading klass from an array klass
2305   const TypeKlassPtr *tkls = tp->isa_klassptr();
2306   if (tkls != NULL && !StressReflectiveCode) {
2307     if (!tkls->is_loaded()) {
2308       return _type;             // Bail out if not loaded
2309     }
2310     ciKlass* klass = tkls->klass();
2311     if( klass->is_obj_array_klass() &&
2312         tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) {
2313       ciKlass* elem = klass->as_obj_array_klass()->element_klass();
2314       // // Always returning precise element type is incorrect,
2315       // // e.g., element type could be object and array may contain strings
2316       // return TypeKlassPtr::make(TypePtr::Constant, elem, 0);
2317 
2318       // The array's TypeKlassPtr was declared 'precise' or 'not precise'
2319       // according to the element type's subclassing.
2320       return TypeKlassPtr::make(tkls->ptr(), elem, Type::Offset(0), elem->flatten_array());
2321     } else if (klass->is_value_array_klass() &&
2322                tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) {
2323       ciKlass* elem = klass->as_value_array_klass()->element_klass();
2324       return TypeKlassPtr::make(tkls->ptr(), elem, Type::Offset(0), true);
2325     }
2326     if( klass->is_instance_klass() && tkls->klass_is_exact() &&
2327         tkls->offset() == in_bytes(Klass::super_offset())) {
2328       ciKlass* sup = klass->as_instance_klass()->super();
2329       // The field is Klass::_super.  Return its (constant) value.
2330       // (Folds up the 2nd indirection in aClassConstant.getSuperClass().)
2331       return sup ? TypeKlassPtr::make(sup) : TypePtr::NULL_PTR;
2332     }
2333   }
2334 
2335   // Bailout case
2336   return LoadNode::Value(phase);
2337 }
2338 
2339 //------------------------------Identity---------------------------------------
2340 // To clean up reflective code, simplify k.java_mirror.as_klass to plain k.
2341 // Also feed through the klass in Allocate(...klass...)._klass.
2342 Node* LoadKlassNode::Identity(PhaseGVN* phase) {
2343   return klass_identity_common(phase);
2344 }
2345 
2346 const Type* GetStoragePropertyNode::Value(PhaseGVN* phase) const {
2347   if (in(1) != NULL) {
2348     const Type* in1_t = phase->type(in(1));
2349     if (in1_t == Type::TOP) {
2350       return Type::TOP;
2351     }
2352     const TypeKlassPtr* tk = in1_t->make_ptr()->is_klassptr();
2353     ciArrayKlass* ak = tk->klass()->as_array_klass();
2354     ciKlass* elem = ak->element_klass();
2355     if (tk->klass_is_exact() || (!elem->is_java_lang_Object() && !elem->is_interface() && !elem->is_valuetype())) {
2356       int props_shift = in1_t->isa_narrowklass() ? oopDesc::narrow_storage_props_shift : oopDesc::wide_storage_props_shift;
2357       ArrayStorageProperties props = ak->storage_properties();
2358       intptr_t storage_properties = 0;
2359       if ((Opcode() == Op_GetFlattenedProperty && props.is_flattened()) ||
2360           (Opcode() == Op_GetNullFreeProperty && props.is_null_free())) {
2361         storage_properties = 1;
2362       }
2363       if (in1_t->isa_narrowklass()) {
2364         return TypeInt::make((int)storage_properties);
2365       }
2366       return TypeX::make(storage_properties);
2367     }
2368   }
2369   return bottom_type();
2370 }
2371 
2372 Node* GetStoragePropertyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2373   if (!can_reshape) {
2374     return NULL;
2375   }
2376   if (in(1) != NULL && in(1)->is_Phi()) {
2377     Node* phi = in(1);
2378     Node* r = phi->in(0);
2379     Node* new_phi = new PhiNode(r, bottom_type());
2380     for (uint i = 1; i < r->req(); i++) {
2381       Node* in = phi->in(i);
2382       if (in == NULL) continue;
2383       Node* n = clone();
2384       n->set_req(1, in);
2385       new_phi->init_req(i, phase->transform(n));
2386     }
2387     return new_phi;
2388   }
2389   return NULL;
2390 }
2391 
2392 Node* LoadNode::klass_identity_common(PhaseGVN* phase) {
2393   Node* x = LoadNode::Identity(phase);
2394   if (x != this)  return x;
2395 
2396   // Take apart the address into an oop and and offset.
2397   // Return 'this' if we cannot.
2398   Node*    adr    = in(MemNode::Address);
2399   intptr_t offset = 0;
2400   Node*    base   = AddPNode::Ideal_base_and_offset(adr, phase, offset);
2401   if (base == NULL)     return this;
2402   const TypeOopPtr* toop = phase->type(adr)->isa_oopptr();
2403   if (toop == NULL)     return this;
2404 
2405   // Step over potential GC barrier for OopHandle resolve


< prev index next >