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