src/share/vm/opto/callnode.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6723
0bf37f737702
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, 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 #include "precompiled.hpp"
aoqi@0 26 #include "ci/bcEscapeAnalyzer.hpp"
aoqi@0 27 #include "compiler/oopMap.hpp"
aoqi@0 28 #include "opto/callGenerator.hpp"
aoqi@0 29 #include "opto/callnode.hpp"
aoqi@0 30 #include "opto/escape.hpp"
aoqi@0 31 #include "opto/locknode.hpp"
aoqi@0 32 #include "opto/machnode.hpp"
aoqi@0 33 #include "opto/matcher.hpp"
aoqi@0 34 #include "opto/parse.hpp"
aoqi@0 35 #include "opto/regalloc.hpp"
aoqi@0 36 #include "opto/regmask.hpp"
aoqi@0 37 #include "opto/rootnode.hpp"
aoqi@0 38 #include "opto/runtime.hpp"
aoqi@0 39
aoqi@0 40 // Portions of code courtesy of Clifford Click
aoqi@0 41
aoqi@0 42 // Optimization - Graph Style
aoqi@0 43
aoqi@0 44 //=============================================================================
aoqi@0 45 uint StartNode::size_of() const { return sizeof(*this); }
aoqi@0 46 uint StartNode::cmp( const Node &n ) const
aoqi@0 47 { return _domain == ((StartNode&)n)._domain; }
aoqi@0 48 const Type *StartNode::bottom_type() const { return _domain; }
aoqi@0 49 const Type *StartNode::Value(PhaseTransform *phase) const { return _domain; }
aoqi@0 50 #ifndef PRODUCT
aoqi@0 51 void StartNode::dump_spec(outputStream *st) const { st->print(" #"); _domain->dump_on(st);}
aoqi@0 52 #endif
aoqi@0 53
aoqi@0 54 //------------------------------Ideal------------------------------------------
aoqi@0 55 Node *StartNode::Ideal(PhaseGVN *phase, bool can_reshape){
aoqi@0 56 return remove_dead_region(phase, can_reshape) ? this : NULL;
aoqi@0 57 }
aoqi@0 58
aoqi@0 59 //------------------------------calling_convention-----------------------------
aoqi@0 60 void StartNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
aoqi@0 61 Matcher::calling_convention( sig_bt, parm_regs, argcnt, false );
aoqi@0 62 }
aoqi@0 63
aoqi@0 64 //------------------------------Registers--------------------------------------
aoqi@0 65 const RegMask &StartNode::in_RegMask(uint) const {
aoqi@0 66 return RegMask::Empty;
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 //------------------------------match------------------------------------------
aoqi@0 70 // Construct projections for incoming parameters, and their RegMask info
aoqi@0 71 Node *StartNode::match( const ProjNode *proj, const Matcher *match ) {
aoqi@0 72 switch (proj->_con) {
aoqi@0 73 case TypeFunc::Control:
aoqi@0 74 case TypeFunc::I_O:
aoqi@0 75 case TypeFunc::Memory:
aoqi@0 76 return new (match->C) MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
aoqi@0 77 case TypeFunc::FramePtr:
aoqi@0 78 return new (match->C) MachProjNode(this,proj->_con,Matcher::c_frame_ptr_mask, Op_RegP);
aoqi@0 79 case TypeFunc::ReturnAdr:
aoqi@0 80 return new (match->C) MachProjNode(this,proj->_con,match->_return_addr_mask,Op_RegP);
aoqi@0 81 case TypeFunc::Parms:
aoqi@0 82 default: {
aoqi@0 83 uint parm_num = proj->_con - TypeFunc::Parms;
aoqi@0 84 const Type *t = _domain->field_at(proj->_con);
aoqi@0 85 if (t->base() == Type::Half) // 2nd half of Longs and Doubles
aoqi@0 86 return new (match->C) ConNode(Type::TOP);
aoqi@0 87 uint ideal_reg = t->ideal_reg();
aoqi@0 88 RegMask &rm = match->_calling_convention_mask[parm_num];
aoqi@0 89 return new (match->C) MachProjNode(this,proj->_con,rm,ideal_reg);
aoqi@0 90 }
aoqi@0 91 }
aoqi@0 92 return NULL;
aoqi@0 93 }
aoqi@0 94
aoqi@0 95 //------------------------------StartOSRNode----------------------------------
aoqi@0 96 // The method start node for an on stack replacement adapter
aoqi@0 97
aoqi@0 98 //------------------------------osr_domain-----------------------------
aoqi@0 99 const TypeTuple *StartOSRNode::osr_domain() {
aoqi@0 100 const Type **fields = TypeTuple::fields(2);
aoqi@0 101 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
aoqi@0 102
aoqi@0 103 return TypeTuple::make(TypeFunc::Parms+1, fields);
aoqi@0 104 }
aoqi@0 105
aoqi@0 106 //=============================================================================
aoqi@0 107 const char * const ParmNode::names[TypeFunc::Parms+1] = {
aoqi@0 108 "Control", "I_O", "Memory", "FramePtr", "ReturnAdr", "Parms"
aoqi@0 109 };
aoqi@0 110
aoqi@0 111 #ifndef PRODUCT
aoqi@0 112 void ParmNode::dump_spec(outputStream *st) const {
aoqi@0 113 if( _con < TypeFunc::Parms ) {
aoqi@0 114 st->print("%s", names[_con]);
aoqi@0 115 } else {
aoqi@0 116 st->print("Parm%d: ",_con-TypeFunc::Parms);
aoqi@0 117 // Verbose and WizardMode dump bottom_type for all nodes
aoqi@0 118 if( !Verbose && !WizardMode ) bottom_type()->dump_on(st);
aoqi@0 119 }
aoqi@0 120 }
aoqi@0 121 #endif
aoqi@0 122
aoqi@0 123 uint ParmNode::ideal_reg() const {
aoqi@0 124 switch( _con ) {
aoqi@0 125 case TypeFunc::Control : // fall through
aoqi@0 126 case TypeFunc::I_O : // fall through
aoqi@0 127 case TypeFunc::Memory : return 0;
aoqi@0 128 case TypeFunc::FramePtr : // fall through
aoqi@0 129 case TypeFunc::ReturnAdr: return Op_RegP;
aoqi@0 130 default : assert( _con > TypeFunc::Parms, "" );
aoqi@0 131 // fall through
aoqi@0 132 case TypeFunc::Parms : {
aoqi@0 133 // Type of argument being passed
aoqi@0 134 const Type *t = in(0)->as_Start()->_domain->field_at(_con);
aoqi@0 135 return t->ideal_reg();
aoqi@0 136 }
aoqi@0 137 }
aoqi@0 138 ShouldNotReachHere();
aoqi@0 139 return 0;
aoqi@0 140 }
aoqi@0 141
aoqi@0 142 //=============================================================================
aoqi@0 143 ReturnNode::ReturnNode(uint edges, Node *cntrl, Node *i_o, Node *memory, Node *frameptr, Node *retadr ) : Node(edges) {
aoqi@0 144 init_req(TypeFunc::Control,cntrl);
aoqi@0 145 init_req(TypeFunc::I_O,i_o);
aoqi@0 146 init_req(TypeFunc::Memory,memory);
aoqi@0 147 init_req(TypeFunc::FramePtr,frameptr);
aoqi@0 148 init_req(TypeFunc::ReturnAdr,retadr);
aoqi@0 149 }
aoqi@0 150
aoqi@0 151 Node *ReturnNode::Ideal(PhaseGVN *phase, bool can_reshape){
aoqi@0 152 return remove_dead_region(phase, can_reshape) ? this : NULL;
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 const Type *ReturnNode::Value( PhaseTransform *phase ) const {
aoqi@0 156 return ( phase->type(in(TypeFunc::Control)) == Type::TOP)
aoqi@0 157 ? Type::TOP
aoqi@0 158 : Type::BOTTOM;
aoqi@0 159 }
aoqi@0 160
aoqi@0 161 // Do we Match on this edge index or not? No edges on return nodes
aoqi@0 162 uint ReturnNode::match_edge(uint idx) const {
aoqi@0 163 return 0;
aoqi@0 164 }
aoqi@0 165
aoqi@0 166
aoqi@0 167 #ifndef PRODUCT
aoqi@0 168 void ReturnNode::dump_req(outputStream *st) const {
aoqi@0 169 // Dump the required inputs, enclosed in '(' and ')'
aoqi@0 170 uint i; // Exit value of loop
aoqi@0 171 for (i = 0; i < req(); i++) { // For all required inputs
aoqi@0 172 if (i == TypeFunc::Parms) st->print("returns");
aoqi@0 173 if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
aoqi@0 174 else st->print("_ ");
aoqi@0 175 }
aoqi@0 176 }
aoqi@0 177 #endif
aoqi@0 178
aoqi@0 179 //=============================================================================
aoqi@0 180 RethrowNode::RethrowNode(
aoqi@0 181 Node* cntrl,
aoqi@0 182 Node* i_o,
aoqi@0 183 Node* memory,
aoqi@0 184 Node* frameptr,
aoqi@0 185 Node* ret_adr,
aoqi@0 186 Node* exception
aoqi@0 187 ) : Node(TypeFunc::Parms + 1) {
aoqi@0 188 init_req(TypeFunc::Control , cntrl );
aoqi@0 189 init_req(TypeFunc::I_O , i_o );
aoqi@0 190 init_req(TypeFunc::Memory , memory );
aoqi@0 191 init_req(TypeFunc::FramePtr , frameptr );
aoqi@0 192 init_req(TypeFunc::ReturnAdr, ret_adr);
aoqi@0 193 init_req(TypeFunc::Parms , exception);
aoqi@0 194 }
aoqi@0 195
aoqi@0 196 Node *RethrowNode::Ideal(PhaseGVN *phase, bool can_reshape){
aoqi@0 197 return remove_dead_region(phase, can_reshape) ? this : NULL;
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 const Type *RethrowNode::Value( PhaseTransform *phase ) const {
aoqi@0 201 return (phase->type(in(TypeFunc::Control)) == Type::TOP)
aoqi@0 202 ? Type::TOP
aoqi@0 203 : Type::BOTTOM;
aoqi@0 204 }
aoqi@0 205
aoqi@0 206 uint RethrowNode::match_edge(uint idx) const {
aoqi@0 207 return 0;
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 #ifndef PRODUCT
aoqi@0 211 void RethrowNode::dump_req(outputStream *st) const {
aoqi@0 212 // Dump the required inputs, enclosed in '(' and ')'
aoqi@0 213 uint i; // Exit value of loop
aoqi@0 214 for (i = 0; i < req(); i++) { // For all required inputs
aoqi@0 215 if (i == TypeFunc::Parms) st->print("exception");
aoqi@0 216 if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
aoqi@0 217 else st->print("_ ");
aoqi@0 218 }
aoqi@0 219 }
aoqi@0 220 #endif
aoqi@0 221
aoqi@0 222 //=============================================================================
aoqi@0 223 // Do we Match on this edge index or not? Match only target address & method
aoqi@0 224 uint TailCallNode::match_edge(uint idx) const {
aoqi@0 225 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 //=============================================================================
aoqi@0 229 // Do we Match on this edge index or not? Match only target address & oop
aoqi@0 230 uint TailJumpNode::match_edge(uint idx) const {
aoqi@0 231 return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
aoqi@0 232 }
aoqi@0 233
aoqi@0 234 //=============================================================================
aoqi@0 235 JVMState::JVMState(ciMethod* method, JVMState* caller) :
aoqi@0 236 _method(method) {
aoqi@0 237 assert(method != NULL, "must be valid call site");
aoqi@0 238 _reexecute = Reexecute_Undefined;
aoqi@0 239 debug_only(_bci = -99); // random garbage value
aoqi@0 240 debug_only(_map = (SafePointNode*)-1);
aoqi@0 241 _caller = caller;
aoqi@0 242 _depth = 1 + (caller == NULL ? 0 : caller->depth());
aoqi@0 243 _locoff = TypeFunc::Parms;
aoqi@0 244 _stkoff = _locoff + _method->max_locals();
aoqi@0 245 _monoff = _stkoff + _method->max_stack();
aoqi@0 246 _scloff = _monoff;
aoqi@0 247 _endoff = _monoff;
aoqi@0 248 _sp = 0;
aoqi@0 249 }
aoqi@0 250 JVMState::JVMState(int stack_size) :
aoqi@0 251 _method(NULL) {
aoqi@0 252 _bci = InvocationEntryBci;
aoqi@0 253 _reexecute = Reexecute_Undefined;
aoqi@0 254 debug_only(_map = (SafePointNode*)-1);
aoqi@0 255 _caller = NULL;
aoqi@0 256 _depth = 1;
aoqi@0 257 _locoff = TypeFunc::Parms;
aoqi@0 258 _stkoff = _locoff;
aoqi@0 259 _monoff = _stkoff + stack_size;
aoqi@0 260 _scloff = _monoff;
aoqi@0 261 _endoff = _monoff;
aoqi@0 262 _sp = 0;
aoqi@0 263 }
aoqi@0 264
aoqi@0 265 //--------------------------------of_depth-------------------------------------
aoqi@0 266 JVMState* JVMState::of_depth(int d) const {
aoqi@0 267 const JVMState* jvmp = this;
aoqi@0 268 assert(0 < d && (uint)d <= depth(), "oob");
aoqi@0 269 for (int skip = depth() - d; skip > 0; skip--) {
aoqi@0 270 jvmp = jvmp->caller();
aoqi@0 271 }
aoqi@0 272 assert(jvmp->depth() == (uint)d, "found the right one");
aoqi@0 273 return (JVMState*)jvmp;
aoqi@0 274 }
aoqi@0 275
aoqi@0 276 //-----------------------------same_calls_as-----------------------------------
aoqi@0 277 bool JVMState::same_calls_as(const JVMState* that) const {
aoqi@0 278 if (this == that) return true;
aoqi@0 279 if (this->depth() != that->depth()) return false;
aoqi@0 280 const JVMState* p = this;
aoqi@0 281 const JVMState* q = that;
aoqi@0 282 for (;;) {
aoqi@0 283 if (p->_method != q->_method) return false;
aoqi@0 284 if (p->_method == NULL) return true; // bci is irrelevant
aoqi@0 285 if (p->_bci != q->_bci) return false;
aoqi@0 286 if (p->_reexecute != q->_reexecute) return false;
aoqi@0 287 p = p->caller();
aoqi@0 288 q = q->caller();
aoqi@0 289 if (p == q) return true;
aoqi@0 290 assert(p != NULL && q != NULL, "depth check ensures we don't run off end");
aoqi@0 291 }
aoqi@0 292 }
aoqi@0 293
aoqi@0 294 //------------------------------debug_start------------------------------------
aoqi@0 295 uint JVMState::debug_start() const {
aoqi@0 296 debug_only(JVMState* jvmroot = of_depth(1));
aoqi@0 297 assert(jvmroot->locoff() <= this->locoff(), "youngest JVMState must be last");
aoqi@0 298 return of_depth(1)->locoff();
aoqi@0 299 }
aoqi@0 300
aoqi@0 301 //-------------------------------debug_end-------------------------------------
aoqi@0 302 uint JVMState::debug_end() const {
aoqi@0 303 debug_only(JVMState* jvmroot = of_depth(1));
aoqi@0 304 assert(jvmroot->endoff() <= this->endoff(), "youngest JVMState must be last");
aoqi@0 305 return endoff();
aoqi@0 306 }
aoqi@0 307
aoqi@0 308 //------------------------------debug_depth------------------------------------
aoqi@0 309 uint JVMState::debug_depth() const {
aoqi@0 310 uint total = 0;
aoqi@0 311 for (const JVMState* jvmp = this; jvmp != NULL; jvmp = jvmp->caller()) {
aoqi@0 312 total += jvmp->debug_size();
aoqi@0 313 }
aoqi@0 314 return total;
aoqi@0 315 }
aoqi@0 316
aoqi@0 317 #ifndef PRODUCT
aoqi@0 318
aoqi@0 319 //------------------------------format_helper----------------------------------
aoqi@0 320 // Given an allocation (a Chaitin object) and a Node decide if the Node carries
aoqi@0 321 // any defined value or not. If it does, print out the register or constant.
aoqi@0 322 static void format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, const char *msg, uint i, GrowableArray<SafePointScalarObjectNode*> *scobjs ) {
aoqi@0 323 if (n == NULL) { st->print(" NULL"); return; }
aoqi@0 324 if (n->is_SafePointScalarObject()) {
aoqi@0 325 // Scalar replacement.
aoqi@0 326 SafePointScalarObjectNode* spobj = n->as_SafePointScalarObject();
aoqi@0 327 scobjs->append_if_missing(spobj);
aoqi@0 328 int sco_n = scobjs->find(spobj);
aoqi@0 329 assert(sco_n >= 0, "");
aoqi@0 330 st->print(" %s%d]=#ScObj" INT32_FORMAT, msg, i, sco_n);
aoqi@0 331 return;
aoqi@0 332 }
aoqi@0 333 if (regalloc->node_regs_max_index() > 0 &&
aoqi@0 334 OptoReg::is_valid(regalloc->get_reg_first(n))) { // Check for undefined
aoqi@0 335 char buf[50];
aoqi@0 336 regalloc->dump_register(n,buf);
aoqi@0 337 st->print(" %s%d]=%s",msg,i,buf);
aoqi@0 338 } else { // No register, but might be constant
aoqi@0 339 const Type *t = n->bottom_type();
aoqi@0 340 switch (t->base()) {
aoqi@0 341 case Type::Int:
aoqi@0 342 st->print(" %s%d]=#"INT32_FORMAT,msg,i,t->is_int()->get_con());
aoqi@0 343 break;
aoqi@0 344 case Type::AnyPtr:
aoqi@0 345 assert( t == TypePtr::NULL_PTR || n->in_dump(), "" );
aoqi@0 346 st->print(" %s%d]=#NULL",msg,i);
aoqi@0 347 break;
aoqi@0 348 case Type::AryPtr:
aoqi@0 349 case Type::InstPtr:
aoqi@0 350 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->isa_oopptr()->const_oop()));
aoqi@0 351 break;
aoqi@0 352 case Type::KlassPtr:
aoqi@0 353 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_klassptr()->klass()));
aoqi@0 354 break;
aoqi@0 355 case Type::MetadataPtr:
aoqi@0 356 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_metadataptr()->metadata()));
aoqi@0 357 break;
aoqi@0 358 case Type::NarrowOop:
aoqi@0 359 st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_oopptr()->const_oop()));
aoqi@0 360 break;
aoqi@0 361 case Type::RawPtr:
aoqi@0 362 st->print(" %s%d]=#Raw" INTPTR_FORMAT,msg,i,p2i(t->is_rawptr()));
aoqi@0 363 break;
aoqi@0 364 case Type::DoubleCon:
aoqi@0 365 st->print(" %s%d]=#%fD",msg,i,t->is_double_constant()->_d);
aoqi@0 366 break;
aoqi@0 367 case Type::FloatCon:
aoqi@0 368 st->print(" %s%d]=#%fF",msg,i,t->is_float_constant()->_f);
aoqi@0 369 break;
aoqi@0 370 case Type::Long:
aoqi@0 371 st->print(" %s%d]=#"INT64_FORMAT,msg,i,(int64_t)(t->is_long()->get_con()));
aoqi@0 372 break;
aoqi@0 373 case Type::Half:
aoqi@0 374 case Type::Top:
aoqi@0 375 st->print(" %s%d]=_",msg,i);
aoqi@0 376 break;
aoqi@0 377 default: ShouldNotReachHere();
aoqi@0 378 }
aoqi@0 379 }
aoqi@0 380 }
aoqi@0 381
aoqi@0 382 //------------------------------format-----------------------------------------
aoqi@0 383 void JVMState::format(PhaseRegAlloc *regalloc, const Node *n, outputStream* st) const {
aoqi@0 384 st->print(" #");
aoqi@0 385 if (_method) {
aoqi@0 386 _method->print_short_name(st);
aoqi@0 387 st->print(" @ bci:%d ",_bci);
aoqi@0 388 } else {
aoqi@0 389 st->print_cr(" runtime stub ");
aoqi@0 390 return;
aoqi@0 391 }
aoqi@0 392 if (n->is_MachSafePoint()) {
aoqi@0 393 GrowableArray<SafePointScalarObjectNode*> scobjs;
aoqi@0 394 MachSafePointNode *mcall = n->as_MachSafePoint();
aoqi@0 395 uint i;
aoqi@0 396 // Print locals
aoqi@0 397 for (i = 0; i < (uint)loc_size(); i++)
aoqi@0 398 format_helper(regalloc, st, mcall->local(this, i), "L[", i, &scobjs);
aoqi@0 399 // Print stack
aoqi@0 400 for (i = 0; i < (uint)stk_size(); i++) {
aoqi@0 401 if ((uint)(_stkoff + i) >= mcall->len())
aoqi@0 402 st->print(" oob ");
aoqi@0 403 else
aoqi@0 404 format_helper(regalloc, st, mcall->stack(this, i), "STK[", i, &scobjs);
aoqi@0 405 }
aoqi@0 406 for (i = 0; (int)i < nof_monitors(); i++) {
aoqi@0 407 Node *box = mcall->monitor_box(this, i);
aoqi@0 408 Node *obj = mcall->monitor_obj(this, i);
aoqi@0 409 if (regalloc->node_regs_max_index() > 0 &&
aoqi@0 410 OptoReg::is_valid(regalloc->get_reg_first(box))) {
aoqi@0 411 box = BoxLockNode::box_node(box);
aoqi@0 412 format_helper(regalloc, st, box, "MON-BOX[", i, &scobjs);
aoqi@0 413 } else {
aoqi@0 414 OptoReg::Name box_reg = BoxLockNode::reg(box);
aoqi@0 415 st->print(" MON-BOX%d=%s+%d",
aoqi@0 416 i,
aoqi@0 417 OptoReg::regname(OptoReg::c_frame_pointer),
aoqi@0 418 regalloc->reg2offset(box_reg));
aoqi@0 419 }
aoqi@0 420 const char* obj_msg = "MON-OBJ[";
aoqi@0 421 if (EliminateLocks) {
aoqi@0 422 if (BoxLockNode::box_node(box)->is_eliminated())
aoqi@0 423 obj_msg = "MON-OBJ(LOCK ELIMINATED)[";
aoqi@0 424 }
aoqi@0 425 format_helper(regalloc, st, obj, obj_msg, i, &scobjs);
aoqi@0 426 }
aoqi@0 427
aoqi@0 428 for (i = 0; i < (uint)scobjs.length(); i++) {
aoqi@0 429 // Scalar replaced objects.
aoqi@0 430 st->cr();
aoqi@0 431 st->print(" # ScObj" INT32_FORMAT " ", i);
aoqi@0 432 SafePointScalarObjectNode* spobj = scobjs.at(i);
aoqi@0 433 ciKlass* cik = spobj->bottom_type()->is_oopptr()->klass();
aoqi@0 434 assert(cik->is_instance_klass() ||
aoqi@0 435 cik->is_array_klass(), "Not supported allocation.");
aoqi@0 436 ciInstanceKlass *iklass = NULL;
aoqi@0 437 if (cik->is_instance_klass()) {
aoqi@0 438 cik->print_name_on(st);
aoqi@0 439 iklass = cik->as_instance_klass();
aoqi@0 440 } else if (cik->is_type_array_klass()) {
aoqi@0 441 cik->as_array_klass()->base_element_type()->print_name_on(st);
aoqi@0 442 st->print("[%d]", spobj->n_fields());
aoqi@0 443 } else if (cik->is_obj_array_klass()) {
aoqi@0 444 ciKlass* cie = cik->as_obj_array_klass()->base_element_klass();
aoqi@0 445 if (cie->is_instance_klass()) {
aoqi@0 446 cie->print_name_on(st);
aoqi@0 447 } else if (cie->is_type_array_klass()) {
aoqi@0 448 cie->as_array_klass()->base_element_type()->print_name_on(st);
aoqi@0 449 } else {
aoqi@0 450 ShouldNotReachHere();
aoqi@0 451 }
aoqi@0 452 st->print("[%d]", spobj->n_fields());
aoqi@0 453 int ndim = cik->as_array_klass()->dimension() - 1;
aoqi@0 454 while (ndim-- > 0) {
aoqi@0 455 st->print("[]");
aoqi@0 456 }
aoqi@0 457 }
aoqi@0 458 st->print("={");
aoqi@0 459 uint nf = spobj->n_fields();
aoqi@0 460 if (nf > 0) {
aoqi@0 461 uint first_ind = spobj->first_index(mcall->jvms());
aoqi@0 462 Node* fld_node = mcall->in(first_ind);
aoqi@0 463 ciField* cifield;
aoqi@0 464 if (iklass != NULL) {
aoqi@0 465 st->print(" [");
aoqi@0 466 cifield = iklass->nonstatic_field_at(0);
aoqi@0 467 cifield->print_name_on(st);
aoqi@0 468 format_helper(regalloc, st, fld_node, ":", 0, &scobjs);
aoqi@0 469 } else {
aoqi@0 470 format_helper(regalloc, st, fld_node, "[", 0, &scobjs);
aoqi@0 471 }
aoqi@0 472 for (uint j = 1; j < nf; j++) {
aoqi@0 473 fld_node = mcall->in(first_ind+j);
aoqi@0 474 if (iklass != NULL) {
aoqi@0 475 st->print(", [");
aoqi@0 476 cifield = iklass->nonstatic_field_at(j);
aoqi@0 477 cifield->print_name_on(st);
aoqi@0 478 format_helper(regalloc, st, fld_node, ":", j, &scobjs);
aoqi@0 479 } else {
aoqi@0 480 format_helper(regalloc, st, fld_node, ", [", j, &scobjs);
aoqi@0 481 }
aoqi@0 482 }
aoqi@0 483 }
aoqi@0 484 st->print(" }");
aoqi@0 485 }
aoqi@0 486 }
aoqi@0 487 st->cr();
aoqi@0 488 if (caller() != NULL) caller()->format(regalloc, n, st);
aoqi@0 489 }
aoqi@0 490
aoqi@0 491
aoqi@0 492 void JVMState::dump_spec(outputStream *st) const {
aoqi@0 493 if (_method != NULL) {
aoqi@0 494 bool printed = false;
aoqi@0 495 if (!Verbose) {
aoqi@0 496 // The JVMS dumps make really, really long lines.
aoqi@0 497 // Take out the most boring parts, which are the package prefixes.
aoqi@0 498 char buf[500];
aoqi@0 499 stringStream namest(buf, sizeof(buf));
aoqi@0 500 _method->print_short_name(&namest);
aoqi@0 501 if (namest.count() < sizeof(buf)) {
aoqi@0 502 const char* name = namest.base();
aoqi@0 503 if (name[0] == ' ') ++name;
aoqi@0 504 const char* endcn = strchr(name, ':'); // end of class name
aoqi@0 505 if (endcn == NULL) endcn = strchr(name, '(');
aoqi@0 506 if (endcn == NULL) endcn = name + strlen(name);
aoqi@0 507 while (endcn > name && endcn[-1] != '.' && endcn[-1] != '/')
aoqi@0 508 --endcn;
aoqi@0 509 st->print(" %s", endcn);
aoqi@0 510 printed = true;
aoqi@0 511 }
aoqi@0 512 }
aoqi@0 513 if (!printed)
aoqi@0 514 _method->print_short_name(st);
aoqi@0 515 st->print(" @ bci:%d",_bci);
aoqi@0 516 if(_reexecute == Reexecute_True)
aoqi@0 517 st->print(" reexecute");
aoqi@0 518 } else {
aoqi@0 519 st->print(" runtime stub");
aoqi@0 520 }
aoqi@0 521 if (caller() != NULL) caller()->dump_spec(st);
aoqi@0 522 }
aoqi@0 523
aoqi@0 524
aoqi@0 525 void JVMState::dump_on(outputStream* st) const {
aoqi@0 526 bool print_map = _map && !((uintptr_t)_map & 1) &&
aoqi@0 527 ((caller() == NULL) || (caller()->map() != _map));
aoqi@0 528 if (print_map) {
aoqi@0 529 if (_map->len() > _map->req()) { // _map->has_exceptions()
aoqi@0 530 Node* ex = _map->in(_map->req()); // _map->next_exception()
aoqi@0 531 // skip the first one; it's already being printed
aoqi@0 532 while (ex != NULL && ex->len() > ex->req()) {
aoqi@0 533 ex = ex->in(ex->req()); // ex->next_exception()
aoqi@0 534 ex->dump(1);
aoqi@0 535 }
aoqi@0 536 }
aoqi@0 537 _map->dump(Verbose ? 2 : 1);
aoqi@0 538 }
aoqi@0 539 if (caller() != NULL) {
aoqi@0 540 caller()->dump_on(st);
aoqi@0 541 }
aoqi@0 542 st->print("JVMS depth=%d loc=%d stk=%d arg=%d mon=%d scalar=%d end=%d mondepth=%d sp=%d bci=%d reexecute=%s method=",
aoqi@0 543 depth(), locoff(), stkoff(), argoff(), monoff(), scloff(), endoff(), monitor_depth(), sp(), bci(), should_reexecute()?"true":"false");
aoqi@0 544 if (_method == NULL) {
aoqi@0 545 st->print_cr("(none)");
aoqi@0 546 } else {
aoqi@0 547 _method->print_name(st);
aoqi@0 548 st->cr();
aoqi@0 549 if (bci() >= 0 && bci() < _method->code_size()) {
aoqi@0 550 st->print(" bc: ");
aoqi@0 551 _method->print_codes_on(bci(), bci()+1, st);
aoqi@0 552 }
aoqi@0 553 }
aoqi@0 554 }
aoqi@0 555
aoqi@0 556 // Extra way to dump a jvms from the debugger,
aoqi@0 557 // to avoid a bug with C++ member function calls.
aoqi@0 558 void dump_jvms(JVMState* jvms) {
aoqi@0 559 jvms->dump();
aoqi@0 560 }
aoqi@0 561 #endif
aoqi@0 562
aoqi@0 563 //--------------------------clone_shallow--------------------------------------
aoqi@0 564 JVMState* JVMState::clone_shallow(Compile* C) const {
aoqi@0 565 JVMState* n = has_method() ? new (C) JVMState(_method, _caller) : new (C) JVMState(0);
aoqi@0 566 n->set_bci(_bci);
aoqi@0 567 n->_reexecute = _reexecute;
aoqi@0 568 n->set_locoff(_locoff);
aoqi@0 569 n->set_stkoff(_stkoff);
aoqi@0 570 n->set_monoff(_monoff);
aoqi@0 571 n->set_scloff(_scloff);
aoqi@0 572 n->set_endoff(_endoff);
aoqi@0 573 n->set_sp(_sp);
aoqi@0 574 n->set_map(_map);
aoqi@0 575 return n;
aoqi@0 576 }
aoqi@0 577
aoqi@0 578 //---------------------------clone_deep----------------------------------------
aoqi@0 579 JVMState* JVMState::clone_deep(Compile* C) const {
aoqi@0 580 JVMState* n = clone_shallow(C);
aoqi@0 581 for (JVMState* p = n; p->_caller != NULL; p = p->_caller) {
aoqi@0 582 p->_caller = p->_caller->clone_shallow(C);
aoqi@0 583 }
aoqi@0 584 assert(n->depth() == depth(), "sanity");
aoqi@0 585 assert(n->debug_depth() == debug_depth(), "sanity");
aoqi@0 586 return n;
aoqi@0 587 }
aoqi@0 588
aoqi@0 589 /**
aoqi@0 590 * Reset map for all callers
aoqi@0 591 */
aoqi@0 592 void JVMState::set_map_deep(SafePointNode* map) {
aoqi@0 593 for (JVMState* p = this; p->_caller != NULL; p = p->_caller) {
aoqi@0 594 p->set_map(map);
aoqi@0 595 }
aoqi@0 596 }
aoqi@0 597
aoqi@0 598 // Adapt offsets in in-array after adding or removing an edge.
aoqi@0 599 // Prerequisite is that the JVMState is used by only one node.
aoqi@0 600 void JVMState::adapt_position(int delta) {
aoqi@0 601 for (JVMState* jvms = this; jvms != NULL; jvms = jvms->caller()) {
aoqi@0 602 jvms->set_locoff(jvms->locoff() + delta);
aoqi@0 603 jvms->set_stkoff(jvms->stkoff() + delta);
aoqi@0 604 jvms->set_monoff(jvms->monoff() + delta);
aoqi@0 605 jvms->set_scloff(jvms->scloff() + delta);
aoqi@0 606 jvms->set_endoff(jvms->endoff() + delta);
aoqi@0 607 }
aoqi@0 608 }
aoqi@0 609
aoqi@0 610 // Mirror the stack size calculation in the deopt code
aoqi@0 611 // How much stack space would we need at this point in the program in
aoqi@0 612 // case of deoptimization?
aoqi@0 613 int JVMState::interpreter_frame_size() const {
aoqi@0 614 const JVMState* jvms = this;
aoqi@0 615 int size = 0;
aoqi@0 616 int callee_parameters = 0;
aoqi@0 617 int callee_locals = 0;
aoqi@0 618 int extra_args = method()->max_stack() - stk_size();
aoqi@0 619
aoqi@0 620 while (jvms != NULL) {
aoqi@0 621 int locks = jvms->nof_monitors();
aoqi@0 622 int temps = jvms->stk_size();
aoqi@0 623 bool is_top_frame = (jvms == this);
aoqi@0 624 ciMethod* method = jvms->method();
aoqi@0 625
aoqi@0 626 int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),
aoqi@0 627 temps + callee_parameters,
aoqi@0 628 extra_args,
aoqi@0 629 locks,
aoqi@0 630 callee_parameters,
aoqi@0 631 callee_locals,
aoqi@0 632 is_top_frame);
aoqi@0 633 size += frame_size;
aoqi@0 634
aoqi@0 635 callee_parameters = method->size_of_parameters();
aoqi@0 636 callee_locals = method->max_locals();
aoqi@0 637 extra_args = 0;
aoqi@0 638 jvms = jvms->caller();
aoqi@0 639 }
aoqi@0 640 return size + Deoptimization::last_frame_adjust(0, callee_locals) * BytesPerWord;
aoqi@0 641 }
aoqi@0 642
aoqi@0 643 //=============================================================================
aoqi@0 644 uint CallNode::cmp( const Node &n ) const
aoqi@0 645 { return _tf == ((CallNode&)n)._tf && _jvms == ((CallNode&)n)._jvms; }
aoqi@0 646 #ifndef PRODUCT
aoqi@0 647 void CallNode::dump_req(outputStream *st) const {
aoqi@0 648 // Dump the required inputs, enclosed in '(' and ')'
aoqi@0 649 uint i; // Exit value of loop
aoqi@0 650 for (i = 0; i < req(); i++) { // For all required inputs
aoqi@0 651 if (i == TypeFunc::Parms) st->print("(");
aoqi@0 652 if (in(i)) st->print("%c%d ", Compile::current()->node_arena()->contains(in(i)) ? ' ' : 'o', in(i)->_idx);
aoqi@0 653 else st->print("_ ");
aoqi@0 654 }
aoqi@0 655 st->print(")");
aoqi@0 656 }
aoqi@0 657
aoqi@0 658 void CallNode::dump_spec(outputStream *st) const {
aoqi@0 659 st->print(" ");
aoqi@0 660 tf()->dump_on(st);
aoqi@0 661 if (_cnt != COUNT_UNKNOWN) st->print(" C=%f",_cnt);
aoqi@0 662 if (jvms() != NULL) jvms()->dump_spec(st);
aoqi@0 663 }
aoqi@0 664 #endif
aoqi@0 665
aoqi@0 666 const Type *CallNode::bottom_type() const { return tf()->range(); }
aoqi@0 667 const Type *CallNode::Value(PhaseTransform *phase) const {
aoqi@0 668 if (phase->type(in(0)) == Type::TOP) return Type::TOP;
aoqi@0 669 return tf()->range();
aoqi@0 670 }
aoqi@0 671
aoqi@0 672 //------------------------------calling_convention-----------------------------
aoqi@0 673 void CallNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
aoqi@0 674 // Use the standard compiler calling convention
aoqi@0 675 Matcher::calling_convention( sig_bt, parm_regs, argcnt, true );
aoqi@0 676 }
aoqi@0 677
aoqi@0 678
aoqi@0 679 //------------------------------match------------------------------------------
aoqi@0 680 // Construct projections for control, I/O, memory-fields, ..., and
aoqi@0 681 // return result(s) along with their RegMask info
aoqi@0 682 Node *CallNode::match( const ProjNode *proj, const Matcher *match ) {
aoqi@0 683 switch (proj->_con) {
aoqi@0 684 case TypeFunc::Control:
aoqi@0 685 case TypeFunc::I_O:
aoqi@0 686 case TypeFunc::Memory:
aoqi@0 687 return new (match->C) MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
aoqi@0 688
aoqi@0 689 case TypeFunc::Parms+1: // For LONG & DOUBLE returns
aoqi@0 690 assert(tf()->_range->field_at(TypeFunc::Parms+1) == Type::HALF, "");
aoqi@0 691 // 2nd half of doubles and longs
aoqi@0 692 return new (match->C) MachProjNode(this,proj->_con, RegMask::Empty, (uint)OptoReg::Bad);
aoqi@0 693
aoqi@0 694 case TypeFunc::Parms: { // Normal returns
aoqi@0 695 uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
aoqi@0 696 OptoRegPair regs = is_CallRuntime()
aoqi@0 697 ? match->c_return_value(ideal_reg,true) // Calls into C runtime
aoqi@0 698 : match-> return_value(ideal_reg,true); // Calls into compiled Java code
aoqi@0 699 RegMask rm = RegMask(regs.first());
aoqi@0 700 if( OptoReg::is_valid(regs.second()) )
aoqi@0 701 rm.Insert( regs.second() );
aoqi@0 702 return new (match->C) MachProjNode(this,proj->_con,rm,ideal_reg);
aoqi@0 703 }
aoqi@0 704
aoqi@0 705 case TypeFunc::ReturnAdr:
aoqi@0 706 case TypeFunc::FramePtr:
aoqi@0 707 default:
aoqi@0 708 ShouldNotReachHere();
aoqi@0 709 }
aoqi@0 710 return NULL;
aoqi@0 711 }
aoqi@0 712
aoqi@0 713 // Do we Match on this edge index or not? Match no edges
aoqi@0 714 uint CallNode::match_edge(uint idx) const {
aoqi@0 715 return 0;
aoqi@0 716 }
aoqi@0 717
aoqi@0 718 //
aoqi@0 719 // Determine whether the call could modify the field of the specified
aoqi@0 720 // instance at the specified offset.
aoqi@0 721 //
aoqi@0 722 bool CallNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {
aoqi@0 723 assert((t_oop != NULL), "sanity");
aoqi@0 724 if (t_oop->is_known_instance()) {
aoqi@0 725 // The instance_id is set only for scalar-replaceable allocations which
aoqi@0 726 // are not passed as arguments according to Escape Analysis.
aoqi@0 727 return false;
aoqi@0 728 }
aoqi@0 729 if (t_oop->is_ptr_to_boxed_value()) {
aoqi@0 730 ciKlass* boxing_klass = t_oop->klass();
aoqi@0 731 if (is_CallStaticJava() && as_CallStaticJava()->is_boxing_method()) {
aoqi@0 732 // Skip unrelated boxing methods.
aoqi@0 733 Node* proj = proj_out(TypeFunc::Parms);
aoqi@0 734 if ((proj == NULL) || (phase->type(proj)->is_instptr()->klass() != boxing_klass)) {
aoqi@0 735 return false;
aoqi@0 736 }
aoqi@0 737 }
aoqi@0 738 if (is_CallJava() && as_CallJava()->method() != NULL) {
aoqi@0 739 ciMethod* meth = as_CallJava()->method();
aoqi@0 740 if (meth->is_accessor()) {
aoqi@0 741 return false;
aoqi@0 742 }
aoqi@0 743 // May modify (by reflection) if an boxing object is passed
aoqi@0 744 // as argument or returned.
aoqi@0 745 if (returns_pointer() && (proj_out(TypeFunc::Parms) != NULL)) {
aoqi@0 746 Node* proj = proj_out(TypeFunc::Parms);
aoqi@0 747 const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr();
aoqi@0 748 if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||
aoqi@0 749 (inst_t->klass() == boxing_klass))) {
aoqi@0 750 return true;
aoqi@0 751 }
aoqi@0 752 }
aoqi@0 753 const TypeTuple* d = tf()->domain();
aoqi@0 754 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
aoqi@0 755 const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr();
aoqi@0 756 if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||
aoqi@0 757 (inst_t->klass() == boxing_klass))) {
aoqi@0 758 return true;
aoqi@0 759 }
aoqi@0 760 }
aoqi@0 761 return false;
aoqi@0 762 }
aoqi@0 763 }
aoqi@0 764 return true;
aoqi@0 765 }
aoqi@0 766
aoqi@0 767 // Does this call have a direct reference to n other than debug information?
aoqi@0 768 bool CallNode::has_non_debug_use(Node *n) {
aoqi@0 769 const TypeTuple * d = tf()->domain();
aoqi@0 770 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
aoqi@0 771 Node *arg = in(i);
aoqi@0 772 if (arg == n) {
aoqi@0 773 return true;
aoqi@0 774 }
aoqi@0 775 }
aoqi@0 776 return false;
aoqi@0 777 }
aoqi@0 778
aoqi@0 779 // Returns the unique CheckCastPP of a call
aoqi@0 780 // or 'this' if there are several CheckCastPP
aoqi@0 781 // or returns NULL if there is no one.
aoqi@0 782 Node *CallNode::result_cast() {
aoqi@0 783 Node *cast = NULL;
aoqi@0 784
aoqi@0 785 Node *p = proj_out(TypeFunc::Parms);
aoqi@0 786 if (p == NULL)
aoqi@0 787 return NULL;
aoqi@0 788
aoqi@0 789 for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
aoqi@0 790 Node *use = p->fast_out(i);
aoqi@0 791 if (use->is_CheckCastPP()) {
aoqi@0 792 if (cast != NULL) {
aoqi@0 793 return this; // more than 1 CheckCastPP
aoqi@0 794 }
aoqi@0 795 cast = use;
aoqi@0 796 }
aoqi@0 797 }
aoqi@0 798 return cast;
aoqi@0 799 }
aoqi@0 800
aoqi@0 801
aoqi@0 802 void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj) {
aoqi@0 803 projs->fallthrough_proj = NULL;
aoqi@0 804 projs->fallthrough_catchproj = NULL;
aoqi@0 805 projs->fallthrough_ioproj = NULL;
aoqi@0 806 projs->catchall_ioproj = NULL;
aoqi@0 807 projs->catchall_catchproj = NULL;
aoqi@0 808 projs->fallthrough_memproj = NULL;
aoqi@0 809 projs->catchall_memproj = NULL;
aoqi@0 810 projs->resproj = NULL;
aoqi@0 811 projs->exobj = NULL;
aoqi@0 812
aoqi@0 813 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
aoqi@0 814 ProjNode *pn = fast_out(i)->as_Proj();
aoqi@0 815 if (pn->outcnt() == 0) continue;
aoqi@0 816 switch (pn->_con) {
aoqi@0 817 case TypeFunc::Control:
aoqi@0 818 {
aoqi@0 819 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
aoqi@0 820 projs->fallthrough_proj = pn;
aoqi@0 821 DUIterator_Fast jmax, j = pn->fast_outs(jmax);
aoqi@0 822 const Node *cn = pn->fast_out(j);
aoqi@0 823 if (cn->is_Catch()) {
aoqi@0 824 ProjNode *cpn = NULL;
aoqi@0 825 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
aoqi@0 826 cpn = cn->fast_out(k)->as_Proj();
aoqi@0 827 assert(cpn->is_CatchProj(), "must be a CatchProjNode");
aoqi@0 828 if (cpn->_con == CatchProjNode::fall_through_index)
aoqi@0 829 projs->fallthrough_catchproj = cpn;
aoqi@0 830 else {
aoqi@0 831 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
aoqi@0 832 projs->catchall_catchproj = cpn;
aoqi@0 833 }
aoqi@0 834 }
aoqi@0 835 }
aoqi@0 836 break;
aoqi@0 837 }
aoqi@0 838 case TypeFunc::I_O:
aoqi@0 839 if (pn->_is_io_use)
aoqi@0 840 projs->catchall_ioproj = pn;
aoqi@0 841 else
aoqi@0 842 projs->fallthrough_ioproj = pn;
aoqi@0 843 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
aoqi@0 844 Node* e = pn->out(j);
aoqi@0 845 if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
aoqi@0 846 assert(projs->exobj == NULL, "only one");
aoqi@0 847 projs->exobj = e;
aoqi@0 848 }
aoqi@0 849 }
aoqi@0 850 break;
aoqi@0 851 case TypeFunc::Memory:
aoqi@0 852 if (pn->_is_io_use)
aoqi@0 853 projs->catchall_memproj = pn;
aoqi@0 854 else
aoqi@0 855 projs->fallthrough_memproj = pn;
aoqi@0 856 break;
aoqi@0 857 case TypeFunc::Parms:
aoqi@0 858 projs->resproj = pn;
aoqi@0 859 break;
aoqi@0 860 default:
aoqi@0 861 assert(false, "unexpected projection from allocation node.");
aoqi@0 862 }
aoqi@0 863 }
aoqi@0 864
aoqi@0 865 // The resproj may not exist because the result couuld be ignored
aoqi@0 866 // and the exception object may not exist if an exception handler
aoqi@0 867 // swallows the exception but all the other must exist and be found.
aoqi@0 868 assert(projs->fallthrough_proj != NULL, "must be found");
aoqi@0 869 assert(Compile::current()->inlining_incrementally() || projs->fallthrough_catchproj != NULL, "must be found");
aoqi@0 870 assert(Compile::current()->inlining_incrementally() || projs->fallthrough_memproj != NULL, "must be found");
aoqi@0 871 assert(Compile::current()->inlining_incrementally() || projs->fallthrough_ioproj != NULL, "must be found");
aoqi@0 872 assert(Compile::current()->inlining_incrementally() || projs->catchall_catchproj != NULL, "must be found");
aoqi@0 873 if (separate_io_proj) {
aoqi@0 874 assert(Compile::current()->inlining_incrementally() || projs->catchall_memproj != NULL, "must be found");
aoqi@0 875 assert(Compile::current()->inlining_incrementally() || projs->catchall_ioproj != NULL, "must be found");
aoqi@0 876 }
aoqi@0 877 }
aoqi@0 878
aoqi@0 879 Node *CallNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 880 CallGenerator* cg = generator();
aoqi@0 881 if (can_reshape && cg != NULL && cg->is_mh_late_inline() && !cg->already_attempted()) {
aoqi@0 882 // Check whether this MH handle call becomes a candidate for inlining
aoqi@0 883 ciMethod* callee = cg->method();
aoqi@0 884 vmIntrinsics::ID iid = callee->intrinsic_id();
aoqi@0 885 if (iid == vmIntrinsics::_invokeBasic) {
aoqi@0 886 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
aoqi@0 887 phase->C->prepend_late_inline(cg);
aoqi@0 888 set_generator(NULL);
aoqi@0 889 }
aoqi@0 890 } else {
aoqi@0 891 assert(callee->has_member_arg(), "wrong type of call?");
aoqi@0 892 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
aoqi@0 893 phase->C->prepend_late_inline(cg);
aoqi@0 894 set_generator(NULL);
aoqi@0 895 }
aoqi@0 896 }
aoqi@0 897 }
aoqi@0 898 return SafePointNode::Ideal(phase, can_reshape);
aoqi@0 899 }
aoqi@0 900
aoqi@0 901
aoqi@0 902 //=============================================================================
aoqi@0 903 uint CallJavaNode::size_of() const { return sizeof(*this); }
aoqi@0 904 uint CallJavaNode::cmp( const Node &n ) const {
aoqi@0 905 CallJavaNode &call = (CallJavaNode&)n;
aoqi@0 906 return CallNode::cmp(call) && _method == call._method;
aoqi@0 907 }
aoqi@0 908 #ifndef PRODUCT
aoqi@0 909 void CallJavaNode::dump_spec(outputStream *st) const {
aoqi@0 910 if( _method ) _method->print_short_name(st);
aoqi@0 911 CallNode::dump_spec(st);
aoqi@0 912 }
aoqi@0 913 #endif
aoqi@0 914
aoqi@0 915 //=============================================================================
aoqi@0 916 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
aoqi@0 917 uint CallStaticJavaNode::cmp( const Node &n ) const {
aoqi@0 918 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
aoqi@0 919 return CallJavaNode::cmp(call);
aoqi@0 920 }
aoqi@0 921
aoqi@0 922 //----------------------------uncommon_trap_request----------------------------
aoqi@0 923 // If this is an uncommon trap, return the request code, else zero.
aoqi@0 924 int CallStaticJavaNode::uncommon_trap_request() const {
aoqi@0 925 if (_name != NULL && !strcmp(_name, "uncommon_trap")) {
aoqi@0 926 return extract_uncommon_trap_request(this);
aoqi@0 927 }
aoqi@0 928 return 0;
aoqi@0 929 }
aoqi@0 930 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
aoqi@0 931 #ifndef PRODUCT
aoqi@0 932 if (!(call->req() > TypeFunc::Parms &&
aoqi@0 933 call->in(TypeFunc::Parms) != NULL &&
aoqi@0 934 call->in(TypeFunc::Parms)->is_Con())) {
aoqi@0 935 assert(in_dump() != 0, "OK if dumping");
aoqi@0 936 tty->print("[bad uncommon trap]");
aoqi@0 937 return 0;
aoqi@0 938 }
aoqi@0 939 #endif
aoqi@0 940 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
aoqi@0 941 }
aoqi@0 942
aoqi@0 943 #ifndef PRODUCT
aoqi@0 944 void CallStaticJavaNode::dump_spec(outputStream *st) const {
aoqi@0 945 st->print("# Static ");
aoqi@0 946 if (_name != NULL) {
aoqi@0 947 st->print("%s", _name);
aoqi@0 948 int trap_req = uncommon_trap_request();
aoqi@0 949 if (trap_req != 0) {
aoqi@0 950 char buf[100];
aoqi@0 951 st->print("(%s)",
aoqi@0 952 Deoptimization::format_trap_request(buf, sizeof(buf),
aoqi@0 953 trap_req));
aoqi@0 954 }
aoqi@0 955 st->print(" ");
aoqi@0 956 }
aoqi@0 957 CallJavaNode::dump_spec(st);
aoqi@0 958 }
aoqi@0 959 #endif
aoqi@0 960
aoqi@0 961 //=============================================================================
aoqi@0 962 uint CallDynamicJavaNode::size_of() const { return sizeof(*this); }
aoqi@0 963 uint CallDynamicJavaNode::cmp( const Node &n ) const {
aoqi@0 964 CallDynamicJavaNode &call = (CallDynamicJavaNode&)n;
aoqi@0 965 return CallJavaNode::cmp(call);
aoqi@0 966 }
aoqi@0 967 #ifndef PRODUCT
aoqi@0 968 void CallDynamicJavaNode::dump_spec(outputStream *st) const {
aoqi@0 969 st->print("# Dynamic ");
aoqi@0 970 CallJavaNode::dump_spec(st);
aoqi@0 971 }
aoqi@0 972 #endif
aoqi@0 973
aoqi@0 974 //=============================================================================
aoqi@0 975 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
aoqi@0 976 uint CallRuntimeNode::cmp( const Node &n ) const {
aoqi@0 977 CallRuntimeNode &call = (CallRuntimeNode&)n;
aoqi@0 978 return CallNode::cmp(call) && !strcmp(_name,call._name);
aoqi@0 979 }
aoqi@0 980 #ifndef PRODUCT
aoqi@0 981 void CallRuntimeNode::dump_spec(outputStream *st) const {
aoqi@0 982 st->print("# ");
aoqi@0 983 st->print("%s", _name);
aoqi@0 984 CallNode::dump_spec(st);
aoqi@0 985 }
aoqi@0 986 #endif
aoqi@0 987
aoqi@0 988 //------------------------------calling_convention-----------------------------
aoqi@0 989 void CallRuntimeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
aoqi@0 990 Matcher::c_calling_convention( sig_bt, parm_regs, argcnt );
aoqi@0 991 }
aoqi@0 992
aoqi@0 993 //=============================================================================
aoqi@0 994 //------------------------------calling_convention-----------------------------
aoqi@0 995
aoqi@0 996
aoqi@0 997 //=============================================================================
aoqi@0 998 #ifndef PRODUCT
aoqi@0 999 void CallLeafNode::dump_spec(outputStream *st) const {
aoqi@0 1000 st->print("# ");
aoqi@0 1001 st->print("%s", _name);
aoqi@0 1002 CallNode::dump_spec(st);
aoqi@0 1003 }
aoqi@0 1004 #endif
aoqi@0 1005
aoqi@0 1006 //=============================================================================
aoqi@0 1007
aoqi@0 1008 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
aoqi@0 1009 assert(verify_jvms(jvms), "jvms must match");
aoqi@0 1010 int loc = jvms->locoff() + idx;
aoqi@0 1011 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
aoqi@0 1012 // If current local idx is top then local idx - 1 could
aoqi@0 1013 // be a long/double that needs to be killed since top could
aoqi@0 1014 // represent the 2nd half ofthe long/double.
aoqi@0 1015 uint ideal = in(loc -1)->ideal_reg();
aoqi@0 1016 if (ideal == Op_RegD || ideal == Op_RegL) {
aoqi@0 1017 // set other (low index) half to top
aoqi@0 1018 set_req(loc - 1, in(loc));
aoqi@0 1019 }
aoqi@0 1020 }
aoqi@0 1021 set_req(loc, c);
aoqi@0 1022 }
aoqi@0 1023
aoqi@0 1024 uint SafePointNode::size_of() const { return sizeof(*this); }
aoqi@0 1025 uint SafePointNode::cmp( const Node &n ) const {
aoqi@0 1026 return (&n == this); // Always fail except on self
aoqi@0 1027 }
aoqi@0 1028
aoqi@0 1029 //-------------------------set_next_exception----------------------------------
aoqi@0 1030 void SafePointNode::set_next_exception(SafePointNode* n) {
aoqi@0 1031 assert(n == NULL || n->Opcode() == Op_SafePoint, "correct value for next_exception");
aoqi@0 1032 if (len() == req()) {
aoqi@0 1033 if (n != NULL) add_prec(n);
aoqi@0 1034 } else {
aoqi@0 1035 set_prec(req(), n);
aoqi@0 1036 }
aoqi@0 1037 }
aoqi@0 1038
aoqi@0 1039
aoqi@0 1040 //----------------------------next_exception-----------------------------------
aoqi@0 1041 SafePointNode* SafePointNode::next_exception() const {
aoqi@0 1042 if (len() == req()) {
aoqi@0 1043 return NULL;
aoqi@0 1044 } else {
aoqi@0 1045 Node* n = in(req());
aoqi@0 1046 assert(n == NULL || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
aoqi@0 1047 return (SafePointNode*) n;
aoqi@0 1048 }
aoqi@0 1049 }
aoqi@0 1050
aoqi@0 1051
aoqi@0 1052 //------------------------------Ideal------------------------------------------
aoqi@0 1053 // Skip over any collapsed Regions
aoqi@0 1054 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1055 return remove_dead_region(phase, can_reshape) ? this : NULL;
aoqi@0 1056 }
aoqi@0 1057
aoqi@0 1058 //------------------------------Identity---------------------------------------
aoqi@0 1059 // Remove obviously duplicate safepoints
aoqi@0 1060 Node *SafePointNode::Identity( PhaseTransform *phase ) {
aoqi@0 1061
aoqi@0 1062 // If you have back to back safepoints, remove one
aoqi@0 1063 if( in(TypeFunc::Control)->is_SafePoint() )
aoqi@0 1064 return in(TypeFunc::Control);
aoqi@0 1065
aoqi@0 1066 if( in(0)->is_Proj() ) {
aoqi@0 1067 Node *n0 = in(0)->in(0);
aoqi@0 1068 // Check if he is a call projection (except Leaf Call)
aoqi@0 1069 if( n0->is_Catch() ) {
aoqi@0 1070 n0 = n0->in(0)->in(0);
aoqi@0 1071 assert( n0->is_Call(), "expect a call here" );
aoqi@0 1072 }
aoqi@0 1073 if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) {
aoqi@0 1074 // Useless Safepoint, so remove it
aoqi@0 1075 return in(TypeFunc::Control);
aoqi@0 1076 }
aoqi@0 1077 }
aoqi@0 1078
aoqi@0 1079 return this;
aoqi@0 1080 }
aoqi@0 1081
aoqi@0 1082 //------------------------------Value------------------------------------------
aoqi@0 1083 const Type *SafePointNode::Value( PhaseTransform *phase ) const {
aoqi@0 1084 if( phase->type(in(0)) == Type::TOP ) return Type::TOP;
aoqi@0 1085 if( phase->eqv( in(0), this ) ) return Type::TOP; // Dead infinite loop
aoqi@0 1086 return Type::CONTROL;
aoqi@0 1087 }
aoqi@0 1088
aoqi@0 1089 #ifndef PRODUCT
aoqi@0 1090 void SafePointNode::dump_spec(outputStream *st) const {
aoqi@0 1091 st->print(" SafePoint ");
aoqi@0 1092 }
aoqi@0 1093 #endif
aoqi@0 1094
aoqi@0 1095 const RegMask &SafePointNode::in_RegMask(uint idx) const {
aoqi@0 1096 if( idx < TypeFunc::Parms ) return RegMask::Empty;
aoqi@0 1097 // Values outside the domain represent debug info
aoqi@0 1098 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
aoqi@0 1099 }
aoqi@0 1100 const RegMask &SafePointNode::out_RegMask() const {
aoqi@0 1101 return RegMask::Empty;
aoqi@0 1102 }
aoqi@0 1103
aoqi@0 1104
aoqi@0 1105 void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {
aoqi@0 1106 assert((int)grow_by > 0, "sanity");
aoqi@0 1107 int monoff = jvms->monoff();
aoqi@0 1108 int scloff = jvms->scloff();
aoqi@0 1109 int endoff = jvms->endoff();
aoqi@0 1110 assert(endoff == (int)req(), "no other states or debug info after me");
aoqi@0 1111 Node* top = Compile::current()->top();
aoqi@0 1112 for (uint i = 0; i < grow_by; i++) {
aoqi@0 1113 ins_req(monoff, top);
aoqi@0 1114 }
aoqi@0 1115 jvms->set_monoff(monoff + grow_by);
aoqi@0 1116 jvms->set_scloff(scloff + grow_by);
aoqi@0 1117 jvms->set_endoff(endoff + grow_by);
aoqi@0 1118 }
aoqi@0 1119
aoqi@0 1120 void SafePointNode::push_monitor(const FastLockNode *lock) {
aoqi@0 1121 // Add a LockNode, which points to both the original BoxLockNode (the
aoqi@0 1122 // stack space for the monitor) and the Object being locked.
aoqi@0 1123 const int MonitorEdges = 2;
aoqi@0 1124 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
aoqi@0 1125 assert(req() == jvms()->endoff(), "correct sizing");
aoqi@0 1126 int nextmon = jvms()->scloff();
aoqi@0 1127 if (GenerateSynchronizationCode) {
aoqi@0 1128 ins_req(nextmon, lock->box_node());
aoqi@0 1129 ins_req(nextmon+1, lock->obj_node());
aoqi@0 1130 } else {
aoqi@0 1131 Node* top = Compile::current()->top();
aoqi@0 1132 ins_req(nextmon, top);
aoqi@0 1133 ins_req(nextmon, top);
aoqi@0 1134 }
aoqi@0 1135 jvms()->set_scloff(nextmon + MonitorEdges);
aoqi@0 1136 jvms()->set_endoff(req());
aoqi@0 1137 }
aoqi@0 1138
aoqi@0 1139 void SafePointNode::pop_monitor() {
aoqi@0 1140 // Delete last monitor from debug info
aoqi@0 1141 debug_only(int num_before_pop = jvms()->nof_monitors());
aoqi@0 1142 const int MonitorEdges = 2;
aoqi@0 1143 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
aoqi@0 1144 int scloff = jvms()->scloff();
aoqi@0 1145 int endoff = jvms()->endoff();
aoqi@0 1146 int new_scloff = scloff - MonitorEdges;
aoqi@0 1147 int new_endoff = endoff - MonitorEdges;
aoqi@0 1148 jvms()->set_scloff(new_scloff);
aoqi@0 1149 jvms()->set_endoff(new_endoff);
aoqi@0 1150 while (scloff > new_scloff) del_req_ordered(--scloff);
aoqi@0 1151 assert(jvms()->nof_monitors() == num_before_pop-1, "");
aoqi@0 1152 }
aoqi@0 1153
aoqi@0 1154 Node *SafePointNode::peek_monitor_box() const {
aoqi@0 1155 int mon = jvms()->nof_monitors() - 1;
aoqi@0 1156 assert(mon >= 0, "most have a monitor");
aoqi@0 1157 return monitor_box(jvms(), mon);
aoqi@0 1158 }
aoqi@0 1159
aoqi@0 1160 Node *SafePointNode::peek_monitor_obj() const {
aoqi@0 1161 int mon = jvms()->nof_monitors() - 1;
aoqi@0 1162 assert(mon >= 0, "most have a monitor");
aoqi@0 1163 return monitor_obj(jvms(), mon);
aoqi@0 1164 }
aoqi@0 1165
aoqi@0 1166 // Do we Match on this edge index or not? Match no edges
aoqi@0 1167 uint SafePointNode::match_edge(uint idx) const {
aoqi@0 1168 if( !needs_polling_address_input() )
aoqi@0 1169 return 0;
aoqi@0 1170
aoqi@0 1171 return (TypeFunc::Parms == idx);
aoqi@0 1172 }
aoqi@0 1173
aoqi@0 1174 //============== SafePointScalarObjectNode ==============
aoqi@0 1175
aoqi@0 1176 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp,
aoqi@0 1177 #ifdef ASSERT
aoqi@0 1178 AllocateNode* alloc,
aoqi@0 1179 #endif
aoqi@0 1180 uint first_index,
aoqi@0 1181 uint n_fields) :
aoqi@0 1182 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
aoqi@0 1183 #ifdef ASSERT
aoqi@0 1184 _alloc(alloc),
aoqi@0 1185 #endif
aoqi@0 1186 _first_index(first_index),
aoqi@0 1187 _n_fields(n_fields)
aoqi@0 1188 {
aoqi@0 1189 init_class_id(Class_SafePointScalarObject);
aoqi@0 1190 }
aoqi@0 1191
aoqi@0 1192 // Do not allow value-numbering for SafePointScalarObject node.
aoqi@0 1193 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
aoqi@0 1194 uint SafePointScalarObjectNode::cmp( const Node &n ) const {
aoqi@0 1195 return (&n == this); // Always fail except on self
aoqi@0 1196 }
aoqi@0 1197
aoqi@0 1198 uint SafePointScalarObjectNode::ideal_reg() const {
aoqi@0 1199 return 0; // No matching to machine instruction
aoqi@0 1200 }
aoqi@0 1201
aoqi@0 1202 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
aoqi@0 1203 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
aoqi@0 1204 }
aoqi@0 1205
aoqi@0 1206 const RegMask &SafePointScalarObjectNode::out_RegMask() const {
aoqi@0 1207 return RegMask::Empty;
aoqi@0 1208 }
aoqi@0 1209
aoqi@0 1210 uint SafePointScalarObjectNode::match_edge(uint idx) const {
aoqi@0 1211 return 0;
aoqi@0 1212 }
aoqi@0 1213
aoqi@0 1214 SafePointScalarObjectNode*
aoqi@0 1215 SafePointScalarObjectNode::clone(Dict* sosn_map) const {
aoqi@0 1216 void* cached = (*sosn_map)[(void*)this];
aoqi@0 1217 if (cached != NULL) {
aoqi@0 1218 return (SafePointScalarObjectNode*)cached;
aoqi@0 1219 }
aoqi@0 1220 SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone();
aoqi@0 1221 sosn_map->Insert((void*)this, (void*)res);
aoqi@0 1222 return res;
aoqi@0 1223 }
aoqi@0 1224
aoqi@0 1225
aoqi@0 1226 #ifndef PRODUCT
aoqi@0 1227 void SafePointScalarObjectNode::dump_spec(outputStream *st) const {
aoqi@0 1228 st->print(" # fields@[%d..%d]", first_index(),
aoqi@0 1229 first_index() + n_fields() - 1);
aoqi@0 1230 }
aoqi@0 1231
aoqi@0 1232 #endif
aoqi@0 1233
aoqi@0 1234 //=============================================================================
aoqi@0 1235 uint AllocateNode::size_of() const { return sizeof(*this); }
aoqi@0 1236
aoqi@0 1237 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
aoqi@0 1238 Node *ctrl, Node *mem, Node *abio,
aoqi@0 1239 Node *size, Node *klass_node, Node *initial_test)
aoqi@0 1240 : CallNode(atype, NULL, TypeRawPtr::BOTTOM)
aoqi@0 1241 {
aoqi@0 1242 init_class_id(Class_Allocate);
aoqi@0 1243 init_flags(Flag_is_macro);
aoqi@0 1244 _is_scalar_replaceable = false;
aoqi@0 1245 _is_non_escaping = false;
aoqi@0 1246 Node *topnode = C->top();
aoqi@0 1247
aoqi@0 1248 init_req( TypeFunc::Control , ctrl );
aoqi@0 1249 init_req( TypeFunc::I_O , abio );
aoqi@0 1250 init_req( TypeFunc::Memory , mem );
aoqi@0 1251 init_req( TypeFunc::ReturnAdr, topnode );
aoqi@0 1252 init_req( TypeFunc::FramePtr , topnode );
aoqi@0 1253 init_req( AllocSize , size);
aoqi@0 1254 init_req( KlassNode , klass_node);
aoqi@0 1255 init_req( InitialTest , initial_test);
aoqi@0 1256 init_req( ALength , topnode);
aoqi@0 1257 C->add_macro_node(this);
aoqi@0 1258 }
aoqi@0 1259
aoqi@0 1260 //=============================================================================
aoqi@0 1261 Node* AllocateArrayNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1262 if (remove_dead_region(phase, can_reshape)) return this;
aoqi@0 1263 // Don't bother trying to transform a dead node
aoqi@0 1264 if (in(0) && in(0)->is_top()) return NULL;
aoqi@0 1265
aoqi@0 1266 const Type* type = phase->type(Ideal_length());
aoqi@0 1267 if (type->isa_int() && type->is_int()->_hi < 0) {
aoqi@0 1268 if (can_reshape) {
aoqi@0 1269 PhaseIterGVN *igvn = phase->is_IterGVN();
aoqi@0 1270 // Unreachable fall through path (negative array length),
aoqi@0 1271 // the allocation can only throw so disconnect it.
aoqi@0 1272 Node* proj = proj_out(TypeFunc::Control);
aoqi@0 1273 Node* catchproj = NULL;
aoqi@0 1274 if (proj != NULL) {
aoqi@0 1275 for (DUIterator_Fast imax, i = proj->fast_outs(imax); i < imax; i++) {
aoqi@0 1276 Node *cn = proj->fast_out(i);
aoqi@0 1277 if (cn->is_Catch()) {
aoqi@0 1278 catchproj = cn->as_Multi()->proj_out(CatchProjNode::fall_through_index);
aoqi@0 1279 break;
aoqi@0 1280 }
aoqi@0 1281 }
aoqi@0 1282 }
aoqi@0 1283 if (catchproj != NULL && catchproj->outcnt() > 0 &&
aoqi@0 1284 (catchproj->outcnt() > 1 ||
aoqi@0 1285 catchproj->unique_out()->Opcode() != Op_Halt)) {
aoqi@0 1286 assert(catchproj->is_CatchProj(), "must be a CatchProjNode");
aoqi@0 1287 Node* nproj = catchproj->clone();
aoqi@0 1288 igvn->register_new_node_with_optimizer(nproj);
aoqi@0 1289
aoqi@0 1290 Node *frame = new (phase->C) ParmNode( phase->C->start(), TypeFunc::FramePtr );
aoqi@0 1291 frame = phase->transform(frame);
aoqi@0 1292 // Halt & Catch Fire
aoqi@0 1293 Node *halt = new (phase->C) HaltNode( nproj, frame );
aoqi@0 1294 phase->C->root()->add_req(halt);
aoqi@0 1295 phase->transform(halt);
aoqi@0 1296
aoqi@0 1297 igvn->replace_node(catchproj, phase->C->top());
aoqi@0 1298 return this;
aoqi@0 1299 }
aoqi@0 1300 } else {
aoqi@0 1301 // Can't correct it during regular GVN so register for IGVN
aoqi@0 1302 phase->C->record_for_igvn(this);
aoqi@0 1303 }
aoqi@0 1304 }
aoqi@0 1305 return NULL;
aoqi@0 1306 }
aoqi@0 1307
aoqi@0 1308 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
aoqi@0 1309 // CastII, if appropriate. If we are not allowed to create new nodes, and
aoqi@0 1310 // a CastII is appropriate, return NULL.
aoqi@0 1311 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseTransform *phase, bool allow_new_nodes) {
aoqi@0 1312 Node *length = in(AllocateNode::ALength);
aoqi@0 1313 assert(length != NULL, "length is not null");
aoqi@0 1314
aoqi@0 1315 const TypeInt* length_type = phase->find_int_type(length);
aoqi@0 1316 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
aoqi@0 1317
aoqi@0 1318 if (ary_type != NULL && length_type != NULL) {
aoqi@0 1319 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
aoqi@0 1320 if (narrow_length_type != length_type) {
aoqi@0 1321 // Assert one of:
aoqi@0 1322 // - the narrow_length is 0
aoqi@0 1323 // - the narrow_length is not wider than length
aoqi@0 1324 assert(narrow_length_type == TypeInt::ZERO ||
aoqi@0 1325 length_type->is_con() && narrow_length_type->is_con() &&
aoqi@0 1326 (narrow_length_type->_hi <= length_type->_lo) ||
aoqi@0 1327 (narrow_length_type->_hi <= length_type->_hi &&
aoqi@0 1328 narrow_length_type->_lo >= length_type->_lo),
aoqi@0 1329 "narrow type must be narrower than length type");
aoqi@0 1330
aoqi@0 1331 // Return NULL if new nodes are not allowed
aoqi@0 1332 if (!allow_new_nodes) return NULL;
aoqi@0 1333 // Create a cast which is control dependent on the initialization to
aoqi@0 1334 // propagate the fact that the array length must be positive.
aoqi@0 1335 length = new (phase->C) CastIINode(length, narrow_length_type);
aoqi@0 1336 length->set_req(0, initialization()->proj_out(0));
aoqi@0 1337 }
aoqi@0 1338 }
aoqi@0 1339
aoqi@0 1340 return length;
aoqi@0 1341 }
aoqi@0 1342
aoqi@0 1343 //=============================================================================
aoqi@0 1344 uint LockNode::size_of() const { return sizeof(*this); }
aoqi@0 1345
aoqi@0 1346 // Redundant lock elimination
aoqi@0 1347 //
aoqi@0 1348 // There are various patterns of locking where we release and
aoqi@0 1349 // immediately reacquire a lock in a piece of code where no operations
aoqi@0 1350 // occur in between that would be observable. In those cases we can
aoqi@0 1351 // skip releasing and reacquiring the lock without violating any
aoqi@0 1352 // fairness requirements. Doing this around a loop could cause a lock
aoqi@0 1353 // to be held for a very long time so we concentrate on non-looping
aoqi@0 1354 // control flow. We also require that the operations are fully
aoqi@0 1355 // redundant meaning that we don't introduce new lock operations on
aoqi@0 1356 // some paths so to be able to eliminate it on others ala PRE. This
aoqi@0 1357 // would probably require some more extensive graph manipulation to
aoqi@0 1358 // guarantee that the memory edges were all handled correctly.
aoqi@0 1359 //
aoqi@0 1360 // Assuming p is a simple predicate which can't trap in any way and s
aoqi@0 1361 // is a synchronized method consider this code:
aoqi@0 1362 //
aoqi@0 1363 // s();
aoqi@0 1364 // if (p)
aoqi@0 1365 // s();
aoqi@0 1366 // else
aoqi@0 1367 // s();
aoqi@0 1368 // s();
aoqi@0 1369 //
aoqi@0 1370 // 1. The unlocks of the first call to s can be eliminated if the
aoqi@0 1371 // locks inside the then and else branches are eliminated.
aoqi@0 1372 //
aoqi@0 1373 // 2. The unlocks of the then and else branches can be eliminated if
aoqi@0 1374 // the lock of the final call to s is eliminated.
aoqi@0 1375 //
aoqi@0 1376 // Either of these cases subsumes the simple case of sequential control flow
aoqi@0 1377 //
aoqi@0 1378 // Addtionally we can eliminate versions without the else case:
aoqi@0 1379 //
aoqi@0 1380 // s();
aoqi@0 1381 // if (p)
aoqi@0 1382 // s();
aoqi@0 1383 // s();
aoqi@0 1384 //
aoqi@0 1385 // 3. In this case we eliminate the unlock of the first s, the lock
aoqi@0 1386 // and unlock in the then case and the lock in the final s.
aoqi@0 1387 //
aoqi@0 1388 // Note also that in all these cases the then/else pieces don't have
aoqi@0 1389 // to be trivial as long as they begin and end with synchronization
aoqi@0 1390 // operations.
aoqi@0 1391 //
aoqi@0 1392 // s();
aoqi@0 1393 // if (p)
aoqi@0 1394 // s();
aoqi@0 1395 // f();
aoqi@0 1396 // s();
aoqi@0 1397 // s();
aoqi@0 1398 //
aoqi@0 1399 // The code will work properly for this case, leaving in the unlock
aoqi@0 1400 // before the call to f and the relock after it.
aoqi@0 1401 //
aoqi@0 1402 // A potentially interesting case which isn't handled here is when the
aoqi@0 1403 // locking is partially redundant.
aoqi@0 1404 //
aoqi@0 1405 // s();
aoqi@0 1406 // if (p)
aoqi@0 1407 // s();
aoqi@0 1408 //
aoqi@0 1409 // This could be eliminated putting unlocking on the else case and
aoqi@0 1410 // eliminating the first unlock and the lock in the then side.
aoqi@0 1411 // Alternatively the unlock could be moved out of the then side so it
aoqi@0 1412 // was after the merge and the first unlock and second lock
aoqi@0 1413 // eliminated. This might require less manipulation of the memory
aoqi@0 1414 // state to get correct.
aoqi@0 1415 //
aoqi@0 1416 // Additionally we might allow work between a unlock and lock before
aoqi@0 1417 // giving up eliminating the locks. The current code disallows any
aoqi@0 1418 // conditional control flow between these operations. A formulation
aoqi@0 1419 // similar to partial redundancy elimination computing the
aoqi@0 1420 // availability of unlocking and the anticipatability of locking at a
aoqi@0 1421 // program point would allow detection of fully redundant locking with
aoqi@0 1422 // some amount of work in between. I'm not sure how often I really
aoqi@0 1423 // think that would occur though. Most of the cases I've seen
aoqi@0 1424 // indicate it's likely non-trivial work would occur in between.
aoqi@0 1425 // There may be other more complicated constructs where we could
aoqi@0 1426 // eliminate locking but I haven't seen any others appear as hot or
aoqi@0 1427 // interesting.
aoqi@0 1428 //
aoqi@0 1429 // Locking and unlocking have a canonical form in ideal that looks
aoqi@0 1430 // roughly like this:
aoqi@0 1431 //
aoqi@0 1432 // <obj>
aoqi@0 1433 // | \\------+
aoqi@0 1434 // | \ \
aoqi@0 1435 // | BoxLock \
aoqi@0 1436 // | | | \
aoqi@0 1437 // | | \ \
aoqi@0 1438 // | | FastLock
aoqi@0 1439 // | | /
aoqi@0 1440 // | | /
aoqi@0 1441 // | | |
aoqi@0 1442 //
aoqi@0 1443 // Lock
aoqi@0 1444 // |
aoqi@0 1445 // Proj #0
aoqi@0 1446 // |
aoqi@0 1447 // MembarAcquire
aoqi@0 1448 // |
aoqi@0 1449 // Proj #0
aoqi@0 1450 //
aoqi@0 1451 // MembarRelease
aoqi@0 1452 // |
aoqi@0 1453 // Proj #0
aoqi@0 1454 // |
aoqi@0 1455 // Unlock
aoqi@0 1456 // |
aoqi@0 1457 // Proj #0
aoqi@0 1458 //
aoqi@0 1459 //
aoqi@0 1460 // This code proceeds by processing Lock nodes during PhaseIterGVN
aoqi@0 1461 // and searching back through its control for the proper code
aoqi@0 1462 // patterns. Once it finds a set of lock and unlock operations to
aoqi@0 1463 // eliminate they are marked as eliminatable which causes the
aoqi@0 1464 // expansion of the Lock and Unlock macro nodes to make the operation a NOP
aoqi@0 1465 //
aoqi@0 1466 //=============================================================================
aoqi@0 1467
aoqi@0 1468 //
aoqi@0 1469 // Utility function to skip over uninteresting control nodes. Nodes skipped are:
aoqi@0 1470 // - copy regions. (These may not have been optimized away yet.)
aoqi@0 1471 // - eliminated locking nodes
aoqi@0 1472 //
aoqi@0 1473 static Node *next_control(Node *ctrl) {
aoqi@0 1474 if (ctrl == NULL)
aoqi@0 1475 return NULL;
aoqi@0 1476 while (1) {
aoqi@0 1477 if (ctrl->is_Region()) {
aoqi@0 1478 RegionNode *r = ctrl->as_Region();
aoqi@0 1479 Node *n = r->is_copy();
aoqi@0 1480 if (n == NULL)
aoqi@0 1481 break; // hit a region, return it
aoqi@0 1482 else
aoqi@0 1483 ctrl = n;
aoqi@0 1484 } else if (ctrl->is_Proj()) {
aoqi@0 1485 Node *in0 = ctrl->in(0);
aoqi@0 1486 if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {
aoqi@0 1487 ctrl = in0->in(0);
aoqi@0 1488 } else {
aoqi@0 1489 break;
aoqi@0 1490 }
aoqi@0 1491 } else {
aoqi@0 1492 break; // found an interesting control
aoqi@0 1493 }
aoqi@0 1494 }
aoqi@0 1495 return ctrl;
aoqi@0 1496 }
aoqi@0 1497 //
aoqi@0 1498 // Given a control, see if it's the control projection of an Unlock which
aoqi@0 1499 // operating on the same object as lock.
aoqi@0 1500 //
aoqi@0 1501 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
aoqi@0 1502 GrowableArray<AbstractLockNode*> &lock_ops) {
aoqi@0 1503 ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;
aoqi@0 1504 if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
aoqi@0 1505 Node *n = ctrl_proj->in(0);
aoqi@0 1506 if (n != NULL && n->is_Unlock()) {
aoqi@0 1507 UnlockNode *unlock = n->as_Unlock();
aoqi@0 1508 if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&
aoqi@0 1509 BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
aoqi@0 1510 !unlock->is_eliminated()) {
aoqi@0 1511 lock_ops.append(unlock);
aoqi@0 1512 return true;
aoqi@0 1513 }
aoqi@0 1514 }
aoqi@0 1515 }
aoqi@0 1516 return false;
aoqi@0 1517 }
aoqi@0 1518
aoqi@0 1519 //
aoqi@0 1520 // Find the lock matching an unlock. Returns null if a safepoint
aoqi@0 1521 // or complicated control is encountered first.
aoqi@0 1522 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
aoqi@0 1523 LockNode *lock_result = NULL;
aoqi@0 1524 // find the matching lock, or an intervening safepoint
aoqi@0 1525 Node *ctrl = next_control(unlock->in(0));
aoqi@0 1526 while (1) {
aoqi@0 1527 assert(ctrl != NULL, "invalid control graph");
aoqi@0 1528 assert(!ctrl->is_Start(), "missing lock for unlock");
aoqi@0 1529 if (ctrl->is_top()) break; // dead control path
aoqi@0 1530 if (ctrl->is_Proj()) ctrl = ctrl->in(0);
aoqi@0 1531 if (ctrl->is_SafePoint()) {
aoqi@0 1532 break; // found a safepoint (may be the lock we are searching for)
aoqi@0 1533 } else if (ctrl->is_Region()) {
aoqi@0 1534 // Check for a simple diamond pattern. Punt on anything more complicated
aoqi@0 1535 if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
aoqi@0 1536 Node *in1 = next_control(ctrl->in(1));
aoqi@0 1537 Node *in2 = next_control(ctrl->in(2));
aoqi@0 1538 if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
aoqi@0 1539 (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
aoqi@0 1540 ctrl = next_control(in1->in(0)->in(0));
aoqi@0 1541 } else {
aoqi@0 1542 break;
aoqi@0 1543 }
aoqi@0 1544 } else {
aoqi@0 1545 break;
aoqi@0 1546 }
aoqi@0 1547 } else {
aoqi@0 1548 ctrl = next_control(ctrl->in(0)); // keep searching
aoqi@0 1549 }
aoqi@0 1550 }
aoqi@0 1551 if (ctrl->is_Lock()) {
aoqi@0 1552 LockNode *lock = ctrl->as_Lock();
aoqi@0 1553 if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&
aoqi@0 1554 BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
aoqi@0 1555 lock_result = lock;
aoqi@0 1556 }
aoqi@0 1557 }
aoqi@0 1558 return lock_result;
aoqi@0 1559 }
aoqi@0 1560
aoqi@0 1561 // This code corresponds to case 3 above.
aoqi@0 1562
aoqi@0 1563 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
aoqi@0 1564 GrowableArray<AbstractLockNode*> &lock_ops) {
aoqi@0 1565 Node* if_node = node->in(0);
aoqi@0 1566 bool if_true = node->is_IfTrue();
aoqi@0 1567
aoqi@0 1568 if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
aoqi@0 1569 Node *lock_ctrl = next_control(if_node->in(0));
aoqi@0 1570 if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
aoqi@0 1571 Node* lock1_node = NULL;
aoqi@0 1572 ProjNode* proj = if_node->as_If()->proj_out(!if_true);
aoqi@0 1573 if (if_true) {
aoqi@0 1574 if (proj->is_IfFalse() && proj->outcnt() == 1) {
aoqi@0 1575 lock1_node = proj->unique_out();
aoqi@0 1576 }
aoqi@0 1577 } else {
aoqi@0 1578 if (proj->is_IfTrue() && proj->outcnt() == 1) {
aoqi@0 1579 lock1_node = proj->unique_out();
aoqi@0 1580 }
aoqi@0 1581 }
aoqi@0 1582 if (lock1_node != NULL && lock1_node->is_Lock()) {
aoqi@0 1583 LockNode *lock1 = lock1_node->as_Lock();
aoqi@0 1584 if (lock->obj_node()->eqv_uncast(lock1->obj_node()) &&
aoqi@0 1585 BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
aoqi@0 1586 !lock1->is_eliminated()) {
aoqi@0 1587 lock_ops.append(lock1);
aoqi@0 1588 return true;
aoqi@0 1589 }
aoqi@0 1590 }
aoqi@0 1591 }
aoqi@0 1592 }
aoqi@0 1593
aoqi@0 1594 lock_ops.trunc_to(0);
aoqi@0 1595 return false;
aoqi@0 1596 }
aoqi@0 1597
aoqi@0 1598 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
aoqi@0 1599 GrowableArray<AbstractLockNode*> &lock_ops) {
aoqi@0 1600 // check each control merging at this point for a matching unlock.
aoqi@0 1601 // in(0) should be self edge so skip it.
aoqi@0 1602 for (int i = 1; i < (int)region->req(); i++) {
aoqi@0 1603 Node *in_node = next_control(region->in(i));
aoqi@0 1604 if (in_node != NULL) {
aoqi@0 1605 if (find_matching_unlock(in_node, lock, lock_ops)) {
aoqi@0 1606 // found a match so keep on checking.
aoqi@0 1607 continue;
aoqi@0 1608 } else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) {
aoqi@0 1609 continue;
aoqi@0 1610 }
aoqi@0 1611
aoqi@0 1612 // If we fall through to here then it was some kind of node we
aoqi@0 1613 // don't understand or there wasn't a matching unlock, so give
aoqi@0 1614 // up trying to merge locks.
aoqi@0 1615 lock_ops.trunc_to(0);
aoqi@0 1616 return false;
aoqi@0 1617 }
aoqi@0 1618 }
aoqi@0 1619 return true;
aoqi@0 1620
aoqi@0 1621 }
aoqi@0 1622
aoqi@0 1623 #ifndef PRODUCT
aoqi@0 1624 //
aoqi@0 1625 // Create a counter which counts the number of times this lock is acquired
aoqi@0 1626 //
aoqi@0 1627 void AbstractLockNode::create_lock_counter(JVMState* state) {
aoqi@0 1628 _counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter);
aoqi@0 1629 }
aoqi@0 1630
aoqi@0 1631 void AbstractLockNode::set_eliminated_lock_counter() {
aoqi@0 1632 if (_counter) {
aoqi@0 1633 // Update the counter to indicate that this lock was eliminated.
aoqi@0 1634 // The counter update code will stay around even though the
aoqi@0 1635 // optimizer will eliminate the lock operation itself.
aoqi@0 1636 _counter->set_tag(NamedCounter::EliminatedLockCounter);
aoqi@0 1637 }
aoqi@0 1638 }
aoqi@0 1639 #endif
aoqi@0 1640
aoqi@0 1641 //=============================================================================
aoqi@0 1642 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1643
aoqi@0 1644 // perform any generic optimizations first (returns 'this' or NULL)
aoqi@0 1645 Node *result = SafePointNode::Ideal(phase, can_reshape);
aoqi@0 1646 if (result != NULL) return result;
aoqi@0 1647 // Don't bother trying to transform a dead node
aoqi@0 1648 if (in(0) && in(0)->is_top()) return NULL;
aoqi@0 1649
aoqi@0 1650 // Now see if we can optimize away this lock. We don't actually
aoqi@0 1651 // remove the locking here, we simply set the _eliminate flag which
aoqi@0 1652 // prevents macro expansion from expanding the lock. Since we don't
aoqi@0 1653 // modify the graph, the value returned from this function is the
aoqi@0 1654 // one computed above.
aoqi@0 1655 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
aoqi@0 1656 //
aoqi@0 1657 // If we are locking an unescaped object, the lock/unlock is unnecessary
aoqi@0 1658 //
aoqi@0 1659 ConnectionGraph *cgr = phase->C->congraph();
aoqi@0 1660 if (cgr != NULL && cgr->not_global_escape(obj_node())) {
aoqi@0 1661 assert(!is_eliminated() || is_coarsened(), "sanity");
aoqi@0 1662 // The lock could be marked eliminated by lock coarsening
aoqi@0 1663 // code during first IGVN before EA. Replace coarsened flag
aoqi@0 1664 // to eliminate all associated locks/unlocks.
aoqi@0 1665 this->set_non_esc_obj();
aoqi@0 1666 return result;
aoqi@0 1667 }
aoqi@0 1668
aoqi@0 1669 //
aoqi@0 1670 // Try lock coarsening
aoqi@0 1671 //
aoqi@0 1672 PhaseIterGVN* iter = phase->is_IterGVN();
aoqi@0 1673 if (iter != NULL && !is_eliminated()) {
aoqi@0 1674
aoqi@0 1675 GrowableArray<AbstractLockNode*> lock_ops;
aoqi@0 1676
aoqi@0 1677 Node *ctrl = next_control(in(0));
aoqi@0 1678
aoqi@0 1679 // now search back for a matching Unlock
aoqi@0 1680 if (find_matching_unlock(ctrl, this, lock_ops)) {
aoqi@0 1681 // found an unlock directly preceding this lock. This is the
aoqi@0 1682 // case of single unlock directly control dependent on a
aoqi@0 1683 // single lock which is the trivial version of case 1 or 2.
aoqi@0 1684 } else if (ctrl->is_Region() ) {
aoqi@0 1685 if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) {
aoqi@0 1686 // found lock preceded by multiple unlocks along all paths
aoqi@0 1687 // joining at this point which is case 3 in description above.
aoqi@0 1688 }
aoqi@0 1689 } else {
aoqi@0 1690 // see if this lock comes from either half of an if and the
aoqi@0 1691 // predecessors merges unlocks and the other half of the if
aoqi@0 1692 // performs a lock.
aoqi@0 1693 if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) {
aoqi@0 1694 // found unlock splitting to an if with locks on both branches.
aoqi@0 1695 }
aoqi@0 1696 }
aoqi@0 1697
aoqi@0 1698 if (lock_ops.length() > 0) {
aoqi@0 1699 // add ourselves to the list of locks to be eliminated.
aoqi@0 1700 lock_ops.append(this);
aoqi@0 1701
aoqi@0 1702 #ifndef PRODUCT
aoqi@0 1703 if (PrintEliminateLocks) {
aoqi@0 1704 int locks = 0;
aoqi@0 1705 int unlocks = 0;
aoqi@0 1706 for (int i = 0; i < lock_ops.length(); i++) {
aoqi@0 1707 AbstractLockNode* lock = lock_ops.at(i);
aoqi@0 1708 if (lock->Opcode() == Op_Lock)
aoqi@0 1709 locks++;
aoqi@0 1710 else
aoqi@0 1711 unlocks++;
aoqi@0 1712 if (Verbose) {
aoqi@0 1713 lock->dump(1);
aoqi@0 1714 }
aoqi@0 1715 }
aoqi@0 1716 tty->print_cr("***Eliminated %d unlocks and %d locks", unlocks, locks);
aoqi@0 1717 }
aoqi@0 1718 #endif
aoqi@0 1719
aoqi@0 1720 // for each of the identified locks, mark them
aoqi@0 1721 // as eliminatable
aoqi@0 1722 for (int i = 0; i < lock_ops.length(); i++) {
aoqi@0 1723 AbstractLockNode* lock = lock_ops.at(i);
aoqi@0 1724
aoqi@0 1725 // Mark it eliminated by coarsening and update any counters
aoqi@0 1726 lock->set_coarsened();
aoqi@0 1727 }
aoqi@0 1728 } else if (ctrl->is_Region() &&
aoqi@0 1729 iter->_worklist.member(ctrl)) {
aoqi@0 1730 // We weren't able to find any opportunities but the region this
aoqi@0 1731 // lock is control dependent on hasn't been processed yet so put
aoqi@0 1732 // this lock back on the worklist so we can check again once any
aoqi@0 1733 // region simplification has occurred.
aoqi@0 1734 iter->_worklist.push(this);
aoqi@0 1735 }
aoqi@0 1736 }
aoqi@0 1737 }
aoqi@0 1738
aoqi@0 1739 return result;
aoqi@0 1740 }
aoqi@0 1741
aoqi@0 1742 //=============================================================================
aoqi@0 1743 bool LockNode::is_nested_lock_region() {
aoqi@0 1744 BoxLockNode* box = box_node()->as_BoxLock();
aoqi@0 1745 int stk_slot = box->stack_slot();
aoqi@0 1746 if (stk_slot <= 0)
aoqi@0 1747 return false; // External lock or it is not Box (Phi node).
aoqi@0 1748
aoqi@0 1749 // Ignore complex cases: merged locks or multiple locks.
aoqi@0 1750 Node* obj = obj_node();
aoqi@0 1751 LockNode* unique_lock = NULL;
aoqi@0 1752 if (!box->is_simple_lock_region(&unique_lock, obj) ||
aoqi@0 1753 (unique_lock != this)) {
aoqi@0 1754 return false;
aoqi@0 1755 }
aoqi@0 1756
aoqi@0 1757 // Look for external lock for the same object.
aoqi@0 1758 SafePointNode* sfn = this->as_SafePoint();
aoqi@0 1759 JVMState* youngest_jvms = sfn->jvms();
aoqi@0 1760 int max_depth = youngest_jvms->depth();
aoqi@0 1761 for (int depth = 1; depth <= max_depth; depth++) {
aoqi@0 1762 JVMState* jvms = youngest_jvms->of_depth(depth);
aoqi@0 1763 int num_mon = jvms->nof_monitors();
aoqi@0 1764 // Loop over monitors
aoqi@0 1765 for (int idx = 0; idx < num_mon; idx++) {
aoqi@0 1766 Node* obj_node = sfn->monitor_obj(jvms, idx);
aoqi@0 1767 BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
aoqi@0 1768 if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
aoqi@0 1769 return true;
aoqi@0 1770 }
aoqi@0 1771 }
aoqi@0 1772 }
aoqi@0 1773 return false;
aoqi@0 1774 }
aoqi@0 1775
aoqi@0 1776 //=============================================================================
aoqi@0 1777 uint UnlockNode::size_of() const { return sizeof(*this); }
aoqi@0 1778
aoqi@0 1779 //=============================================================================
aoqi@0 1780 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1781
aoqi@0 1782 // perform any generic optimizations first (returns 'this' or NULL)
aoqi@0 1783 Node *result = SafePointNode::Ideal(phase, can_reshape);
aoqi@0 1784 if (result != NULL) return result;
aoqi@0 1785 // Don't bother trying to transform a dead node
aoqi@0 1786 if (in(0) && in(0)->is_top()) return NULL;
aoqi@0 1787
aoqi@0 1788 // Now see if we can optimize away this unlock. We don't actually
aoqi@0 1789 // remove the unlocking here, we simply set the _eliminate flag which
aoqi@0 1790 // prevents macro expansion from expanding the unlock. Since we don't
aoqi@0 1791 // modify the graph, the value returned from this function is the
aoqi@0 1792 // one computed above.
aoqi@0 1793 // Escape state is defined after Parse phase.
aoqi@0 1794 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
aoqi@0 1795 //
aoqi@0 1796 // If we are unlocking an unescaped object, the lock/unlock is unnecessary.
aoqi@0 1797 //
aoqi@0 1798 ConnectionGraph *cgr = phase->C->congraph();
aoqi@0 1799 if (cgr != NULL && cgr->not_global_escape(obj_node())) {
aoqi@0 1800 assert(!is_eliminated() || is_coarsened(), "sanity");
aoqi@0 1801 // The lock could be marked eliminated by lock coarsening
aoqi@0 1802 // code during first IGVN before EA. Replace coarsened flag
aoqi@0 1803 // to eliminate all associated locks/unlocks.
aoqi@0 1804 this->set_non_esc_obj();
aoqi@0 1805 }
aoqi@0 1806 }
aoqi@0 1807 return result;
aoqi@0 1808 }

mercurial