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