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