1736 assert( off != Type::OffsetBot || 1737 // arrays can be cast to Objects 1738 tp->is_oopptr()->klass()->is_java_lang_Object() || 1739 // unsafe field access may not have a constant offset 1740 C->has_unsafe_access(), 1741 "Field accesses must be precise" ); 1742 // For oop loads, we expect the _type to be precise. 1743 1744 // Optimize loads from constant fields. 1745 const TypeInstPtr* tinst = tp->is_instptr(); 1746 ciObject* const_oop = tinst->const_oop(); 1747 if (!is_mismatched_access() && off != Type::OffsetBot && const_oop != NULL && const_oop->is_instance()) { 1748 const Type* con_type = Type::make_constant_from_field(const_oop->as_instance(), off, is_unsigned(), memory_type()); 1749 if (con_type != NULL) { 1750 return con_type; 1751 } 1752 } 1753 } else if (tp->base() == Type::KlassPtr) { 1754 assert( off != Type::OffsetBot || 1755 // arrays can be cast to Objects 1756 tp->is_klassptr()->klass()->is_java_lang_Object() || 1757 // also allow array-loading from the primary supertype 1758 // array during subtype checks 1759 Opcode() == Op_LoadKlass, 1760 "Field accesses must be precise" ); 1761 // For klass/static loads, we expect the _type to be precise 1762 } 1763 1764 const TypeKlassPtr *tkls = tp->isa_klassptr(); 1765 if (tkls != NULL && !StressReflectiveCode) { 1766 ciKlass* klass = tkls->klass(); 1767 if (klass->is_loaded() && tkls->klass_is_exact()) { 1768 // We are loading a field from a Klass metaobject whose identity 1769 // is known at compile time (the type is "exact" or "precise"). 1770 // Check for fields we know are maintained as constants by the VM. 1771 if (tkls->offset() == in_bytes(Klass::super_check_offset_offset())) { 1772 // The field is Klass::_super_check_offset. Return its (constant) value. 1773 // (Folds up type checking code.) 1774 assert(Opcode() == Op_LoadI, "must load an int from _super_check_offset"); 1775 return TypeInt::make(klass->super_check_offset()); 1776 } 1777 // Compute index into primary_supers array 1778 juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*); 1779 // Check for overflowing; use unsigned compare to handle the negative case. 1780 if( depth < ciKlass::primary_super_limit() ) { 1781 // The field is an element of Klass::_primary_supers. Return its (constant) value. 1782 // (Folds up type checking code.) 1783 assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers"); 1784 ciKlass *ss = klass->super_of_depth(depth); 1785 return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR; 1786 } 1787 const Type* aift = load_array_final_field(tkls, klass); 1788 if (aift != NULL) return aift; 1789 if (tkls->offset() == in_bytes(Klass::java_mirror_offset())) { 1790 // The field is Klass::_java_mirror. Return its (constant) value. 1791 // (Folds up the 2nd indirection in anObjConstant.getClass().) 1792 assert(Opcode() == Op_LoadP, "must load an oop from _java_mirror"); 1793 return TypeInstPtr::make(klass->java_mirror()); 1794 } 1795 } 1796 1797 // We can still check if we are loading from the primary_supers array at a 1798 // shallow enough depth. Even though the klass is not exact, entries less 1799 // than or equal to its super depth are correct. 1800 if (klass->is_loaded() ) { 1801 ciType *inner = klass; 1802 while( inner->is_obj_array_klass() ) 1803 inner = inner->as_obj_array_klass()->base_element_type(); 1804 if( inner->is_instance_klass() && 1805 !inner->as_instance_klass()->flags().is_interface() ) { 1806 // Compute index into primary_supers array 1807 juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*); 1808 // Check for overflowing; use unsigned compare to handle the negative case. 1809 if( depth < ciKlass::primary_super_limit() && 1810 depth <= klass->super_depth() ) { // allow self-depth checks to handle self-check case 1811 // The field is an element of Klass::_primary_supers. Return its (constant) value. 1812 // (Folds up type checking code.) 1813 assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers"); 1814 ciKlass *ss = klass->super_of_depth(depth); 1815 return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR; 1816 } 1817 } 1818 } 1819 1820 // If the type is enough to determine that the thing is not an array, 2111 // Add a dependence; if any subclass added we need to recompile 2112 if (!ik->is_final()) { 2113 phase->C->dependencies()->assert_leaf_type(ik); 2114 } 2115 // Return precise array klass 2116 return TypeKlassPtr::make(ak); 2117 } 2118 } 2119 return TypeKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0)); 2120 } else { // Found a type-array? 2121 //assert(!UseExactTypes, "this code should be useless with exact types"); 2122 assert( ak->is_type_array_klass(), "" ); 2123 return TypeKlassPtr::make(ak); // These are always precise 2124 } 2125 } 2126 } 2127 2128 // Check for loading klass from an array klass 2129 const TypeKlassPtr *tkls = tp->isa_klassptr(); 2130 if (tkls != NULL && !StressReflectiveCode) { 2131 ciKlass* klass = tkls->klass(); 2132 if( !klass->is_loaded() ) 2133 return _type; // Bail out if not loaded 2134 if( klass->is_obj_array_klass() && 2135 tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) { 2136 ciKlass* elem = klass->as_obj_array_klass()->element_klass(); 2137 // // Always returning precise element type is incorrect, 2138 // // e.g., element type could be object and array may contain strings 2139 // return TypeKlassPtr::make(TypePtr::Constant, elem, 0); 2140 2141 // The array's TypeKlassPtr was declared 'precise' or 'not precise' 2142 // according to the element type's subclassing. 2143 return TypeKlassPtr::make(tkls->ptr(), elem, Type::Offset(0)); 2144 } 2145 if( klass->is_instance_klass() && tkls->klass_is_exact() && 2146 tkls->offset() == in_bytes(Klass::super_offset())) { 2147 ciKlass* sup = klass->as_instance_klass()->super(); 2148 // The field is Klass::_super. Return its (constant) value. 2149 // (Folds up the 2nd indirection in aClassConstant.getSuperClass().) 2150 return sup ? TypeKlassPtr::make(sup) : TypePtr::NULL_PTR; 2151 } 2152 } 2153 | 1736 assert( off != Type::OffsetBot || 1737 // arrays can be cast to Objects 1738 tp->is_oopptr()->klass()->is_java_lang_Object() || 1739 // unsafe field access may not have a constant offset 1740 C->has_unsafe_access(), 1741 "Field accesses must be precise" ); 1742 // For oop loads, we expect the _type to be precise. 1743 1744 // Optimize loads from constant fields. 1745 const TypeInstPtr* tinst = tp->is_instptr(); 1746 ciObject* const_oop = tinst->const_oop(); 1747 if (!is_mismatched_access() && off != Type::OffsetBot && const_oop != NULL && const_oop->is_instance()) { 1748 const Type* con_type = Type::make_constant_from_field(const_oop->as_instance(), off, is_unsigned(), memory_type()); 1749 if (con_type != NULL) { 1750 return con_type; 1751 } 1752 } 1753 } else if (tp->base() == Type::KlassPtr) { 1754 assert( off != Type::OffsetBot || 1755 // arrays can be cast to Objects 1756 tp->is_klassptr()->klass() == NULL || 1757 tp->is_klassptr()->klass()->is_java_lang_Object() || 1758 // also allow array-loading from the primary supertype 1759 // array during subtype checks 1760 Opcode() == Op_LoadKlass, 1761 "Field accesses must be precise" ); 1762 // For klass/static loads, we expect the _type to be precise 1763 } 1764 1765 const TypeKlassPtr *tkls = tp->isa_klassptr(); 1766 if (tkls != NULL && !StressReflectiveCode) { 1767 ciKlass* klass = tkls->klass(); 1768 if (tkls->is_loaded() && tkls->klass_is_exact()) { 1769 // We are loading a field from a Klass metaobject whose identity 1770 // is known at compile time (the type is "exact" or "precise"). 1771 // Check for fields we know are maintained as constants by the VM. 1772 if (tkls->offset() == in_bytes(Klass::super_check_offset_offset())) { 1773 // The field is Klass::_super_check_offset. Return its (constant) value. 1774 // (Folds up type checking code.) 1775 assert(Opcode() == Op_LoadI, "must load an int from _super_check_offset"); 1776 return TypeInt::make(klass->super_check_offset()); 1777 } 1778 // Compute index into primary_supers array 1779 juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*); 1780 // Check for overflowing; use unsigned compare to handle the negative case. 1781 if( depth < ciKlass::primary_super_limit() ) { 1782 // The field is an element of Klass::_primary_supers. Return its (constant) value. 1783 // (Folds up type checking code.) 1784 assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers"); 1785 ciKlass *ss = klass->super_of_depth(depth); 1786 return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR; 1787 } 1788 const Type* aift = load_array_final_field(tkls, klass); 1789 if (aift != NULL) return aift; 1790 if (tkls->offset() == in_bytes(Klass::java_mirror_offset())) { 1791 // The field is Klass::_java_mirror. Return its (constant) value. 1792 // (Folds up the 2nd indirection in anObjConstant.getClass().) 1793 assert(Opcode() == Op_LoadP, "must load an oop from _java_mirror"); 1794 return TypeInstPtr::make(klass->java_mirror()); 1795 } 1796 } 1797 1798 // We can still check if we are loading from the primary_supers array at a 1799 // shallow enough depth. Even though the klass is not exact, entries less 1800 // than or equal to its super depth are correct. 1801 if (tkls->is_loaded()) { 1802 ciType *inner = klass; 1803 while( inner->is_obj_array_klass() ) 1804 inner = inner->as_obj_array_klass()->base_element_type(); 1805 if( inner->is_instance_klass() && 1806 !inner->as_instance_klass()->flags().is_interface() ) { 1807 // Compute index into primary_supers array 1808 juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*); 1809 // Check for overflowing; use unsigned compare to handle the negative case. 1810 if( depth < ciKlass::primary_super_limit() && 1811 depth <= klass->super_depth() ) { // allow self-depth checks to handle self-check case 1812 // The field is an element of Klass::_primary_supers. Return its (constant) value. 1813 // (Folds up type checking code.) 1814 assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers"); 1815 ciKlass *ss = klass->super_of_depth(depth); 1816 return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR; 1817 } 1818 } 1819 } 1820 1821 // If the type is enough to determine that the thing is not an array, 2112 // Add a dependence; if any subclass added we need to recompile 2113 if (!ik->is_final()) { 2114 phase->C->dependencies()->assert_leaf_type(ik); 2115 } 2116 // Return precise array klass 2117 return TypeKlassPtr::make(ak); 2118 } 2119 } 2120 return TypeKlassPtr::make(TypePtr::NotNull, ak, Type::Offset(0)); 2121 } else { // Found a type-array? 2122 //assert(!UseExactTypes, "this code should be useless with exact types"); 2123 assert( ak->is_type_array_klass(), "" ); 2124 return TypeKlassPtr::make(ak); // These are always precise 2125 } 2126 } 2127 } 2128 2129 // Check for loading klass from an array klass 2130 const TypeKlassPtr *tkls = tp->isa_klassptr(); 2131 if (tkls != NULL && !StressReflectiveCode) { 2132 if (!tkls->is_loaded()) { 2133 return _type; // Bail out if not loaded 2134 } 2135 ciKlass* klass = tkls->klass(); 2136 if( klass->is_obj_array_klass() && 2137 tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) { 2138 ciKlass* elem = klass->as_obj_array_klass()->element_klass(); 2139 // // Always returning precise element type is incorrect, 2140 // // e.g., element type could be object and array may contain strings 2141 // return TypeKlassPtr::make(TypePtr::Constant, elem, 0); 2142 2143 // The array's TypeKlassPtr was declared 'precise' or 'not precise' 2144 // according to the element type's subclassing. 2145 return TypeKlassPtr::make(tkls->ptr(), elem, Type::Offset(0)); 2146 } 2147 if( klass->is_instance_klass() && tkls->klass_is_exact() && 2148 tkls->offset() == in_bytes(Klass::super_offset())) { 2149 ciKlass* sup = klass->as_instance_klass()->super(); 2150 // The field is Klass::_super. Return its (constant) value. 2151 // (Folds up the 2nd indirection in aClassConstant.getSuperClass().) 2152 return sup ? TypeKlassPtr::make(sup) : TypePtr::NULL_PTR; 2153 } 2154 } 2155 |