< prev index next >

src/hotspot/share/opto/memnode.cpp

Print this page

   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "classfile/javaClasses.hpp"

  27 #include "compiler/compileLog.hpp"
  28 #include "gc/shared/barrierSet.hpp"
  29 #include "gc/shared/c2/barrierSetC2.hpp"
  30 #include "gc/shared/tlab_globals.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "oops/objArrayKlass.hpp"
  34 #include "opto/addnode.hpp"
  35 #include "opto/arraycopynode.hpp"
  36 #include "opto/cfgnode.hpp"
  37 #include "opto/compile.hpp"
  38 #include "opto/connode.hpp"
  39 #include "opto/convertnode.hpp"
  40 #include "opto/loopnode.hpp"
  41 #include "opto/machnode.hpp"
  42 #include "opto/matcher.hpp"
  43 #include "opto/memnode.hpp"
  44 #include "opto/mempointer.hpp"
  45 #include "opto/mulnode.hpp"
  46 #include "opto/narrowptrnode.hpp"

1960   // Steps (a), (b):  Walk past independent stores to find an exact match.
1961   if (prev_mem != nullptr && prev_mem != in(MemNode::Memory)) {
1962     // (c) See if we can fold up on the spot, but don't fold up here.
1963     // Fold-up might require truncation (for LoadB/LoadS/LoadUS) or
1964     // just return a prior value, which is done by Identity calls.
1965     if (can_see_stored_value(prev_mem, phase)) {
1966       // Make ready for step (d):
1967       set_req_X(MemNode::Memory, prev_mem, phase);
1968       return this;
1969     }
1970   }
1971 
1972   return progress ? this : nullptr;
1973 }
1974 
1975 // Helper to recognize certain Klass fields which are invariant across
1976 // some group of array types (e.g., int[] or all T[] where T < Object).
1977 const Type*
1978 LoadNode::load_array_final_field(const TypeKlassPtr *tkls,
1979                                  ciKlass* klass) const {
1980   assert(!UseCompactObjectHeaders || tkls->offset() != in_bytes(Klass::prototype_header_offset()),


1981          "must not happen");
1982   if (tkls->offset() == in_bytes(Klass::access_flags_offset())) {
1983     // The field is Klass::_access_flags.  Return its (constant) value.
1984     assert(Opcode() == Op_LoadUS, "must load an unsigned short from _access_flags");
1985     return TypeInt::make(klass->access_flags());
1986   }
1987   if (tkls->offset() == in_bytes(Klass::misc_flags_offset())) {
1988     // The field is Klass::_misc_flags.  Return its (constant) value.
1989     assert(Opcode() == Op_LoadUB, "must load an unsigned byte from _misc_flags");
1990     return TypeInt::make(klass->misc_flags());
1991   }
1992   if (tkls->offset() == in_bytes(Klass::layout_helper_offset())) {
1993     // The field is Klass::_layout_helper.  Return its constant value if known.
1994     assert(Opcode() == Op_LoadI, "must load an int from _layout_helper");
1995     return TypeInt::make(klass->layout_helper());
1996   }
1997 
1998   // No match.
1999   return nullptr;
2000 }

2143         assert(adr->Opcode() == Op_LoadP, "must load an oop from _java_mirror");
2144         assert(Opcode() == Op_LoadP, "must load an oop from _java_mirror");
2145         return TypeInstPtr::make(klass->java_mirror());
2146       }
2147     }
2148   }
2149 
2150   const TypeKlassPtr *tkls = tp->isa_klassptr();
2151   if (tkls != nullptr) {
2152     if (tkls->is_loaded() && tkls->klass_is_exact()) {
2153       ciKlass* klass = tkls->exact_klass();
2154       // We are loading a field from a Klass metaobject whose identity
2155       // is known at compile time (the type is "exact" or "precise").
2156       // Check for fields we know are maintained as constants by the VM.
2157       if (tkls->offset() == in_bytes(Klass::super_check_offset_offset())) {
2158         // The field is Klass::_super_check_offset.  Return its (constant) value.
2159         // (Folds up type checking code.)
2160         assert(Opcode() == Op_LoadI, "must load an int from _super_check_offset");
2161         return TypeInt::make(klass->super_check_offset());
2162       }
2163       if (UseCompactObjectHeaders) {


2164         if (tkls->offset() == in_bytes(Klass::prototype_header_offset())) {
2165           // The field is Klass::_prototype_header. Return its (constant) value.
2166           assert(this->Opcode() == Op_LoadX, "must load a proper type from _prototype_header");
2167           return TypeX::make(klass->prototype_header());
2168         }
2169       }
2170       // Compute index into primary_supers array
2171       juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*);
2172       // Check for overflowing; use unsigned compare to handle the negative case.
2173       if( depth < ciKlass::primary_super_limit() ) {
2174         // The field is an element of Klass::_primary_supers.  Return its (constant) value.
2175         // (Folds up type checking code.)
2176         assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers");
2177         ciKlass *ss = klass->super_of_depth(depth);
2178         return ss ? TypeKlassPtr::make(ss, Type::trust_interfaces) : TypePtr::NULL_PTR;
2179       }
2180       const Type* aift = load_array_final_field(tkls, klass);
2181       if (aift != nullptr)  return aift;
2182     }
2183 

   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "classfile/javaClasses.hpp"
  27 #include "code/aotCodeCache.hpp"
  28 #include "compiler/compileLog.hpp"
  29 #include "gc/shared/barrierSet.hpp"
  30 #include "gc/shared/c2/barrierSetC2.hpp"
  31 #include "gc/shared/tlab_globals.hpp"
  32 #include "memory/allocation.inline.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "oops/objArrayKlass.hpp"
  35 #include "opto/addnode.hpp"
  36 #include "opto/arraycopynode.hpp"
  37 #include "opto/cfgnode.hpp"
  38 #include "opto/compile.hpp"
  39 #include "opto/connode.hpp"
  40 #include "opto/convertnode.hpp"
  41 #include "opto/loopnode.hpp"
  42 #include "opto/machnode.hpp"
  43 #include "opto/matcher.hpp"
  44 #include "opto/memnode.hpp"
  45 #include "opto/mempointer.hpp"
  46 #include "opto/mulnode.hpp"
  47 #include "opto/narrowptrnode.hpp"

