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