src/share/vm/opto/memnode.hpp

Thu, 06 Mar 2008 10:30:17 -0800

author
kvn
date
Thu, 06 Mar 2008 10:30:17 -0800
changeset 473
b789bcaf2dd9
parent 468
3288958bf319
child 499
b8f5ba577b02
permissions
-rw-r--r--

6667610: (Escape Analysis) retry compilation without EA if it fails
Summary: During split unique types EA could exceed nodes limit and fail the method compilation.
Reviewed-by: rasbold

     1 /*
     2  * Copyright 1997-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // Portions of code courtesy of Clifford Click
    27 class MultiNode;
    28 class PhaseCCP;
    29 class PhaseTransform;
    31 //------------------------------MemNode----------------------------------------
    32 // Load or Store, possibly throwing a NULL pointer exception
    33 class MemNode : public Node {
    34 protected:
    35 #ifdef ASSERT
    36   const TypePtr* _adr_type;     // What kind of memory is being addressed?
    37 #endif
    38   virtual uint size_of() const; // Size is bigger (ASSERT only)
    39 public:
    40   enum { Control,               // When is it safe to do this load?
    41          Memory,                // Chunk of memory is being loaded from
    42          Address,               // Actually address, derived from base
    43          ValueIn,               // Value to store
    44          OopStore               // Preceeding oop store, only in StoreCM
    45   };
    46 protected:
    47   MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at )
    48     : Node(c0,c1,c2   ) {
    49     init_class_id(Class_Mem);
    50     debug_only(_adr_type=at; adr_type();)
    51   }
    52   MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3 )
    53     : Node(c0,c1,c2,c3) {
    54     init_class_id(Class_Mem);
    55     debug_only(_adr_type=at; adr_type();)
    56   }
    57   MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3, Node *c4)
    58     : Node(c0,c1,c2,c3,c4) {
    59     init_class_id(Class_Mem);
    60     debug_only(_adr_type=at; adr_type();)
    61   }
    63 public:
    64   // Helpers for the optimizer.  Documented in memnode.cpp.
    65   static bool detect_ptr_independence(Node* p1, AllocateNode* a1,
    66                                       Node* p2, AllocateNode* a2,
    67                                       PhaseTransform* phase);
    68   static bool adr_phi_is_loop_invariant(Node* adr_phi, Node* cast);
    70   // This one should probably be a phase-specific function:
    71   static bool detect_dominating_control(Node* dom, Node* sub);
    73   // Is this Node a MemNode or some descendent?  Default is YES.
    74   virtual Node *Ideal_DU_postCCP( PhaseCCP *ccp );
    76   virtual const class TypePtr *adr_type() const;  // returns bottom_type of address
    78   // Shared code for Ideal methods:
    79   Node *Ideal_common(PhaseGVN *phase, bool can_reshape);  // Return -1 for short-circuit NULL.
    81   // Helper function for adr_type() implementations.
    82   static const TypePtr* calculate_adr_type(const Type* t, const TypePtr* cross_check = NULL);
    84   // Raw access function, to allow copying of adr_type efficiently in
    85   // product builds and retain the debug info for debug builds.
    86   const TypePtr *raw_adr_type() const {
    87 #ifdef ASSERT
    88     return _adr_type;
    89 #else
    90     return 0;
    91 #endif
    92   }
    94   // Map a load or store opcode to its corresponding store opcode.
    95   // (Return -1 if unknown.)
    96   virtual int store_Opcode() const { return -1; }
    98   // What is the type of the value in memory?  (T_VOID mean "unspecified".)
    99   virtual BasicType memory_type() const = 0;
   100   virtual int memory_size() const {
   101 #ifdef ASSERT
   102     return type2aelembytes(memory_type(), true);
   103 #else
   104     return type2aelembytes(memory_type());
   105 #endif
   106   }
   108   // Search through memory states which precede this node (load or store).
   109   // Look for an exact match for the address, with no intervening
   110   // aliased stores.
   111   Node* find_previous_store(PhaseTransform* phase);
   113   // Can this node (load or store) accurately see a stored value in
   114   // the given memory state?  (The state may or may not be in(Memory).)
   115   Node* can_see_stored_value(Node* st, PhaseTransform* phase) const;
   117 #ifndef PRODUCT
   118   static void dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st);
   119   virtual void dump_spec(outputStream *st) const;
   120 #endif
   121 };
   123 //------------------------------LoadNode---------------------------------------
   124 // Load value; requires Memory and Address
   125 class LoadNode : public MemNode {
   126 protected:
   127   virtual uint cmp( const Node &n ) const;
   128   virtual uint size_of() const; // Size is bigger
   129   const Type* const _type;      // What kind of value is loaded?
   130 public:
   132   LoadNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *rt )
   133     : MemNode(c,mem,adr,at), _type(rt) {
   134     init_class_id(Class_Load);
   135   }
   137   // Polymorphic factory method:
   138   static LoadNode* make( Compile *C, Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *rt, BasicType bt );
   140   virtual uint hash()   const;  // Check the type
   142   // Handle algebraic identities here.  If we have an identity, return the Node
   143   // we are equivalent to.  We look for Load of a Store.
   144   virtual Node *Identity( PhaseTransform *phase );
   146   // If the load is from Field memory and the pointer is non-null, we can
   147   // zero out the control input.
   148   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   150   // Recover original value from boxed values
   151   Node *eliminate_autobox(PhaseGVN *phase);
   153   // Compute a new Type for this node.  Basically we just do the pre-check,
   154   // then call the virtual add() to set the type.
   155   virtual const Type *Value( PhaseTransform *phase ) const;
   157   virtual uint ideal_reg() const;
   158   virtual const Type *bottom_type() const;
   159   // Following method is copied from TypeNode:
   160   void set_type(const Type* t) {
   161     assert(t != NULL, "sanity");
   162     debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH);
   163     *(const Type**)&_type = t;   // cast away const-ness
   164     // If this node is in the hash table, make sure it doesn't need a rehash.
   165     assert(check_hash == NO_HASH || check_hash == hash(), "type change must preserve hash code");
   166   }
   167   const Type* type() const { assert(_type != NULL, "sanity"); return _type; };
   169   // Do not match memory edge
   170   virtual uint match_edge(uint idx) const;
   172   // Map a load opcode to its corresponding store opcode.
   173   virtual int store_Opcode() const = 0;
   175 #ifndef PRODUCT
   176   virtual void dump_spec(outputStream *st) const;
   177 #endif
   178 protected:
   179   const Type* load_array_final_field(const TypeKlassPtr *tkls,
   180                                      ciKlass* klass) const;
   181 };
   183 //------------------------------LoadBNode--------------------------------------
   184 // Load a byte (8bits signed) from memory
   185 class LoadBNode : public LoadNode {
   186 public:
   187   LoadBNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::BYTE )
   188     : LoadNode(c,mem,adr,at,ti) {}
   189   virtual int Opcode() const;
   190   virtual uint ideal_reg() const { return Op_RegI; }
   191   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   192   virtual int store_Opcode() const { return Op_StoreB; }
   193   virtual BasicType memory_type() const { return T_BYTE; }
   194 };
   196 //------------------------------LoadCNode--------------------------------------
   197 // Load a char (16bits unsigned) from memory
   198 class LoadCNode : public LoadNode {
   199 public:
   200   LoadCNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::CHAR )
   201     : LoadNode(c,mem,adr,at,ti) {}
   202   virtual int Opcode() const;
   203   virtual uint ideal_reg() const { return Op_RegI; }
   204   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   205   virtual int store_Opcode() const { return Op_StoreC; }
   206   virtual BasicType memory_type() const { return T_CHAR; }
   207 };
   209 //------------------------------LoadINode--------------------------------------
   210 // Load an integer from memory
   211 class LoadINode : public LoadNode {
   212 public:
   213   LoadINode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::INT )
   214     : LoadNode(c,mem,adr,at,ti) {}
   215   virtual int Opcode() const;
   216   virtual uint ideal_reg() const { return Op_RegI; }
   217   virtual int store_Opcode() const { return Op_StoreI; }
   218   virtual BasicType memory_type() const { return T_INT; }
   219 };
   221 //------------------------------LoadRangeNode----------------------------------
   222 // Load an array length from the array
   223 class LoadRangeNode : public LoadINode {
   224 public:
   225   LoadRangeNode( Node *c, Node *mem, Node *adr, const TypeInt *ti = TypeInt::POS )
   226     : LoadINode(c,mem,adr,TypeAryPtr::RANGE,ti) {}
   227   virtual int Opcode() const;
   228   virtual const Type *Value( PhaseTransform *phase ) const;
   229   virtual Node *Identity( PhaseTransform *phase );
   230 };
   232 //------------------------------LoadLNode--------------------------------------
   233 // Load a long from memory
   234 class LoadLNode : public LoadNode {
   235   virtual uint hash() const { return LoadNode::hash() + _require_atomic_access; }
   236   virtual uint cmp( const Node &n ) const {
   237     return _require_atomic_access == ((LoadLNode&)n)._require_atomic_access
   238       && LoadNode::cmp(n);
   239   }
   240   virtual uint size_of() const { return sizeof(*this); }
   241   const bool _require_atomic_access;  // is piecewise load forbidden?
   243 public:
   244   LoadLNode( Node *c, Node *mem, Node *adr, const TypePtr* at,
   245              const TypeLong *tl = TypeLong::LONG,
   246              bool require_atomic_access = false )
   247     : LoadNode(c,mem,adr,at,tl)
   248     , _require_atomic_access(require_atomic_access)
   249   {}
   250   virtual int Opcode() const;
   251   virtual uint ideal_reg() const { return Op_RegL; }
   252   virtual int store_Opcode() const { return Op_StoreL; }
   253   virtual BasicType memory_type() const { return T_LONG; }
   254   bool require_atomic_access() { return _require_atomic_access; }
   255   static LoadLNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt);
   256 #ifndef PRODUCT
   257   virtual void dump_spec(outputStream *st) const {
   258     LoadNode::dump_spec(st);
   259     if (_require_atomic_access)  st->print(" Atomic!");
   260   }
   261 #endif
   262 };
   264 //------------------------------LoadL_unalignedNode----------------------------
   265 // Load a long from unaligned memory
   266 class LoadL_unalignedNode : public LoadLNode {
   267 public:
   268   LoadL_unalignedNode( Node *c, Node *mem, Node *adr, const TypePtr* at )
   269     : LoadLNode(c,mem,adr,at) {}
   270   virtual int Opcode() const;
   271 };
   273 //------------------------------LoadFNode--------------------------------------
   274 // Load a float (64 bits) from memory
   275 class LoadFNode : public LoadNode {
   276 public:
   277   LoadFNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t = Type::FLOAT )
   278     : LoadNode(c,mem,adr,at,t) {}
   279   virtual int Opcode() const;
   280   virtual uint ideal_reg() const { return Op_RegF; }
   281   virtual int store_Opcode() const { return Op_StoreF; }
   282   virtual BasicType memory_type() const { return T_FLOAT; }
   283 };
   285 //------------------------------LoadDNode--------------------------------------
   286 // Load a double (64 bits) from memory
   287 class LoadDNode : public LoadNode {
   288 public:
   289   LoadDNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t = Type::DOUBLE )
   290     : LoadNode(c,mem,adr,at,t) {}
   291   virtual int Opcode() const;
   292   virtual uint ideal_reg() const { return Op_RegD; }
   293   virtual int store_Opcode() const { return Op_StoreD; }
   294   virtual BasicType memory_type() const { return T_DOUBLE; }
   295 };
   297 //------------------------------LoadD_unalignedNode----------------------------
   298 // Load a double from unaligned memory
   299 class LoadD_unalignedNode : public LoadDNode {
   300 public:
   301   LoadD_unalignedNode( Node *c, Node *mem, Node *adr, const TypePtr* at )
   302     : LoadDNode(c,mem,adr,at) {}
   303   virtual int Opcode() const;
   304 };
   306 //------------------------------LoadPNode--------------------------------------
   307 // Load a pointer from memory (either object or array)
   308 class LoadPNode : public LoadNode {
   309 public:
   310   LoadPNode( Node *c, Node *mem, Node *adr, const TypePtr *at, const TypePtr* t )
   311     : LoadNode(c,mem,adr,at,t) {}
   312   virtual int Opcode() const;
   313   virtual uint ideal_reg() const { return Op_RegP; }
   314   virtual int store_Opcode() const { return Op_StoreP; }
   315   virtual BasicType memory_type() const { return T_ADDRESS; }
   316   // depends_only_on_test is almost always true, and needs to be almost always
   317   // true to enable key hoisting & commoning optimizations.  However, for the
   318   // special case of RawPtr loads from TLS top & end, the control edge carries
   319   // the dependence preventing hoisting past a Safepoint instead of the memory
   320   // edge.  (An unfortunate consequence of having Safepoints not set Raw
   321   // Memory; itself an unfortunate consequence of having Nodes which produce
   322   // results (new raw memory state) inside of loops preventing all manner of
   323   // other optimizations).  Basically, it's ugly but so is the alternative.
   324   // See comment in macro.cpp, around line 125 expand_allocate_common().
   325   virtual bool depends_only_on_test() const { return adr_type() != TypeRawPtr::BOTTOM; }
   326 };
   328 //------------------------------LoadKlassNode----------------------------------
   329 // Load a Klass from an object
   330 class LoadKlassNode : public LoadPNode {
   331 public:
   332   LoadKlassNode( Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeKlassPtr *tk = TypeKlassPtr::OBJECT )
   333     : LoadPNode(c,mem,adr,at,tk) {}
   334   virtual int Opcode() const;
   335   virtual const Type *Value( PhaseTransform *phase ) const;
   336   virtual Node *Identity( PhaseTransform *phase );
   337   virtual bool depends_only_on_test() const { return true; }
   338 };
   340 //------------------------------LoadSNode--------------------------------------
   341 // Load a short (16bits signed) from memory
   342 class LoadSNode : public LoadNode {
   343 public:
   344   LoadSNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::SHORT )
   345     : LoadNode(c,mem,adr,at,ti) {}
   346   virtual int Opcode() const;
   347   virtual uint ideal_reg() const { return Op_RegI; }
   348   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   349   virtual int store_Opcode() const { return Op_StoreC; }
   350   virtual BasicType memory_type() const { return T_SHORT; }
   351 };
   353 //------------------------------StoreNode--------------------------------------
   354 // Store value; requires Store, Address and Value
   355 class StoreNode : public MemNode {
   356 protected:
   357   virtual uint cmp( const Node &n ) const;
   358   virtual bool depends_only_on_test() const { return false; }
   360   Node *Ideal_masked_input       (PhaseGVN *phase, uint mask);
   361   Node *Ideal_sign_extended_input(PhaseGVN *phase, int  num_bits);
   363 public:
   364   StoreNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val )
   365     : MemNode(c,mem,adr,at,val) {
   366     init_class_id(Class_Store);
   367   }
   368   StoreNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store )
   369     : MemNode(c,mem,adr,at,val,oop_store) {
   370     init_class_id(Class_Store);
   371   }
   373   // Polymorphic factory method:
   374   static StoreNode* make( Compile *C, Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, BasicType bt );
   376   virtual uint hash() const;    // Check the type
   378   // If the store is to Field memory and the pointer is non-null, we can
   379   // zero out the control input.
   380   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   382   // Compute a new Type for this node.  Basically we just do the pre-check,
   383   // then call the virtual add() to set the type.
   384   virtual const Type *Value( PhaseTransform *phase ) const;
   386   // Check for identity function on memory (Load then Store at same address)
   387   virtual Node *Identity( PhaseTransform *phase );
   389   // Do not match memory edge
   390   virtual uint match_edge(uint idx) const;
   392   virtual const Type *bottom_type() const;  // returns Type::MEMORY
   394   // Map a store opcode to its corresponding own opcode, trivially.
   395   virtual int store_Opcode() const { return Opcode(); }
   397   // have all possible loads of the value stored been optimized away?
   398   bool value_never_loaded(PhaseTransform *phase) const;
   399 };
   401 //------------------------------StoreBNode-------------------------------------
   402 // Store byte to memory
   403 class StoreBNode : public StoreNode {
   404 public:
   405   StoreBNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
   406   virtual int Opcode() const;
   407   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   408   virtual BasicType memory_type() const { return T_BYTE; }
   409 };
   411 //------------------------------StoreCNode-------------------------------------
   412 // Store char/short to memory
   413 class StoreCNode : public StoreNode {
   414 public:
   415   StoreCNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
   416   virtual int Opcode() const;
   417   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   418   virtual BasicType memory_type() const { return T_CHAR; }
   419 };
   421 //------------------------------StoreINode-------------------------------------
   422 // Store int to memory
   423 class StoreINode : public StoreNode {
   424 public:
   425   StoreINode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
   426   virtual int Opcode() const;
   427   virtual BasicType memory_type() const { return T_INT; }
   428 };
   430 //------------------------------StoreLNode-------------------------------------
   431 // Store long to memory
   432 class StoreLNode : public StoreNode {
   433   virtual uint hash() const { return StoreNode::hash() + _require_atomic_access; }
   434   virtual uint cmp( const Node &n ) const {
   435     return _require_atomic_access == ((StoreLNode&)n)._require_atomic_access
   436       && StoreNode::cmp(n);
   437   }
   438   virtual uint size_of() const { return sizeof(*this); }
   439   const bool _require_atomic_access;  // is piecewise store forbidden?
   441 public:
   442   StoreLNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val,
   443               bool require_atomic_access = false )
   444     : StoreNode(c,mem,adr,at,val)
   445     , _require_atomic_access(require_atomic_access)
   446   {}
   447   virtual int Opcode() const;
   448   virtual BasicType memory_type() const { return T_LONG; }
   449   bool require_atomic_access() { return _require_atomic_access; }
   450   static StoreLNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val);
   451 #ifndef PRODUCT
   452   virtual void dump_spec(outputStream *st) const {
   453     StoreNode::dump_spec(st);
   454     if (_require_atomic_access)  st->print(" Atomic!");
   455   }
   456 #endif
   457 };
   459 //------------------------------StoreFNode-------------------------------------
   460 // Store float to memory
   461 class StoreFNode : public StoreNode {
   462 public:
   463   StoreFNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
   464   virtual int Opcode() const;
   465   virtual BasicType memory_type() const { return T_FLOAT; }
   466 };
   468 //------------------------------StoreDNode-------------------------------------
   469 // Store double to memory
   470 class StoreDNode : public StoreNode {
   471 public:
   472   StoreDNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
   473   virtual int Opcode() const;
   474   virtual BasicType memory_type() const { return T_DOUBLE; }
   475 };
   477 //------------------------------StorePNode-------------------------------------
   478 // Store pointer to memory
   479 class StorePNode : public StoreNode {
   480 public:
   481   StorePNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {}
   482   virtual int Opcode() const;
   483   virtual BasicType memory_type() const { return T_ADDRESS; }
   484 };
   486 //------------------------------StoreCMNode-----------------------------------
   487 // Store card-mark byte to memory for CM
   488 // The last StoreCM before a SafePoint must be preserved and occur after its "oop" store
   489 // Preceeding equivalent StoreCMs may be eliminated.
   490 class StoreCMNode : public StoreNode {
   491 public:
   492   StoreCMNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store ) : StoreNode(c,mem,adr,at,val,oop_store) {}
   493   virtual int Opcode() const;
   494   virtual Node *Identity( PhaseTransform *phase );
   495   virtual const Type *Value( PhaseTransform *phase ) const;
   496   virtual BasicType memory_type() const { return T_VOID; } // unspecific
   497 };
   499 //------------------------------LoadPLockedNode---------------------------------
   500 // Load-locked a pointer from memory (either object or array).
   501 // On Sparc & Intel this is implemented as a normal pointer load.
   502 // On PowerPC and friends it's a real load-locked.
   503 class LoadPLockedNode : public LoadPNode {
   504 public:
   505   LoadPLockedNode( Node *c, Node *mem, Node *adr )
   506     : LoadPNode(c,mem,adr,TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM) {}
   507   virtual int Opcode() const;
   508   virtual int store_Opcode() const { return Op_StorePConditional; }
   509   virtual bool depends_only_on_test() const { return true; }
   510 };
   512 //------------------------------LoadLLockedNode---------------------------------
   513 // Load-locked a pointer from memory (either object or array).
   514 // On Sparc & Intel this is implemented as a normal long load.
   515 class LoadLLockedNode : public LoadLNode {
   516 public:
   517   LoadLLockedNode( Node *c, Node *mem, Node *adr )
   518     : LoadLNode(c,mem,adr,TypeRawPtr::BOTTOM, TypeLong::LONG) {}
   519   virtual int Opcode() const;
   520   virtual int store_Opcode() const { return Op_StoreLConditional; }
   521 };
   523 //------------------------------SCMemProjNode---------------------------------------
   524 // This class defines a projection of the memory  state of a store conditional node.
   525 // These nodes return a value, but also update memory.
   526 class SCMemProjNode : public ProjNode {
   527 public:
   528   enum {SCMEMPROJCON = (uint)-2};
   529   SCMemProjNode( Node *src) : ProjNode( src, SCMEMPROJCON) { }
   530   virtual int Opcode() const;
   531   virtual bool      is_CFG() const  { return false; }
   532   virtual const Type *bottom_type() const {return Type::MEMORY;}
   533   virtual const TypePtr *adr_type() const { return in(0)->in(MemNode::Memory)->adr_type();}
   534   virtual uint ideal_reg() const { return 0;} // memory projections don't have a register
   535   virtual const Type *Value( PhaseTransform *phase ) const;
   536 #ifndef PRODUCT
   537   virtual void dump_spec(outputStream *st) const {};
   538 #endif
   539 };
   541 //------------------------------LoadStoreNode---------------------------
   542 class LoadStoreNode : public Node {
   543 public:
   544   enum {
   545     ExpectedIn = MemNode::ValueIn+1 // One more input than MemNode
   546   };
   547   LoadStoreNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex);
   548   virtual bool depends_only_on_test() const { return false; }
   549   virtual const Type *bottom_type() const { return TypeInt::BOOL; }
   550   virtual uint ideal_reg() const { return Op_RegI; }
   551   virtual uint match_edge(uint idx) const { return idx == MemNode::Address || idx == MemNode::ValueIn; }
   552 };
   554 //------------------------------StorePConditionalNode---------------------------
   555 // Conditionally store pointer to memory, if no change since prior
   556 // load-locked.  Sets flags for success or failure of the store.
   557 class StorePConditionalNode : public LoadStoreNode {
   558 public:
   559   StorePConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreNode(c, mem, adr, val, ll) { }
   560   virtual int Opcode() const;
   561   // Produces flags
   562   virtual uint ideal_reg() const { return Op_RegFlags; }
   563 };
   565 //------------------------------StoreLConditionalNode---------------------------
   566 // Conditionally store long to memory, if no change since prior
   567 // load-locked.  Sets flags for success or failure of the store.
   568 class StoreLConditionalNode : public LoadStoreNode {
   569 public:
   570   StoreLConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreNode(c, mem, adr, val, ll) { }
   571   virtual int Opcode() const;
   572 };
   575 //------------------------------CompareAndSwapLNode---------------------------
   576 class CompareAndSwapLNode : public LoadStoreNode {
   577 public:
   578   CompareAndSwapLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreNode(c, mem, adr, val, ex) { }
   579   virtual int Opcode() const;
   580 };
   583 //------------------------------CompareAndSwapINode---------------------------
   584 class CompareAndSwapINode : public LoadStoreNode {
   585 public:
   586   CompareAndSwapINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreNode(c, mem, adr, val, ex) { }
   587   virtual int Opcode() const;
   588 };
   591 //------------------------------CompareAndSwapPNode---------------------------
   592 class CompareAndSwapPNode : public LoadStoreNode {
   593 public:
   594   CompareAndSwapPNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreNode(c, mem, adr, val, ex) { }
   595   virtual int Opcode() const;
   596 };
   598 //------------------------------ClearArray-------------------------------------
   599 class ClearArrayNode: public Node {
   600 public:
   601   ClearArrayNode( Node *ctrl, Node *arymem, Node *word_cnt, Node *base ) : Node(ctrl,arymem,word_cnt,base) {}
   602   virtual int         Opcode() const;
   603   virtual const Type *bottom_type() const { return Type::MEMORY; }
   604   // ClearArray modifies array elements, and so affects only the
   605   // array memory addressed by the bottom_type of its base address.
   606   virtual const class TypePtr *adr_type() const;
   607   virtual Node *Identity( PhaseTransform *phase );
   608   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   609   virtual uint match_edge(uint idx) const;
   611   // Clear the given area of an object or array.
   612   // The start offset must always be aligned mod BytesPerInt.
   613   // The end offset must always be aligned mod BytesPerLong.
   614   // Return the new memory.
   615   static Node* clear_memory(Node* control, Node* mem, Node* dest,
   616                             intptr_t start_offset,
   617                             intptr_t end_offset,
   618                             PhaseGVN* phase);
   619   static Node* clear_memory(Node* control, Node* mem, Node* dest,
   620                             intptr_t start_offset,
   621                             Node* end_offset,
   622                             PhaseGVN* phase);
   623   static Node* clear_memory(Node* control, Node* mem, Node* dest,
   624                             Node* start_offset,
   625                             Node* end_offset,
   626                             PhaseGVN* phase);
   627 };
   629 //------------------------------StrComp-------------------------------------
   630 class StrCompNode: public Node {
   631 public:
   632   StrCompNode(Node *control,
   633               Node* char_array_mem,
   634               Node* value_mem,
   635               Node* count_mem,
   636               Node* offset_mem,
   637               Node* s1, Node* s2): Node(control,
   638                                         char_array_mem,
   639                                         value_mem,
   640                                         count_mem,
   641                                         offset_mem,
   642                                         s1, s2) {};
   643   virtual int Opcode() const;
   644   virtual bool depends_only_on_test() const { return false; }
   645   virtual const Type* bottom_type() const { return TypeInt::INT; }
   646   // a StrCompNode (conservatively) aliases with everything:
   647   virtual const TypePtr* adr_type() const { return TypePtr::BOTTOM; }
   648   virtual uint match_edge(uint idx) const;
   649   virtual uint ideal_reg() const { return Op_RegI; }
   650   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   651 };
   653 //------------------------------MemBar-----------------------------------------
   654 // There are different flavors of Memory Barriers to match the Java Memory
   655 // Model.  Monitor-enter and volatile-load act as Aquires: no following ref
   656 // can be moved to before them.  We insert a MemBar-Acquire after a FastLock or
   657 // volatile-load.  Monitor-exit and volatile-store act as Release: no
   658 // preceeding ref can be moved to after them.  We insert a MemBar-Release
   659 // before a FastUnlock or volatile-store.  All volatiles need to be
   660 // serialized, so we follow all volatile-stores with a MemBar-Volatile to
   661 // seperate it from any following volatile-load.
   662 class MemBarNode: public MultiNode {
   663   virtual uint hash() const ;                  // { return NO_HASH; }
   664   virtual uint cmp( const Node &n ) const ;    // Always fail, except on self
   666   virtual uint size_of() const { return sizeof(*this); }
   667   // Memory type this node is serializing.  Usually either rawptr or bottom.
   668   const TypePtr* _adr_type;
   670 public:
   671   enum {
   672     Precedent = TypeFunc::Parms  // optional edge to force precedence
   673   };
   674   MemBarNode(Compile* C, int alias_idx, Node* precedent);
   675   virtual int Opcode() const = 0;
   676   virtual const class TypePtr *adr_type() const { return _adr_type; }
   677   virtual const Type *Value( PhaseTransform *phase ) const;
   678   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   679   virtual uint match_edge(uint idx) const { return 0; }
   680   virtual const Type *bottom_type() const { return TypeTuple::MEMBAR; }
   681   virtual Node *match( const ProjNode *proj, const Matcher *m );
   682   // Factory method.  Builds a wide or narrow membar.
   683   // Optional 'precedent' becomes an extra edge if not null.
   684   static MemBarNode* make(Compile* C, int opcode,
   685                           int alias_idx = Compile::AliasIdxBot,
   686                           Node* precedent = NULL);
   687 };
   689 // "Acquire" - no following ref can move before (but earlier refs can
   690 // follow, like an early Load stalled in cache).  Requires multi-cpu
   691 // visibility.  Inserted after a volatile load or FastLock.
   692 class MemBarAcquireNode: public MemBarNode {
   693 public:
   694   MemBarAcquireNode(Compile* C, int alias_idx, Node* precedent)
   695     : MemBarNode(C, alias_idx, precedent) {}
   696   virtual int Opcode() const;
   697 };
   699 // "Release" - no earlier ref can move after (but later refs can move
   700 // up, like a speculative pipelined cache-hitting Load).  Requires
   701 // multi-cpu visibility.  Inserted before a volatile store or FastUnLock.
   702 class MemBarReleaseNode: public MemBarNode {
   703 public:
   704   MemBarReleaseNode(Compile* C, int alias_idx, Node* precedent)
   705     : MemBarNode(C, alias_idx, precedent) {}
   706   virtual int Opcode() const;
   707 };
   709 // Ordering between a volatile store and a following volatile load.
   710 // Requires multi-CPU visibility?
   711 class MemBarVolatileNode: public MemBarNode {
   712 public:
   713   MemBarVolatileNode(Compile* C, int alias_idx, Node* precedent)
   714     : MemBarNode(C, alias_idx, precedent) {}
   715   virtual int Opcode() const;
   716 };
   718 // Ordering within the same CPU.  Used to order unsafe memory references
   719 // inside the compiler when we lack alias info.  Not needed "outside" the
   720 // compiler because the CPU does all the ordering for us.
   721 class MemBarCPUOrderNode: public MemBarNode {
   722 public:
   723   MemBarCPUOrderNode(Compile* C, int alias_idx, Node* precedent)
   724     : MemBarNode(C, alias_idx, precedent) {}
   725   virtual int Opcode() const;
   726   virtual uint ideal_reg() const { return 0; } // not matched in the AD file
   727 };
   729 // Isolation of object setup after an AllocateNode and before next safepoint.
   730 // (See comment in memnode.cpp near InitializeNode::InitializeNode for semantics.)
   731 class InitializeNode: public MemBarNode {
   732   friend class AllocateNode;
   734   bool _is_complete;
   736 public:
   737   enum {
   738     Control    = TypeFunc::Control,
   739     Memory     = TypeFunc::Memory,     // MergeMem for states affected by this op
   740     RawAddress = TypeFunc::Parms+0,    // the newly-allocated raw address
   741     RawStores  = TypeFunc::Parms+1     // zero or more stores (or TOP)
   742   };
   744   InitializeNode(Compile* C, int adr_type, Node* rawoop);
   745   virtual int Opcode() const;
   746   virtual uint size_of() const { return sizeof(*this); }
   747   virtual uint ideal_reg() const { return 0; } // not matched in the AD file
   748   virtual const RegMask &in_RegMask(uint) const;  // mask for RawAddress
   750   // Manage incoming memory edges via a MergeMem on in(Memory):
   751   Node* memory(uint alias_idx);
   753   // The raw memory edge coming directly from the Allocation.
   754   // The contents of this memory are *always* all-zero-bits.
   755   Node* zero_memory() { return memory(Compile::AliasIdxRaw); }
   757   // Return the corresponding allocation for this initialization (or null if none).
   758   // (Note: Both InitializeNode::allocation and AllocateNode::initialization
   759   // are defined in graphKit.cpp, which sets up the bidirectional relation.)
   760   AllocateNode* allocation();
   762   // Anything other than zeroing in this init?
   763   bool is_non_zero();
   765   // An InitializeNode must completed before macro expansion is done.
   766   // Completion requires that the AllocateNode must be followed by
   767   // initialization of the new memory to zero, then to any initializers.
   768   bool is_complete() { return _is_complete; }
   770   // Mark complete.  (Must not yet be complete.)
   771   void set_complete(PhaseGVN* phase);
   773 #ifdef ASSERT
   774   // ensure all non-degenerate stores are ordered and non-overlapping
   775   bool stores_are_sane(PhaseTransform* phase);
   776 #endif //ASSERT
   778   // See if this store can be captured; return offset where it initializes.
   779   // Return 0 if the store cannot be moved (any sort of problem).
   780   intptr_t can_capture_store(StoreNode* st, PhaseTransform* phase);
   782   // Capture another store; reformat it to write my internal raw memory.
   783   // Return the captured copy, else NULL if there is some sort of problem.
   784   Node* capture_store(StoreNode* st, intptr_t start, PhaseTransform* phase);
   786   // Find captured store which corresponds to the range [start..start+size).
   787   // Return my own memory projection (meaning the initial zero bits)
   788   // if there is no such store.  Return NULL if there is a problem.
   789   Node* find_captured_store(intptr_t start, int size_in_bytes, PhaseTransform* phase);
   791   // Called when the associated AllocateNode is expanded into CFG.
   792   Node* complete_stores(Node* rawctl, Node* rawmem, Node* rawptr,
   793                         intptr_t header_size, Node* size_in_bytes,
   794                         PhaseGVN* phase);
   796  private:
   797   void remove_extra_zeroes();
   799   // Find out where a captured store should be placed (or already is placed).
   800   int captured_store_insertion_point(intptr_t start, int size_in_bytes,
   801                                      PhaseTransform* phase);
   803   static intptr_t get_store_offset(Node* st, PhaseTransform* phase);
   805   Node* make_raw_address(intptr_t offset, PhaseTransform* phase);
   807   bool detect_init_independence(Node* n, bool st_is_pinned, int& count);
   809   void coalesce_subword_stores(intptr_t header_size, Node* size_in_bytes,
   810                                PhaseGVN* phase);
   812   intptr_t find_next_fullword_store(uint i, PhaseGVN* phase);
   813 };
   815 //------------------------------MergeMem---------------------------------------
   816 // (See comment in memnode.cpp near MergeMemNode::MergeMemNode for semantics.)
   817 class MergeMemNode: public Node {
   818   virtual uint hash() const ;                  // { return NO_HASH; }
   819   virtual uint cmp( const Node &n ) const ;    // Always fail, except on self
   820   friend class MergeMemStream;
   821   MergeMemNode(Node* def);  // clients use MergeMemNode::make
   823 public:
   824   // If the input is a whole memory state, clone it with all its slices intact.
   825   // Otherwise, make a new memory state with just that base memory input.
   826   // In either case, the result is a newly created MergeMem.
   827   static MergeMemNode* make(Compile* C, Node* base_memory);
   829   virtual int Opcode() const;
   830   virtual Node *Identity( PhaseTransform *phase );
   831   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
   832   virtual uint ideal_reg() const { return NotAMachineReg; }
   833   virtual uint match_edge(uint idx) const { return 0; }
   834   virtual const RegMask &out_RegMask() const;
   835   virtual const Type *bottom_type() const { return Type::MEMORY; }
   836   virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; }
   837   // sparse accessors
   838   // Fetch the previously stored "set_memory_at", or else the base memory.
   839   // (Caller should clone it if it is a phi-nest.)
   840   Node* memory_at(uint alias_idx) const;
   841   // set the memory, regardless of its previous value
   842   void set_memory_at(uint alias_idx, Node* n);
   843   // the "base" is the memory that provides the non-finite support
   844   Node* base_memory() const       { return in(Compile::AliasIdxBot); }
   845   // warning: setting the base can implicitly set any of the other slices too
   846   void set_base_memory(Node* def);
   847   // sentinel value which denotes a copy of the base memory:
   848   Node*   empty_memory() const    { return in(Compile::AliasIdxTop); }
   849   static Node* make_empty_memory(); // where the sentinel comes from
   850   bool is_empty_memory(Node* n) const { assert((n == empty_memory()) == n->is_top(), "sanity"); return n->is_top(); }
   851   // hook for the iterator, to perform any necessary setup
   852   void iteration_setup(const MergeMemNode* other = NULL);
   853   // push sentinels until I am at least as long as the other (semantic no-op)
   854   void grow_to_match(const MergeMemNode* other);
   855   bool verify_sparse() const PRODUCT_RETURN0;
   856 #ifndef PRODUCT
   857   virtual void dump_spec(outputStream *st) const;
   858 #endif
   859 };
   861 class MergeMemStream : public StackObj {
   862  private:
   863   MergeMemNode*       _mm;
   864   const MergeMemNode* _mm2;  // optional second guy, contributes non-empty iterations
   865   Node*               _mm_base;  // loop-invariant base memory of _mm
   866   int                 _idx;
   867   int                 _cnt;
   868   Node*               _mem;
   869   Node*               _mem2;
   870   int                 _cnt2;
   872   void init(MergeMemNode* mm, const MergeMemNode* mm2 = NULL) {
   873     // subsume_node will break sparseness at times, whenever a memory slice
   874     // folds down to a copy of the base ("fat") memory.  In such a case,
   875     // the raw edge will update to base, although it should be top.
   876     // This iterator will recognize either top or base_memory as an
   877     // "empty" slice.  See is_empty, is_empty2, and next below.
   878     //
   879     // The sparseness property is repaired in MergeMemNode::Ideal.
   880     // As long as access to a MergeMem goes through this iterator
   881     // or the memory_at accessor, flaws in the sparseness will
   882     // never be observed.
   883     //
   884     // Also, iteration_setup repairs sparseness.
   885     assert(mm->verify_sparse(), "please, no dups of base");
   886     assert(mm2==NULL || mm2->verify_sparse(), "please, no dups of base");
   888     _mm  = mm;
   889     _mm_base = mm->base_memory();
   890     _mm2 = mm2;
   891     _cnt = mm->req();
   892     _idx = Compile::AliasIdxBot-1; // start at the base memory
   893     _mem = NULL;
   894     _mem2 = NULL;
   895   }
   897 #ifdef ASSERT
   898   Node* check_memory() const {
   899     if (at_base_memory())
   900       return _mm->base_memory();
   901     else if ((uint)_idx < _mm->req() && !_mm->in(_idx)->is_top())
   902       return _mm->memory_at(_idx);
   903     else
   904       return _mm_base;
   905   }
   906   Node* check_memory2() const {
   907     return at_base_memory()? _mm2->base_memory(): _mm2->memory_at(_idx);
   908   }
   909 #endif
   911   static bool match_memory(Node* mem, const MergeMemNode* mm, int idx) PRODUCT_RETURN0;
   912   void assert_synch() const {
   913     assert(!_mem || _idx >= _cnt || match_memory(_mem, _mm, _idx),
   914            "no side-effects except through the stream");
   915   }
   917  public:
   919   // expected usages:
   920   // for (MergeMemStream mms(mem->is_MergeMem()); next_non_empty(); ) { ... }
   921   // for (MergeMemStream mms(mem1, mem2); next_non_empty2(); ) { ... }
   923   // iterate over one merge
   924   MergeMemStream(MergeMemNode* mm) {
   925     mm->iteration_setup();
   926     init(mm);
   927     debug_only(_cnt2 = 999);
   928   }
   929   // iterate in parallel over two merges
   930   // only iterates through non-empty elements of mm2
   931   MergeMemStream(MergeMemNode* mm, const MergeMemNode* mm2) {
   932     assert(mm2, "second argument must be a MergeMem also");
   933     ((MergeMemNode*)mm2)->iteration_setup();  // update hidden state
   934     mm->iteration_setup(mm2);
   935     init(mm, mm2);
   936     _cnt2 = mm2->req();
   937   }
   938 #ifdef ASSERT
   939   ~MergeMemStream() {
   940     assert_synch();
   941   }
   942 #endif
   944   MergeMemNode* all_memory() const {
   945     return _mm;
   946   }
   947   Node* base_memory() const {
   948     assert(_mm_base == _mm->base_memory(), "no update to base memory, please");
   949     return _mm_base;
   950   }
   951   const MergeMemNode* all_memory2() const {
   952     assert(_mm2 != NULL, "");
   953     return _mm2;
   954   }
   955   bool at_base_memory() const {
   956     return _idx == Compile::AliasIdxBot;
   957   }
   958   int alias_idx() const {
   959     assert(_mem, "must call next 1st");
   960     return _idx;
   961   }
   963   const TypePtr* adr_type() const {
   964     return Compile::current()->get_adr_type(alias_idx());
   965   }
   967   const TypePtr* adr_type(Compile* C) const {
   968     return C->get_adr_type(alias_idx());
   969   }
   970   bool is_empty() const {
   971     assert(_mem, "must call next 1st");
   972     assert(_mem->is_top() == (_mem==_mm->empty_memory()), "correct sentinel");
   973     return _mem->is_top();
   974   }
   975   bool is_empty2() const {
   976     assert(_mem2, "must call next 1st");
   977     assert(_mem2->is_top() == (_mem2==_mm2->empty_memory()), "correct sentinel");
   978     return _mem2->is_top();
   979   }
   980   Node* memory() const {
   981     assert(!is_empty(), "must not be empty");
   982     assert_synch();
   983     return _mem;
   984   }
   985   // get the current memory, regardless of empty or non-empty status
   986   Node* force_memory() const {
   987     assert(!is_empty() || !at_base_memory(), "");
   988     // Use _mm_base to defend against updates to _mem->base_memory().
   989     Node *mem = _mem->is_top() ? _mm_base : _mem;
   990     assert(mem == check_memory(), "");
   991     return mem;
   992   }
   993   Node* memory2() const {
   994     assert(_mem2 == check_memory2(), "");
   995     return _mem2;
   996   }
   997   void set_memory(Node* mem) {
   998     if (at_base_memory()) {
   999       // Note that this does not change the invariant _mm_base.
  1000       _mm->set_base_memory(mem);
  1001     } else {
  1002       _mm->set_memory_at(_idx, mem);
  1004     _mem = mem;
  1005     assert_synch();
  1008   // Recover from a side effect to the MergeMemNode.
  1009   void set_memory() {
  1010     _mem = _mm->in(_idx);
  1013   bool next()  { return next(false); }
  1014   bool next2() { return next(true); }
  1016   bool next_non_empty()  { return next_non_empty(false); }
  1017   bool next_non_empty2() { return next_non_empty(true); }
  1018   // next_non_empty2 can yield states where is_empty() is true
  1020  private:
  1021   // find the next item, which might be empty
  1022   bool next(bool have_mm2) {
  1023     assert((_mm2 != NULL) == have_mm2, "use other next");
  1024     assert_synch();
  1025     if (++_idx < _cnt) {
  1026       // Note:  This iterator allows _mm to be non-sparse.
  1027       // It behaves the same whether _mem is top or base_memory.
  1028       _mem = _mm->in(_idx);
  1029       if (have_mm2)
  1030         _mem2 = _mm2->in((_idx < _cnt2) ? _idx : Compile::AliasIdxTop);
  1031       return true;
  1033     return false;
  1036   // find the next non-empty item
  1037   bool next_non_empty(bool have_mm2) {
  1038     while (next(have_mm2)) {
  1039       if (!is_empty()) {
  1040         // make sure _mem2 is filled in sensibly
  1041         if (have_mm2 && _mem2->is_top())  _mem2 = _mm2->base_memory();
  1042         return true;
  1043       } else if (have_mm2 && !is_empty2()) {
  1044         return true;   // is_empty() == true
  1047     return false;
  1049 };
  1051 //------------------------------Prefetch---------------------------------------
  1053 // Non-faulting prefetch load.  Prefetch for many reads.
  1054 class PrefetchReadNode : public Node {
  1055 public:
  1056   PrefetchReadNode(Node *abio, Node *adr) : Node(0,abio,adr) {}
  1057   virtual int Opcode() const;
  1058   virtual uint ideal_reg() const { return NotAMachineReg; }
  1059   virtual uint match_edge(uint idx) const { return idx==2; }
  1060   virtual const Type *bottom_type() const { return Type::ABIO; }
  1061 };
  1063 // Non-faulting prefetch load.  Prefetch for many reads & many writes.
  1064 class PrefetchWriteNode : public Node {
  1065 public:
  1066   PrefetchWriteNode(Node *abio, Node *adr) : Node(0,abio,adr) {}
  1067   virtual int Opcode() const;
  1068   virtual uint ideal_reg() const { return NotAMachineReg; }
  1069   virtual uint match_edge(uint idx) const { return idx==2; }
  1070   virtual const Type *bottom_type() const { return Type::ABIO; }
  1071 };

mercurial