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