1831 if ((base_type != NULL) && base_type->is_autobox_cache()) { 1832 // It could be narrow oop 1833 assert(jt->make_ptr()->ptr() == TypePtr::NotNull,"sanity"); 1834 } 1835 } 1836 } 1837 #endif 1838 return jt; 1839 } 1840 } 1841 } else if (tp->base() == Type::InstPtr) { 1842 assert( off != Type::OffsetBot || 1843 // arrays can be cast to Objects 1844 tp->is_oopptr()->klass()->is_java_lang_Object() || 1845 tp->is_oopptr()->klass() == ciEnv::current()->Class_klass() || 1846 // unsafe field access may not have a constant offset 1847 C->has_unsafe_access(), 1848 "Field accesses must be precise" ); 1849 // For oop loads, we expect the _type to be precise. 1850 1851 // Optimize loads from constant fields. 1852 const TypeInstPtr* tinst = tp->is_instptr(); 1853 ciObject* const_oop = tinst->const_oop(); 1854 if (!is_mismatched_access() && off != Type::OffsetBot && const_oop != NULL && const_oop->is_instance()) { 1855 BasicType bt = memory_type(); 1856 ciType* mirror_type = const_oop->as_instance()->java_mirror_type(); 1857 if (mirror_type != NULL && mirror_type->is_valuetype()) { 1858 ciValueKlass* vk = mirror_type->as_value_klass(); 1859 if (off == vk->default_value_offset()) { 1860 // Loading a special hidden field that contains the oop of the default value type 1861 const Type* const_oop = TypeInstPtr::make(vk->default_value_instance()); 1862 return (bt == T_NARROWOOP) ? const_oop->make_narrowoop() : const_oop; 1863 } 1864 } 1865 const Type* con_type = Type::make_constant_from_field(const_oop->as_instance(), off, is_unsigned(), bt); 1866 if (con_type != NULL) { 1867 return con_type; 1868 } 1869 } 1870 } else if (tp->base() == Type::KlassPtr) { 1871 assert( off != Type::OffsetBot || 1872 // arrays can be cast to Objects 1873 tp->is_klassptr()->klass() == NULL || 1874 tp->is_klassptr()->klass()->is_java_lang_Object() || 1875 // also allow array-loading from the primary supertype 2219 // See if we can become precise: no subklasses and no interface 2220 // (Note: We need to support verified interfaces.) 2221 if (!ik->is_interface() && !ik->has_subklass()) { 2222 //assert(!UseExactTypes, "this code should be useless with exact types"); 2223 // Add a dependence; if any subclass added we need to recompile 2224 if (!ik->is_final()) { 2225 // %%% should use stronger assert_unique_concrete_subtype instead 2226 phase->C->dependencies()->assert_leaf_type(ik); 2227 } 2228 // Return precise klass 2229 return TypeKlassPtr::make(ik); 2230 } 2231 2232 // Return root of possible klass 2233 return TypeKlassPtr::make(TypePtr::NotNull, ik, Type::Offset(0)); 2234 } 2235 } 2236 2237 // Check for loading klass from an array 2238 const TypeAryPtr *tary = tp->isa_aryptr(); 2239 if( tary != NULL ) { 2240 ciKlass *tary_klass = tary->klass(); 2241 if (tary_klass != NULL // can be NULL when at BOTTOM or TOP 2242 && tary->offset() == oopDesc::klass_offset_in_bytes()) { 2243 if (tary->klass_is_exact()) { 2244 return TypeKlassPtr::make(tary_klass); 2245 } 2246 ciArrayKlass *ak = tary->klass()->as_array_klass(); 2247 // If the klass is an object array, we defer the question to the 2248 // array component klass. 2249 if( ak->is_obj_array_klass() ) { 2250 assert( ak->is_loaded(), "" ); 2251 ciKlass *base_k = ak->as_obj_array_klass()->base_element_klass(); 2252 if( base_k->is_loaded() && base_k->is_instance_klass() ) { 2253 ciInstanceKlass* ik = base_k->as_instance_klass(); 2254 // See if we can become precise: no subklasses and no interface 2255 if (!ik->is_interface() && !ik->has_subklass()) { 2256 //assert(!UseExactTypes, "this code should be useless with exact types"); 2257 // Add a dependence; if any subclass added we need to recompile 2258 if (!ik->is_final()) { 2259 phase->C->dependencies()->assert_leaf_type(ik); 2260 } 2261 // Return precise array klass 2262 return TypeKlassPtr::make(ak); 2263 } 2264 } 2265 return TypeKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0)); 2266 } else { // Found a type-array? 2267 //assert(!UseExactTypes, "this code should be useless with exact types"); 2268 assert( ak->is_type_array_klass(), "" ); 2269 return TypeKlassPtr::make(ak); // These are always precise 2270 } 2271 } 2272 } 2273 2274 // Check for loading klass from an array klass 2275 const TypeKlassPtr *tkls = tp->isa_klassptr(); 2276 if (tkls != NULL && !StressReflectiveCode) { 2277 if (!tkls->is_loaded()) { 2278 return _type; // Bail out if not loaded 2279 } 2280 ciKlass* klass = tkls->klass(); 2281 if( klass->is_obj_array_klass() && 2282 tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) { 2283 ciKlass* elem = klass->as_obj_array_klass()->element_klass(); 2284 // // Always returning precise element type is incorrect, 2285 // // e.g., element type could be object and array may contain strings 2286 // return TypeKlassPtr::make(TypePtr::Constant, elem, 0); 2287 2288 // The array's TypeKlassPtr was declared 'precise' or 'not precise' 2289 // according to the element type's subclassing. 2290 return TypeKlassPtr::make(tkls->ptr(), elem, Type::Offset(0)); 2291 } 2292 if( klass->is_instance_klass() && tkls->klass_is_exact() && 2293 tkls->offset() == in_bytes(Klass::super_offset())) { 2294 ciKlass* sup = klass->as_instance_klass()->super(); 2295 // The field is Klass::_super. Return its (constant) value. 2296 // (Folds up the 2nd indirection in aClassConstant.getSuperClass().) 2297 return sup ? TypeKlassPtr::make(sup) : TypePtr::NULL_PTR; 2298 } 2299 } 2300 2301 // Bailout case 2302 return LoadNode::Value(phase); 2303 } 2304 2305 //------------------------------Identity--------------------------------------- 2306 // To clean up reflective code, simplify k.java_mirror.as_klass to plain k. 2307 // Also feed through the klass in Allocate(...klass...)._klass. 2308 Node* LoadKlassNode::Identity(PhaseGVN* phase) { 2309 return klass_identity_common(phase); | 1831 if ((base_type != NULL) && base_type->is_autobox_cache()) { 1832 // It could be narrow oop 1833 assert(jt->make_ptr()->ptr() == TypePtr::NotNull,"sanity"); 1834 } 1835 } 1836 } 1837 #endif 1838 return jt; 1839 } 1840 } 1841 } else if (tp->base() == Type::InstPtr) { 1842 assert( off != Type::OffsetBot || 1843 // arrays can be cast to Objects 1844 tp->is_oopptr()->klass()->is_java_lang_Object() || 1845 tp->is_oopptr()->klass() == ciEnv::current()->Class_klass() || 1846 // unsafe field access may not have a constant offset 1847 C->has_unsafe_access(), 1848 "Field accesses must be precise" ); 1849 // For oop loads, we expect the _type to be precise. 1850 1851 const TypeInstPtr* tinst = tp->is_instptr(); 1852 BasicType bt = memory_type(); 1853 1854 // Fold component and value mirror loads 1855 ciInstanceKlass* ik = tinst->klass()->as_instance_klass(); 1856 if (ik == phase->C->env()->Class_klass() && (off == java_lang_Class::component_mirror_offset_in_bytes() || 1857 off == java_lang_Class::value_mirror_offset_in_bytes())) { 1858 ciType* mirror_type = tinst->java_mirror_type(); 1859 if (mirror_type != NULL) { 1860 const Type* const_oop = TypePtr::NULL_PTR; 1861 if (mirror_type->is_array_klass()) { 1862 const_oop = TypeInstPtr::make(mirror_type->as_array_klass()->component_mirror_instance()); 1863 } else if (mirror_type->is_valuetype()) { 1864 const_oop = TypeInstPtr::make(mirror_type->as_value_klass()->value_mirror_instance()); 1865 } 1866 return (bt == T_NARROWOOP) ? const_oop->make_narrowoop() : const_oop; 1867 } 1868 } 1869 1870 // Optimize loads from constant fields. 1871 ciObject* const_oop = tinst->const_oop(); 1872 if (!is_mismatched_access() && off != Type::OffsetBot && const_oop != NULL && const_oop->is_instance()) { 1873 ciType* mirror_type = const_oop->as_instance()->java_mirror_type(); 1874 if (mirror_type != NULL && mirror_type->is_valuetype()) { 1875 ciValueKlass* vk = mirror_type->as_value_klass(); 1876 if (off == vk->default_value_offset()) { 1877 // Loading a special hidden field that contains the oop of the default value type 1878 const Type* const_oop = TypeInstPtr::make(vk->default_value_instance()); 1879 return (bt == T_NARROWOOP) ? const_oop->make_narrowoop() : const_oop; 1880 } 1881 } 1882 const Type* con_type = Type::make_constant_from_field(const_oop->as_instance(), off, is_unsigned(), bt); 1883 if (con_type != NULL) { 1884 return con_type; 1885 } 1886 } 1887 } else if (tp->base() == Type::KlassPtr) { 1888 assert( off != Type::OffsetBot || 1889 // arrays can be cast to Objects 1890 tp->is_klassptr()->klass() == NULL || 1891 tp->is_klassptr()->klass()->is_java_lang_Object() || 1892 // also allow array-loading from the primary supertype 2236 // See if we can become precise: no subklasses and no interface 2237 // (Note: We need to support verified interfaces.) 2238 if (!ik->is_interface() && !ik->has_subklass()) { 2239 //assert(!UseExactTypes, "this code should be useless with exact types"); 2240 // Add a dependence; if any subclass added we need to recompile 2241 if (!ik->is_final()) { 2242 // %%% should use stronger assert_unique_concrete_subtype instead 2243 phase->C->dependencies()->assert_leaf_type(ik); 2244 } 2245 // Return precise klass 2246 return TypeKlassPtr::make(ik); 2247 } 2248 2249 // Return root of possible klass 2250 return TypeKlassPtr::make(TypePtr::NotNull, ik, Type::Offset(0)); 2251 } 2252 } 2253 2254 // Check for loading klass from an array 2255 const TypeAryPtr *tary = tp->isa_aryptr(); 2256 if (tary != NULL) { 2257 ciKlass *tary_klass = tary->klass(); 2258 if (tary_klass != NULL // can be NULL when at BOTTOM or TOP 2259 && tary->offset() == oopDesc::klass_offset_in_bytes()) { 2260 ciArrayKlass* ak = tary_klass->as_array_klass(); 2261 // Do not fold klass loads from [V? because the runtime type might be [V due to [V <: [V? 2262 bool can_be_null_free = !tary->is_known_instance() && ak->is_obj_array_klass() && !ak->storage_properties().is_null_free() && ak->element_klass()->is_valuetype(); 2263 2264 if (tary->klass_is_exact() && !can_be_null_free) { 2265 return TypeKlassPtr::make(tary_klass); 2266 } 2267 2268 // If the klass is an object array, we defer the question to the 2269 // array component klass. 2270 if (ak->is_obj_array_klass() && !can_be_null_free) { 2271 assert(ak->is_loaded(), ""); 2272 ciKlass *base_k = ak->as_obj_array_klass()->base_element_klass(); 2273 if (base_k->is_loaded() && base_k->is_instance_klass()) { 2274 ciInstanceKlass *ik = base_k->as_instance_klass(); 2275 // See if we can become precise: no subklasses and no interface 2276 if (!ik->is_interface() && !ik->has_subklass()) { 2277 //assert(!UseExactTypes, "this code should be useless with exact types"); 2278 // Add a dependence; if any subclass added we need to recompile 2279 if (!ik->is_final()) { 2280 phase->C->dependencies()->assert_leaf_type(ik); 2281 } 2282 // Return precise array klass 2283 return TypeKlassPtr::make(ak); 2284 } 2285 } 2286 return TypeKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0)); 2287 } else if (ak->is_type_array_klass()) { 2288 //assert(!UseExactTypes, "this code should be useless with exact types"); 2289 return TypeKlassPtr::make(ak); // These are always precise 2290 } 2291 } 2292 } 2293 2294 // Check for loading klass from an array klass 2295 const TypeKlassPtr *tkls = tp->isa_klassptr(); 2296 if (tkls != NULL && !StressReflectiveCode) { 2297 if (!tkls->is_loaded()) { 2298 return _type; // Bail out if not loaded 2299 } 2300 ciKlass* klass = tkls->klass(); 2301 if( klass->is_obj_array_klass() && 2302 tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) { 2303 ciKlass* elem = klass->as_obj_array_klass()->element_klass(); 2304 // // Always returning precise element type is incorrect, 2305 // // e.g., element type could be object and array may contain strings 2306 // return TypeKlassPtr::make(TypePtr::Constant, elem, 0); 2307 2308 // The array's TypeKlassPtr was declared 'precise' or 'not precise' 2309 // according to the element type's subclassing. 2310 return TypeKlassPtr::make(tkls->ptr(), elem, Type::Offset(0)); 2311 } else if (klass->is_value_array_klass() && 2312 tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) { 2313 ciKlass* elem = klass->as_value_array_klass()->element_klass(); 2314 return TypeKlassPtr::make(tkls->ptr(), elem, Type::Offset(0)); 2315 } 2316 if( klass->is_instance_klass() && tkls->klass_is_exact() && 2317 tkls->offset() == in_bytes(Klass::super_offset())) { 2318 ciKlass* sup = klass->as_instance_klass()->super(); 2319 // The field is Klass::_super. Return its (constant) value. 2320 // (Folds up the 2nd indirection in aClassConstant.getSuperClass().) 2321 return sup ? TypeKlassPtr::make(sup) : TypePtr::NULL_PTR; 2322 } 2323 } 2324 2325 // Bailout case 2326 return LoadNode::Value(phase); 2327 } 2328 2329 //------------------------------Identity--------------------------------------- 2330 // To clean up reflective code, simplify k.java_mirror.as_klass to plain k. 2331 // Also feed through the klass in Allocate(...klass...)._klass. 2332 Node* LoadKlassNode::Identity(PhaseGVN* phase) { 2333 return klass_identity_common(phase); |