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