1 /*
   2  * Copyright (c) 1997, 2019, 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  */
  24 
  25 #ifndef SHARE_OPTO_MEMNODE_HPP
  26 #define SHARE_OPTO_MEMNODE_HPP
  27 
  28 #include "opto/multnode.hpp"
  29 #include "opto/node.hpp"
  30 #include "opto/opcodes.hpp"
  31 #include "opto/type.hpp"
  32 
  33 // Portions of code courtesy of Clifford Click
  34 
  35 class MultiNode;
  36 class PhaseCCP;
  37 class PhaseTransform;
  38 
  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   bool _unsafe_access;     // Access of unsafe origin.
  46 protected:
  47 #ifdef ASSERT
  48   const TypePtr* _adr_type;     // What kind of memory is being addressed?
  49 #endif
  50   virtual uint size_of() const;
  51 public:
  52   enum { Control,               // When is it safe to do this load?
  53          Memory,                // Chunk of memory is being loaded from
  54          Address,               // Actually address, derived from base
  55          ValueIn,               // Value to store
  56          OopStore               // Preceeding oop store, only in StoreCM
  57   };
  58   typedef enum { unordered = 0,
  59                  acquire,       // Load has to acquire or be succeeded by MemBarAcquire.
  60                  release,       // Store has to release or be preceded by MemBarRelease.
  61                  seqcst,        // LoadStore has to have both acquire and release semantics.
  62                  unset          // The memory ordering is not set (used for testing)
  63   } MemOrd;
  64 protected:
  65   MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at )
  66     : Node(c0,c1,c2   ), _unaligned_access(false), _mismatched_access(false), _unsafe_access(false) {
  67     init_class_id(Class_Mem);
  68     debug_only(_adr_type=at; adr_type();)
  69   }
  70   MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3 )
  71     : Node(c0,c1,c2,c3), _unaligned_access(false), _mismatched_access(false), _unsafe_access(false) {
  72     init_class_id(Class_Mem);
  73     debug_only(_adr_type=at; adr_type();)
  74   }
  75   MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3, Node *c4)
  76     : Node(c0,c1,c2,c3,c4), _unaligned_access(false), _mismatched_access(false), _unsafe_access(false) {
  77     init_class_id(Class_Mem);
  78     debug_only(_adr_type=at; adr_type();)
  79   }
  80 
  81   virtual Node* find_previous_arraycopy(PhaseTransform* phase, Node* ld_alloc, Node*& mem, bool can_see_stored_value) const { return NULL; }
  82   static bool check_if_adr_maybe_raw(Node* adr);
  83 
  84 public:
  85   // Helpers for the optimizer.  Documented in memnode.cpp.
  86   static bool detect_ptr_independence(Node* p1, AllocateNode* a1,
  87                                       Node* p2, AllocateNode* a2,
  88                                       PhaseTransform* phase);
  89   static bool adr_phi_is_loop_invariant(Node* adr_phi, Node* cast);
  90 
  91   static Node *optimize_simple_memory_chain(Node *mchain, const TypeOopPtr *t_oop, Node *load, PhaseGVN *phase);
  92   static Node *optimize_memory_chain(Node *mchain, const TypePtr *t_adr, Node *load, PhaseGVN *phase);
  93   // This one should probably be a phase-specific function:
  94   static bool all_controls_dominate(Node* dom, Node* sub);
  95 
  96   virtual const class TypePtr *adr_type() const;  // returns bottom_type of address
  97 
  98   // Shared code for Ideal methods:
  99   Node *Ideal_common(PhaseGVN *phase, bool can_reshape);  // Return -1 for short-circuit NULL.
 100 
 101   // Helper function for adr_type() implementations.
 102   static const TypePtr* calculate_adr_type(const Type* t, const TypePtr* cross_check = NULL);
 103 
 104   // Raw access function, to allow copying of adr_type efficiently in
 105   // product builds and retain the debug info for debug builds.
 106   const TypePtr *raw_adr_type() const {
 107 #ifdef ASSERT
 108     return _adr_type;
 109 #else
 110     return 0;
 111 #endif
 112   }
 113 
 114   // Map a load or store opcode to its corresponding store opcode.
 115   // (Return -1 if unknown.)
 116   virtual int store_Opcode() const { return -1; }
 117 
 118   // What is the type of the value in memory?  (T_VOID mean "unspecified".)
 119   virtual BasicType memory_type() const = 0;
 120   virtual int memory_size() const {
 121 #ifdef ASSERT
 122     return type2aelembytes(memory_type(), true);
 123 #else
 124     return type2aelembytes(memory_type());
 125 #endif
 126   }
 127 
 128   // Search through memory states which precede this node (load or store).
 129   // Look for an exact match for the address, with no intervening
 130   // aliased stores.
 131   Node* find_previous_store(PhaseTransform* phase);
 132 
 133   // Can this node (load or store) accurately see a stored value in
 134   // the given memory state?  (The state may or may not be in(Memory).)
 135   Node* can_see_stored_value(Node* st, PhaseTransform* phase) const;
 136 
 137   void set_unaligned_access() { _unaligned_access = true; }
 138   bool is_unaligned_access() const { return _unaligned_access; }
 139   void set_mismatched_access() { _mismatched_access = true; }
 140   bool is_mismatched_access() const { return _mismatched_access; }
 141   void set_unsafe_access() { _unsafe_access = true; }
 142   bool is_unsafe_access() const { return _unsafe_access; }
 143 
 144 #ifndef PRODUCT
 145   static void dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st);
 146   virtual void dump_spec(outputStream *st) const;
 147 #endif
 148 };
 149 
 150 //------------------------------LoadNode---------------------------------------
 151 // Load value; requires Memory and Address
 152 class LoadNode : public MemNode {
 153 public:
 154   // Some loads (from unsafe) should be pinned: they don't depend only
 155   // on the dominating test.  The field _control_dependency below records
 156   // whether that node depends only on the dominating test.
 157   // Methods used to build LoadNodes pass an argument of type enum
 158   // ControlDependency instead of a boolean because those methods
 159   // typically have multiple boolean parameters with default values:
 160   // passing the wrong boolean to one of these parameters by mistake
 161   // goes easily unnoticed. Using an enum, the compiler can check that
 162   // the type of a value and the type of the parameter match.
 163   enum ControlDependency {
 164     Pinned,
 165     DependsOnlyOnTest
 166   };
 167 
 168   enum LoadBarrier {
 169     UnProcessed     = 0,
 170     RequireBarrier  = 1,
 171     WeakBarrier     = 3,  // Inclusive with RequireBarrier
 172     ExpandedBarrier = 4
 173   };
 174 
 175 private:
 176   // LoadNode::hash() doesn't take the _control_dependency field
 177   // into account: If the graph already has a non-pinned LoadNode and
 178   // we add a pinned LoadNode with the same inputs, it's safe for GVN
 179   // to replace the pinned LoadNode with the non-pinned LoadNode,
 180   // otherwise it wouldn't be safe to have a non pinned LoadNode with
 181   // those inputs in the first place. If the graph already has a
 182   // pinned LoadNode and we add a non pinned LoadNode with the same
 183   // inputs, it's safe (but suboptimal) for GVN to replace the
 184   // non-pinned LoadNode by the pinned LoadNode.
 185   ControlDependency _control_dependency;
 186 
 187   // On platforms with weak memory ordering (e.g., PPC, Ia64) we distinguish
 188   // loads that can be reordered, and such requiring acquire semantics to
 189   // adhere to the Java specification.  The required behaviour is stored in
 190   // this field.
 191   const MemOrd _mo;
 192 
 193   uint _barrier; // Bit field with barrier information
 194 
 195 protected:
 196   virtual bool cmp(const Node &n) const;
 197   virtual uint size_of() const; // Size is bigger
 198   // Should LoadNode::Ideal() attempt to remove control edges?
 199   virtual bool can_remove_control() const;
 200   const Type* const _type;      // What kind of value is loaded?
 201 
 202   virtual Node* find_previous_arraycopy(PhaseTransform* phase, Node* ld_alloc, Node*& mem, bool can_see_stored_value) const;
 203 public:
 204 
 205   LoadNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *rt, MemOrd mo, ControlDependency control_dependency)
 206     : MemNode(c,mem,adr,at), _control_dependency(control_dependency), _mo(mo), _barrier(LoadNode::UnProcessed), _type(rt) {
 207     init_class_id(Class_Load);
 208   }
 209   inline bool is_unordered() const { return !is_acquire(); }
 210   inline bool is_acquire() const {
 211     assert(_mo == unordered || _mo == acquire, "unexpected");
 212     return _mo == acquire;
 213   }
 214   inline bool is_unsigned() const {
 215     int lop = Opcode();
 216     return (lop == Op_LoadUB) || (lop == Op_LoadUS);
 217   }
 218 
 219   // Polymorphic factory method:
 220   static Node* make(PhaseGVN& gvn, Node *c, Node *mem, Node *adr,
 221                     const TypePtr* at, const Type *rt, BasicType bt,
 222                     MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest,
 223                     bool unaligned = false, bool mismatched = false, bool unsafe = false);
 224 
 225   virtual uint hash()   const;  // Check the type
 226 
 227   // Handle algebraic identities here.  If we have an identity, return the Node
 228   // we are equivalent to.  We look for Load of a Store.
 229   virtual Node* Identity(PhaseGVN* phase);
 230 
 231   // If the load is from Field memory and the pointer is non-null, it might be possible to
 232   // zero out the control input.
 233   // If the offset is constant and the base is an object allocation,
 234   // try to hook me up to the exact initializing store.
 235   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 236 
 237   // Split instance field load through Phi.
 238   Node* split_through_phi(PhaseGVN *phase);
 239 
 240   // Recover original value from boxed values
 241   Node *eliminate_autobox(PhaseGVN *phase);
 242 
 243   // Compute a new Type for this node.  Basically we just do the pre-check,
 244   // then call the virtual add() to set the type.
 245   virtual const Type* Value(PhaseGVN* phase) const;
 246 
 247   // Common methods for LoadKlass and LoadNKlass nodes.
 248   const Type* klass_value_common(PhaseGVN* phase) const;
 249   Node* klass_identity_common(PhaseGVN* phase);
 250 
 251   virtual uint ideal_reg() const;
 252   virtual const Type *bottom_type() const;
 253   // Following method is copied from TypeNode:
 254   void set_type(const Type* t) {
 255     assert(t != NULL, "sanity");
 256     debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH);
 257     *(const Type**)&_type = t;   // cast away const-ness
 258     // If this node is in the hash table, make sure it doesn't need a rehash.
 259     assert(check_hash == NO_HASH || check_hash == hash(), "type change must preserve hash code");
 260   }
 261   const Type* type() const { assert(_type != NULL, "sanity"); return _type; };
 262 
 263   // Do not match memory edge
 264   virtual uint match_edge(uint idx) const;
 265 
 266   // Map a load opcode to its corresponding store opcode.
 267   virtual int store_Opcode() const = 0;
 268 
 269   // Check if the load's memory input is a Phi node with the same control.
 270   bool is_instance_field_load_with_local_phi(Node* ctrl);
 271 
 272   Node* convert_to_unsigned_load(PhaseGVN& gvn);
 273   Node* convert_to_signed_load(PhaseGVN& gvn);
 274 
 275   void copy_barrier_info(const Node* n) { _barrier = n->as_Load()->_barrier; }
 276 
 277   bool is_barrier_required()      { return _barrier & RequireBarrier; }  // load has any type of barrier
 278   bool is_barrier_weak()          { return _barrier & WeakBarrier; }     // only some barriers are weak
 279   bool is_barrier_expanded()      { return _barrier & ExpandedBarrier; }
 280   void set_barrier(bool weak)     { weak ? _barrier |= WeakBarrier : _barrier |= RequireBarrier; }
 281   void set_barrier_expanded()     { _barrier |= ExpandedBarrier; }
 282 
 283 #ifndef PRODUCT
 284   virtual void dump_spec(outputStream *st) const;
 285 #endif
 286 #ifdef ASSERT
 287   // Helper function to allow a raw load without control edge for some cases
 288   static bool is_immutable_value(Node* adr);
 289 #endif
 290 protected:
 291   const Type* load_array_final_field(const TypeKlassPtr *tkls,
 292                                      ciKlass* klass) const;
 293 
 294   Node* can_see_arraycopy_value(Node* st, PhaseGVN* phase) const;
 295 
 296   // depends_only_on_test is almost always true, and needs to be almost always
 297   // true to enable key hoisting & commoning optimizations.  However, for the
 298   // special case of RawPtr loads from TLS top & end, and other loads performed by
 299   // GC barriers, the control edge carries the dependence preventing hoisting past
 300   // a Safepoint instead of the memory edge.  (An unfortunate consequence of having
 301   // Safepoints not set Raw Memory; itself an unfortunate consequence of having Nodes
 302   // which produce results (new raw memory state) inside of loops preventing all
 303   // manner of other optimizations).  Basically, it's ugly but so is the alternative.
 304   // See comment in macro.cpp, around line 125 expand_allocate_common().
 305   virtual bool depends_only_on_test() const {
 306     return adr_type() != TypeRawPtr::BOTTOM && _control_dependency == DependsOnlyOnTest;
 307   }
 308 };
 309 
 310 //------------------------------LoadBNode--------------------------------------
 311 // Load a byte (8bits signed) from memory
 312 class LoadBNode : public LoadNode {
 313 public:
 314   LoadBNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 315     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
 316   virtual int Opcode() const;
 317   virtual uint ideal_reg() const { return Op_RegI; }
 318   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 319   virtual const Type* Value(PhaseGVN* phase) const;
 320   virtual int store_Opcode() const { return Op_StoreB; }
 321   virtual BasicType memory_type() const { return T_BYTE; }
 322 };
 323 
 324 //------------------------------LoadUBNode-------------------------------------
 325 // Load a unsigned byte (8bits unsigned) from memory
 326 class LoadUBNode : public LoadNode {
 327 public:
 328   LoadUBNode(Node* c, Node* mem, Node* adr, const TypePtr* at, const TypeInt* ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 329     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
 330   virtual int Opcode() const;
 331   virtual uint ideal_reg() const { return Op_RegI; }
 332   virtual Node* Ideal(PhaseGVN *phase, bool can_reshape);
 333   virtual const Type* Value(PhaseGVN* phase) const;
 334   virtual int store_Opcode() const { return Op_StoreB; }
 335   virtual BasicType memory_type() const { return T_BYTE; }
 336 };
 337 
 338 //------------------------------LoadUSNode-------------------------------------
 339 // Load an unsigned short/char (16bits unsigned) from memory
 340 class LoadUSNode : public LoadNode {
 341 public:
 342   LoadUSNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 343     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
 344   virtual int Opcode() const;
 345   virtual uint ideal_reg() const { return Op_RegI; }
 346   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 347   virtual const Type* Value(PhaseGVN* phase) const;
 348   virtual int store_Opcode() const { return Op_StoreC; }
 349   virtual BasicType memory_type() const { return T_CHAR; }
 350 };
 351 
 352 //------------------------------LoadSNode--------------------------------------
 353 // Load a short (16bits signed) from memory
 354 class LoadSNode : public LoadNode {
 355 public:
 356   LoadSNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 357     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
 358   virtual int Opcode() const;
 359   virtual uint ideal_reg() const { return Op_RegI; }
 360   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 361   virtual const Type* Value(PhaseGVN* phase) const;
 362   virtual int store_Opcode() const { return Op_StoreC; }
 363   virtual BasicType memory_type() const { return T_SHORT; }
 364 };
 365 
 366 //------------------------------LoadINode--------------------------------------
 367 // Load an integer from memory
 368 class LoadINode : public LoadNode {
 369 public:
 370   LoadINode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 371     : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {}
 372   virtual int Opcode() const;
 373   virtual uint ideal_reg() const { return Op_RegI; }
 374   virtual int store_Opcode() const { return Op_StoreI; }
 375   virtual BasicType memory_type() const { return T_INT; }
 376 };
 377 
 378 //------------------------------LoadRangeNode----------------------------------
 379 // Load an array length from the array
 380 class LoadRangeNode : public LoadINode {
 381 public:
 382   LoadRangeNode(Node *c, Node *mem, Node *adr, const TypeInt *ti = TypeInt::POS)
 383     : LoadINode(c, mem, adr, TypeAryPtr::RANGE, ti, MemNode::unordered) {}
 384   virtual int Opcode() const;
 385   virtual const Type* Value(PhaseGVN* phase) const;
 386   virtual Node* Identity(PhaseGVN* phase);
 387   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 388 };
 389 
 390 //------------------------------LoadLNode--------------------------------------
 391 // Load a long from memory
 392 class LoadLNode : public LoadNode {
 393   virtual uint hash() const { return LoadNode::hash() + _require_atomic_access; }
 394   virtual bool cmp( const Node &n ) const {
 395     return _require_atomic_access == ((LoadLNode&)n)._require_atomic_access
 396       && LoadNode::cmp(n);
 397   }
 398   virtual uint size_of() const { return sizeof(*this); }
 399   const bool _require_atomic_access;  // is piecewise load forbidden?
 400 
 401 public:
 402   LoadLNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeLong *tl,
 403             MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest, bool require_atomic_access = false)
 404     : LoadNode(c, mem, adr, at, tl, mo, control_dependency), _require_atomic_access(require_atomic_access) {}
 405   virtual int Opcode() const;
 406   virtual uint ideal_reg() const { return Op_RegL; }
 407   virtual int store_Opcode() const { return Op_StoreL; }
 408   virtual BasicType memory_type() const { return T_LONG; }
 409   bool require_atomic_access() const { return _require_atomic_access; }
 410   static LoadLNode* make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type,
 411                                 const Type* rt, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest,
 412                                 bool unaligned = false, bool mismatched = false, bool unsafe = false);
 413 #ifndef PRODUCT
 414   virtual void dump_spec(outputStream *st) const {
 415     LoadNode::dump_spec(st);
 416     if (_require_atomic_access)  st->print(" Atomic!");
 417   }
 418 #endif
 419 };
 420 
 421 //------------------------------LoadL_unalignedNode----------------------------
 422 // Load a long from unaligned memory
 423 class LoadL_unalignedNode : public LoadLNode {
 424 public:
 425   LoadL_unalignedNode(Node *c, Node *mem, Node *adr, const TypePtr* at, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 426     : LoadLNode(c, mem, adr, at, TypeLong::LONG, mo, control_dependency) {}
 427   virtual int Opcode() const;
 428 };
 429 
 430 //------------------------------LoadFNode--------------------------------------
 431 // Load a float (64 bits) from memory
 432 class LoadFNode : public LoadNode {
 433 public:
 434   LoadFNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 435     : LoadNode(c, mem, adr, at, t, mo, control_dependency) {}
 436   virtual int Opcode() const;
 437   virtual uint ideal_reg() const { return Op_RegF; }
 438   virtual int store_Opcode() const { return Op_StoreF; }
 439   virtual BasicType memory_type() const { return T_FLOAT; }
 440 };
 441 
 442 //------------------------------LoadDNode--------------------------------------
 443 // Load a double (64 bits) from memory
 444 class LoadDNode : public LoadNode {
 445   virtual uint hash() const { return LoadNode::hash() + _require_atomic_access; }
 446   virtual bool cmp( const Node &n ) const {
 447     return _require_atomic_access == ((LoadDNode&)n)._require_atomic_access
 448       && LoadNode::cmp(n);
 449   }
 450   virtual uint size_of() const { return sizeof(*this); }
 451   const bool _require_atomic_access;  // is piecewise load forbidden?
 452 
 453 public:
 454   LoadDNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t,
 455             MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest, bool require_atomic_access = false)
 456     : LoadNode(c, mem, adr, at, t, mo, control_dependency), _require_atomic_access(require_atomic_access) {}
 457   virtual int Opcode() const;
 458   virtual uint ideal_reg() const { return Op_RegD; }
 459   virtual int store_Opcode() const { return Op_StoreD; }
 460   virtual BasicType memory_type() const { return T_DOUBLE; }
 461   bool require_atomic_access() const { return _require_atomic_access; }
 462   static LoadDNode* make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type,
 463                                 const Type* rt, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest,
 464                                 bool unaligned = false, bool mismatched = false, bool unsafe = false);
 465 #ifndef PRODUCT
 466   virtual void dump_spec(outputStream *st) const {
 467     LoadNode::dump_spec(st);
 468     if (_require_atomic_access)  st->print(" Atomic!");
 469   }
 470 #endif
 471 };
 472 
 473 //------------------------------LoadD_unalignedNode----------------------------
 474 // Load a double from unaligned memory
 475 class LoadD_unalignedNode : public LoadDNode {
 476 public:
 477   LoadD_unalignedNode(Node *c, Node *mem, Node *adr, const TypePtr* at, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 478     : LoadDNode(c, mem, adr, at, Type::DOUBLE, mo, control_dependency) {}
 479   virtual int Opcode() const;
 480 };
 481 
 482 //------------------------------LoadPNode--------------------------------------
 483 // Load a pointer from memory (either object or array)
 484 class LoadPNode : public LoadNode {
 485 public:
 486   LoadPNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypePtr* t, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 487     : LoadNode(c, mem, adr, at, t, mo, control_dependency) {}
 488   virtual int Opcode() const;
 489   virtual uint ideal_reg() const { return Op_RegP; }
 490   virtual int store_Opcode() const { return Op_StoreP; }
 491   virtual BasicType memory_type() const { return T_ADDRESS; }
 492 };
 493 
 494 
 495 //------------------------------LoadNNode--------------------------------------
 496 // Load a narrow oop from memory (either object or array)
 497 class LoadNNode : public LoadNode {
 498 public:
 499   LoadNNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const Type* t, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest)
 500     : LoadNode(c, mem, adr, at, t, mo, control_dependency) {}
 501   virtual int Opcode() const;
 502   virtual uint ideal_reg() const { return Op_RegN; }
 503   virtual int store_Opcode() const { return Op_StoreN; }
 504   virtual BasicType memory_type() const { return T_NARROWOOP; }
 505 };
 506 
 507 //------------------------------LoadKlassNode----------------------------------
 508 // Load a Klass from an object
 509 class LoadKlassNode : public LoadPNode {
 510 protected:
 511   // In most cases, LoadKlassNode does not have the control input set. If the control
 512   // input is set, it must not be removed (by LoadNode::Ideal()).
 513   virtual bool can_remove_control() const;
 514 public:
 515   LoadKlassNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeKlassPtr *tk, MemOrd mo)
 516     : LoadPNode(c, mem, adr, at, tk, mo) {}
 517   virtual int Opcode() const;
 518   virtual const Type* Value(PhaseGVN* phase) const;
 519   virtual Node* Identity(PhaseGVN* phase);
 520   virtual bool depends_only_on_test() const { return true; }
 521 
 522   // Polymorphic factory method:
 523   static Node* make(PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* at,
 524                     const TypeKlassPtr* tk = TypeKlassPtr::OBJECT);
 525 };
 526 
 527 //------------------------------LoadNKlassNode---------------------------------
 528 // Load a narrow Klass from an object.
 529 class LoadNKlassNode : public LoadNNode {
 530 public:
 531   LoadNKlassNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeNarrowKlass *tk, MemOrd mo)
 532     : LoadNNode(c, mem, adr, at, tk, mo) {}
 533   virtual int Opcode() const;
 534   virtual uint ideal_reg() const { return Op_RegN; }
 535   virtual int store_Opcode() const { return Op_StoreNKlass; }
 536   virtual BasicType memory_type() const { return T_NARROWKLASS; }
 537 
 538   virtual const Type* Value(PhaseGVN* phase) const;
 539   virtual Node* Identity(PhaseGVN* phase);
 540   virtual bool depends_only_on_test() const { return true; }
 541 };
 542 
 543 
 544 //------------------------------StoreNode--------------------------------------
 545 // Store value; requires Store, Address and Value
 546 class StoreNode : public MemNode {
 547 private:
 548   // On platforms with weak memory ordering (e.g., PPC, Ia64) we distinguish
 549   // stores that can be reordered, and such requiring release semantics to
 550   // adhere to the Java specification.  The required behaviour is stored in
 551   // this field.
 552   const MemOrd _mo;
 553   // Needed for proper cloning.
 554   virtual uint size_of() const { return sizeof(*this); }
 555 protected:
 556   virtual bool cmp( const Node &n ) const;
 557   virtual bool depends_only_on_test() const { return false; }
 558 
 559   Node *Ideal_masked_input       (PhaseGVN *phase, uint mask);
 560   Node *Ideal_sign_extended_input(PhaseGVN *phase, int  num_bits);
 561 
 562 public:
 563   // We must ensure that stores of object references will be visible
 564   // only after the object's initialization. So the callers of this
 565   // procedure must indicate that the store requires `release'
 566   // semantics, if the stored value is an object reference that might
 567   // point to a new object and may become externally visible.
 568   StoreNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
 569     : MemNode(c, mem, adr, at, val), _mo(mo) {
 570     init_class_id(Class_Store);
 571   }
 572   StoreNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store, MemOrd mo)
 573     : MemNode(c, mem, adr, at, val, oop_store), _mo(mo) {
 574     init_class_id(Class_Store);
 575   }
 576 
 577   inline bool is_unordered() const { return !is_release(); }
 578   inline bool is_release() const {
 579     assert((_mo == unordered || _mo == release), "unexpected");
 580     return _mo == release;
 581   }
 582 
 583   // Conservatively release stores of object references in order to
 584   // ensure visibility of object initialization.
 585   static inline MemOrd release_if_reference(const BasicType t) {
 586 #ifdef AARCH64
 587     // AArch64 doesn't need a release store here because object
 588     // initialization contains the necessary barriers.
 589     return unordered;
 590 #else
 591     const MemOrd mo = (t == T_ARRAY ||
 592                        t == T_ADDRESS || // Might be the address of an object reference (`boxing').
 593                        t == T_OBJECT) ? release : unordered;
 594     return mo;
 595 #endif
 596   }
 597 
 598   // Polymorphic factory method
 599   //
 600   // We must ensure that stores of object references will be visible
 601   // only after the object's initialization. So the callers of this
 602   // procedure must indicate that the store requires `release'
 603   // semantics, if the stored value is an object reference that might
 604   // point to a new object and may become externally visible.
 605   static StoreNode* make(PhaseGVN& gvn, Node *c, Node *mem, Node *adr,
 606                          const TypePtr* at, Node *val, BasicType bt, MemOrd mo);
 607 
 608   virtual uint hash() const;    // Check the type
 609 
 610   // If the store is to Field memory and the pointer is non-null, we can
 611   // zero out the control input.
 612   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 613 
 614   // Compute a new Type for this node.  Basically we just do the pre-check,
 615   // then call the virtual add() to set the type.
 616   virtual const Type* Value(PhaseGVN* phase) const;
 617 
 618   // Check for identity function on memory (Load then Store at same address)
 619   virtual Node* Identity(PhaseGVN* phase);
 620 
 621   // Do not match memory edge
 622   virtual uint match_edge(uint idx) const;
 623 
 624   virtual const Type *bottom_type() const;  // returns Type::MEMORY
 625 
 626   // Map a store opcode to its corresponding own opcode, trivially.
 627   virtual int store_Opcode() const { return Opcode(); }
 628 
 629   // have all possible loads of the value stored been optimized away?
 630   bool value_never_loaded(PhaseTransform *phase) const;
 631 
 632   MemBarNode* trailing_membar() const;
 633 };
 634 
 635 //------------------------------StoreBNode-------------------------------------
 636 // Store byte to memory
 637 class StoreBNode : public StoreNode {
 638 public:
 639   StoreBNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
 640     : StoreNode(c, mem, adr, at, val, mo) {}
 641   virtual int Opcode() const;
 642   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 643   virtual BasicType memory_type() const { return T_BYTE; }
 644 };
 645 
 646 //------------------------------StoreCNode-------------------------------------
 647 // Store char/short to memory
 648 class StoreCNode : public StoreNode {
 649 public:
 650   StoreCNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
 651     : StoreNode(c, mem, adr, at, val, mo) {}
 652   virtual int Opcode() const;
 653   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 654   virtual BasicType memory_type() const { return T_CHAR; }
 655 };
 656 
 657 //------------------------------StoreINode-------------------------------------
 658 // Store int to memory
 659 class StoreINode : public StoreNode {
 660 public:
 661   StoreINode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
 662     : StoreNode(c, mem, adr, at, val, mo) {}
 663   virtual int Opcode() const;
 664   virtual BasicType memory_type() const { return T_INT; }
 665 };
 666 
 667 //------------------------------StoreLNode-------------------------------------
 668 // Store long to memory
 669 class StoreLNode : public StoreNode {
 670   virtual uint hash() const { return StoreNode::hash() + _require_atomic_access; }
 671   virtual bool cmp( const Node &n ) const {
 672     return _require_atomic_access == ((StoreLNode&)n)._require_atomic_access
 673       && StoreNode::cmp(n);
 674   }
 675   virtual uint size_of() const { return sizeof(*this); }
 676   const bool _require_atomic_access;  // is piecewise store forbidden?
 677 
 678 public:
 679   StoreLNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo, bool require_atomic_access = false)
 680     : StoreNode(c, mem, adr, at, val, mo), _require_atomic_access(require_atomic_access) {}
 681   virtual int Opcode() const;
 682   virtual BasicType memory_type() const { return T_LONG; }
 683   bool require_atomic_access() const { return _require_atomic_access; }
 684   static StoreLNode* make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val, MemOrd mo);
 685 #ifndef PRODUCT
 686   virtual void dump_spec(outputStream *st) const {
 687     StoreNode::dump_spec(st);
 688     if (_require_atomic_access)  st->print(" Atomic!");
 689   }
 690 #endif
 691 };
 692 
 693 //------------------------------StoreFNode-------------------------------------
 694 // Store float to memory
 695 class StoreFNode : public StoreNode {
 696 public:
 697   StoreFNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
 698     : StoreNode(c, mem, adr, at, val, mo) {}
 699   virtual int Opcode() const;
 700   virtual BasicType memory_type() const { return T_FLOAT; }
 701 };
 702 
 703 //------------------------------StoreDNode-------------------------------------
 704 // Store double to memory
 705 class StoreDNode : public StoreNode {
 706   virtual uint hash() const { return StoreNode::hash() + _require_atomic_access; }
 707   virtual bool cmp( const Node &n ) const {
 708     return _require_atomic_access == ((StoreDNode&)n)._require_atomic_access
 709       && StoreNode::cmp(n);
 710   }
 711   virtual uint size_of() const { return sizeof(*this); }
 712   const bool _require_atomic_access;  // is piecewise store forbidden?
 713 public:
 714   StoreDNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val,
 715              MemOrd mo, bool require_atomic_access = false)
 716     : StoreNode(c, mem, adr, at, val, mo), _require_atomic_access(require_atomic_access) {}
 717   virtual int Opcode() const;
 718   virtual BasicType memory_type() const { return T_DOUBLE; }
 719   bool require_atomic_access() const { return _require_atomic_access; }
 720   static StoreDNode* make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val, MemOrd mo);
 721 #ifndef PRODUCT
 722   virtual void dump_spec(outputStream *st) const {
 723     StoreNode::dump_spec(st);
 724     if (_require_atomic_access)  st->print(" Atomic!");
 725   }
 726 #endif
 727 
 728 };
 729 
 730 //------------------------------StorePNode-------------------------------------
 731 // Store pointer to memory
 732 class StorePNode : public StoreNode {
 733 public:
 734   StorePNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
 735     : StoreNode(c, mem, adr, at, val, mo) {}
 736   virtual int Opcode() const;
 737   virtual BasicType memory_type() const { return T_ADDRESS; }
 738 };
 739 
 740 //------------------------------StoreNNode-------------------------------------
 741 // Store narrow oop to memory
 742 class StoreNNode : public StoreNode {
 743 public:
 744   StoreNNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
 745     : StoreNode(c, mem, adr, at, val, mo) {}
 746   virtual int Opcode() const;
 747   virtual BasicType memory_type() const { return T_NARROWOOP; }
 748 };
 749 
 750 //------------------------------StoreNKlassNode--------------------------------------
 751 // Store narrow klass to memory
 752 class StoreNKlassNode : public StoreNNode {
 753 public:
 754   StoreNKlassNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo)
 755     : StoreNNode(c, mem, adr, at, val, mo) {}
 756   virtual int Opcode() const;
 757   virtual BasicType memory_type() const { return T_NARROWKLASS; }
 758 };
 759 
 760 //------------------------------StoreCMNode-----------------------------------
 761 // Store card-mark byte to memory for CM
 762 // The last StoreCM before a SafePoint must be preserved and occur after its "oop" store
 763 // Preceeding equivalent StoreCMs may be eliminated.
 764 class StoreCMNode : public StoreNode {
 765  private:
 766   virtual uint hash() const { return StoreNode::hash() + _oop_alias_idx; }
 767   virtual bool cmp( const Node &n ) const {
 768     return _oop_alias_idx == ((StoreCMNode&)n)._oop_alias_idx
 769       && StoreNode::cmp(n);
 770   }
 771   virtual uint size_of() const { return sizeof(*this); }
 772   int _oop_alias_idx;   // The alias_idx of OopStore
 773 
 774 public:
 775   StoreCMNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store, int oop_alias_idx ) :
 776     StoreNode(c, mem, adr, at, val, oop_store, MemNode::release),
 777     _oop_alias_idx(oop_alias_idx) {
 778     assert(_oop_alias_idx >= Compile::AliasIdxRaw ||
 779            _oop_alias_idx == Compile::AliasIdxBot && Compile::current()->AliasLevel() == 0,
 780            "bad oop alias idx");
 781   }
 782   virtual int Opcode() const;
 783   virtual Node* Identity(PhaseGVN* phase);
 784   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 785   virtual const Type* Value(PhaseGVN* phase) const;
 786   virtual BasicType memory_type() const { return T_VOID; } // unspecific
 787   int oop_alias_idx() const { return _oop_alias_idx; }
 788 };
 789 
 790 //------------------------------LoadPLockedNode---------------------------------
 791 // Load-locked a pointer from memory (either object or array).
 792 // On Sparc & Intel this is implemented as a normal pointer load.
 793 // On PowerPC and friends it's a real load-locked.
 794 class LoadPLockedNode : public LoadPNode {
 795 public:
 796   LoadPLockedNode(Node *c, Node *mem, Node *adr, MemOrd mo)
 797     : LoadPNode(c, mem, adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM, mo) {}
 798   virtual int Opcode() const;
 799   virtual int store_Opcode() const { return Op_StorePConditional; }
 800   virtual bool depends_only_on_test() const { return true; }
 801 };
 802 
 803 //------------------------------SCMemProjNode---------------------------------------
 804 // This class defines a projection of the memory  state of a store conditional node.
 805 // These nodes return a value, but also update memory.
 806 class SCMemProjNode : public ProjNode {
 807 public:
 808   enum {SCMEMPROJCON = (uint)-2};
 809   SCMemProjNode( Node *src) : ProjNode( src, SCMEMPROJCON) { }
 810   virtual int Opcode() const;
 811   virtual bool      is_CFG() const  { return false; }
 812   virtual const Type *bottom_type() const {return Type::MEMORY;}
 813   virtual const TypePtr *adr_type() const {
 814     Node* ctrl = in(0);
 815     if (ctrl == NULL)  return NULL; // node is dead
 816     return ctrl->in(MemNode::Memory)->adr_type();
 817   }
 818   virtual uint ideal_reg() const { return 0;} // memory projections don't have a register
 819   virtual const Type* Value(PhaseGVN* phase) const;
 820 #ifndef PRODUCT
 821   virtual void dump_spec(outputStream *st) const {};
 822 #endif
 823 };
 824 
 825 //------------------------------LoadStoreNode---------------------------
 826 // Note: is_Mem() method returns 'true' for this class.
 827 class LoadStoreNode : public Node {
 828 private:
 829   const Type* const _type;      // What kind of value is loaded?
 830   const TypePtr* _adr_type;     // What kind of memory is being addressed?
 831   bool _has_barrier;
 832   virtual uint size_of() const; // Size is bigger
 833 public:
 834   LoadStoreNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* rt, uint required );
 835   virtual bool depends_only_on_test() const { return false; }
 836   virtual uint match_edge(uint idx) const { return idx == MemNode::Address || idx == MemNode::ValueIn; }
 837 
 838   virtual const Type *bottom_type() const { return _type; }
 839   virtual uint ideal_reg() const;
 840   virtual const class TypePtr *adr_type() const { return _adr_type; }  // returns bottom_type of address
 841 
 842   bool result_not_used() const;
 843   MemBarNode* trailing_membar() const;
 844   void set_has_barrier() { _has_barrier = true; };
 845   bool has_barrier() const { return _has_barrier; };
 846 };
 847 
 848 class LoadStoreConditionalNode : public LoadStoreNode {
 849 public:
 850   enum {
 851     ExpectedIn = MemNode::ValueIn+1 // One more input than MemNode
 852   };
 853   LoadStoreConditionalNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex);
 854 };
 855 
 856 //------------------------------StorePConditionalNode---------------------------
 857 // Conditionally store pointer to memory, if no change since prior
 858 // load-locked.  Sets flags for success or failure of the store.
 859 class StorePConditionalNode : public LoadStoreConditionalNode {
 860 public:
 861   StorePConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreConditionalNode(c, mem, adr, val, ll) { }
 862   virtual int Opcode() const;
 863   // Produces flags
 864   virtual uint ideal_reg() const { return Op_RegFlags; }
 865 };
 866 
 867 //------------------------------StoreIConditionalNode---------------------------
 868 // Conditionally store int to memory, if no change since prior
 869 // load-locked.  Sets flags for success or failure of the store.
 870 class StoreIConditionalNode : public LoadStoreConditionalNode {
 871 public:
 872   StoreIConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ii ) : LoadStoreConditionalNode(c, mem, adr, val, ii) { }
 873   virtual int Opcode() const;
 874   // Produces flags
 875   virtual uint ideal_reg() const { return Op_RegFlags; }
 876 };
 877 
 878 //------------------------------StoreLConditionalNode---------------------------
 879 // Conditionally store long to memory, if no change since prior
 880 // load-locked.  Sets flags for success or failure of the store.
 881 class StoreLConditionalNode : public LoadStoreConditionalNode {
 882 public:
 883   StoreLConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreConditionalNode(c, mem, adr, val, ll) { }
 884   virtual int Opcode() const;
 885   // Produces flags
 886   virtual uint ideal_reg() const { return Op_RegFlags; }
 887 };
 888 
 889 class CompareAndSwapNode : public LoadStoreConditionalNode {
 890 private:
 891   const MemNode::MemOrd _mem_ord;
 892 public:
 893   CompareAndSwapNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : LoadStoreConditionalNode(c, mem, adr, val, ex), _mem_ord(mem_ord) {}
 894   MemNode::MemOrd order() const {
 895     return _mem_ord;
 896   }
 897 };
 898 
 899 class CompareAndExchangeNode : public LoadStoreNode {
 900 private:
 901   const MemNode::MemOrd _mem_ord;
 902 public:
 903   enum {
 904     ExpectedIn = MemNode::ValueIn+1 // One more input than MemNode
 905   };
 906   CompareAndExchangeNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord, const TypePtr* at, const Type* t) :
 907     LoadStoreNode(c, mem, adr, val, at, t, 5), _mem_ord(mem_ord) {
 908      init_req(ExpectedIn, ex );
 909   }
 910 
 911   MemNode::MemOrd order() const {
 912     return _mem_ord;
 913   }
 914 };
 915 
 916 //------------------------------CompareAndSwapBNode---------------------------
 917 class CompareAndSwapBNode : public CompareAndSwapNode {
 918 public:
 919   CompareAndSwapBNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 920   virtual int Opcode() const;
 921 };
 922 
 923 //------------------------------CompareAndSwapSNode---------------------------
 924 class CompareAndSwapSNode : public CompareAndSwapNode {
 925 public:
 926   CompareAndSwapSNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 927   virtual int Opcode() const;
 928 };
 929 
 930 //------------------------------CompareAndSwapINode---------------------------
 931 class CompareAndSwapINode : public CompareAndSwapNode {
 932 public:
 933   CompareAndSwapINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 934   virtual int Opcode() const;
 935 };
 936 
 937 //------------------------------CompareAndSwapLNode---------------------------
 938 class CompareAndSwapLNode : public CompareAndSwapNode {
 939 public:
 940   CompareAndSwapLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 941   virtual int Opcode() const;
 942 };
 943 
 944 //------------------------------CompareAndSwapPNode---------------------------
 945 class CompareAndSwapPNode : public CompareAndSwapNode {
 946 public:
 947   CompareAndSwapPNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 948   virtual int Opcode() const;
 949 };
 950 
 951 //------------------------------CompareAndSwapNNode---------------------------
 952 class CompareAndSwapNNode : public CompareAndSwapNode {
 953 public:
 954   CompareAndSwapNNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 955   virtual int Opcode() const;
 956 };
 957 
 958 //------------------------------WeakCompareAndSwapBNode---------------------------
 959 class WeakCompareAndSwapBNode : public CompareAndSwapNode {
 960 public:
 961   WeakCompareAndSwapBNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 962   virtual int Opcode() const;
 963 };
 964 
 965 //------------------------------WeakCompareAndSwapSNode---------------------------
 966 class WeakCompareAndSwapSNode : public CompareAndSwapNode {
 967 public:
 968   WeakCompareAndSwapSNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 969   virtual int Opcode() const;
 970 };
 971 
 972 //------------------------------WeakCompareAndSwapINode---------------------------
 973 class WeakCompareAndSwapINode : public CompareAndSwapNode {
 974 public:
 975   WeakCompareAndSwapINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 976   virtual int Opcode() const;
 977 };
 978 
 979 //------------------------------WeakCompareAndSwapLNode---------------------------
 980 class WeakCompareAndSwapLNode : public CompareAndSwapNode {
 981 public:
 982   WeakCompareAndSwapLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 983   virtual int Opcode() const;
 984 };
 985 
 986 //------------------------------WeakCompareAndSwapPNode---------------------------
 987 class WeakCompareAndSwapPNode : public CompareAndSwapNode {
 988 public:
 989   WeakCompareAndSwapPNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 990   virtual int Opcode() const;
 991 };
 992 
 993 //------------------------------WeakCompareAndSwapNNode---------------------------
 994 class WeakCompareAndSwapNNode : public CompareAndSwapNode {
 995 public:
 996   WeakCompareAndSwapNNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { }
 997   virtual int Opcode() const;
 998 };
 999 
1000 //------------------------------CompareAndExchangeBNode---------------------------
1001 class CompareAndExchangeBNode : public CompareAndExchangeNode {
1002 public:
1003   CompareAndExchangeBNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, TypeInt::BYTE) { }
1004   virtual int Opcode() const;
1005 };
1006 
1007 
1008 //------------------------------CompareAndExchangeSNode---------------------------
1009 class CompareAndExchangeSNode : public CompareAndExchangeNode {
1010 public:
1011   CompareAndExchangeSNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, TypeInt::SHORT) { }
1012   virtual int Opcode() const;
1013 };
1014 
1015 //------------------------------CompareAndExchangeLNode---------------------------
1016 class CompareAndExchangeLNode : public CompareAndExchangeNode {
1017 public:
1018   CompareAndExchangeLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, TypeLong::LONG) { }
1019   virtual int Opcode() const;
1020 };
1021 
1022 
1023 //------------------------------CompareAndExchangeINode---------------------------
1024 class CompareAndExchangeINode : public CompareAndExchangeNode {
1025 public:
1026   CompareAndExchangeINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, TypeInt::INT) { }
1027   virtual int Opcode() const;
1028 };
1029 
1030 
1031 //------------------------------CompareAndExchangePNode---------------------------
1032 class CompareAndExchangePNode : public CompareAndExchangeNode {
1033 public:
1034   CompareAndExchangePNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, const Type* t, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, t) { }
1035   virtual int Opcode() const;
1036 };
1037 
1038 //------------------------------CompareAndExchangeNNode---------------------------
1039 class CompareAndExchangeNNode : public CompareAndExchangeNode {
1040 public:
1041   CompareAndExchangeNNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, const Type* t, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, t) { }
1042   virtual int Opcode() const;
1043 };
1044 
1045 //------------------------------GetAndAddBNode---------------------------
1046 class GetAndAddBNode : public LoadStoreNode {
1047 public:
1048   GetAndAddBNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::BYTE, 4) { }
1049   virtual int Opcode() const;
1050 };
1051 
1052 //------------------------------GetAndAddSNode---------------------------
1053 class GetAndAddSNode : public LoadStoreNode {
1054 public:
1055   GetAndAddSNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::SHORT, 4) { }
1056   virtual int Opcode() const;
1057 };
1058 
1059 //------------------------------GetAndAddINode---------------------------
1060 class GetAndAddINode : public LoadStoreNode {
1061 public:
1062   GetAndAddINode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::INT, 4) { }
1063   virtual int Opcode() const;
1064 };
1065 
1066 //------------------------------GetAndAddLNode---------------------------
1067 class GetAndAddLNode : public LoadStoreNode {
1068 public:
1069   GetAndAddLNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeLong::LONG, 4) { }
1070   virtual int Opcode() const;
1071 };
1072 
1073 //------------------------------GetAndSetBNode---------------------------
1074 class GetAndSetBNode : public LoadStoreNode {
1075 public:
1076   GetAndSetBNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::BYTE, 4) { }
1077   virtual int Opcode() const;
1078 };
1079 
1080 //------------------------------GetAndSetSNode---------------------------
1081 class GetAndSetSNode : public LoadStoreNode {
1082 public:
1083   GetAndSetSNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::SHORT, 4) { }
1084   virtual int Opcode() const;
1085 };
1086 
1087 //------------------------------GetAndSetINode---------------------------
1088 class GetAndSetINode : public LoadStoreNode {
1089 public:
1090   GetAndSetINode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::INT, 4) { }
1091   virtual int Opcode() const;
1092 };
1093 
1094 //------------------------------GetAndSetLNode---------------------------
1095 class GetAndSetLNode : public LoadStoreNode {
1096 public:
1097   GetAndSetLNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeLong::LONG, 4) { }
1098   virtual int Opcode() const;
1099 };
1100 
1101 //------------------------------GetAndSetPNode---------------------------
1102 class GetAndSetPNode : public LoadStoreNode {
1103 public:
1104   GetAndSetPNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* t ) : LoadStoreNode(c, mem, adr, val, at, t, 4) { }
1105   virtual int Opcode() const;
1106 };
1107 
1108 //------------------------------GetAndSetNNode---------------------------
1109 class GetAndSetNNode : public LoadStoreNode {
1110 public:
1111   GetAndSetNNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* t ) : LoadStoreNode(c, mem, adr, val, at, t, 4) { }
1112   virtual int Opcode() const;
1113 };
1114 
1115 //------------------------------ClearArray-------------------------------------
1116 class ClearArrayNode: public Node {
1117 private:
1118   bool _is_large;
1119 public:
1120   ClearArrayNode( Node *ctrl, Node *arymem, Node *word_cnt, Node *base, bool is_large)
1121     : Node(ctrl,arymem,word_cnt,base), _is_large(is_large) {
1122     init_class_id(Class_ClearArray);
1123   }
1124   virtual int         Opcode() const;
1125   virtual const Type *bottom_type() const { return Type::MEMORY; }
1126   // ClearArray modifies array elements, and so affects only the
1127   // array memory addressed by the bottom_type of its base address.
1128   virtual const class TypePtr *adr_type() const;
1129   virtual Node* Identity(PhaseGVN* phase);
1130   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
1131   virtual uint match_edge(uint idx) const;
1132   bool is_large() const { return _is_large; }
1133 
1134   // Clear the given area of an object or array.
1135   // The start offset must always be aligned mod BytesPerInt.
1136   // The end offset must always be aligned mod BytesPerLong.
1137   // Return the new memory.
1138   static Node* clear_memory(Node* control, Node* mem, Node* dest,
1139                             intptr_t start_offset,
1140                             intptr_t end_offset,
1141                             PhaseGVN* phase);
1142   static Node* clear_memory(Node* control, Node* mem, Node* dest,
1143                             intptr_t start_offset,
1144                             Node* end_offset,
1145                             PhaseGVN* phase);
1146   static Node* clear_memory(Node* control, Node* mem, Node* dest,
1147                             Node* start_offset,
1148                             Node* end_offset,
1149                             PhaseGVN* phase);
1150   // Return allocation input memory edge if it is different instance
1151   // or itself if it is the one we are looking for.
1152   static bool step_through(Node** np, uint instance_id, PhaseTransform* phase);
1153 };
1154 
1155 //------------------------------MemBar-----------------------------------------
1156 // There are different flavors of Memory Barriers to match the Java Memory
1157 // Model.  Monitor-enter and volatile-load act as Aquires: no following ref
1158 // can be moved to before them.  We insert a MemBar-Acquire after a FastLock or
1159 // volatile-load.  Monitor-exit and volatile-store act as Release: no
1160 // preceding ref can be moved to after them.  We insert a MemBar-Release
1161 // before a FastUnlock or volatile-store.  All volatiles need to be
1162 // serialized, so we follow all volatile-stores with a MemBar-Volatile to
1163 // separate it from any following volatile-load.
1164 class MemBarNode: public MultiNode {
1165   virtual uint hash() const ;                  // { return NO_HASH; }
1166   virtual bool cmp( const Node &n ) const ;    // Always fail, except on self
1167 
1168   virtual uint size_of() const { return sizeof(*this); }
1169   // Memory type this node is serializing.  Usually either rawptr or bottom.
1170   const TypePtr* _adr_type;
1171 
1172   // How is this membar related to a nearby memory access?
1173   enum {
1174     Standalone,
1175     TrailingLoad,
1176     TrailingStore,
1177     LeadingStore,
1178     TrailingLoadStore,
1179     LeadingLoadStore
1180   } _kind;
1181 
1182 #ifdef ASSERT
1183   uint _pair_idx;
1184 #endif
1185 
1186 public:
1187   enum {
1188     Precedent = TypeFunc::Parms  // optional edge to force precedence
1189   };
1190   MemBarNode(Compile* C, int alias_idx, Node* precedent);
1191   virtual int Opcode() const = 0;
1192   virtual const class TypePtr *adr_type() const { return _adr_type; }
1193   virtual const Type* Value(PhaseGVN* phase) const;
1194   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
1195   virtual uint match_edge(uint idx) const { return 0; }
1196   virtual const Type *bottom_type() const { return TypeTuple::MEMBAR; }
1197   virtual Node *match( const ProjNode *proj, const Matcher *m );
1198   // Factory method.  Builds a wide or narrow membar.
1199   // Optional 'precedent' becomes an extra edge if not null.
1200   static MemBarNode* make(Compile* C, int opcode,
1201                           int alias_idx = Compile::AliasIdxBot,
1202                           Node* precedent = NULL);
1203 
1204   MemBarNode* trailing_membar() const;
1205   MemBarNode* leading_membar() const;
1206 
1207   void set_trailing_load() { _kind = TrailingLoad; }
1208   bool trailing_load() const { return _kind == TrailingLoad; }
1209   bool trailing_store() const { return _kind == TrailingStore; }
1210   bool leading_store() const { return _kind == LeadingStore; }
1211   bool trailing_load_store() const { return _kind == TrailingLoadStore; }
1212   bool leading_load_store() const { return _kind == LeadingLoadStore; }
1213   bool trailing() const { return _kind == TrailingLoad || _kind == TrailingStore || _kind == TrailingLoadStore; }
1214   bool leading() const { return _kind == LeadingStore || _kind == LeadingLoadStore; }
1215   bool standalone() const { return _kind == Standalone; }
1216 
1217   static void set_store_pair(MemBarNode* leading, MemBarNode* trailing);
1218   static void set_load_store_pair(MemBarNode* leading, MemBarNode* trailing);
1219 
1220   void remove(PhaseIterGVN *igvn);
1221 };
1222 
1223 // "Acquire" - no following ref can move before (but earlier refs can
1224 // follow, like an early Load stalled in cache).  Requires multi-cpu
1225 // visibility.  Inserted after a volatile load.
1226 class MemBarAcquireNode: public MemBarNode {
1227 public:
1228   MemBarAcquireNode(Compile* C, int alias_idx, Node* precedent)
1229     : MemBarNode(C, alias_idx, precedent) {}
1230   virtual int Opcode() const;
1231 };
1232 
1233 // "Acquire" - no following ref can move before (but earlier refs can
1234 // follow, like an early Load stalled in cache).  Requires multi-cpu
1235 // visibility.  Inserted independ of any load, as required
1236 // for intrinsic Unsafe.loadFence().
1237 class LoadFenceNode: public MemBarNode {
1238 public:
1239   LoadFenceNode(Compile* C, int alias_idx, Node* precedent)
1240     : MemBarNode(C, alias_idx, precedent) {}
1241   virtual int Opcode() const;
1242 };
1243 
1244 // "Release" - no earlier ref can move after (but later refs can move
1245 // up, like a speculative pipelined cache-hitting Load).  Requires
1246 // multi-cpu visibility.  Inserted before a volatile store.
1247 class MemBarReleaseNode: public MemBarNode {
1248 public:
1249   MemBarReleaseNode(Compile* C, int alias_idx, Node* precedent)
1250     : MemBarNode(C, alias_idx, precedent) {}
1251   virtual int Opcode() const;
1252 };
1253 
1254 // "Release" - no earlier ref can move after (but later refs can move
1255 // up, like a speculative pipelined cache-hitting Load).  Requires
1256 // multi-cpu visibility.  Inserted independent of any store, as required
1257 // for intrinsic Unsafe.storeFence().
1258 class StoreFenceNode: public MemBarNode {
1259 public:
1260   StoreFenceNode(Compile* C, int alias_idx, Node* precedent)
1261     : MemBarNode(C, alias_idx, precedent) {}
1262   virtual int Opcode() const;
1263 };
1264 
1265 // "Acquire" - no following ref can move before (but earlier refs can
1266 // follow, like an early Load stalled in cache).  Requires multi-cpu
1267 // visibility.  Inserted after a FastLock.
1268 class MemBarAcquireLockNode: public MemBarNode {
1269 public:
1270   MemBarAcquireLockNode(Compile* C, int alias_idx, Node* precedent)
1271     : MemBarNode(C, alias_idx, precedent) {}
1272   virtual int Opcode() const;
1273 };
1274 
1275 // "Release" - no earlier ref can move after (but later refs can move
1276 // up, like a speculative pipelined cache-hitting Load).  Requires
1277 // multi-cpu visibility.  Inserted before a FastUnLock.
1278 class MemBarReleaseLockNode: public MemBarNode {
1279 public:
1280   MemBarReleaseLockNode(Compile* C, int alias_idx, Node* precedent)
1281     : MemBarNode(C, alias_idx, precedent) {}
1282   virtual int Opcode() const;
1283 };
1284 
1285 class MemBarStoreStoreNode: public MemBarNode {
1286 public:
1287   MemBarStoreStoreNode(Compile* C, int alias_idx, Node* precedent)
1288     : MemBarNode(C, alias_idx, precedent) {
1289     init_class_id(Class_MemBarStoreStore);
1290   }
1291   virtual int Opcode() const;
1292 };
1293 
1294 // Ordering between a volatile store and a following volatile load.
1295 // Requires multi-CPU visibility?
1296 class MemBarVolatileNode: public MemBarNode {
1297 public:
1298   MemBarVolatileNode(Compile* C, int alias_idx, Node* precedent)
1299     : MemBarNode(C, alias_idx, precedent) {}
1300   virtual int Opcode() const;
1301 };
1302 
1303 // Ordering within the same CPU.  Used to order unsafe memory references
1304 // inside the compiler when we lack alias info.  Not needed "outside" the
1305 // compiler because the CPU does all the ordering for us.
1306 class MemBarCPUOrderNode: public MemBarNode {
1307 public:
1308   MemBarCPUOrderNode(Compile* C, int alias_idx, Node* precedent)
1309     : MemBarNode(C, alias_idx, precedent) {}
1310   virtual int Opcode() const;
1311   virtual uint ideal_reg() const { return 0; } // not matched in the AD file
1312 };
1313 
1314 class OnSpinWaitNode: public MemBarNode {
1315 public:
1316   OnSpinWaitNode(Compile* C, int alias_idx, Node* precedent)
1317     : MemBarNode(C, alias_idx, precedent) {}
1318   virtual int Opcode() const;
1319 };
1320 
1321 // Isolation of object setup after an AllocateNode and before next safepoint.
1322 // (See comment in memnode.cpp near InitializeNode::InitializeNode for semantics.)
1323 class InitializeNode: public MemBarNode {
1324   friend class AllocateNode;
1325 
1326   enum {
1327     Incomplete    = 0,
1328     Complete      = 1,
1329     WithArraycopy = 2
1330   };
1331   int _is_complete;
1332 
1333   bool _does_not_escape;
1334 
1335 public:
1336   enum {
1337     Control    = TypeFunc::Control,
1338     Memory     = TypeFunc::Memory,     // MergeMem for states affected by this op
1339     RawAddress = TypeFunc::Parms+0,    // the newly-allocated raw address
1340     RawStores  = TypeFunc::Parms+1     // zero or more stores (or TOP)
1341   };
1342 
1343   InitializeNode(Compile* C, int adr_type, Node* rawoop);
1344   virtual int Opcode() const;
1345   virtual uint size_of() const { return sizeof(*this); }
1346   virtual uint ideal_reg() const { return 0; } // not matched in the AD file
1347   virtual const RegMask &in_RegMask(uint) const;  // mask for RawAddress
1348 
1349   // Manage incoming memory edges via a MergeMem on in(Memory):
1350   Node* memory(uint alias_idx);
1351 
1352   // The raw memory edge coming directly from the Allocation.
1353   // The contents of this memory are *always* all-zero-bits.
1354   Node* zero_memory() { return memory(Compile::AliasIdxRaw); }
1355 
1356   // Return the corresponding allocation for this initialization (or null if none).
1357   // (Note: Both InitializeNode::allocation and AllocateNode::initialization
1358   // are defined in graphKit.cpp, which sets up the bidirectional relation.)
1359   AllocateNode* allocation();
1360 
1361   // Anything other than zeroing in this init?
1362   bool is_non_zero();
1363 
1364   // An InitializeNode must completed before macro expansion is done.
1365   // Completion requires that the AllocateNode must be followed by
1366   // initialization of the new memory to zero, then to any initializers.
1367   bool is_complete() { return _is_complete != Incomplete; }
1368   bool is_complete_with_arraycopy() { return (_is_complete & WithArraycopy) != 0; }
1369 
1370   // Mark complete.  (Must not yet be complete.)
1371   void set_complete(PhaseGVN* phase);
1372   void set_complete_with_arraycopy() { _is_complete = Complete | WithArraycopy; }
1373 
1374   bool does_not_escape() { return _does_not_escape; }
1375   void set_does_not_escape() { _does_not_escape = true; }
1376 
1377 #ifdef ASSERT
1378   // ensure all non-degenerate stores are ordered and non-overlapping
1379   bool stores_are_sane(PhaseTransform* phase);
1380 #endif //ASSERT
1381 
1382   // See if this store can be captured; return offset where it initializes.
1383   // Return 0 if the store cannot be moved (any sort of problem).
1384   intptr_t can_capture_store(StoreNode* st, PhaseTransform* phase, bool can_reshape);
1385 
1386   // Capture another store; reformat it to write my internal raw memory.
1387   // Return the captured copy, else NULL if there is some sort of problem.
1388   Node* capture_store(StoreNode* st, intptr_t start, PhaseTransform* phase, bool can_reshape);
1389 
1390   // Find captured store which corresponds to the range [start..start+size).
1391   // Return my own memory projection (meaning the initial zero bits)
1392   // if there is no such store.  Return NULL if there is a problem.
1393   Node* find_captured_store(intptr_t start, int size_in_bytes, PhaseTransform* phase);
1394 
1395   // Called when the associated AllocateNode is expanded into CFG.
1396   Node* complete_stores(Node* rawctl, Node* rawmem, Node* rawptr,
1397                         intptr_t header_size, Node* size_in_bytes,
1398                         PhaseGVN* phase);
1399 
1400  private:
1401   void remove_extra_zeroes();
1402 
1403   // Find out where a captured store should be placed (or already is placed).
1404   int captured_store_insertion_point(intptr_t start, int size_in_bytes,
1405                                      PhaseTransform* phase);
1406 
1407   static intptr_t get_store_offset(Node* st, PhaseTransform* phase);
1408 
1409   Node* make_raw_address(intptr_t offset, PhaseTransform* phase);
1410 
1411   bool detect_init_independence(Node* n, int& count);
1412 
1413   void coalesce_subword_stores(intptr_t header_size, Node* size_in_bytes,
1414                                PhaseGVN* phase);
1415 
1416   intptr_t find_next_fullword_store(uint i, PhaseGVN* phase);
1417 };
1418 
1419 //------------------------------MergeMem---------------------------------------
1420 // (See comment in memnode.cpp near MergeMemNode::MergeMemNode for semantics.)
1421 class MergeMemNode: public Node {
1422   virtual uint hash() const ;                  // { return NO_HASH; }
1423   virtual bool cmp( const Node &n ) const ;    // Always fail, except on self
1424   friend class MergeMemStream;
1425   MergeMemNode(Node* def);  // clients use MergeMemNode::make
1426 
1427 public:
1428   // If the input is a whole memory state, clone it with all its slices intact.
1429   // Otherwise, make a new memory state with just that base memory input.
1430   // In either case, the result is a newly created MergeMem.
1431   static MergeMemNode* make(Node* base_memory);
1432 
1433   virtual int Opcode() const;
1434   virtual Node* Identity(PhaseGVN* phase);
1435   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
1436   virtual uint ideal_reg() const { return NotAMachineReg; }
1437   virtual uint match_edge(uint idx) const { return 0; }
1438   virtual const RegMask &out_RegMask() const;
1439   virtual const Type *bottom_type() const { return Type::MEMORY; }
1440   virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; }
1441   // sparse accessors
1442   // Fetch the previously stored "set_memory_at", or else the base memory.
1443   // (Caller should clone it if it is a phi-nest.)
1444   Node* memory_at(uint alias_idx) const;
1445   // set the memory, regardless of its previous value
1446   void set_memory_at(uint alias_idx, Node* n);
1447   // the "base" is the memory that provides the non-finite support
1448   Node* base_memory() const       { return in(Compile::AliasIdxBot); }
1449   // warning: setting the base can implicitly set any of the other slices too
1450   void set_base_memory(Node* def);
1451   // sentinel value which denotes a copy of the base memory:
1452   Node*   empty_memory() const    { return in(Compile::AliasIdxTop); }
1453   static Node* make_empty_memory(); // where the sentinel comes from
1454   bool is_empty_memory(Node* n) const { assert((n == empty_memory()) == n->is_top(), "sanity"); return n->is_top(); }
1455   // hook for the iterator, to perform any necessary setup
1456   void iteration_setup(const MergeMemNode* other = NULL);
1457   // push sentinels until I am at least as long as the other (semantic no-op)
1458   void grow_to_match(const MergeMemNode* other);
1459   bool verify_sparse() const PRODUCT_RETURN0;
1460 #ifndef PRODUCT
1461   virtual void dump_spec(outputStream *st) const;
1462 #endif
1463 };
1464 
1465 class MergeMemStream : public StackObj {
1466  private:
1467   MergeMemNode*       _mm;
1468   const MergeMemNode* _mm2;  // optional second guy, contributes non-empty iterations
1469   Node*               _mm_base;  // loop-invariant base memory of _mm
1470   int                 _idx;
1471   int                 _cnt;
1472   Node*               _mem;
1473   Node*               _mem2;
1474   int                 _cnt2;
1475 
1476   void init(MergeMemNode* mm, const MergeMemNode* mm2 = NULL) {
1477     // subsume_node will break sparseness at times, whenever a memory slice
1478     // folds down to a copy of the base ("fat") memory.  In such a case,
1479     // the raw edge will update to base, although it should be top.
1480     // This iterator will recognize either top or base_memory as an
1481     // "empty" slice.  See is_empty, is_empty2, and next below.
1482     //
1483     // The sparseness property is repaired in MergeMemNode::Ideal.
1484     // As long as access to a MergeMem goes through this iterator
1485     // or the memory_at accessor, flaws in the sparseness will
1486     // never be observed.
1487     //
1488     // Also, iteration_setup repairs sparseness.
1489     assert(mm->verify_sparse(), "please, no dups of base");
1490     assert(mm2==NULL || mm2->verify_sparse(), "please, no dups of base");
1491 
1492     _mm  = mm;
1493     _mm_base = mm->base_memory();
1494     _mm2 = mm2;
1495     _cnt = mm->req();
1496     _idx = Compile::AliasIdxBot-1; // start at the base memory
1497     _mem = NULL;
1498     _mem2 = NULL;
1499   }
1500 
1501 #ifdef ASSERT
1502   Node* check_memory() const {
1503     if (at_base_memory())
1504       return _mm->base_memory();
1505     else if ((uint)_idx < _mm->req() && !_mm->in(_idx)->is_top())
1506       return _mm->memory_at(_idx);
1507     else
1508       return _mm_base;
1509   }
1510   Node* check_memory2() const {
1511     return at_base_memory()? _mm2->base_memory(): _mm2->memory_at(_idx);
1512   }
1513 #endif
1514 
1515   static bool match_memory(Node* mem, const MergeMemNode* mm, int idx) PRODUCT_RETURN0;
1516   void assert_synch() const {
1517     assert(!_mem || _idx >= _cnt || match_memory(_mem, _mm, _idx),
1518            "no side-effects except through the stream");
1519   }
1520 
1521  public:
1522 
1523   // expected usages:
1524   // for (MergeMemStream mms(mem->is_MergeMem()); next_non_empty(); ) { ... }
1525   // for (MergeMemStream mms(mem1, mem2); next_non_empty2(); ) { ... }
1526 
1527   // iterate over one merge
1528   MergeMemStream(MergeMemNode* mm) {
1529     mm->iteration_setup();
1530     init(mm);
1531     debug_only(_cnt2 = 999);
1532   }
1533   // iterate in parallel over two merges
1534   // only iterates through non-empty elements of mm2
1535   MergeMemStream(MergeMemNode* mm, const MergeMemNode* mm2) {
1536     assert(mm2, "second argument must be a MergeMem also");
1537     ((MergeMemNode*)mm2)->iteration_setup();  // update hidden state
1538     mm->iteration_setup(mm2);
1539     init(mm, mm2);
1540     _cnt2 = mm2->req();
1541   }
1542 #ifdef ASSERT
1543   ~MergeMemStream() {
1544     assert_synch();
1545   }
1546 #endif
1547 
1548   MergeMemNode* all_memory() const {
1549     return _mm;
1550   }
1551   Node* base_memory() const {
1552     assert(_mm_base == _mm->base_memory(), "no update to base memory, please");
1553     return _mm_base;
1554   }
1555   const MergeMemNode* all_memory2() const {
1556     assert(_mm2 != NULL, "");
1557     return _mm2;
1558   }
1559   bool at_base_memory() const {
1560     return _idx == Compile::AliasIdxBot;
1561   }
1562   int alias_idx() const {
1563     assert(_mem, "must call next 1st");
1564     return _idx;
1565   }
1566 
1567   const TypePtr* adr_type() const {
1568     return Compile::current()->get_adr_type(alias_idx());
1569   }
1570 
1571   const TypePtr* adr_type(Compile* C) const {
1572     return C->get_adr_type(alias_idx());
1573   }
1574   bool is_empty() const {
1575     assert(_mem, "must call next 1st");
1576     assert(_mem->is_top() == (_mem==_mm->empty_memory()), "correct sentinel");
1577     return _mem->is_top();
1578   }
1579   bool is_empty2() const {
1580     assert(_mem2, "must call next 1st");
1581     assert(_mem2->is_top() == (_mem2==_mm2->empty_memory()), "correct sentinel");
1582     return _mem2->is_top();
1583   }
1584   Node* memory() const {
1585     assert(!is_empty(), "must not be empty");
1586     assert_synch();
1587     return _mem;
1588   }
1589   // get the current memory, regardless of empty or non-empty status
1590   Node* force_memory() const {
1591     assert(!is_empty() || !at_base_memory(), "");
1592     // Use _mm_base to defend against updates to _mem->base_memory().
1593     Node *mem = _mem->is_top() ? _mm_base : _mem;
1594     assert(mem == check_memory(), "");
1595     return mem;
1596   }
1597   Node* memory2() const {
1598     assert(_mem2 == check_memory2(), "");
1599     return _mem2;
1600   }
1601   void set_memory(Node* mem) {
1602     if (at_base_memory()) {
1603       // Note that this does not change the invariant _mm_base.
1604       _mm->set_base_memory(mem);
1605     } else {
1606       _mm->set_memory_at(_idx, mem);
1607     }
1608     _mem = mem;
1609     assert_synch();
1610   }
1611 
1612   // Recover from a side effect to the MergeMemNode.
1613   void set_memory() {
1614     _mem = _mm->in(_idx);
1615   }
1616 
1617   bool next()  { return next(false); }
1618   bool next2() { return next(true); }
1619 
1620   bool next_non_empty()  { return next_non_empty(false); }
1621   bool next_non_empty2() { return next_non_empty(true); }
1622   // next_non_empty2 can yield states where is_empty() is true
1623 
1624  private:
1625   // find the next item, which might be empty
1626   bool next(bool have_mm2) {
1627     assert((_mm2 != NULL) == have_mm2, "use other next");
1628     assert_synch();
1629     if (++_idx < _cnt) {
1630       // Note:  This iterator allows _mm to be non-sparse.
1631       // It behaves the same whether _mem is top or base_memory.
1632       _mem = _mm->in(_idx);
1633       if (have_mm2)
1634         _mem2 = _mm2->in((_idx < _cnt2) ? _idx : Compile::AliasIdxTop);
1635       return true;
1636     }
1637     return false;
1638   }
1639 
1640   // find the next non-empty item
1641   bool next_non_empty(bool have_mm2) {
1642     while (next(have_mm2)) {
1643       if (!is_empty()) {
1644         // make sure _mem2 is filled in sensibly
1645         if (have_mm2 && _mem2->is_top())  _mem2 = _mm2->base_memory();
1646         return true;
1647       } else if (have_mm2 && !is_empty2()) {
1648         return true;   // is_empty() == true
1649       }
1650     }
1651     return false;
1652   }
1653 };
1654 
1655 //------------------------------Prefetch---------------------------------------
1656 
1657 // Allocation prefetch which may fault, TLAB size have to be adjusted.
1658 class PrefetchAllocationNode : public Node {
1659 public:
1660   PrefetchAllocationNode(Node *mem, Node *adr) : Node(0,mem,adr) {}
1661   virtual int Opcode() const;
1662   virtual uint ideal_reg() const { return NotAMachineReg; }
1663   virtual uint match_edge(uint idx) const { return idx==2; }
1664   virtual const Type *bottom_type() const { return ( AllocatePrefetchStyle == 3 ) ? Type::MEMORY : Type::ABIO; }
1665 };
1666 
1667 #endif // SHARE_OPTO_MEMNODE_HPP