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