1 /* 2 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_OPTO_CALLNODE_HPP 26 #define SHARE_OPTO_CALLNODE_HPP 27 28 #include "opto/connode.hpp" 29 #include "opto/mulnode.hpp" 30 #include "opto/multnode.hpp" 31 #include "opto/opcodes.hpp" 32 #include "opto/phaseX.hpp" 33 #include "opto/replacednodes.hpp" 34 #include "opto/type.hpp" 35 #include "utilities/growableArray.hpp" 36 37 // Portions of code courtesy of Clifford Click 38 39 // Optimization - Graph Style 40 41 class NamedCounter; 42 class MultiNode; 43 class SafePointNode; 44 class CallNode; 45 class CallJavaNode; 46 class CallStaticJavaNode; 47 class CallDynamicJavaNode; 48 class CallRuntimeNode; 49 class CallLeafNode; 50 class CallLeafNoFPNode; 51 class CallLeafVectorNode; 52 class AllocateNode; 53 class AllocateArrayNode; 54 class AbstractLockNode; 55 class LockNode; 56 class UnlockNode; 57 class FastLockNode; 58 59 //------------------------------StartNode-------------------------------------- 60 // The method start node 61 class StartNode : public MultiNode { 62 virtual bool cmp( const Node &n ) const; 63 virtual uint size_of() const; // Size is bigger 64 public: 65 const TypeTuple *_domain; 66 StartNode( Node *root, const TypeTuple *domain ) : MultiNode(2), _domain(domain) { 67 init_class_id(Class_Start); 68 init_req(0,this); 69 init_req(1,root); 70 } 71 virtual int Opcode() const; 72 virtual bool pinned() const { return true; }; 73 virtual const Type *bottom_type() const; 74 virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; } 75 virtual const Type* Value(PhaseGVN* phase) const; 76 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 77 virtual void calling_convention( BasicType* sig_bt, VMRegPair *parm_reg, uint length ) const; 78 virtual const RegMask &in_RegMask(uint) const; 79 virtual Node *match( const ProjNode *proj, const Matcher *m ); 80 virtual uint ideal_reg() const { return 0; } 81 #ifndef PRODUCT 82 virtual void dump_spec(outputStream *st) const; 83 virtual void dump_compact_spec(outputStream *st) const; 84 #endif 85 }; 86 87 //------------------------------StartOSRNode----------------------------------- 88 // The method start node for on stack replacement code 89 class StartOSRNode : public StartNode { 90 public: 91 StartOSRNode( Node *root, const TypeTuple *domain ) : StartNode(root, domain) {} 92 virtual int Opcode() const; 93 static const TypeTuple *osr_domain(); 94 }; 95 96 97 //------------------------------ParmNode--------------------------------------- 98 // Incoming parameters 99 class ParmNode : public ProjNode { 100 static const char * const names[TypeFunc::Parms+1]; 101 public: 102 ParmNode( StartNode *src, uint con ) : ProjNode(src,con) { 103 init_class_id(Class_Parm); 104 } 105 virtual int Opcode() const; 106 virtual bool is_CFG() const { return (_con == TypeFunc::Control); } 107 virtual uint ideal_reg() const; 108 #ifndef PRODUCT 109 virtual void dump_spec(outputStream *st) const; 110 virtual void dump_compact_spec(outputStream *st) const; 111 #endif 112 }; 113 114 115 //------------------------------ReturnNode------------------------------------- 116 // Return from subroutine node 117 class ReturnNode : public Node { 118 public: 119 ReturnNode(uint edges, Node* cntrl, Node* i_o, Node* memory, Node* frameptr, Node* retadr); 120 virtual int Opcode() const; 121 virtual bool is_CFG() const { return true; } 122 virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash 123 virtual bool depends_only_on_test() const { return false; } 124 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 125 virtual const Type* Value(PhaseGVN* phase) const; 126 virtual uint ideal_reg() const { return NotAMachineReg; } 127 virtual uint match_edge(uint idx) const; 128 #ifndef PRODUCT 129 virtual void dump_req(outputStream *st = tty, DumpConfig* dc = nullptr) const; 130 #endif 131 }; 132 133 134 //------------------------------RethrowNode------------------------------------ 135 // Rethrow of exception at call site. Ends a procedure before rethrowing; 136 // ends the current basic block like a ReturnNode. Restores registers and 137 // unwinds stack. Rethrow happens in the caller's method. 138 class RethrowNode : public Node { 139 public: 140 RethrowNode( Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *ret_adr, Node *exception ); 141 virtual int Opcode() const; 142 virtual bool is_CFG() const { return true; } 143 virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash 144 virtual bool depends_only_on_test() const { return false; } 145 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 146 virtual const Type* Value(PhaseGVN* phase) const; 147 virtual uint match_edge(uint idx) const; 148 virtual uint ideal_reg() const { return NotAMachineReg; } 149 #ifndef PRODUCT 150 virtual void dump_req(outputStream *st = tty, DumpConfig* dc = nullptr) const; 151 #endif 152 }; 153 154 155 //------------------------------ForwardExceptionNode--------------------------- 156 // Pop stack frame and jump to StubRoutines::forward_exception_entry() 157 class ForwardExceptionNode : public ReturnNode { 158 public: 159 ForwardExceptionNode(Node* cntrl, Node* i_o, Node* memory, Node* frameptr, Node* retadr) 160 : ReturnNode(TypeFunc::Parms, cntrl, i_o, memory, frameptr, retadr) { 161 } 162 163 virtual int Opcode() const; 164 }; 165 166 //------------------------------TailCallNode----------------------------------- 167 // Pop stack frame and jump indirect 168 class TailCallNode : public ReturnNode { 169 public: 170 TailCallNode( Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *retadr, Node *target, Node *moop ) 171 : ReturnNode( TypeFunc::Parms+2, cntrl, i_o, memory, frameptr, retadr ) { 172 init_req(TypeFunc::Parms, target); 173 init_req(TypeFunc::Parms+1, moop); 174 } 175 176 virtual int Opcode() const; 177 virtual uint match_edge(uint idx) const; 178 }; 179 180 //------------------------------TailJumpNode----------------------------------- 181 // Pop stack frame and jump indirect 182 class TailJumpNode : public ReturnNode { 183 public: 184 TailJumpNode( Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *target, Node *ex_oop) 185 : ReturnNode(TypeFunc::Parms+2, cntrl, i_o, memory, frameptr, Compile::current()->top()) { 186 init_req(TypeFunc::Parms, target); 187 init_req(TypeFunc::Parms+1, ex_oop); 188 } 189 190 virtual int Opcode() const; 191 virtual uint match_edge(uint idx) const; 192 }; 193 194 //-------------------------------JVMState------------------------------------- 195 // A linked list of JVMState nodes captures the whole interpreter state, 196 // plus GC roots, for all active calls at some call site in this compilation 197 // unit. (If there is no inlining, then the list has exactly one link.) 198 // This provides a way to map the optimized program back into the interpreter, 199 // or to let the GC mark the stack. 200 class JVMState : public ResourceObj { 201 public: 202 typedef enum { 203 Reexecute_Undefined = -1, // not defined -- will be translated into false later 204 Reexecute_False = 0, // false -- do not reexecute 205 Reexecute_True = 1 // true -- reexecute the bytecode 206 } ReexecuteState; //Reexecute State 207 208 private: 209 JVMState* _caller; // List pointer for forming scope chains 210 uint _depth; // One more than caller depth, or one. 211 uint _locoff; // Offset to locals in input edge mapping 212 uint _stkoff; // Offset to stack in input edge mapping 213 uint _monoff; // Offset to monitors in input edge mapping 214 uint _scloff; // Offset to fields of scalar objs in input edge mapping 215 uint _endoff; // Offset to end of input edge mapping 216 uint _sp; // Java Expression Stack Pointer for this state 217 int _bci; // Byte Code Index of this JVM point 218 ReexecuteState _reexecute; // Whether this bytecode need to be re-executed 219 ciMethod* _method; // Method Pointer 220 SafePointNode* _map; // Map node associated with this scope 221 public: 222 friend class Compile; 223 friend class PreserveReexecuteState; 224 225 // Because JVMState objects live over the entire lifetime of the 226 // Compile object, they are allocated into the comp_arena, which 227 // does not get resource marked or reset during the compile process 228 void *operator new( size_t x, Compile* C ) throw() { return C->comp_arena()->Amalloc(x); } 229 void operator delete( void * ) { } // fast deallocation 230 231 // Create a new JVMState, ready for abstract interpretation. 232 JVMState(ciMethod* method, JVMState* caller); 233 JVMState(int stack_size); // root state; has a null method 234 235 // Access functions for the JVM 236 // ... --|--- loc ---|--- stk ---|--- arg ---|--- mon ---|--- scl ---| 237 // \ locoff \ stkoff \ argoff \ monoff \ scloff \ endoff 238 uint locoff() const { return _locoff; } 239 uint stkoff() const { return _stkoff; } 240 uint argoff() const { return _stkoff + _sp; } 241 uint monoff() const { return _monoff; } 242 uint scloff() const { return _scloff; } 243 uint endoff() const { return _endoff; } 244 uint oopoff() const { return debug_end(); } 245 246 int loc_size() const { return stkoff() - locoff(); } 247 int stk_size() const { return monoff() - stkoff(); } 248 int mon_size() const { return scloff() - monoff(); } 249 int scl_size() const { return endoff() - scloff(); } 250 251 bool is_loc(uint i) const { return locoff() <= i && i < stkoff(); } 252 bool is_stk(uint i) const { return stkoff() <= i && i < monoff(); } 253 bool is_mon(uint i) const { return monoff() <= i && i < scloff(); } 254 bool is_scl(uint i) const { return scloff() <= i && i < endoff(); } 255 256 uint sp() const { return _sp; } 257 int bci() const { return _bci; } 258 bool should_reexecute() const { return _reexecute==Reexecute_True; } 259 bool is_reexecute_undefined() const { return _reexecute==Reexecute_Undefined; } 260 bool has_method() const { return _method != nullptr; } 261 ciMethod* method() const { assert(has_method(), ""); return _method; } 262 JVMState* caller() const { return _caller; } 263 SafePointNode* map() const { return _map; } 264 uint depth() const { return _depth; } 265 uint debug_start() const; // returns locoff of root caller 266 uint debug_end() const; // returns endoff of self 267 uint debug_size() const { 268 return loc_size() + sp() + mon_size() + scl_size(); 269 } 270 uint debug_depth() const; // returns sum of debug_size values at all depths 271 272 // Returns the JVM state at the desired depth (1 == root). 273 JVMState* of_depth(int d) const; 274 275 // Tells if two JVM states have the same call chain (depth, methods, & bcis). 276 bool same_calls_as(const JVMState* that) const; 277 278 // Monitors (monitors are stored as (boxNode, objNode) pairs 279 enum { logMonitorEdges = 1 }; 280 int nof_monitors() const { return mon_size() >> logMonitorEdges; } 281 int monitor_depth() const { return nof_monitors() + (caller() ? caller()->monitor_depth() : 0); } 282 int monitor_box_offset(int idx) const { return monoff() + (idx << logMonitorEdges) + 0; } 283 int monitor_obj_offset(int idx) const { return monoff() + (idx << logMonitorEdges) + 1; } 284 bool is_monitor_box(uint off) const { 285 assert(is_mon(off), "should be called only for monitor edge"); 286 return (0 == bitfield(off - monoff(), 0, logMonitorEdges)); 287 } 288 bool is_monitor_use(uint off) const { return (is_mon(off) 289 && is_monitor_box(off)) 290 || (caller() && caller()->is_monitor_use(off)); } 291 292 // Initialization functions for the JVM 293 void set_locoff(uint off) { _locoff = off; } 294 void set_stkoff(uint off) { _stkoff = off; } 295 void set_monoff(uint off) { _monoff = off; } 296 void set_scloff(uint off) { _scloff = off; } 297 void set_endoff(uint off) { _endoff = off; } 298 void set_offsets(uint off) { 299 _locoff = _stkoff = _monoff = _scloff = _endoff = off; 300 } 301 void set_map(SafePointNode* map) { _map = map; } 302 void bind_map(SafePointNode* map); // set_map() and set_jvms() for the SafePointNode 303 void set_sp(uint sp) { _sp = sp; } 304 // _reexecute is initialized to "undefined" for a new bci 305 void set_bci(int bci) {if(_bci != bci)_reexecute=Reexecute_Undefined; _bci = bci; } 306 void set_should_reexecute(bool reexec) {_reexecute = reexec ? Reexecute_True : Reexecute_False;} 307 308 // Miscellaneous utility functions 309 JVMState* clone_deep(Compile* C) const; // recursively clones caller chain 310 JVMState* clone_shallow(Compile* C) const; // retains uncloned caller 311 void set_map_deep(SafePointNode *map);// reset map for all callers 312 void adapt_position(int delta); // Adapt offsets in in-array after adding an edge. 313 int interpreter_frame_size() const; 314 315 #ifndef PRODUCT 316 void print_method_with_lineno(outputStream* st, bool show_name) const; 317 void format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const; 318 void dump_spec(outputStream *st) const; 319 void dump_on(outputStream* st) const; 320 void dump() const { 321 dump_on(tty); 322 } 323 #endif 324 }; 325 326 //------------------------------SafePointNode---------------------------------- 327 // A SafePointNode is a subclass of a MultiNode for convenience (and 328 // potential code sharing) only - conceptually it is independent of 329 // the Node semantics. 330 class SafePointNode : public MultiNode { 331 friend JVMState; 332 friend class GraphKit; 333 334 virtual bool cmp( const Node &n ) const; 335 virtual uint size_of() const; // Size is bigger 336 337 protected: 338 JVMState* const _jvms; // Pointer to list of JVM State objects 339 // Many calls take *all* of memory as input, 340 // but some produce a limited subset of that memory as output. 341 // The adr_type reports the call's behavior as a store, not a load. 342 const TypePtr* _adr_type; // What type of memory does this node produce? 343 ReplacedNodes _replaced_nodes; // During parsing: list of pair of nodes from calls to GraphKit::replace_in_map() 344 bool _has_ea_local_in_scope; // NoEscape or ArgEscape objects in JVM States 345 346 void set_jvms(JVMState* s) { 347 assert(s != nullptr, "assign null value to _jvms"); 348 *(JVMState**)&_jvms = s; // override const attribute in the accessor 349 } 350 public: 351 SafePointNode(uint edges, JVMState* jvms, 352 // A plain safepoint advertises no memory effects (null): 353 const TypePtr* adr_type = nullptr) 354 : MultiNode( edges ), 355 _jvms(jvms), 356 _adr_type(adr_type), 357 _has_ea_local_in_scope(false) 358 { 359 init_class_id(Class_SafePoint); 360 } 361 362 JVMState* jvms() const { return _jvms; } 363 virtual bool needs_deep_clone_jvms(Compile* C) { return false; } 364 void clone_jvms(Compile* C) { 365 if (jvms() != nullptr) { 366 if (needs_deep_clone_jvms(C)) { 367 set_jvms(jvms()->clone_deep(C)); 368 jvms()->set_map_deep(this); 369 } else { 370 jvms()->clone_shallow(C)->bind_map(this); 371 } 372 } 373 } 374 375 private: 376 void verify_input(JVMState* jvms, uint idx) const { 377 assert(verify_jvms(jvms), "jvms must match"); 378 Node* n = in(idx); 379 assert((!n->bottom_type()->isa_long() && !n->bottom_type()->isa_double()) || 380 in(idx + 1)->is_top(), "2nd half of long/double"); 381 } 382 383 public: 384 // Functionality from old debug nodes which has changed 385 Node *local(JVMState* jvms, uint idx) const { 386 verify_input(jvms, jvms->locoff() + idx); 387 return in(jvms->locoff() + idx); 388 } 389 Node *stack(JVMState* jvms, uint idx) const { 390 verify_input(jvms, jvms->stkoff() + idx); 391 return in(jvms->stkoff() + idx); 392 } 393 Node *argument(JVMState* jvms, uint idx) const { 394 verify_input(jvms, jvms->argoff() + idx); 395 return in(jvms->argoff() + idx); 396 } 397 Node *monitor_box(JVMState* jvms, uint idx) const { 398 assert(verify_jvms(jvms), "jvms must match"); 399 return in(jvms->monitor_box_offset(idx)); 400 } 401 Node *monitor_obj(JVMState* jvms, uint idx) const { 402 assert(verify_jvms(jvms), "jvms must match"); 403 return in(jvms->monitor_obj_offset(idx)); 404 } 405 406 void set_local(JVMState* jvms, uint idx, Node *c); 407 408 void set_stack(JVMState* jvms, uint idx, Node *c) { 409 assert(verify_jvms(jvms), "jvms must match"); 410 set_req(jvms->stkoff() + idx, c); 411 } 412 void set_argument(JVMState* jvms, uint idx, Node *c) { 413 assert(verify_jvms(jvms), "jvms must match"); 414 set_req(jvms->argoff() + idx, c); 415 } 416 void ensure_stack(JVMState* jvms, uint stk_size) { 417 assert(verify_jvms(jvms), "jvms must match"); 418 int grow_by = (int)stk_size - (int)jvms->stk_size(); 419 if (grow_by > 0) grow_stack(jvms, grow_by); 420 } 421 void grow_stack(JVMState* jvms, uint grow_by); 422 // Handle monitor stack 423 void push_monitor( const FastLockNode *lock ); 424 void pop_monitor (); 425 Node *peek_monitor_box() const; 426 Node *peek_monitor_obj() const; 427 // Peek Operand Stacks, JVMS 2.6.2 428 Node* peek_operand(uint off = 0) const; 429 430 // Access functions for the JVM 431 Node *control () const { return in(TypeFunc::Control ); } 432 Node *i_o () const { return in(TypeFunc::I_O ); } 433 Node *memory () const { return in(TypeFunc::Memory ); } 434 Node *returnadr() const { return in(TypeFunc::ReturnAdr); } 435 Node *frameptr () const { return in(TypeFunc::FramePtr ); } 436 437 void set_control ( Node *c ) { set_req(TypeFunc::Control,c); } 438 void set_i_o ( Node *c ) { set_req(TypeFunc::I_O ,c); } 439 void set_memory ( Node *c ) { set_req(TypeFunc::Memory ,c); } 440 441 MergeMemNode* merged_memory() const { 442 return in(TypeFunc::Memory)->as_MergeMem(); 443 } 444 445 // The parser marks useless maps as dead when it's done with them: 446 bool is_killed() { return in(TypeFunc::Control) == nullptr; } 447 448 // Exception states bubbling out of subgraphs such as inlined calls 449 // are recorded here. (There might be more than one, hence the "next".) 450 // This feature is used only for safepoints which serve as "maps" 451 // for JVM states during parsing, intrinsic expansion, etc. 452 SafePointNode* next_exception() const; 453 void set_next_exception(SafePointNode* n); 454 bool has_exceptions() const { return next_exception() != nullptr; } 455 456 // Helper methods to operate on replaced nodes 457 ReplacedNodes replaced_nodes() const { 458 return _replaced_nodes; 459 } 460 461 void set_replaced_nodes(ReplacedNodes replaced_nodes) { 462 _replaced_nodes = replaced_nodes; 463 } 464 465 void clone_replaced_nodes() { 466 _replaced_nodes.clone(); 467 } 468 void record_replaced_node(Node* initial, Node* improved) { 469 _replaced_nodes.record(initial, improved); 470 } 471 void transfer_replaced_nodes_from(SafePointNode* sfpt, uint idx = 0) { 472 _replaced_nodes.transfer_from(sfpt->_replaced_nodes, idx); 473 } 474 void delete_replaced_nodes() { 475 _replaced_nodes.reset(); 476 } 477 void apply_replaced_nodes(uint idx) { 478 _replaced_nodes.apply(this, idx); 479 } 480 void merge_replaced_nodes_with(SafePointNode* sfpt) { 481 _replaced_nodes.merge_with(sfpt->_replaced_nodes); 482 } 483 bool has_replaced_nodes() const { 484 return !_replaced_nodes.is_empty(); 485 } 486 void set_has_ea_local_in_scope(bool b) { 487 _has_ea_local_in_scope = b; 488 } 489 bool has_ea_local_in_scope() const { 490 return _has_ea_local_in_scope; 491 } 492 493 void disconnect_from_root(PhaseIterGVN *igvn); 494 495 // Standard Node stuff 496 virtual int Opcode() const; 497 virtual bool pinned() const { return true; } 498 virtual const Type* Value(PhaseGVN* phase) const; 499 virtual const Type* bottom_type() const { return Type::CONTROL; } 500 virtual const TypePtr* adr_type() const { return _adr_type; } 501 void set_adr_type(const TypePtr* adr_type) { _adr_type = adr_type; } 502 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 503 virtual Node* Identity(PhaseGVN* phase); 504 virtual uint ideal_reg() const { return 0; } 505 virtual const RegMask &in_RegMask(uint) const; 506 virtual const RegMask &out_RegMask() const; 507 virtual uint match_edge(uint idx) const; 508 509 #ifndef PRODUCT 510 virtual void dump_spec(outputStream *st) const; 511 #endif 512 }; 513 514 //------------------------------SafePointScalarObjectNode---------------------- 515 // A SafePointScalarObjectNode represents the state of a scalarized object 516 // at a safepoint. 517 class SafePointScalarObjectNode: public TypeNode { 518 uint _first_index; // First input edge relative index of a SafePoint node where 519 // states of the scalarized object fields are collected. 520 uint _depth; // Depth of the JVM state the _first_index field refers to 521 uint _n_fields; // Number of non-static fields of the scalarized object. 522 523 Node* _alloc; // Just for debugging purposes. 524 525 virtual uint hash() const; 526 virtual bool cmp( const Node &n ) const; 527 528 uint first_index() const { return _first_index; } 529 530 public: 531 SafePointScalarObjectNode(const TypeOopPtr* tp, Node* alloc, uint first_index, uint depth, uint n_fields); 532 533 virtual int Opcode() const; 534 virtual uint ideal_reg() const; 535 virtual const RegMask &in_RegMask(uint) const; 536 virtual const RegMask &out_RegMask() const; 537 virtual uint match_edge(uint idx) const; 538 539 uint first_index(JVMState* jvms) const { 540 assert(jvms != nullptr, "missed JVMS"); 541 return jvms->of_depth(_depth)->scloff() + _first_index; 542 } 543 uint n_fields() const { return _n_fields; } 544 545 #ifdef ASSERT 546 Node* alloc() const { return _alloc; } 547 #endif 548 549 virtual uint size_of() const { return sizeof(*this); } 550 551 // Assumes that "this" is an argument to a safepoint node "s", and that 552 // "new_call" is being created to correspond to "s". But the difference 553 // between the start index of the jvmstates of "new_call" and "s" is 554 // "jvms_adj". Produce and return a SafePointScalarObjectNode that 555 // corresponds appropriately to "this" in "new_call". Assumes that 556 // "sosn_map" is a map, specific to the translation of "s" to "new_call", 557 // mapping old SafePointScalarObjectNodes to new, to avoid multiple copies. 558 SafePointScalarObjectNode* clone(Dict* sosn_map, bool& new_node) const; 559 560 #ifndef PRODUCT 561 virtual void dump_spec(outputStream *st) const; 562 #endif 563 }; 564 565 //------------------------------SafePointScalarMergeNode---------------------- 566 // 567 // This class represents an allocation merge that is used as debug information 568 // and had at least one of its input scalar replaced. 569 // 570 // The required inputs of this node, except the control, are pointers to 571 // SafePointScalarObjectNodes that describe scalarized inputs of the original 572 // allocation merge. The other(s) properties of the class are described below. 573 // 574 // _merge_pointer_idx : index in the SafePointNode's input array where the 575 // description of the _allocation merge_ starts. The index is zero based and 576 // relative to the SafePoint's scloff. The two entries in the SafePointNode's 577 // input array starting at '_merge_pointer_idx` are Phi nodes representing: 578 // 579 // 1) The original merge Phi. During rematerialization this input will only be 580 // used if the "selector Phi" (see below) indicates that the execution of the 581 // Phi took the path of a non scalarized input. 582 // 583 // 2) A "selector Phi". The output of this Phi will be '-1' if the execution 584 // of the method exercised a non scalarized input of the original Phi. 585 // Otherwise, the output will be >=0, and it will indicate the index-1 in the 586 // SafePointScalarMergeNode input array where the description of the 587 // scalarized object that should be used is. 588 // 589 // As an example, consider a Phi merging 3 inputs, of which the last 2 are 590 // scalar replaceable. 591 // 592 // Phi(Region, NSR, SR, SR) 593 // 594 // During scalar replacement the SR inputs will be changed to null: 595 // 596 // Phi(Region, NSR, nullptr, nullptr) 597 // 598 // A corresponding selector Phi will be created with a configuration like this: 599 // 600 // Phi(Region, -1, 0, 1) 601 // 602 // During execution of the compiled method, if the execution reaches a Trap, the 603 // output of the selector Phi will tell if we need to rematerialize one of the 604 // scalar replaced inputs or if we should just use the pointer returned by the 605 // original Phi. 606 607 class SafePointScalarMergeNode: public TypeNode { 608 int _merge_pointer_idx; // This is the first input edge relative 609 // index of a SafePoint node where metadata information relative 610 // to restoring the merge is stored. The corresponding input 611 // in the associated SafePoint will point to a Phi representing 612 // potential non-scalar replaced objects. 613 614 virtual uint hash() const; 615 virtual bool cmp( const Node &n ) const; 616 617 public: 618 SafePointScalarMergeNode(const TypeOopPtr* tp, int merge_pointer_idx); 619 620 virtual int Opcode() const; 621 virtual uint ideal_reg() const; 622 virtual const RegMask &in_RegMask(uint) const; 623 virtual const RegMask &out_RegMask() const; 624 virtual uint match_edge(uint idx) const; 625 626 virtual uint size_of() const { return sizeof(*this); } 627 628 int merge_pointer_idx(JVMState* jvms) const { 629 assert(jvms != nullptr, "JVMS reference is null."); 630 return jvms->scloff() + _merge_pointer_idx; 631 } 632 633 int selector_idx(JVMState* jvms) const { 634 assert(jvms != nullptr, "JVMS reference is null."); 635 return jvms->scloff() + _merge_pointer_idx + 1; 636 } 637 638 // Assumes that "this" is an argument to a safepoint node "s", and that 639 // "new_call" is being created to correspond to "s". But the difference 640 // between the start index of the jvmstates of "new_call" and "s" is 641 // "jvms_adj". Produce and return a SafePointScalarObjectNode that 642 // corresponds appropriately to "this" in "new_call". Assumes that 643 // "sosn_map" is a map, specific to the translation of "s" to "new_call", 644 // mapping old SafePointScalarObjectNodes to new, to avoid multiple copies. 645 SafePointScalarMergeNode* clone(Dict* sosn_map, bool& new_node) const; 646 647 #ifndef PRODUCT 648 virtual void dump_spec(outputStream *st) const; 649 #endif 650 }; 651 652 // Simple container for the outgoing projections of a call. Useful 653 // for serious surgery on calls. 654 class CallProjections : public StackObj { 655 public: 656 Node* fallthrough_proj; 657 Node* fallthrough_catchproj; 658 Node* fallthrough_memproj; 659 Node* fallthrough_ioproj; 660 Node* catchall_catchproj; 661 Node* catchall_memproj; 662 Node* catchall_ioproj; 663 Node* resproj; 664 Node* exobj; 665 }; 666 667 class CallGenerator; 668 669 //------------------------------CallNode--------------------------------------- 670 // Call nodes now subsume the function of debug nodes at callsites, so they 671 // contain the functionality of a full scope chain of debug nodes. 672 class CallNode : public SafePointNode { 673 674 protected: 675 bool may_modify_arraycopy_helper(const TypeOopPtr* dest_t, const TypeOopPtr* t_oop, PhaseValues* phase); 676 677 public: 678 const TypeFunc* _tf; // Function type 679 address _entry_point; // Address of method being called 680 float _cnt; // Estimate of number of times called 681 CallGenerator* _generator; // corresponding CallGenerator for some late inline calls 682 const char* _name; // Printable name, if _method is null 683 684 CallNode(const TypeFunc* tf, address addr, const TypePtr* adr_type, JVMState* jvms = nullptr) 685 : SafePointNode(tf->domain()->cnt(), jvms, adr_type), 686 _tf(tf), 687 _entry_point(addr), 688 _cnt(COUNT_UNKNOWN), 689 _generator(nullptr), 690 _name(nullptr) 691 { 692 init_class_id(Class_Call); 693 } 694 695 const TypeFunc* tf() const { return _tf; } 696 address entry_point() const { return _entry_point; } 697 float cnt() const { return _cnt; } 698 CallGenerator* generator() const { return _generator; } 699 700 void set_tf(const TypeFunc* tf) { _tf = tf; } 701 void set_entry_point(address p) { _entry_point = p; } 702 void set_cnt(float c) { _cnt = c; } 703 void set_generator(CallGenerator* cg) { _generator = cg; } 704 705 virtual const Type* bottom_type() const; 706 virtual const Type* Value(PhaseGVN* phase) const; 707 virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 708 virtual Node* Identity(PhaseGVN* phase) { return this; } 709 virtual bool cmp(const Node &n) const; 710 virtual uint size_of() const = 0; 711 virtual void calling_convention(BasicType* sig_bt, VMRegPair* parm_regs, uint argcnt) const; 712 virtual Node* match(const ProjNode* proj, const Matcher* m); 713 virtual uint ideal_reg() const { return NotAMachineReg; } 714 // Are we guaranteed that this node is a safepoint? Not true for leaf calls and 715 // for some macro nodes whose expansion does not have a safepoint on the fast path. 716 virtual bool guaranteed_safepoint() { return true; } 717 // For macro nodes, the JVMState gets modified during expansion. If calls 718 // use MachConstantBase, it gets modified during matching. So when cloning 719 // the node the JVMState must be deep cloned. Default is to shallow clone. 720 virtual bool needs_deep_clone_jvms(Compile* C) { return C->needs_deep_clone_jvms(); } 721 722 // Returns true if the call may modify n 723 virtual bool may_modify(const TypeOopPtr* t_oop, PhaseValues* phase); 724 // Does this node have a use of n other than in debug information? 725 bool has_non_debug_use(Node* n); 726 // Returns the unique CheckCastPP of a call 727 // or result projection is there are several CheckCastPP 728 // or returns null if there is no one. 729 Node* result_cast(); 730 // Does this node returns pointer? 731 bool returns_pointer() const { 732 const TypeTuple* r = tf()->range(); 733 return (r->cnt() > TypeFunc::Parms && 734 r->field_at(TypeFunc::Parms)->isa_ptr()); 735 } 736 737 // Collect all the interesting edges from a call for use in 738 // replacing the call by something else. Used by macro expansion 739 // and the late inlining support. 740 void extract_projections(CallProjections* projs, bool separate_io_proj, bool do_asserts = true); 741 742 virtual uint match_edge(uint idx) const; 743 744 bool is_call_to_arraycopystub() const; 745 746 virtual void copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) {} 747 748 #ifndef PRODUCT 749 virtual void dump_req(outputStream* st = tty, DumpConfig* dc = nullptr) const; 750 virtual void dump_spec(outputStream* st) const; 751 #endif 752 }; 753 754 755 //------------------------------CallJavaNode----------------------------------- 756 // Make a static or dynamic subroutine call node using Java calling 757 // convention. (The "Java" calling convention is the compiler's calling 758 // convention, as opposed to the interpreter's or that of native C.) 759 class CallJavaNode : public CallNode { 760 protected: 761 virtual bool cmp( const Node &n ) const; 762 virtual uint size_of() const; // Size is bigger 763 764 ciMethod* _method; // Method being direct called 765 bool _optimized_virtual; 766 bool _method_handle_invoke; 767 bool _override_symbolic_info; // Override symbolic call site info from bytecode 768 bool _arg_escape; // ArgEscape in parameter list 769 public: 770 CallJavaNode(const TypeFunc* tf , address addr, ciMethod* method) 771 : CallNode(tf, addr, TypePtr::BOTTOM), 772 _method(method), 773 _optimized_virtual(false), 774 _method_handle_invoke(false), 775 _override_symbolic_info(false), 776 _arg_escape(false) 777 { 778 init_class_id(Class_CallJava); 779 } 780 781 virtual int Opcode() const; 782 ciMethod* method() const { return _method; } 783 void set_method(ciMethod *m) { _method = m; } 784 void set_optimized_virtual(bool f) { _optimized_virtual = f; } 785 bool is_optimized_virtual() const { return _optimized_virtual; } 786 void set_method_handle_invoke(bool f) { _method_handle_invoke = f; } 787 bool is_method_handle_invoke() const { return _method_handle_invoke; } 788 void set_override_symbolic_info(bool f) { _override_symbolic_info = f; } 789 bool override_symbolic_info() const { return _override_symbolic_info; } 790 void set_arg_escape(bool f) { _arg_escape = f; } 791 bool arg_escape() const { return _arg_escape; } 792 void copy_call_debug_info(PhaseIterGVN* phase, SafePointNode *sfpt); 793 void register_for_late_inline(); 794 795 DEBUG_ONLY( bool validate_symbolic_info() const; ) 796 797 #ifndef PRODUCT 798 virtual void dump_spec(outputStream *st) const; 799 virtual void dump_compact_spec(outputStream *st) const; 800 #endif 801 }; 802 803 //------------------------------CallStaticJavaNode----------------------------- 804 // Make a direct subroutine call using Java calling convention (for static 805 // calls and optimized virtual calls, plus calls to wrappers for run-time 806 // routines); generates static stub. 807 class CallStaticJavaNode : public CallJavaNode { 808 virtual bool cmp( const Node &n ) const; 809 virtual uint size_of() const; // Size is bigger 810 public: 811 CallStaticJavaNode(Compile* C, const TypeFunc* tf, address addr, ciMethod* method) 812 : CallJavaNode(tf, addr, method) { 813 init_class_id(Class_CallStaticJava); 814 if (C->eliminate_boxing() && (method != nullptr) && method->is_boxing_method()) { 815 init_flags(Flag_is_macro); 816 C->add_macro_node(this); 817 } 818 } 819 CallStaticJavaNode(const TypeFunc* tf, address addr, const char* name, const TypePtr* adr_type) 820 : CallJavaNode(tf, addr, nullptr) { 821 init_class_id(Class_CallStaticJava); 822 // This node calls a runtime stub, which often has narrow memory effects. 823 _adr_type = adr_type; 824 _name = name; 825 } 826 827 // If this is an uncommon trap, return the request code, else zero. 828 int uncommon_trap_request() const; 829 bool is_uncommon_trap() const; 830 static int extract_uncommon_trap_request(const Node* call); 831 832 bool is_boxing_method() const { 833 return is_macro() && (method() != nullptr) && method()->is_boxing_method(); 834 } 835 // Late inlining modifies the JVMState, so we need to deep clone it 836 // when the call node is cloned (because it is macro node). 837 virtual bool needs_deep_clone_jvms(Compile* C) { 838 return is_boxing_method() || CallNode::needs_deep_clone_jvms(C); 839 } 840 841 virtual int Opcode() const; 842 virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 843 844 #ifndef PRODUCT 845 virtual void dump_spec(outputStream *st) const; 846 virtual void dump_compact_spec(outputStream *st) const; 847 #endif 848 }; 849 850 //------------------------------CallDynamicJavaNode---------------------------- 851 // Make a dispatched call using Java calling convention. 852 class CallDynamicJavaNode : public CallJavaNode { 853 virtual bool cmp( const Node &n ) const; 854 virtual uint size_of() const; // Size is bigger 855 public: 856 CallDynamicJavaNode(const TypeFunc* tf , address addr, ciMethod* method, int vtable_index) 857 : CallJavaNode(tf,addr,method), _vtable_index(vtable_index) { 858 init_class_id(Class_CallDynamicJava); 859 } 860 861 // Late inlining modifies the JVMState, so we need to deep clone it 862 // when the call node is cloned. 863 virtual bool needs_deep_clone_jvms(Compile* C) { 864 return IncrementalInlineVirtual || CallNode::needs_deep_clone_jvms(C); 865 } 866 867 int _vtable_index; 868 virtual int Opcode() const; 869 virtual Node* Ideal(PhaseGVN* phase, bool can_reshape); 870 #ifndef PRODUCT 871 virtual void dump_spec(outputStream *st) const; 872 #endif 873 }; 874 875 //------------------------------CallRuntimeNode-------------------------------- 876 // Make a direct subroutine call node into compiled C++ code. 877 class CallRuntimeNode : public CallNode { 878 protected: 879 virtual bool cmp( const Node &n ) const; 880 virtual uint size_of() const; // Size is bigger 881 public: 882 CallRuntimeNode(const TypeFunc* tf, address addr, const char* name, 883 const TypePtr* adr_type, JVMState* jvms = nullptr) 884 : CallNode(tf, addr, adr_type, jvms) 885 { 886 init_class_id(Class_CallRuntime); 887 _name = name; 888 } 889 890 virtual int Opcode() const; 891 virtual void calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const; 892 893 #ifndef PRODUCT 894 virtual void dump_spec(outputStream *st) const; 895 #endif 896 }; 897 898 //------------------------------CallLeafNode----------------------------------- 899 // Make a direct subroutine call node into compiled C++ code, without 900 // safepoints 901 class CallLeafNode : public CallRuntimeNode { 902 public: 903 CallLeafNode(const TypeFunc* tf, address addr, const char* name, 904 const TypePtr* adr_type) 905 : CallRuntimeNode(tf, addr, name, adr_type) 906 { 907 init_class_id(Class_CallLeaf); 908 } 909 virtual int Opcode() const; 910 virtual bool guaranteed_safepoint() { return false; } 911 #ifndef PRODUCT 912 virtual void dump_spec(outputStream *st) const; 913 #endif 914 }; 915 916 //------------------------------CallLeafNoFPNode------------------------------- 917 // CallLeafNode, not using floating point or using it in the same manner as 918 // the generated code 919 class CallLeafNoFPNode : public CallLeafNode { 920 public: 921 CallLeafNoFPNode(const TypeFunc* tf, address addr, const char* name, 922 const TypePtr* adr_type) 923 : CallLeafNode(tf, addr, name, adr_type) 924 { 925 init_class_id(Class_CallLeafNoFP); 926 } 927 virtual int Opcode() const; 928 }; 929 930 //------------------------------CallLeafVectorNode------------------------------- 931 // CallLeafNode but calling with vector calling convention instead. 932 class CallLeafVectorNode : public CallLeafNode { 933 private: 934 uint _num_bits; 935 protected: 936 virtual bool cmp( const Node &n ) const; 937 virtual uint size_of() const; // Size is bigger 938 public: 939 CallLeafVectorNode(const TypeFunc* tf, address addr, const char* name, 940 const TypePtr* adr_type, uint num_bits) 941 : CallLeafNode(tf, addr, name, adr_type), _num_bits(num_bits) 942 { 943 } 944 virtual int Opcode() const; 945 virtual void calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const; 946 }; 947 948 949 //------------------------------Allocate--------------------------------------- 950 // High-level memory allocation 951 // 952 // AllocateNode and AllocateArrayNode are subclasses of CallNode because they will 953 // get expanded into a code sequence containing a call. Unlike other CallNodes, 954 // they have 2 memory projections and 2 i_o projections (which are distinguished by 955 // the _is_io_use flag in the projection.) This is needed when expanding the node in 956 // order to differentiate the uses of the projection on the normal control path from 957 // those on the exception return path. 958 // 959 class AllocateNode : public CallNode { 960 public: 961 enum { 962 // Output: 963 RawAddress = TypeFunc::Parms, // the newly-allocated raw address 964 // Inputs: 965 AllocSize = TypeFunc::Parms, // size (in bytes) of the new object 966 KlassNode, // type (maybe dynamic) of the obj. 967 InitialTest, // slow-path test (may be constant) 968 ALength, // array length (or TOP if none) 969 ValidLengthTest, 970 ParmLimit 971 }; 972 973 static const TypeFunc* alloc_type(const Type* t) { 974 const Type** fields = TypeTuple::fields(ParmLimit - TypeFunc::Parms); 975 fields[AllocSize] = TypeInt::POS; 976 fields[KlassNode] = TypeInstPtr::NOTNULL; 977 fields[InitialTest] = TypeInt::BOOL; 978 fields[ALength] = t; // length (can be a bad length) 979 fields[ValidLengthTest] = TypeInt::BOOL; 980 981 const TypeTuple *domain = TypeTuple::make(ParmLimit, fields); 982 983 // create result type (range) 984 fields = TypeTuple::fields(1); 985 fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Returned oop 986 987 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 988 989 return TypeFunc::make(domain, range); 990 } 991 992 // Result of Escape Analysis 993 bool _is_scalar_replaceable; 994 bool _is_non_escaping; 995 // True when MemBar for new is redundant with MemBar at initialzer exit 996 bool _is_allocation_MemBar_redundant; 997 998 virtual uint size_of() const; // Size is bigger 999 AllocateNode(Compile* C, const TypeFunc *atype, Node *ctrl, Node *mem, Node *abio, 1000 Node *size, Node *klass_node, Node *initial_test); 1001 // Expansion modifies the JVMState, so we need to deep clone it 1002 virtual bool needs_deep_clone_jvms(Compile* C) { return true; } 1003 virtual int Opcode() const; 1004 virtual uint ideal_reg() const { return Op_RegP; } 1005 virtual bool guaranteed_safepoint() { return false; } 1006 1007 // allocations do not modify their arguments 1008 virtual bool may_modify(const TypeOopPtr* t_oop, PhaseValues* phase) { return false;} 1009 1010 // Pattern-match a possible usage of AllocateNode. 1011 // Return null if no allocation is recognized. 1012 // The operand is the pointer produced by the (possible) allocation. 1013 // It must be a projection of the Allocate or its subsequent CastPP. 1014 // (Note: This function is defined in file graphKit.cpp, near 1015 // GraphKit::new_instance/new_array, whose output it recognizes.) 1016 // The 'ptr' may not have an offset unless the 'offset' argument is given. 1017 static AllocateNode* Ideal_allocation(Node* ptr); 1018 1019 // Fancy version which uses AddPNode::Ideal_base_and_offset to strip 1020 // an offset, which is reported back to the caller. 1021 // (Note: AllocateNode::Ideal_allocation is defined in graphKit.cpp.) 1022 static AllocateNode* Ideal_allocation(Node* ptr, PhaseValues* phase, 1023 intptr_t& offset); 1024 1025 // Dig the klass operand out of a (possible) allocation site. 1026 static Node* Ideal_klass(Node* ptr, PhaseValues* phase) { 1027 AllocateNode* allo = Ideal_allocation(ptr); 1028 return (allo == nullptr) ? nullptr : allo->in(KlassNode); 1029 } 1030 1031 // Conservatively small estimate of offset of first non-header byte. 1032 int minimum_header_size() { 1033 return is_AllocateArray() ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 1034 instanceOopDesc::base_offset_in_bytes(); 1035 } 1036 1037 // Return the corresponding initialization barrier (or null if none). 1038 // Walks out edges to find it... 1039 // (Note: Both InitializeNode::allocation and AllocateNode::initialization 1040 // are defined in graphKit.cpp, which sets up the bidirectional relation.) 1041 InitializeNode* initialization(); 1042 1043 // Convenience for initialization->maybe_set_complete(phase) 1044 bool maybe_set_complete(PhaseGVN* phase); 1045 1046 // Return true if allocation doesn't escape thread, its escape state 1047 // needs be noEscape or ArgEscape. InitializeNode._does_not_escape 1048 // is true when its allocation's escape state is noEscape or 1049 // ArgEscape. In case allocation's InitializeNode is null, check 1050 // AlllocateNode._is_non_escaping flag. 1051 // AlllocateNode._is_non_escaping is true when its escape state is 1052 // noEscape. 1053 bool does_not_escape_thread() { 1054 InitializeNode* init = nullptr; 1055 return _is_non_escaping || (((init = initialization()) != nullptr) && init->does_not_escape()); 1056 } 1057 1058 // If object doesn't escape in <.init> method and there is memory barrier 1059 // inserted at exit of its <.init>, memory barrier for new is not necessary. 1060 // Inovke this method when MemBar at exit of initializer and post-dominate 1061 // allocation node. 1062 void compute_MemBar_redundancy(ciMethod* initializer); 1063 bool is_allocation_MemBar_redundant() { return _is_allocation_MemBar_redundant; } 1064 1065 Node* make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem); 1066 1067 NOT_PRODUCT(virtual void dump_spec(outputStream* st) const;) 1068 }; 1069 1070 //------------------------------AllocateArray--------------------------------- 1071 // 1072 // High-level array allocation 1073 // 1074 class AllocateArrayNode : public AllocateNode { 1075 public: 1076 AllocateArrayNode(Compile* C, const TypeFunc* atype, Node* ctrl, Node* mem, Node* abio, Node* size, Node* klass_node, 1077 Node* initial_test, Node* count_val, Node* valid_length_test) 1078 : AllocateNode(C, atype, ctrl, mem, abio, size, klass_node, 1079 initial_test) 1080 { 1081 init_class_id(Class_AllocateArray); 1082 set_req(AllocateNode::ALength, count_val); 1083 set_req(AllocateNode::ValidLengthTest, valid_length_test); 1084 } 1085 virtual int Opcode() const; 1086 1087 // Dig the length operand out of a array allocation site. 1088 Node* Ideal_length() { 1089 return in(AllocateNode::ALength); 1090 } 1091 1092 // Dig the length operand out of a array allocation site and narrow the 1093 // type with a CastII, if necesssary 1094 Node* make_ideal_length(const TypeOopPtr* ary_type, PhaseValues* phase, bool can_create = true); 1095 1096 // Pattern-match a possible usage of AllocateArrayNode. 1097 // Return null if no allocation is recognized. 1098 static AllocateArrayNode* Ideal_array_allocation(Node* ptr) { 1099 AllocateNode* allo = Ideal_allocation(ptr); 1100 return (allo == nullptr || !allo->is_AllocateArray()) 1101 ? nullptr : allo->as_AllocateArray(); 1102 } 1103 }; 1104 1105 //------------------------------AbstractLockNode----------------------------------- 1106 class AbstractLockNode: public CallNode { 1107 private: 1108 enum { 1109 Regular = 0, // Normal lock 1110 NonEscObj, // Lock is used for non escaping object 1111 Coarsened, // Lock was coarsened 1112 Nested // Nested lock 1113 } _kind; 1114 1115 static const char* _kind_names[Nested+1]; 1116 1117 #ifndef PRODUCT 1118 NamedCounter* _counter; 1119 #endif 1120 1121 protected: 1122 // helper functions for lock elimination 1123 // 1124 1125 bool find_matching_unlock(const Node* ctrl, LockNode* lock, 1126 GrowableArray<AbstractLockNode*> &lock_ops); 1127 bool find_lock_and_unlock_through_if(Node* node, LockNode* lock, 1128 GrowableArray<AbstractLockNode*> &lock_ops); 1129 bool find_unlocks_for_region(const RegionNode* region, LockNode* lock, 1130 GrowableArray<AbstractLockNode*> &lock_ops); 1131 LockNode *find_matching_lock(UnlockNode* unlock); 1132 1133 // Update the counter to indicate that this lock was eliminated. 1134 void set_eliminated_lock_counter() PRODUCT_RETURN; 1135 1136 public: 1137 AbstractLockNode(const TypeFunc *tf) 1138 : CallNode(tf, nullptr, TypeRawPtr::BOTTOM), 1139 _kind(Regular) 1140 { 1141 #ifndef PRODUCT 1142 _counter = nullptr; 1143 #endif 1144 } 1145 virtual int Opcode() const = 0; 1146 Node * obj_node() const {return in(TypeFunc::Parms + 0); } 1147 Node * box_node() const {return in(TypeFunc::Parms + 1); } 1148 Node * fastlock_node() const {return in(TypeFunc::Parms + 2); } 1149 void set_box_node(Node* box) { set_req(TypeFunc::Parms + 1, box); } 1150 1151 const Type *sub(const Type *t1, const Type *t2) const { return TypeInt::CC;} 1152 1153 virtual uint size_of() const { return sizeof(*this); } 1154 1155 bool is_eliminated() const { return (_kind != Regular); } 1156 bool is_non_esc_obj() const { return (_kind == NonEscObj); } 1157 bool is_coarsened() const { return (_kind == Coarsened); } 1158 bool is_nested() const { return (_kind == Nested); } 1159 1160 const char * kind_as_string() const; 1161 void log_lock_optimization(Compile* c, const char * tag, Node* bad_lock = nullptr) const; 1162 1163 void set_non_esc_obj() { _kind = NonEscObj; set_eliminated_lock_counter(); } 1164 void set_coarsened() { _kind = Coarsened; set_eliminated_lock_counter(); } 1165 void set_nested() { _kind = Nested; set_eliminated_lock_counter(); } 1166 1167 // Check that all locks/unlocks associated with object come from balanced regions. 1168 // They can become unbalanced after coarsening optimization or on OSR entry. 1169 bool is_balanced(); 1170 1171 // locking does not modify its arguments 1172 virtual bool may_modify(const TypeOopPtr* t_oop, PhaseValues* phase){ return false; } 1173 1174 #ifndef PRODUCT 1175 void create_lock_counter(JVMState* s); 1176 NamedCounter* counter() const { return _counter; } 1177 virtual void dump_spec(outputStream* st) const; 1178 virtual void dump_compact_spec(outputStream* st) const; 1179 #endif 1180 }; 1181 1182 //------------------------------Lock--------------------------------------- 1183 // High-level lock operation 1184 // 1185 // This is a subclass of CallNode because it is a macro node which gets expanded 1186 // into a code sequence containing a call. This node takes 3 "parameters": 1187 // 0 - object to lock 1188 // 1 - a BoxLockNode 1189 // 2 - a FastLockNode 1190 // 1191 class LockNode : public AbstractLockNode { 1192 static const TypeFunc* _lock_type_Type; 1193 public: 1194 1195 static inline const TypeFunc* lock_type() { 1196 assert(_lock_type_Type != nullptr, "should be initialized"); 1197 return _lock_type_Type; 1198 } 1199 1200 static void initialize_lock_Type() { 1201 assert(_lock_type_Type == nullptr, "should be called once"); 1202 // create input type (domain) 1203 const Type **fields = TypeTuple::fields(3); 1204 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // Object to be Locked 1205 fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // Address of stack location for lock 1206 fields[TypeFunc::Parms+2] = TypeInt::BOOL; // FastLock 1207 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+3,fields); 1208 1209 // create result type (range) 1210 fields = TypeTuple::fields(0); 1211 1212 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields); 1213 1214 _lock_type_Type = TypeFunc::make(domain,range); 1215 } 1216 1217 virtual int Opcode() const; 1218 virtual uint size_of() const; // Size is bigger 1219 LockNode(Compile* C, const TypeFunc *tf) : AbstractLockNode( tf ) { 1220 init_class_id(Class_Lock); 1221 init_flags(Flag_is_macro); 1222 C->add_macro_node(this); 1223 } 1224 virtual bool guaranteed_safepoint() { return false; } 1225 1226 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1227 // Expansion modifies the JVMState, so we need to deep clone it 1228 virtual bool needs_deep_clone_jvms(Compile* C) { return true; } 1229 1230 bool is_nested_lock_region(); // Is this Lock nested? 1231 bool is_nested_lock_region(Compile * c); // Why isn't this Lock nested? 1232 }; 1233 1234 //------------------------------Unlock--------------------------------------- 1235 // High-level unlock operation 1236 class UnlockNode : public AbstractLockNode { 1237 private: 1238 #ifdef ASSERT 1239 JVMState* const _dbg_jvms; // Pointer to list of JVM State objects 1240 #endif 1241 public: 1242 virtual int Opcode() const; 1243 virtual uint size_of() const; // Size is bigger 1244 UnlockNode(Compile* C, const TypeFunc *tf) : AbstractLockNode( tf ) 1245 #ifdef ASSERT 1246 , _dbg_jvms(nullptr) 1247 #endif 1248 { 1249 init_class_id(Class_Unlock); 1250 init_flags(Flag_is_macro); 1251 C->add_macro_node(this); 1252 } 1253 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1254 // unlock is never a safepoint 1255 virtual bool guaranteed_safepoint() { return false; } 1256 #ifdef ASSERT 1257 void set_dbg_jvms(JVMState* s) { 1258 *(JVMState**)&_dbg_jvms = s; // override const attribute in the accessor 1259 } 1260 JVMState* dbg_jvms() const { return _dbg_jvms; } 1261 #else 1262 JVMState* dbg_jvms() const { return nullptr; } 1263 #endif 1264 }; 1265 #endif // SHARE_OPTO_CALLNODE_HPP