< 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 
1983   if (tkls->isa_instklassptr() && tkls->offset() == in_bytes(InstanceKlass::access_flags_offset())) {
1984     // The field is InstanceKlass::_access_flags.  Return its (constant) value.
1985     assert(Opcode() == Op_LoadUS, "must load an unsigned short from _access_flags");
1986     ciInstanceKlass* iklass = tkls->is_instklassptr()->instance_klass();
1987     return TypeInt::make(iklass->access_flags());
1988   }
1989   if (tkls->offset() == in_bytes(Klass::misc_flags_offset())) {
1990     // The field is Klass::_misc_flags.  Return its (constant) value.
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.

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


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

   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 
1986   if (tkls->isa_instklassptr() && tkls->offset() == in_bytes(InstanceKlass::access_flags_offset())) {
1987     // The field is InstanceKlass::_access_flags.  Return its (constant) value.
1988     assert(Opcode() == Op_LoadUS, "must load an unsigned short from _access_flags");
1989     ciInstanceKlass* iklass = tkls->is_instklassptr()->instance_klass();
1990     return TypeInt::make(iklass->access_flags());
1991   }
1992   if (tkls->offset() == in_bytes(Klass::misc_flags_offset())) {
1993     // The field is Klass::_misc_flags.  Return its (constant) value.
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.

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