1961   // Steps (a), (b):  Walk past independent stores to find an exact match.
1962   if (prev_mem != nullptr && prev_mem != in(MemNode::Memory)) {
1963     // (c) See if we can fold up on the spot, but don't fold up here.
1964     // Fold-up might require truncation (for LoadB/LoadS/LoadUS) or
1965     // just return a prior value, which is done by Identity calls.
1966     if (can_see_stored_value(prev_mem, phase)) {
1967       // Make ready for step (d):
1968       set_req_X(MemNode::Memory, prev_mem, phase);
1969       return this;
1970     }
1971   }
1972 
1973   return progress ? this : nullptr;
1974 }
1975 
1976 // Helper to recognize certain Klass fields which are invariant across
1977 // some group of array types (e.g., int[] or all T[] where T < Object).
1978 const Type*
1979 LoadNode::load_array_final_field(const TypeKlassPtr *tkls,
1980                                  ciKlass* klass) const {
1981   assert(!UseCompactObjectHeaders ||
1982          AOTCodeCache::is_on_for_dump() ||
1983          tkls->offset() != in_bytes(Klass::prototype_header_offset()),
1984          "must not happen");
1985   if (tkls->offset() == in_bytes(Klass::access_flags_offset())) {
1986     // The field is Klass::_access_flags.  Return its (constant) value.
1987     assert(Opcode() == Op_LoadUS, "must load an unsigned short from _access_flags");
1988     return TypeInt::make(klass->access_flags());
1989   }
1990   if (tkls->offset() == in_bytes(Klass::misc_flags_offset())) {
1991     // The field is Klass::_misc_flags.  Return its (constant) value.
1992     assert(Opcode() == Op_LoadUB, "must load an unsigned byte from _misc_flags");
1993     return TypeInt::make(klass->misc_flags());
1994   }
1995   if (tkls->offset() == in_bytes(Klass::layout_helper_offset())) {
1996     // The field is Klass::_layout_helper.  Return its constant value if known.
1997     assert(Opcode() == Op_LoadI, "must load an int from _layout_helper");
1998     return TypeInt::make(klass->layout_helper());
1999   }
2000 
2001   // No match.
2002   return nullptr;
2003 }

2146         assert(adr->Opcode() == Op_LoadP, "must load an oop from _java_mirror");
2147         assert(Opcode() == Op_LoadP, "must load an oop from _java_mirror");
2148         return TypeInstPtr::make(klass->java_mirror());
2149       }
2150     }
2151   }
2152 
2153   const TypeKlassPtr *tkls = tp->isa_klassptr();
2154   if (tkls != nullptr) {
2155     if (tkls->is_loaded() && tkls->klass_is_exact()) {
2156       ciKlass* klass = tkls->exact_klass();
2157       // We are loading a field from a Klass metaobject whose identity
2158       // is known at compile time (the type is "exact" or "precise").
2159       // Check for fields we know are maintained as constants by the VM.
2160       if (tkls->offset() == in_bytes(Klass::super_check_offset_offset())) {
2161         // The field is Klass::_super_check_offset.  Return its (constant) value.
2162         // (Folds up type checking code.)
2163         assert(Opcode() == Op_LoadI, "must load an int from _super_check_offset");
2164         return TypeInt::make(klass->super_check_offset());
2165       }
2166       // Class encoding in prototype header may change between runs.
2167       // Force loading prototype header when AOT code is generated.
2168       if (UseCompactObjectHeaders && !AOTCodeCache::is_on_for_dump()) {
2169         if (tkls->offset() == in_bytes(Klass::prototype_header_offset())) {
2170           // The field is Klass::_prototype_header. Return its (constant) value.
2171           assert(this->Opcode() == Op_LoadX, "must load a proper type from _prototype_header");
2172           return TypeX::make(klass->prototype_header());
2173         }
2174       }
2175       // Compute index into primary_supers array
2176       juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*);
2177       // Check for overflowing; use unsigned compare to handle the negative case.
2178       if( depth < ciKlass::primary_super_limit() ) {
2179         // The field is an element of Klass::_primary_supers.  Return its (constant) value.
2180         // (Folds up type checking code.)
2181         assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers");
2182         ciKlass *ss = klass->super_of_depth(depth);
2183         return ss ? TypeKlassPtr::make(ss, Type::trust_interfaces) : TypePtr::NULL_PTR;
2184       }
2185       const Type* aift = load_array_final_field(tkls, klass);
2186       if (aift != nullptr)  return aift;
2187     }
2188 
< prev index next >