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