< 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"

2006     // just return a prior value, which is done by Identity calls.
2007     if (can_see_stored_value(prev_mem, phase)) {
2008       // Make ready for step (d):
2009       set_req_X(MemNode::Memory, prev_mem, phase);
2010       return this;
2011     }
2012   }
2013 
2014   if (!can_reshape) {
2015     phase->record_for_igvn(this);
2016   }
2017 
2018   return nullptr;
2019 }
2020 
2021 // Helper to recognize certain Klass fields which are invariant across
2022 // some group of array types (e.g., int[] or all T[] where T < Object).
2023 const Type*
2024 LoadNode::load_array_final_field(const TypeKlassPtr *tkls,
2025                                  ciKlass* klass) const {
2026   assert(!UseCompactObjectHeaders || tkls->offset() != in_bytes(Klass::prototype_header_offset()),


2027          "must not happen");
2028 
2029   if (tkls->isa_instklassptr() && tkls->offset() == in_bytes(InstanceKlass::access_flags_offset())) {
2030     // The field is InstanceKlass::_access_flags.  Return its (constant) value.
2031     assert(Opcode() == Op_LoadUS, "must load an unsigned short from _access_flags");
2032     ciInstanceKlass* iklass = tkls->is_instklassptr()->instance_klass();
2033     return TypeInt::make(iklass->access_flags());
2034   }
2035   if (tkls->offset() == in_bytes(Klass::misc_flags_offset())) {
2036     // The field is Klass::_misc_flags.  Return its (constant) value.
2037     assert(Opcode() == Op_LoadUB, "must load an unsigned byte from _misc_flags");
2038     return TypeInt::make(klass->misc_flags());
2039   }
2040   if (tkls->offset() == in_bytes(Klass::layout_helper_offset())) {
2041     // The field is Klass::_layout_helper.  Return its constant value if known.
2042     assert(Opcode() == Op_LoadI, "must load an int from _layout_helper");
2043     return TypeInt::make(klass->layout_helper());
2044   }
2045 
2046   // No match.

2187         assert(adr->Opcode() == Op_LoadP, "must load an oop from _java_mirror");
2188         assert(Opcode() == Op_LoadP, "must load an oop from _java_mirror");
2189         return TypeInstPtr::make(klass->java_mirror());
2190       }
2191     }
2192   }
2193 
2194   const TypeKlassPtr *tkls = tp->isa_klassptr();
2195   if (tkls != nullptr) {
2196     if (tkls->is_loaded() && tkls->klass_is_exact()) {
2197       ciKlass* klass = tkls->exact_klass();
2198       // We are loading a field from a Klass metaobject whose identity
2199       // is known at compile time (the type is "exact" or "precise").
2200       // Check for fields we know are maintained as constants by the VM.
2201       if (tkls->offset() == in_bytes(Klass::super_check_offset_offset())) {
2202         // The field is Klass::_super_check_offset.  Return its (constant) value.
2203         // (Folds up type checking code.)
2204         assert(Opcode() == Op_LoadI, "must load an int from _super_check_offset");
2205         return TypeInt::make(klass->super_check_offset());
2206       }
2207       if (UseCompactObjectHeaders) {


2208         if (tkls->offset() == in_bytes(Klass::prototype_header_offset())) {
2209           // The field is Klass::_prototype_header. Return its (constant) value.
2210           assert(this->Opcode() == Op_LoadX, "must load a proper type from _prototype_header");
2211           return TypeX::make(klass->prototype_header());
2212         }
2213       }
2214       // Compute index into primary_supers array
2215       juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*);
2216       // Check for overflowing; use unsigned compare to handle the negative case.
2217       if( depth < ciKlass::primary_super_limit() ) {
2218         // The field is an element of Klass::_primary_supers.  Return its (constant) value.
2219         // (Folds up type checking code.)
2220         assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers");
2221         ciKlass *ss = klass->super_of_depth(depth);
2222         return ss ? TypeKlassPtr::make(ss, Type::trust_interfaces) : TypePtr::NULL_PTR;
2223       }
2224       const Type* aift = load_array_final_field(tkls, klass);
2225       if (aift != nullptr)  return aift;
2226     }
2227 

   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"

