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