src/share/vm/opto/callnode.hpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 8856
ac27a9c85bea
child 10015
eb7ce841ccec
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

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

mercurial