< 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/regalloc.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"

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     // (Folds up the 2nd indirection in Reflection.getClassAccessFlags(aClassConstant).)
1985     assert(Opcode() == Op_LoadUS, "must load an unsigned short from _access_flags");
1986     return TypeInt::make(klass->access_flags());
1987   }
1988   if (tkls->offset() == in_bytes(Klass::misc_flags_offset())) {
1989     // The field is Klass::_misc_flags.  Return its (constant) value.
1990     // (Folds up the 2nd indirection in Reflection.getClassAccessFlags(aClassConstant).)
1991     assert(Opcode() == Op_LoadUB, "must load an unsigned byte from _misc_flags");
1992     return TypeInt::make(klass->misc_flags());
1993   }
1994   if (tkls->offset() == in_bytes(Klass::layout_helper_offset())) {
1995     // The field is Klass::_layout_helper.  Return its constant value if known.
1996     assert(Opcode() == Op_LoadI, "must load an int from _layout_helper");
1997     return TypeInt::make(klass->layout_helper());
1998   }
1999 
2000   // No match.

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


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

   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/regalloc.hpp"
  39 #include "opto/compile.hpp"
  40 #include "opto/connode.hpp"
  41 #include "opto/convertnode.hpp"
  42 #include "opto/loopnode.hpp"
  43 #include "opto/machnode.hpp"
  44 #include "opto/matcher.hpp"
  45 #include "opto/memnode.hpp"
  46 #include "opto/mempointer.hpp"
  47 #include "opto/mulnode.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     // (Folds up the 2nd indirection in Reflection.getClassAccessFlags(aClassConstant).)
1988     assert(Opcode() == Op_LoadUS, "must load an unsigned short from _access_flags");
1989     return TypeInt::make(klass->access_flags());
1990   }
1991   if (tkls->offset() == in_bytes(Klass::misc_flags_offset())) {
1992     // The field is Klass::_misc_flags.  Return its (constant) value.
1993     // (Folds up the 2nd indirection in Reflection.getClassAccessFlags(aClassConstant).)
1994     assert(Opcode() == Op_LoadUB, "must load an unsigned byte from _misc_flags");
1995     return TypeInt::make(klass->misc_flags());
1996   }
1997   if (tkls->offset() == in_bytes(Klass::layout_helper_offset())) {
1998     // The field is Klass::_layout_helper.  Return its constant value if known.
1999     assert(Opcode() == Op_LoadI, "must load an int from _layout_helper");
2000     return TypeInt::make(klass->layout_helper());
2001   }
2002 
2003   // No match.

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