src/share/vm/opto/callnode.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial