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