2007     // just return a prior value, which is done by Identity calls.
2008     if (can_see_stored_value(prev_mem, phase)) {
2009       // Make ready for step (d):
2010       set_req_X(MemNode::Memory, prev_mem, phase);
2011       return this;
2012     }
2013   }
2014 
2015   if (!can_reshape) {
2016     phase->record_for_igvn(this);
2017   }
2018 
2019   return nullptr;
2020 }
2021 
2022 // Helper to recognize certain Klass fields which are invariant across
2023 // some group of array types (e.g., int[] or all T[] where T < Object).
2024 const Type*
2025 LoadNode::load_array_final_field(const TypeKlassPtr *tkls,
2026                                  ciKlass* klass) const {
2027   assert(!UseCompactObjectHeaders ||
2028          AOTCodeCache::is_on_for_dump() ||
2029          tkls->offset() != in_bytes(Klass::prototype_header_offset()),
2030          "must not happen");
2031 
2032   if (tkls->isa_instklassptr() && tkls->offset() == in_bytes(InstanceKlass::access_flags_offset())) {
2033     // The field is InstanceKlass::_access_flags.  Return its (constant) value.
2034     assert(Opcode() == Op_LoadUS, "must load an unsigned short from _access_flags");
2035     ciInstanceKlass* iklass = tkls->is_instklassptr()->instance_klass();
2036     return TypeInt::make(iklass->access_flags());
2037   }
2038   if (tkls->offset() == in_bytes(Klass::misc_flags_offset())) {
2039     // The field is Klass::_misc_flags.  Return its (constant) value.
2040     assert(Opcode() == Op_LoadUB, "must load an unsigned byte from _misc_flags");
2041     return TypeInt::make(klass->misc_flags());
2042   }
2043   if (tkls->offset() == in_bytes(Klass::layout_helper_offset())) {
2044     // The field is Klass::_layout_helper.  Return its constant value if known.
2045     assert(Opcode() == Op_LoadI, "must load an int from _layout_helper");
2046     return TypeInt::make(klass->layout_helper());
2047   }
2048 
2049   // No match.

2190         assert(adr->Opcode() == Op_LoadP, "must load an oop from _java_mirror");
2191         assert(Opcode() == Op_LoadP, "must load an oop from _java_mirror");
2192         return TypeInstPtr::make(klass->java_mirror());
2193       }
2194     }
2195   }
2196 
2197   const TypeKlassPtr *tkls = tp->isa_klassptr();
2198   if (tkls != nullptr) {
2199     if (tkls->is_loaded() && tkls->klass_is_exact()) {
2200       ciKlass* klass = tkls->exact_klass();
2201       // We are loading a field from a Klass metaobject whose identity
2202       // is known at compile time (the type is "exact" or "precise").
2203       // Check for fields we know are maintained as constants by the VM.
2204       if (tkls->offset() == in_bytes(Klass::super_check_offset_offset())) {
2205         // The field is Klass::_super_check_offset.  Return its (constant) value.
2206         // (Folds up type checking code.)
2207         assert(Opcode() == Op_LoadI, "must load an int from _super_check_offset");
2208         return TypeInt::make(klass->super_check_offset());
2209       }
2210       // Class encoding in prototype header may change between runs.
2211       // Force loading prototype header when AOT code is generated.
2212       if (UseCompactObjectHeaders && !AOTCodeCache::is_on_for_dump()) {
2213         if (tkls->offset() == in_bytes(Klass::prototype_header_offset())) {
2214           // The field is Klass::_prototype_header. Return its (constant) value.
2215           assert(this->Opcode() == Op_LoadX, "must load a proper type from _prototype_header");
2216           return TypeX::make(klass->prototype_header());
2217         }
2218       }
2219       // Compute index into primary_supers array
2220       juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*);
2221       // Check for overflowing; use unsigned compare to handle the negative case.
2222       if( depth < ciKlass::primary_super_limit() ) {
2223         // The field is an element of Klass::_primary_supers.  Return its (constant) value.
2224         // (Folds up type checking code.)
2225         assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers");
2226         ciKlass *ss = klass->super_of_depth(depth);
2227         return ss ? TypeKlassPtr::make(ss, Type::trust_interfaces) : TypePtr::NULL_PTR;
2228       }
2229       const Type* aift = load_array_final_field(tkls, klass);
2230       if (aift != nullptr)  return aift;
2231     }
2232 
< prev index next >