src/share/vm/opto/memnode.hpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 8856
ac27a9c85bea
child 9041
95a08233f46c
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #ifndef SHARE_VM_OPTO_MEMNODE_HPP
    26 #define SHARE_VM_OPTO_MEMNODE_HPP
    28 #include "opto/multnode.hpp"
    29 #include "opto/node.hpp"
    30 #include "opto/opcodes.hpp"
    31 #include "opto/type.hpp"
    33 // Portions of code courtesy of Clifford Click
    35 class MultiNode;
    36 class PhaseCCP;
    37 class PhaseTransform;
    39 //------------------------------MemNode----------------------------------------
    40 // Load or Store, possibly throwing a NULL pointer exception
    41 class MemNode : public Node {
    42 private:
    43   bool _unaligned_access; // Unaligned access from unsafe
    44   bool _mismatched_access; // Mismatched access from unsafe: byte read in integer array for instance
    45 protected:
    46 #ifdef ASSERT
    47   const TypePtr* _adr_type;     // What kind of memory is being addressed?
    48 #endif
    49   virtual uint size_of() const;
    50 public:
    51   enum { Control,               // When is it safe to do this load?
    52          Memory,                // Chunk of memory is being loaded from
    53          Address,               // Actually address, derived from base
    54          ValueIn,               // Value to store
    55          OopStore               // Preceeding oop store, only in StoreCM
    56   };
    57   typedef enum { unordered = 0,
    58                  acquire,       // Load has to acquire or be succeeded by MemBarAcquire.
    59                  release        // Store has to release or be preceded by MemBarRelease.
    60   } MemOrd;
    61 protected:
    62   MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at )
    63     : Node(c0,c1,c2   ), _unaligned_access(false), _mismatched_access(false) {
    64     init_class_id(Class_Mem);
    65     debug_only(_adr_type=at; adr_type();)
    66   }
    67   MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3 )
    68     : Node(c0,c1,c2,c3), _unaligned_access(false), _mismatched_access(false) {
    69     init_class_id(Class_Mem);
    70     debug_only(_adr_type=at; adr_type();)
    71   }
    72   MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3, Node *c4)
    73     : Node(c0,c1,c2,c3,c4), _unaligned_access(false), _mismatched_access(false) {
    74     init_class_id(Class_Mem);
    75     debug_only(_adr_type=at; adr_type();)
    76   }
    78 public:
    79   // Helpers for the optimizer.  Documented in memnode.cpp.
    80   static bool detect_ptr_independence(Node* p1, AllocateNode* a1,
    81                                       Node* p2, AllocateNode* a2,
    82                                       PhaseTransform* phase);
    83   static bool adr_phi_is_loop_invariant(Node* adr_phi, Node* cast);
    85   static Node *optimize_simple_memory_chain(Node *mchain, const TypeOopPtr *t_oop, Node *load, PhaseGVN *phase);
    86   static Node *optimize_memory_chain(Node *mchain, const TypePtr *t_adr, Node *load, PhaseGVN *phase);
    87   // This one should probably be a phase-specific function:
    88   static bool all_controls_dominate(Node* dom, Node* sub);
    90   // Find any cast-away of null-ness and keep its control.
    91   static  Node *Ideal_common_DU_postCCP( PhaseCCP *ccp, Node* n, Node* adr );
    92   virtual Node *Ideal_DU_postCCP( PhaseCCP *ccp );
    94   virtual const class TypePtr *adr_type() const;  // returns bottom_type of address
    96   // Shared code for Ideal methods:
    97   Node *Ideal_common(PhaseGVN *phase, bool can_reshape);  // Return -1 for short-circuit NULL.
    99   // Helper function for adr_type() implementations.
   100   static const TypePtr* calculate_adr_type(const Type* t, const TypePtr* cross_check = NULL);
   102   // Raw access function, to allow copying of adr_type efficiently in
   103   // product builds and retain the debug info for debug builds.
   104   const TypePtr *raw_adr_type() const {
   105 #ifdef ASSERT
   106     return _adr_type;
   107 #else
   108     return 0;
   109 #endif
   110   }
   112   // Map a load or store opcode to its corresponding store opcode.
   113   // (Return -1 if unknown.)
   114   virtual int store_Opcode() const { return -1; }
   116   // What is the type of the value in memory?  (T_VOID mean "unspecified".)
   117   virtual BasicType memory_type() const = 0;
   118   virtual int memory_size() const {
   119 #ifdef ASSERT
   120     return type2aelembytes(memory_type(), true);
   121 #else
   122     return type2aelembytes(memory_type());
   123 #endif
   124   }
   126   // Search through memory states which precede this node (load or store).
   127   // Look for an exact match for the address, with no intervening
   128   // aliased stores.
   129   Node* find_previous_store(PhaseTransform* phase);
   131   // Can this node (load or store) accurately see a stored value in
   132   // the given memory state?  (The state may or may not be in(Memory).)
   133   Node* can_see_stored_value(Node* st, PhaseTransform* phase) const;
   135   void set_unaligned_access() { _unaligned_access = true; }
   136   bool is_unaligned_access() const { return _unaligned_access; }
   137   void set_mismatched_access() { _mismatched_access = true; }
   138   bool is_mismatched_access() const { return _mismatched_access; }
   140 #ifndef PRODUCT
   141   static void dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st);
   142   virtual void dump_spec(outputStream *st) const;
   143 #endif
   144 };
   146 //------------------------------LoadNode---------------------------------------
   147 // Load value; requires Memory and Address
   148 class LoadNode : public MemNode {
   149 public:
   150   // Some loads (from unsafe) should be pinned: they don't depend only
   151   // on the dominating test.  The boolean field _depends_only_on_test
   152   // below records whether that node depends only on the dominating
   153   // test.
   154   // Methods used to build LoadNodes pass an argument of type enum
   155   // ControlDependency instead of a boolean because those methods
   156   // typically have multiple boolean parameters with default values:
   157   // passing the wrong boolean to one of these parameters by mistake
   158   // goes easily unnoticed. Using an enum, the compiler can check that
   159   // the type of a value and the type of the parameter match.
   160   enum ControlDependency {
   161     Pinned,
   162     DependsOnlyOnTest
   163   };
   164 private:
   165   // LoadNode::hash() doesn't take the _depends_only_on_test field
   166   // into account: If the graph already has a non-pinned LoadNode and
   167   // we add a pinned LoadNode with the same inputs, it's safe for GVN
   168   // to replace the pinned LoadNode with the non-pinned LoadNode,
   169   // otherwise it wouldn't be safe to have a non pinned LoadNode with
   170   // those inputs in the first place. If the graph already has a
   171   // pinned LoadNode and we add a non pinned LoadNode with the same
   172   // inputs, it's safe (but suboptimal) for GVN to replace the
   173   // non-pinned LoadNode by the pinned LoadNode.
   174   bool _depends_only_on_test;
   176   // On platforms with weak memory ordering (e.g., PPC, Ia64) we distinguish
   177   // loads that can be reordered, and such requiring acquire semantics to
   178   // adhere to the Java specification.  The required behaviour is stored in
   179   // this field.
   180   const MemOrd _mo;
   182 protected:
   183   virtual uint cmp(const Node &n) const;
   184   virtual uint size_of() const; // Size is bigger
   185   // Should LoadNode::Ideal() attempt to remove control edges?
   186   virtual bool can_remove_control() const;
   187   const Type* const _type;      // What kind of value is loaded?
   188 public:
   190   LoadNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *rt, MemOrd mo, ControlDependency control_dependency)
   191     : MemNode(c,mem,adr,at), _type(rt), _mo(mo), _depends_only_on_test(control_dependency == DependsOnlyOnTest) {
   192     init_class_id(Class_Load);
   193   }
   194   inline bool is_unordered() const { return !is_acquire(); }
   195   inline bool is_acquire() const {
   196     assert(_mo == unordered || _mo == acquire, "unexpected");
   197     return _mo == acquire;
   198   }
   200   // Polymorphic factory method:
   201    static Node* make(PhaseGVN& gvn, Node *c, Node *mem, Node *adr,
   202                      const TypePtr* at, const Type *rt, BasicType bt,
   203                      MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest);
   205   virtual uint hash()   const;  // Check the type
   207   // Handle algebraic identities here.  If we have an identity, return the Node
   208   // we are equivalent to.  We look for Load of a Store.
   209   virtual Node *Identity( PhaseTransform *phase );
   211   // If the load is from Field memory and the pointer is non-null, it might be possible to
   212   // zero out the control input.
   213   // If the offset is constant and the base is an object allocation,
   214   // try to hook me up to the exact initializing store.
   215   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   217   // Split instance field load through Phi.
   218   Node* split_through_phi(PhaseGVN *phase);
   220   // Recover original value from boxed values
   221   Node *eliminate_autobox(PhaseGVN *phase);
   223   // Compute a new Type for this node.  Basically we just do the pre-check,
   224   // then call the virtual add() to set the type.
   225   virtual const Type *Value( PhaseTransform *phase ) const;
   227   // Common methods for LoadKlass and LoadNKlass nodes.
   228   const Type *klass_value_common( PhaseTransform *phase ) const;
   229   Node *klass_identity_common( PhaseTransform *phase );
   231   virtual uint ideal_reg() const;
   232   virtual const Type *bottom_type() const;
   233   // Following method is copied from TypeNode:
   234   void set_type(const Type* t) {
   235     assert(t != NULL, "sanity");
   236     debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH);
   237     *(const Type**)&_type = t;   // cast away const-ness
   238     // If this node is in the hash table, make sure it doesn't need a rehash.
   239     assert(check_hash == NO_HASH || check_hash == hash(), "type change must preserve hash code");
   240   }
   241   const Type* type() const { assert(_type != NULL, "sanity"); return _type; };
   243   // Do not match memory edge
   244   virtual uint match_edge(uint idx) const;
   246   // Map a load opcode to its corresponding store opcode.
   247   virtual int store_Opcode() const = 0;
   249   // Check if the load's memory input is a Phi node with the same control.
   250   bool is_instance_field_load_with_local_phi(Node* ctrl);
   252 #ifndef PRODUCT
   253   virtual void dump_spec(outputStream *st) const;
   254 #endif
   255 #ifdef ASSERT
   256   // Helper function to allow a raw load without control edge for some cases
   257   static bool is_immutable_value(Node* adr);
   258 #endif
   259 protected:
   260   const Type* load_array_final_field(const TypeKlassPtr *tkls,
   261                                      ciKlass* klass) const;
   262   // depends_only_on_test is almost always true, and needs to be almost always
   263   // true to enable key hoisting & commoning optimizations.  However, for the
   264   // special case of RawPtr loads from TLS top & end, and other loads performed by
   265   // GC barriers, the control edge carries the dependence preventing hoisting past
   266   // a Safepoint instead of the memory edge.  (An unfortunate consequence of having
   267   // Safepoints not set Raw Memory; itself an unfortunate consequence of having Nodes
   268   // which produce results (new raw memory state) inside of loops preventing all
   269   // manner of other optimizations).  Basically, it's ugly but so is the alternative.
   270   // See comment in macro.cpp, around line 125 expand_allocate_common().
   271   virtual bool depends_only_on_test() const { return adr_type() != TypeRawPtr::BOTTOM && _depends_only_on_test; }
   272 };
   274 //------------------------------LoadBNode--------------------------------------
   275 // Load a byte (8bits signed) from memory
   276 class LoadBNode : public LoadNode {
   277 public:
   278   LoadBNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   279     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
   280   virtual int Opcode() const;
   281   virtual uint ideal_reg() const { return Op_RegI; }
   282   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   283   virtual const Type *Value(PhaseTransform *phase) const;
   284   virtual int store_Opcode() const { return Op_StoreB; }
   285   virtual BasicType memory_type() const { return T_BYTE; }
   286 };
   288 //------------------------------LoadUBNode-------------------------------------
   289 // Load a unsigned byte (8bits unsigned) from memory
   290 class LoadUBNode : public LoadNode {
   291 public:
   292   LoadUBNode(Node* c, Node* mem, Node* adr, const TypePtr* at, const TypeInt* ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   293     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
   294   virtual int Opcode() const;
   295   virtual uint ideal_reg() const { return Op_RegI; }
   296   virtual Node* Ideal(PhaseGVN *phase, bool can_reshape);
   297   virtual const Type *Value(PhaseTransform *phase) const;
   298   virtual int store_Opcode() const { return Op_StoreB; }
   299   virtual BasicType memory_type() const { return T_BYTE; }
   300 };
   302 //------------------------------LoadUSNode-------------------------------------
   303 // Load an unsigned short/char (16bits unsigned) from memory
   304 class LoadUSNode : public LoadNode {
   305 public:
   306   LoadUSNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   307     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
   308   virtual int Opcode() const;
   309   virtual uint ideal_reg() const { return Op_RegI; }
   310   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   311   virtual const Type *Value(PhaseTransform *phase) const;
   312   virtual int store_Opcode() const { return Op_StoreC; }
   313   virtual BasicType memory_type() const { return T_CHAR; }
   314 };
   316 //------------------------------LoadSNode--------------------------------------
   317 // Load a short (16bits signed) from memory
   318 class LoadSNode : public LoadNode {
   319 public:
   320   LoadSNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   321     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
   322   virtual int Opcode() const;
   323   virtual uint ideal_reg() const { return Op_RegI; }
   324   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   325   virtual const Type *Value(PhaseTransform *phase) const;
   326   virtual int store_Opcode() const { return Op_StoreC; }
   327   virtual BasicType memory_type() const { return T_SHORT; }
   328 };
   330 //------------------------------LoadINode--------------------------------------
   331 // Load an integer from memory
   332 class LoadINode : public LoadNode {
   333 public:
   334   LoadINode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   335     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
   336   virtual int Opcode() const;
   337   virtual uint ideal_reg() const { return Op_RegI; }
   338   virtual int store_Opcode() const { return Op_StoreI; }
   339   virtual BasicType memory_type() const { return T_INT; }
   340 };
   342 //------------------------------LoadRangeNode----------------------------------
   343 // Load an array length from the array
   344 class LoadRangeNode : public LoadINode {
   345 public:
   346   LoadRangeNode(Node *c, Node *mem, Node *adr, const TypeInt *ti = TypeInt::POS)
   347     : LoadINode(c, mem, adr, TypeAryPtr::RANGE, ti, MemNode::unordered) {}
   348   virtual int Opcode() const;
   349   virtual const Type *Value( PhaseTransform *phase ) const;
   350   virtual Node *Identity( PhaseTransform *phase );
   351   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   352 };
   354 //------------------------------LoadLNode--------------------------------------
   355 // Load a long from memory
   356 class LoadLNode : public LoadNode {
   357   virtual uint hash() const { return LoadNode::hash() + _require_atomic_access; }
   358   virtual uint cmp( const Node &n ) const {
   359     return _require_atomic_access == ((LoadLNode&)n)._require_atomic_access
   360       && LoadNode::cmp(n);
   361   }
   362   virtual uint size_of() const { return sizeof(*this); }
   363   const bool _require_atomic_access;  // is piecewise load forbidden?
   365 public:
   366   LoadLNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeLong *tl,
   367             MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest, bool require_atomic_access = false)
   368     : LoadNode(c, mem, adr, at, tl, mo, control_dependency), _require_atomic_access(require_atomic_access) {}
   369   virtual int Opcode() const;
   370   virtual uint ideal_reg() const { return Op_RegL; }
   371   virtual int store_Opcode() const { return Op_StoreL; }
   372   virtual BasicType memory_type() const { return T_LONG; }
   373   bool require_atomic_access() const { return _require_atomic_access; }
   374   static LoadLNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type,
   375                                 const Type* rt, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest);
   376 #ifndef PRODUCT
   377   virtual void dump_spec(outputStream *st) const {
   378     LoadNode::dump_spec(st);
   379     if (_require_atomic_access)  st->print(" Atomic!");
   380   }
   381 #endif
   382 };
   384 //------------------------------LoadL_unalignedNode----------------------------
   385 // Load a long from unaligned memory
   386 class LoadL_unalignedNode : public LoadLNode {
   387 public:
   388   LoadL_unalignedNode(Node *c, Node *mem, Node *adr, const TypePtr* at, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   389     : LoadLNode(c, mem, adr, at, TypeLong::LONG, mo, control_dependency) {}
   390   virtual int Opcode() const;
   391 };
   393 //------------------------------LoadFNode--------------------------------------
   394 // Load a float (64 bits) from memory
   395 class LoadFNode : public LoadNode {
   396 public:
   397   LoadFNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   398     : LoadNode(c, mem, adr, at, t, mo, control_dependency) {}
   399   virtual int Opcode() const;
   400   virtual uint ideal_reg() const { return Op_RegF; }
   401   virtual int store_Opcode() const { return Op_StoreF; }
   402   virtual BasicType memory_type() const { return T_FLOAT; }
   403 };
   405 //------------------------------LoadDNode--------------------------------------
   406 // Load a double (64 bits) from memory
   407 class LoadDNode : public LoadNode {
   408   virtual uint hash() const { return LoadNode::hash() + _require_atomic_access; }
   409   virtual uint cmp( const Node &n ) const {
   410     return _require_atomic_access == ((LoadDNode&)n)._require_atomic_access
   411       && LoadNode::cmp(n);
   412   }
   413   virtual uint size_of() const { return sizeof(*this); }
   414   const bool _require_atomic_access;  // is piecewise load forbidden?
   416 public:
   417   LoadDNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t,
   418             MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest, bool require_atomic_access = false)
   419     : LoadNode(c, mem, adr, at, t, mo, control_dependency), _require_atomic_access(require_atomic_access) {}
   420   virtual int Opcode() const;
   421   virtual uint ideal_reg() const { return Op_RegD; }
   422   virtual int store_Opcode() const { return Op_StoreD; }
   423   virtual BasicType memory_type() const { return T_DOUBLE; }
   424   bool require_atomic_access() const { return _require_atomic_access; }
   425   static LoadDNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type,
   426                                 const Type* rt, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest);
   427 #ifndef PRODUCT
   428   virtual void dump_spec(outputStream *st) const {
   429     LoadNode::dump_spec(st);
   430     if (_require_atomic_access)  st->print(" Atomic!");
   431   }
   432 #endif
   433 };
   435 //------------------------------LoadD_unalignedNode----------------------------
   436 // Load a double from unaligned memory
   437 class LoadD_unalignedNode : public LoadDNode {
   438 public:
   439   LoadD_unalignedNode(Node *c, Node *mem, Node *adr, const TypePtr* at, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   440     : LoadDNode(c, mem, adr, at, Type::DOUBLE, mo, control_dependency) {}
   441   virtual int Opcode() const;
   442 };
   444 //------------------------------LoadPNode--------------------------------------
   445 // Load a pointer from memory (either object or array)
   446 class LoadPNode : public LoadNode {
   447 public:
   448   LoadPNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypePtr* t, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   449     : LoadNode(c, mem, adr, at, t, mo, control_dependency) {}
   450   virtual int Opcode() const;
   451   virtual uint ideal_reg() const { return Op_RegP; }
   452   virtual int store_Opcode() const { return Op_StoreP; }
   453   virtual BasicType memory_type() const { return T_ADDRESS; }
   454 };
   457 //------------------------------LoadNNode--------------------------------------
   458 // Load a narrow oop from memory (either object or array)
   459 class LoadNNode : public LoadNode {
   460 public:
   461   LoadNNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const Type* t, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
   462     : LoadNode(c, mem, adr, at, t, mo, control_dependency) {}
   463   virtual int Opcode() const;
   464   virtual uint ideal_reg() const { return Op_RegN; }
   465   virtual int store_Opcode() const { return Op_StoreN; }
   466   virtual BasicType memory_type() const { return T_NARROWOOP; }
   467 };
   469 //------------------------------LoadKlassNode----------------------------------
   470 // Load a Klass from an object
   471 class LoadKlassNode : public LoadPNode {
   472 protected:
   473   // In most cases, LoadKlassNode does not have the control input set. If the control
   474   // input is set, it must not be removed (by LoadNode::Ideal()).
   475   virtual bool can_remove_control() const;
   476 public:
   477   LoadKlassNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeKlassPtr *tk, MemOrd mo)
   478     : LoadPNode(c, mem, adr, at, tk, mo) {}
   479   virtual int Opcode() const;
   480   virtual const Type *Value( PhaseTransform *phase ) const;
   481   virtual Node *Identity( PhaseTransform *phase );
   482   virtual bool depends_only_on_test() const { return true; }
   484   // Polymorphic factory method:
   485   static Node* make(PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* at,
   486                     const TypeKlassPtr* tk = TypeKlassPtr::OBJECT);
   487 };
   489 //------------------------------LoadNKlassNode---------------------------------
   490 // Load a narrow Klass from an object.
   491 class LoadNKlassNode : public LoadNNode {
   492 public:
   493   LoadNKlassNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeNarrowKlass *tk, MemOrd mo)
   494     : LoadNNode(c, mem, adr, at, tk, mo) {}
   495   virtual int Opcode() const;
   496   virtual uint ideal_reg() const { return Op_RegN; }
   497   virtual int store_Opcode() const { return Op_StoreNKlass; }
   498   virtual BasicType memory_type() const { return T_NARROWKLASS; }
   500   virtual const Type *Value( PhaseTransform *phase ) const;
   501   virtual Node *Identity( PhaseTransform *phase );
   502   virtual bool depends_only_on_test() const { return true; }
   503 };
   506 //------------------------------StoreNode--------------------------------------
   507 // Store value; requires Store, Address and Value
   508 class StoreNode : public MemNode {
   509 private:
   510   // On platforms with weak memory ordering (e.g., PPC, Ia64) we distinguish
   511   // stores that can be reordered, and such requiring release semantics to
   512   // adhere to the Java specification.  The required behaviour is stored in
   513   // this field.
   514   const MemOrd _mo;
   515   // Needed for proper cloning.
   516   virtual uint size_of() const { return sizeof(*this); }
   517 protected:
   518   virtual uint cmp( const Node &n ) const;
   519   virtual bool depends_only_on_test() const { return false; }
   521   Node *Ideal_masked_input       (PhaseGVN *phase, uint mask);
   522   Node *Ideal_sign_extended_input(PhaseGVN *phase, int  num_bits);
   524 public:
   525   // We must ensure that stores of object references will be visible
   526   // only after the object's initialization. So the callers of this
   527   // procedure must indicate that the store requires `release'
   528   // semantics, if the stored value is an object reference that might
   529   // point to a new object and may become externally visible.
   530   StoreNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
   531     : MemNode(c, mem, adr, at, val), _mo(mo) {
   532     init_class_id(Class_Store);
   533   }
   534   StoreNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store, MemOrd mo)
   535     : MemNode(c, mem, adr, at, val, oop_store), _mo(mo) {
   536     init_class_id(Class_Store);
   537   }
   539   inline bool is_unordered() const { return !is_release(); }
   540   inline bool is_release() const {
   541     assert((_mo == unordered || _mo == release), "unexpected");
   542     return _mo == release;
   543   }
   545   // Conservatively release stores of object references in order to
   546   // ensure visibility of object initialization.
   547   static inline MemOrd release_if_reference(const BasicType t) {
   548     const MemOrd mo = (t == T_ARRAY ||
   549                        t == T_ADDRESS || // Might be the address of an object reference (`boxing').
   550                        t == T_OBJECT) ? release : unordered;
   551     return mo;
   552   }
   554   // Polymorphic factory method
   555   //
   556   // We must ensure that stores of object references will be visible
   557   // only after the object's initialization. So the callers of this
   558   // procedure must indicate that the store requires `release'
   559   // semantics, if the stored value is an object reference that might
   560   // point to a new object and may become externally visible.
   561   static StoreNode* make(PhaseGVN& gvn, Node *c, Node *mem, Node *adr,
   562                          const TypePtr* at, Node *val, BasicType bt, MemOrd mo);
   564   virtual uint hash() const;    // Check the type
   566   // If the store is to Field memory and the pointer is non-null, we can
   567   // zero out the control input.
   568   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   570   // Compute a new Type for this node.  Basically we just do the pre-check,
   571   // then call the virtual add() to set the type.
   572   virtual const Type *Value( PhaseTransform *phase ) const;
   574   // Check for identity function on memory (Load then Store at same address)
   575   virtual Node *Identity( PhaseTransform *phase );
   577   // Do not match memory edge
   578   virtual uint match_edge(uint idx) const;
   580   virtual const Type *bottom_type() const;  // returns Type::MEMORY
   582   // Map a store opcode to its corresponding own opcode, trivially.
   583   virtual int store_Opcode() const { return Opcode(); }
   585   // have all possible loads of the value stored been optimized away?
   586   bool value_never_loaded(PhaseTransform *phase) const;
   587 };
   589 //------------------------------StoreBNode-------------------------------------
   590 // Store byte to memory
   591 class StoreBNode : public StoreNode {
   592 public:
   593   StoreBNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
   594     : StoreNode(c, mem, adr, at, val, mo) {}
   595   virtual int Opcode() const;
   596   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   597   virtual BasicType memory_type() const { return T_BYTE; }
   598 };
   600 //------------------------------StoreCNode-------------------------------------
   601 // Store char/short to memory
   602 class StoreCNode : public StoreNode {
   603 public:
   604   StoreCNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
   605     : StoreNode(c, mem, adr, at, val, mo) {}
   606   virtual int Opcode() const;
   607   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   608   virtual BasicType memory_type() const { return T_CHAR; }
   609 };
   611 //------------------------------StoreINode-------------------------------------
   612 // Store int to memory
   613 class StoreINode : public StoreNode {
   614 public:
   615   StoreINode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
   616     : StoreNode(c, mem, adr, at, val, mo) {}
   617   virtual int Opcode() const;
   618   virtual BasicType memory_type() const { return T_INT; }
   619 };
   621 //------------------------------StoreLNode-------------------------------------
   622 // Store long to memory
   623 class StoreLNode : public StoreNode {
   624   virtual uint hash() const { return StoreNode::hash() + _require_atomic_access; }
   625   virtual uint cmp( const Node &n ) const {
   626     return _require_atomic_access == ((StoreLNode&)n)._require_atomic_access
   627       && StoreNode::cmp(n);
   628   }
   629   virtual uint size_of() const { return sizeof(*this); }
   630   const bool _require_atomic_access;  // is piecewise store forbidden?
   632 public:
   633   StoreLNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo, bool require_atomic_access = false)
   634     : StoreNode(c, mem, adr, at, val, mo), _require_atomic_access(require_atomic_access) {}
   635   virtual int Opcode() const;
   636   virtual BasicType memory_type() const { return T_LONG; }
   637   bool require_atomic_access() const { return _require_atomic_access; }
   638   static StoreLNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val, MemOrd mo);
   639 #ifndef PRODUCT
   640   virtual void dump_spec(outputStream *st) const {
   641     StoreNode::dump_spec(st);
   642     if (_require_atomic_access)  st->print(" Atomic!");
   643   }
   644 #endif
   645 };
   647 //------------------------------StoreFNode-------------------------------------
   648 // Store float to memory
   649 class StoreFNode : public StoreNode {
   650 public:
   651   StoreFNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
   652     : StoreNode(c, mem, adr, at, val, mo) {}
   653   virtual int Opcode() const;
   654   virtual BasicType memory_type() const { return T_FLOAT; }
   655 };
   657 //------------------------------StoreDNode-------------------------------------
   658 // Store double to memory
   659 class StoreDNode : public StoreNode {
   660   virtual uint hash() const { return StoreNode::hash() + _require_atomic_access; }
   661   virtual uint cmp( const Node &n ) const {
   662     return _require_atomic_access == ((StoreDNode&)n)._require_atomic_access
   663       && StoreNode::cmp(n);
   664   }
   665   virtual uint size_of() const { return sizeof(*this); }
   666   const bool _require_atomic_access;  // is piecewise store forbidden?
   667 public:
   668   StoreDNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val,
   669              MemOrd mo, bool require_atomic_access = false)
   670     : StoreNode(c, mem, adr, at, val, mo), _require_atomic_access(require_atomic_access) {}
   671   virtual int Opcode() const;
   672   virtual BasicType memory_type() const { return T_DOUBLE; }
   673   bool require_atomic_access() const { return _require_atomic_access; }
   674   static StoreDNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val, MemOrd mo);
   675 #ifndef PRODUCT
   676   virtual void dump_spec(outputStream *st) const {
   677     StoreNode::dump_spec(st);
   678     if (_require_atomic_access)  st->print(" Atomic!");
   679   }
   680 #endif
   682 };
   684 //------------------------------StorePNode-------------------------------------
   685 // Store pointer to memory
   686 class StorePNode : public StoreNode {
   687 public:
   688   StorePNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
   689     : StoreNode(c, mem, adr, at, val, mo) {}
   690   virtual int Opcode() const;
   691   virtual BasicType memory_type() const { return T_ADDRESS; }
   692 };
   694 //------------------------------StoreNNode-------------------------------------
   695 // Store narrow oop to memory
   696 class StoreNNode : public StoreNode {
   697 public:
   698   StoreNNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
   699     : StoreNode(c, mem, adr, at, val, mo) {}
   700   virtual int Opcode() const;
   701   virtual BasicType memory_type() const { return T_NARROWOOP; }
   702 };
   704 //------------------------------StoreNKlassNode--------------------------------------
   705 // Store narrow klass to memory
   706 class StoreNKlassNode : public StoreNNode {
   707 public:
   708   StoreNKlassNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
   709     : StoreNNode(c, mem, adr, at, val, mo) {}
   710   virtual int Opcode() const;
   711   virtual BasicType memory_type() const { return T_NARROWKLASS; }
   712 };
   714 //------------------------------StoreCMNode-----------------------------------
   715 // Store card-mark byte to memory for CM
   716 // The last StoreCM before a SafePoint must be preserved and occur after its "oop" store
   717 // Preceeding equivalent StoreCMs may be eliminated.
   718 class StoreCMNode : public StoreNode {
   719  private:
   720   virtual uint hash() const { return StoreNode::hash() + _oop_alias_idx; }
   721   virtual uint cmp( const Node &n ) const {
   722     return _oop_alias_idx == ((StoreCMNode&)n)._oop_alias_idx
   723       && StoreNode::cmp(n);
   724   }
   725   virtual uint size_of() const { return sizeof(*this); }
   726   int _oop_alias_idx;   // The alias_idx of OopStore
   728 public:
   729   StoreCMNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store, int oop_alias_idx ) :
   730     StoreNode(c, mem, adr, at, val, oop_store, MemNode::release),
   731     _oop_alias_idx(oop_alias_idx) {
   732     assert(_oop_alias_idx >= Compile::AliasIdxRaw ||
   733            _oop_alias_idx == Compile::AliasIdxBot && Compile::current()->AliasLevel() == 0,
   734            "bad oop alias idx");
   735   }
   736   virtual int Opcode() const;
   737   virtual Node *Identity( PhaseTransform *phase );
   738   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   739   virtual const Type *Value( PhaseTransform *phase ) const;
   740   virtual BasicType memory_type() const { return T_VOID; } // unspecific
   741   int oop_alias_idx() const { return _oop_alias_idx; }
   742 };
   744 //------------------------------LoadPLockedNode---------------------------------
   745 // Load-locked a pointer from memory (either object or array).
   746 // On Sparc & Intel this is implemented as a normal pointer load.
   747 // On PowerPC and friends it's a real load-locked.
   748 class LoadPLockedNode : public LoadPNode {
   749 public:
   750   LoadPLockedNode(Node *c, Node *mem, Node *adr, MemOrd mo)
   751     : LoadPNode(c, mem, adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM, mo) {}
   752   virtual int Opcode() const;
   753   virtual int store_Opcode() const { return Op_StorePConditional; }
   754   virtual bool depends_only_on_test() const { return true; }
   755 };
   757 //------------------------------SCMemProjNode---------------------------------------
   758 // This class defines a projection of the memory  state of a store conditional node.
   759 // These nodes return a value, but also update memory.
   760 class SCMemProjNode : public ProjNode {
   761 public:
   762   enum {SCMEMPROJCON = (uint)-2};
   763   SCMemProjNode( Node *src) : ProjNode( src, SCMEMPROJCON) { }
   764   virtual int Opcode() const;
   765   virtual bool      is_CFG() const  { return false; }
   766   virtual const Type *bottom_type() const {return Type::MEMORY;}
   767   virtual const TypePtr *adr_type() const { return in(0)->in(MemNode::Memory)->adr_type();}
   768   virtual uint ideal_reg() const { return 0;} // memory projections don't have a register
   769   virtual const Type *Value( PhaseTransform *phase ) const;
   770 #ifndef PRODUCT
   771   virtual void dump_spec(outputStream *st) const {};
   772 #endif
   773 };
   775 //------------------------------LoadStoreNode---------------------------
   776 // Note: is_Mem() method returns 'true' for this class.
   777 class LoadStoreNode : public Node {
   778 private:
   779   const Type* const _type;      // What kind of value is loaded?
   780   const TypePtr* _adr_type;     // What kind of memory is being addressed?
   781   virtual uint size_of() const; // Size is bigger
   782 public:
   783   LoadStoreNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* rt, uint required );
   784   virtual bool depends_only_on_test() const { return false; }
   785   virtual uint match_edge(uint idx) const { return idx == MemNode::Address || idx == MemNode::ValueIn; }
   787   virtual const Type *bottom_type() const { return _type; }
   788   virtual uint ideal_reg() const;
   789   virtual const class TypePtr *adr_type() const { return _adr_type; }  // returns bottom_type of address
   791   bool result_not_used() const;
   792 };
   794 class LoadStoreConditionalNode : public LoadStoreNode {
   795 public:
   796   enum {
   797     ExpectedIn = MemNode::ValueIn+1 // One more input than MemNode
   798   };
   799   LoadStoreConditionalNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex);
   800 };
   802 //------------------------------StorePConditionalNode---------------------------
   803 // Conditionally store pointer to memory, if no change since prior
   804 // load-locked.  Sets flags for success or failure of the store.
   805 class StorePConditionalNode : public LoadStoreConditionalNode {
   806 public:
   807   StorePConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreConditionalNode(c, mem, adr, val, ll) { }
   808   virtual int Opcode() const;
   809   // Produces flags
   810   virtual uint ideal_reg() const { return Op_RegFlags; }
   811 };
   813 //------------------------------StoreIConditionalNode---------------------------
   814 // Conditionally store int to memory, if no change since prior
   815 // load-locked.  Sets flags for success or failure of the store.
   816 class StoreIConditionalNode : public LoadStoreConditionalNode {
   817 public:
   818   StoreIConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ii ) : LoadStoreConditionalNode(c, mem, adr, val, ii) { }
   819   virtual int Opcode() const;
   820   // Produces flags
   821   virtual uint ideal_reg() const { return Op_RegFlags; }
   822 };
   824 //------------------------------StoreLConditionalNode---------------------------
   825 // Conditionally store long to memory, if no change since prior
   826 // load-locked.  Sets flags for success or failure of the store.
   827 class StoreLConditionalNode : public LoadStoreConditionalNode {
   828 public:
   829   StoreLConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreConditionalNode(c, mem, adr, val, ll) { }
   830   virtual int Opcode() const;
   831   // Produces flags
   832   virtual uint ideal_reg() const { return Op_RegFlags; }
   833 };
   836 //------------------------------CompareAndSwapLNode---------------------------
   837 class CompareAndSwapLNode : public LoadStoreConditionalNode {
   838 public:
   839   CompareAndSwapLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreConditionalNode(c, mem, adr, val, ex) { }
   840   virtual int Opcode() const;
   841 };
   844 //------------------------------CompareAndSwapINode---------------------------
   845 class CompareAndSwapINode : public LoadStoreConditionalNode {
   846 public:
   847   CompareAndSwapINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreConditionalNode(c, mem, adr, val, ex) { }
   848   virtual int Opcode() const;
   849 };
   852 //------------------------------CompareAndSwapPNode---------------------------
   853 class CompareAndSwapPNode : public LoadStoreConditionalNode {
   854 public:
   855   CompareAndSwapPNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreConditionalNode(c, mem, adr, val, ex) { }
   856   virtual int Opcode() const;
   857 };
   859 //------------------------------CompareAndSwapNNode---------------------------
   860 class CompareAndSwapNNode : public LoadStoreConditionalNode {
   861 public:
   862   CompareAndSwapNNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreConditionalNode(c, mem, adr, val, ex) { }
   863   virtual int Opcode() const;
   864 };
   866 //------------------------------GetAndAddINode---------------------------
   867 class GetAndAddINode : public LoadStoreNode {
   868 public:
   869   GetAndAddINode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::INT, 4) { }
   870   virtual int Opcode() const;
   871 };
   873 //------------------------------GetAndAddLNode---------------------------
   874 class GetAndAddLNode : public LoadStoreNode {
   875 public:
   876   GetAndAddLNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeLong::LONG, 4) { }
   877   virtual int Opcode() const;
   878 };
   881 //------------------------------GetAndSetINode---------------------------
   882 class GetAndSetINode : public LoadStoreNode {
   883 public:
   884   GetAndSetINode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::INT, 4) { }
   885   virtual int Opcode() const;
   886 };
   888 //------------------------------GetAndSetINode---------------------------
   889 class GetAndSetLNode : public LoadStoreNode {
   890 public:
   891   GetAndSetLNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeLong::LONG, 4) { }
   892   virtual int Opcode() const;
   893 };
   895 //------------------------------GetAndSetPNode---------------------------
   896 class GetAndSetPNode : public LoadStoreNode {
   897 public:
   898   GetAndSetPNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* t ) : LoadStoreNode(c, mem, adr, val, at, t, 4) { }
   899   virtual int Opcode() const;
   900 };
   902 //------------------------------GetAndSetNNode---------------------------
   903 class GetAndSetNNode : public LoadStoreNode {
   904 public:
   905   GetAndSetNNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* t ) : LoadStoreNode(c, mem, adr, val, at, t, 4) { }
   906   virtual int Opcode() const;
   907 };
   909 //------------------------------ClearArray-------------------------------------
   910 class ClearArrayNode: public Node {
   911 public:
   912   ClearArrayNode( Node *ctrl, Node *arymem, Node *word_cnt, Node *base )
   913     : Node(ctrl,arymem,word_cnt,base) {
   914     init_class_id(Class_ClearArray);
   915   }
   916   virtual int         Opcode() const;
   917   virtual const Type *bottom_type() const { return Type::MEMORY; }
   918   // ClearArray modifies array elements, and so affects only the
   919   // array memory addressed by the bottom_type of its base address.
   920   virtual const class TypePtr *adr_type() const;
   921   virtual Node *Identity( PhaseTransform *phase );
   922   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   923   virtual uint match_edge(uint idx) const;
   925   // Clear the given area of an object or array.
   926   // The start offset must always be aligned mod BytesPerInt.
   927   // The end offset must always be aligned mod BytesPerLong.
   928   // Return the new memory.
   929   static Node* clear_memory(Node* control, Node* mem, Node* dest,
   930                             intptr_t start_offset,
   931                             intptr_t end_offset,
   932                             PhaseGVN* phase);
   933   static Node* clear_memory(Node* control, Node* mem, Node* dest,
   934                             intptr_t start_offset,
   935                             Node* end_offset,
   936                             PhaseGVN* phase);
   937   static Node* clear_memory(Node* control, Node* mem, Node* dest,
   938                             Node* start_offset,
   939                             Node* end_offset,
   940                             PhaseGVN* phase);
   941   // Return allocation input memory edge if it is different instance
   942   // or itself if it is the one we are looking for.
   943   static bool step_through(Node** np, uint instance_id, PhaseTransform* phase);
   944 };
   946 //------------------------------StrIntrinsic-------------------------------
   947 // Base class for Ideal nodes used in String instrinsic code.
   948 class StrIntrinsicNode: public Node {
   949 public:
   950   StrIntrinsicNode(Node* control, Node* char_array_mem,
   951                    Node* s1, Node* c1, Node* s2, Node* c2):
   952     Node(control, char_array_mem, s1, c1, s2, c2) {
   953   }
   955   StrIntrinsicNode(Node* control, Node* char_array_mem,
   956                    Node* s1, Node* s2, Node* c):
   957     Node(control, char_array_mem, s1, s2, c) {
   958   }
   960   StrIntrinsicNode(Node* control, Node* char_array_mem,
   961                    Node* s1, Node* s2):
   962     Node(control, char_array_mem, s1, s2) {
   963   }
   965   virtual bool depends_only_on_test() const { return false; }
   966   virtual const TypePtr* adr_type() const { return TypeAryPtr::CHARS; }
   967   virtual uint match_edge(uint idx) const;
   968   virtual uint ideal_reg() const { return Op_RegI; }
   969   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   970   virtual const Type *Value(PhaseTransform *phase) const;
   971 };
   973 //------------------------------StrComp-------------------------------------
   974 class StrCompNode: public StrIntrinsicNode {
   975 public:
   976   StrCompNode(Node* control, Node* char_array_mem,
   977               Node* s1, Node* c1, Node* s2, Node* c2):
   978     StrIntrinsicNode(control, char_array_mem, s1, c1, s2, c2) {};
   979   virtual int Opcode() const;
   980   virtual const Type* bottom_type() const { return TypeInt::INT; }
   981 };
   983 //------------------------------StrEquals-------------------------------------
   984 class StrEqualsNode: public StrIntrinsicNode {
   985 public:
   986   StrEqualsNode(Node* control, Node* char_array_mem,
   987                 Node* s1, Node* s2, Node* c):
   988     StrIntrinsicNode(control, char_array_mem, s1, s2, c) {};
   989   virtual int Opcode() const;
   990   virtual const Type* bottom_type() const { return TypeInt::BOOL; }
   991 };
   993 //------------------------------StrIndexOf-------------------------------------
   994 class StrIndexOfNode: public StrIntrinsicNode {
   995 public:
   996   StrIndexOfNode(Node* control, Node* char_array_mem,
   997               Node* s1, Node* c1, Node* s2, Node* c2):
   998     StrIntrinsicNode(control, char_array_mem, s1, c1, s2, c2) {};
   999   virtual int Opcode() const;
  1000   virtual const Type* bottom_type() const { return TypeInt::INT; }
  1001 };
  1003 //------------------------------AryEq---------------------------------------
  1004 class AryEqNode: public StrIntrinsicNode {
  1005 public:
  1006   AryEqNode(Node* control, Node* char_array_mem, Node* s1, Node* s2):
  1007     StrIntrinsicNode(control, char_array_mem, s1, s2) {};
  1008   virtual int Opcode() const;
  1009   virtual const Type* bottom_type() const { return TypeInt::BOOL; }
  1010 };
  1013 //------------------------------EncodeISOArray--------------------------------
  1014 // encode char[] to byte[] in ISO_8859_1
  1015 class EncodeISOArrayNode: public Node {
  1016 public:
  1017   EncodeISOArrayNode(Node *control, Node* arymem, Node* s1, Node* s2, Node* c): Node(control, arymem, s1, s2, c) {};
  1018   virtual int Opcode() const;
  1019   virtual bool depends_only_on_test() const { return false; }
  1020   virtual const Type* bottom_type() const { return TypeInt::INT; }
  1021   virtual const TypePtr* adr_type() const { return TypePtr::BOTTOM; }
  1022   virtual uint match_edge(uint idx) const;
  1023   virtual uint ideal_reg() const { return Op_RegI; }
  1024   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
  1025   virtual const Type *Value(PhaseTransform *phase) const;
  1026 };
  1028 //------------------------------MemBar-----------------------------------------
  1029 // There are different flavors of Memory Barriers to match the Java Memory
  1030 // Model.  Monitor-enter and volatile-load act as Aquires: no following ref
  1031 // can be moved to before them.  We insert a MemBar-Acquire after a FastLock or
  1032 // volatile-load.  Monitor-exit and volatile-store act as Release: no
  1033 // preceding ref can be moved to after them.  We insert a MemBar-Release
  1034 // before a FastUnlock or volatile-store.  All volatiles need to be
  1035 // serialized, so we follow all volatile-stores with a MemBar-Volatile to
  1036 // separate it from any following volatile-load.
  1037 class MemBarNode: public MultiNode {
  1038   virtual uint hash() const ;                  // { return NO_HASH; }
  1039   virtual uint cmp( const Node &n ) const ;    // Always fail, except on self
  1041   virtual uint size_of() const { return sizeof(*this); }
  1042   // Memory type this node is serializing.  Usually either rawptr or bottom.
  1043   const TypePtr* _adr_type;
  1045 public:
  1046   enum {
  1047     Precedent = TypeFunc::Parms  // optional edge to force precedence
  1048   };
  1049   MemBarNode(Compile* C, int alias_idx, Node* precedent);
  1050   virtual int Opcode() const = 0;
  1051   virtual const class TypePtr *adr_type() const { return _adr_type; }
  1052   virtual const Type *Value( PhaseTransform *phase ) const;
  1053   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
  1054   virtual uint match_edge(uint idx) const { return 0; }
  1055   virtual const Type *bottom_type() const { return TypeTuple::MEMBAR; }
  1056   virtual Node *match( const ProjNode *proj, const Matcher *m );
  1057   // Factory method.  Builds a wide or narrow membar.
  1058   // Optional 'precedent' becomes an extra edge if not null.
  1059   static MemBarNode* make(Compile* C, int opcode,
  1060                           int alias_idx = Compile::AliasIdxBot,
  1061                           Node* precedent = NULL);
  1062 };
  1064 // "Acquire" - no following ref can move before (but earlier refs can
  1065 // follow, like an early Load stalled in cache).  Requires multi-cpu
  1066 // visibility.  Inserted after a volatile load.
  1067 class MemBarAcquireNode: public MemBarNode {
  1068 public:
  1069   MemBarAcquireNode(Compile* C, int alias_idx, Node* precedent)
  1070     : MemBarNode(C, alias_idx, precedent) {}
  1071   virtual int Opcode() const;
  1072 };
  1074 // "Acquire" - no following ref can move before (but earlier refs can
  1075 // follow, like an early Load stalled in cache).  Requires multi-cpu
  1076 // visibility.  Inserted independ of any load, as required
  1077 // for intrinsic sun.misc.Unsafe.loadFence().
  1078 class LoadFenceNode: public MemBarNode {
  1079 public:
  1080   LoadFenceNode(Compile* C, int alias_idx, Node* precedent)
  1081     : MemBarNode(C, alias_idx, precedent) {}
  1082   virtual int Opcode() const;
  1083 };
  1085 // "Release" - no earlier ref can move after (but later refs can move
  1086 // up, like a speculative pipelined cache-hitting Load).  Requires
  1087 // multi-cpu visibility.  Inserted before a volatile store.
  1088 class MemBarReleaseNode: public MemBarNode {
  1089 public:
  1090   MemBarReleaseNode(Compile* C, int alias_idx, Node* precedent)
  1091     : MemBarNode(C, alias_idx, precedent) {}
  1092   virtual int Opcode() const;
  1093 };
  1095 // "Release" - no earlier ref can move after (but later refs can move
  1096 // up, like a speculative pipelined cache-hitting Load).  Requires
  1097 // multi-cpu visibility.  Inserted independent of any store, as required
  1098 // for intrinsic sun.misc.Unsafe.storeFence().
  1099 class StoreFenceNode: public MemBarNode {
  1100 public:
  1101   StoreFenceNode(Compile* C, int alias_idx, Node* precedent)
  1102     : MemBarNode(C, alias_idx, precedent) {}
  1103   virtual int Opcode() const;
  1104 };
  1106 // "Acquire" - no following ref can move before (but earlier refs can
  1107 // follow, like an early Load stalled in cache).  Requires multi-cpu
  1108 // visibility.  Inserted after a FastLock.
  1109 class MemBarAcquireLockNode: public MemBarNode {
  1110 public:
  1111   MemBarAcquireLockNode(Compile* C, int alias_idx, Node* precedent)
  1112     : MemBarNode(C, alias_idx, precedent) {}
  1113   virtual int Opcode() const;
  1114 };
  1116 // "Release" - no earlier ref can move after (but later refs can move
  1117 // up, like a speculative pipelined cache-hitting Load).  Requires
  1118 // multi-cpu visibility.  Inserted before a FastUnLock.
  1119 class MemBarReleaseLockNode: public MemBarNode {
  1120 public:
  1121   MemBarReleaseLockNode(Compile* C, int alias_idx, Node* precedent)
  1122     : MemBarNode(C, alias_idx, precedent) {}
  1123   virtual int Opcode() const;
  1124 };
  1126 class MemBarStoreStoreNode: public MemBarNode {
  1127 public:
  1128   MemBarStoreStoreNode(Compile* C, int alias_idx, Node* precedent)
  1129     : MemBarNode(C, alias_idx, precedent) {
  1130     init_class_id(Class_MemBarStoreStore);
  1132   virtual int Opcode() const;
  1133 };
  1135 // Ordering between a volatile store and a following volatile load.
  1136 // Requires multi-CPU visibility?
  1137 class MemBarVolatileNode: public MemBarNode {
  1138 public:
  1139   MemBarVolatileNode(Compile* C, int alias_idx, Node* precedent)
  1140     : MemBarNode(C, alias_idx, precedent) {}
  1141   virtual int Opcode() const;
  1142 };
  1144 // Ordering within the same CPU.  Used to order unsafe memory references
  1145 // inside the compiler when we lack alias info.  Not needed "outside" the
  1146 // compiler because the CPU does all the ordering for us.
  1147 class MemBarCPUOrderNode: public MemBarNode {
  1148 public:
  1149   MemBarCPUOrderNode(Compile* C, int alias_idx, Node* precedent)
  1150     : MemBarNode(C, alias_idx, precedent) {}
  1151   virtual int Opcode() const;
  1152   virtual uint ideal_reg() const { return 0; } // not matched in the AD file
  1153 };
  1155 // Isolation of object setup after an AllocateNode and before next safepoint.
  1156 // (See comment in memnode.cpp near InitializeNode::InitializeNode for semantics.)
  1157 class InitializeNode: public MemBarNode {
  1158   friend class AllocateNode;
  1160   enum {
  1161     Incomplete    = 0,
  1162     Complete      = 1,
  1163     WithArraycopy = 2
  1164   };
  1165   int _is_complete;
  1167   bool _does_not_escape;
  1169 public:
  1170   enum {
  1171     Control    = TypeFunc::Control,
  1172     Memory     = TypeFunc::Memory,     // MergeMem for states affected by this op
  1173     RawAddress = TypeFunc::Parms+0,    // the newly-allocated raw address
  1174     RawStores  = TypeFunc::Parms+1     // zero or more stores (or TOP)
  1175   };
  1177   InitializeNode(Compile* C, int adr_type, Node* rawoop);
  1178   virtual int Opcode() const;
  1179   virtual uint size_of() const { return sizeof(*this); }
  1180   virtual uint ideal_reg() const { return 0; } // not matched in the AD file
  1181   virtual const RegMask &in_RegMask(uint) const;  // mask for RawAddress
  1183   // Manage incoming memory edges via a MergeMem on in(Memory):
  1184   Node* memory(uint alias_idx);
  1186   // The raw memory edge coming directly from the Allocation.
  1187   // The contents of this memory are *always* all-zero-bits.
  1188   Node* zero_memory() { return memory(Compile::AliasIdxRaw); }
  1190   // Return the corresponding allocation for this initialization (or null if none).
  1191   // (Note: Both InitializeNode::allocation and AllocateNode::initialization
  1192   // are defined in graphKit.cpp, which sets up the bidirectional relation.)
  1193   AllocateNode* allocation();
  1195   // Anything other than zeroing in this init?
  1196   bool is_non_zero();
  1198   // An InitializeNode must completed before macro expansion is done.
  1199   // Completion requires that the AllocateNode must be followed by
  1200   // initialization of the new memory to zero, then to any initializers.
  1201   bool is_complete() { return _is_complete != Incomplete; }
  1202   bool is_complete_with_arraycopy() { return (_is_complete & WithArraycopy) != 0; }
  1204   // Mark complete.  (Must not yet be complete.)
  1205   void set_complete(PhaseGVN* phase);
  1206   void set_complete_with_arraycopy() { _is_complete = Complete | WithArraycopy; }
  1208   bool does_not_escape() { return _does_not_escape; }
  1209   void set_does_not_escape() { _does_not_escape = true; }
  1211 #ifdef ASSERT
  1212   // ensure all non-degenerate stores are ordered and non-overlapping
  1213   bool stores_are_sane(PhaseTransform* phase);
  1214 #endif //ASSERT
  1216   // See if this store can be captured; return offset where it initializes.
  1217   // Return 0 if the store cannot be moved (any sort of problem).
  1218   intptr_t can_capture_store(StoreNode* st, PhaseTransform* phase, bool can_reshape);
  1220   // Capture another store; reformat it to write my internal raw memory.
  1221   // Return the captured copy, else NULL if there is some sort of problem.
  1222   Node* capture_store(StoreNode* st, intptr_t start, PhaseTransform* phase, bool can_reshape);
  1224   // Find captured store which corresponds to the range [start..start+size).
  1225   // Return my own memory projection (meaning the initial zero bits)
  1226   // if there is no such store.  Return NULL if there is a problem.
  1227   Node* find_captured_store(intptr_t start, int size_in_bytes, PhaseTransform* phase);
  1229   // Called when the associated AllocateNode is expanded into CFG.
  1230   Node* complete_stores(Node* rawctl, Node* rawmem, Node* rawptr,
  1231                         intptr_t header_size, Node* size_in_bytes,
  1232                         PhaseGVN* phase);
  1234  private:
  1235   void remove_extra_zeroes();
  1237   // Find out where a captured store should be placed (or already is placed).
  1238   int captured_store_insertion_point(intptr_t start, int size_in_bytes,
  1239                                      PhaseTransform* phase);
  1241   static intptr_t get_store_offset(Node* st, PhaseTransform* phase);
  1243   Node* make_raw_address(intptr_t offset, PhaseTransform* phase);
  1245   bool detect_init_independence(Node* n, int& count);
  1247   void coalesce_subword_stores(intptr_t header_size, Node* size_in_bytes,
  1248                                PhaseGVN* phase);
  1250   intptr_t find_next_fullword_store(uint i, PhaseGVN* phase);
  1251 };
  1253 //------------------------------MergeMem---------------------------------------
  1254 // (See comment in memnode.cpp near MergeMemNode::MergeMemNode for semantics.)
  1255 class MergeMemNode: public Node {
  1256   virtual uint hash() const ;                  // { return NO_HASH; }
  1257   virtual uint cmp( const Node &n ) const ;    // Always fail, except on self
  1258   friend class MergeMemStream;
  1259   MergeMemNode(Node* def);  // clients use MergeMemNode::make
  1261 public:
  1262   // If the input is a whole memory state, clone it with all its slices intact.
  1263   // Otherwise, make a new memory state with just that base memory input.
  1264   // In either case, the result is a newly created MergeMem.
  1265   static MergeMemNode* make(Compile* C, Node* base_memory);
  1267   virtual int Opcode() const;
  1268   virtual Node *Identity( PhaseTransform *phase );
  1269   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
  1270   virtual uint ideal_reg() const { return NotAMachineReg; }
  1271   virtual uint match_edge(uint idx) const { return 0; }
  1272   virtual const RegMask &out_RegMask() const;
  1273   virtual const Type *bottom_type() const { return Type::MEMORY; }
  1274   virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; }
  1275   // sparse accessors
  1276   // Fetch the previously stored "set_memory_at", or else the base memory.
  1277   // (Caller should clone it if it is a phi-nest.)
  1278   Node* memory_at(uint alias_idx) const;
  1279   // set the memory, regardless of its previous value
  1280   void set_memory_at(uint alias_idx, Node* n);
  1281   // the "base" is the memory that provides the non-finite support
  1282   Node* base_memory() const       { return in(Compile::AliasIdxBot); }
  1283   // warning: setting the base can implicitly set any of the other slices too
  1284   void set_base_memory(Node* def);
  1285   // sentinel value which denotes a copy of the base memory:
  1286   Node*   empty_memory() const    { return in(Compile::AliasIdxTop); }
  1287   static Node* make_empty_memory(); // where the sentinel comes from
  1288   bool is_empty_memory(Node* n) const { assert((n == empty_memory()) == n->is_top(), "sanity"); return n->is_top(); }
  1289   // hook for the iterator, to perform any necessary setup
  1290   void iteration_setup(const MergeMemNode* other = NULL);
  1291   // push sentinels until I am at least as long as the other (semantic no-op)
  1292   void grow_to_match(const MergeMemNode* other);
  1293   bool verify_sparse() const PRODUCT_RETURN0;
  1294 #ifndef PRODUCT
  1295   virtual void dump_spec(outputStream *st) const;
  1296 #endif
  1297 };
  1299 class MergeMemStream : public StackObj {
  1300  private:
  1301   MergeMemNode*       _mm;
  1302   const MergeMemNode* _mm2;  // optional second guy, contributes non-empty iterations
  1303   Node*               _mm_base;  // loop-invariant base memory of _mm
  1304   int                 _idx;
  1305   int                 _cnt;
  1306   Node*               _mem;
  1307   Node*               _mem2;
  1308   int                 _cnt2;
  1310   void init(MergeMemNode* mm, const MergeMemNode* mm2 = NULL) {
  1311     // subsume_node will break sparseness at times, whenever a memory slice
  1312     // folds down to a copy of the base ("fat") memory.  In such a case,
  1313     // the raw edge will update to base, although it should be top.
  1314     // This iterator will recognize either top or base_memory as an
  1315     // "empty" slice.  See is_empty, is_empty2, and next below.
  1316     //
  1317     // The sparseness property is repaired in MergeMemNode::Ideal.
  1318     // As long as access to a MergeMem goes through this iterator
  1319     // or the memory_at accessor, flaws in the sparseness will
  1320     // never be observed.
  1321     //
  1322     // Also, iteration_setup repairs sparseness.
  1323     assert(mm->verify_sparse(), "please, no dups of base");
  1324     assert(mm2==NULL || mm2->verify_sparse(), "please, no dups of base");
  1326     _mm  = mm;
  1327     _mm_base = mm->base_memory();
  1328     _mm2 = mm2;
  1329     _cnt = mm->req();
  1330     _idx = Compile::AliasIdxBot-1; // start at the base memory
  1331     _mem = NULL;
  1332     _mem2 = NULL;
  1335 #ifdef ASSERT
  1336   Node* check_memory() const {
  1337     if (at_base_memory())
  1338       return _mm->base_memory();
  1339     else if ((uint)_idx < _mm->req() && !_mm->in(_idx)->is_top())
  1340       return _mm->memory_at(_idx);
  1341     else
  1342       return _mm_base;
  1344   Node* check_memory2() const {
  1345     return at_base_memory()? _mm2->base_memory(): _mm2->memory_at(_idx);
  1347 #endif
  1349   static bool match_memory(Node* mem, const MergeMemNode* mm, int idx) PRODUCT_RETURN0;
  1350   void assert_synch() const {
  1351     assert(!_mem || _idx >= _cnt || match_memory(_mem, _mm, _idx),
  1352            "no side-effects except through the stream");
  1355  public:
  1357   // expected usages:
  1358   // for (MergeMemStream mms(mem->is_MergeMem()); next_non_empty(); ) { ... }
  1359   // for (MergeMemStream mms(mem1, mem2); next_non_empty2(); ) { ... }
  1361   // iterate over one merge
  1362   MergeMemStream(MergeMemNode* mm) {
  1363     mm->iteration_setup();
  1364     init(mm);
  1365     debug_only(_cnt2 = 999);
  1367   // iterate in parallel over two merges
  1368   // only iterates through non-empty elements of mm2
  1369   MergeMemStream(MergeMemNode* mm, const MergeMemNode* mm2) {
  1370     assert(mm2, "second argument must be a MergeMem also");
  1371     ((MergeMemNode*)mm2)->iteration_setup();  // update hidden state
  1372     mm->iteration_setup(mm2);
  1373     init(mm, mm2);
  1374     _cnt2 = mm2->req();
  1376 #ifdef ASSERT
  1377   ~MergeMemStream() {
  1378     assert_synch();
  1380 #endif
  1382   MergeMemNode* all_memory() const {
  1383     return _mm;
  1385   Node* base_memory() const {
  1386     assert(_mm_base == _mm->base_memory(), "no update to base memory, please");
  1387     return _mm_base;
  1389   const MergeMemNode* all_memory2() const {
  1390     assert(_mm2 != NULL, "");
  1391     return _mm2;
  1393   bool at_base_memory() const {
  1394     return _idx == Compile::AliasIdxBot;
  1396   int alias_idx() const {
  1397     assert(_mem, "must call next 1st");
  1398     return _idx;
  1401   const TypePtr* adr_type() const {
  1402     return Compile::current()->get_adr_type(alias_idx());
  1405   const TypePtr* adr_type(Compile* C) const {
  1406     return C->get_adr_type(alias_idx());
  1408   bool is_empty() const {
  1409     assert(_mem, "must call next 1st");
  1410     assert(_mem->is_top() == (_mem==_mm->empty_memory()), "correct sentinel");
  1411     return _mem->is_top();
  1413   bool is_empty2() const {
  1414     assert(_mem2, "must call next 1st");
  1415     assert(_mem2->is_top() == (_mem2==_mm2->empty_memory()), "correct sentinel");
  1416     return _mem2->is_top();
  1418   Node* memory() const {
  1419     assert(!is_empty(), "must not be empty");
  1420     assert_synch();
  1421     return _mem;
  1423   // get the current memory, regardless of empty or non-empty status
  1424   Node* force_memory() const {
  1425     assert(!is_empty() || !at_base_memory(), "");
  1426     // Use _mm_base to defend against updates to _mem->base_memory().
  1427     Node *mem = _mem->is_top() ? _mm_base : _mem;
  1428     assert(mem == check_memory(), "");
  1429     return mem;
  1431   Node* memory2() const {
  1432     assert(_mem2 == check_memory2(), "");
  1433     return _mem2;
  1435   void set_memory(Node* mem) {
  1436     if (at_base_memory()) {
  1437       // Note that this does not change the invariant _mm_base.
  1438       _mm->set_base_memory(mem);
  1439     } else {
  1440       _mm->set_memory_at(_idx, mem);
  1442     _mem = mem;
  1443     assert_synch();
  1446   // Recover from a side effect to the MergeMemNode.
  1447   void set_memory() {
  1448     _mem = _mm->in(_idx);
  1451   bool next()  { return next(false); }
  1452   bool next2() { return next(true); }
  1454   bool next_non_empty()  { return next_non_empty(false); }
  1455   bool next_non_empty2() { return next_non_empty(true); }
  1456   // next_non_empty2 can yield states where is_empty() is true
  1458  private:
  1459   // find the next item, which might be empty
  1460   bool next(bool have_mm2) {
  1461     assert((_mm2 != NULL) == have_mm2, "use other next");
  1462     assert_synch();
  1463     if (++_idx < _cnt) {
  1464       // Note:  This iterator allows _mm to be non-sparse.
  1465       // It behaves the same whether _mem is top or base_memory.
  1466       _mem = _mm->in(_idx);
  1467       if (have_mm2)
  1468         _mem2 = _mm2->in((_idx < _cnt2) ? _idx : Compile::AliasIdxTop);
  1469       return true;
  1471     return false;
  1474   // find the next non-empty item
  1475   bool next_non_empty(bool have_mm2) {
  1476     while (next(have_mm2)) {
  1477       if (!is_empty()) {
  1478         // make sure _mem2 is filled in sensibly
  1479         if (have_mm2 && _mem2->is_top())  _mem2 = _mm2->base_memory();
  1480         return true;
  1481       } else if (have_mm2 && !is_empty2()) {
  1482         return true;   // is_empty() == true
  1485     return false;
  1487 };
  1489 //------------------------------Prefetch---------------------------------------
  1491 // Non-faulting prefetch load.  Prefetch for many reads.
  1492 class PrefetchReadNode : public Node {
  1493 public:
  1494   PrefetchReadNode(Node *abio, Node *adr) : Node(0,abio,adr) {}
  1495   virtual int Opcode() const;
  1496   virtual uint ideal_reg() const { return NotAMachineReg; }
  1497   virtual uint match_edge(uint idx) const { return idx==2; }
  1498   virtual const Type *bottom_type() const { return Type::ABIO; }
  1499 };
  1501 // Non-faulting prefetch load.  Prefetch for many reads & many writes.
  1502 class PrefetchWriteNode : public Node {
  1503 public:
  1504   PrefetchWriteNode(Node *abio, Node *adr) : Node(0,abio,adr) {}
  1505   virtual int Opcode() const;
  1506   virtual uint ideal_reg() const { return NotAMachineReg; }
  1507   virtual uint match_edge(uint idx) const { return idx==2; }
  1508   virtual const Type *bottom_type() const { return Type::ABIO; }
  1509 };
  1511 // Allocation prefetch which may fault, TLAB size have to be adjusted.
  1512 class PrefetchAllocationNode : public Node {
  1513 public:
  1514   PrefetchAllocationNode(Node *mem, Node *adr) : Node(0,mem,adr) {}
  1515   virtual int Opcode() const;
  1516   virtual uint ideal_reg() const { return NotAMachineReg; }
  1517   virtual uint match_edge(uint idx) const { return idx==2; }
  1518   virtual const Type *bottom_type() const { return ( AllocatePrefetchStyle == 3 ) ? Type::MEMORY : Type::ABIO; }
  1519 };
  1521 #endif // SHARE_VM_OPTO_MEMNODE_HPP

mercurial