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