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