src/share/vm/opto/callnode.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7166
f8afcfbdbf1c
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
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
roland@7166 780 // or 'this' if there are several CheckCastPP or unexpected uses
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;
roland@7166 796 } else if (!use->is_Initialize() &&
roland@7166 797 !use->is_AddP()) {
roland@7166 798 // Expected uses are restricted to a CheckCastPP, an Initialize
roland@7166 799 // node, and AddP nodes. If we encounter any other use (a Phi
roland@7166 800 // node can be seen in rare cases) return this to prevent
roland@7166 801 // incorrect optimizations.
roland@7166 802 return this;
aoqi@0 803 }
aoqi@0 804 }
aoqi@0 805 return cast;
aoqi@0 806 }
aoqi@0 807
aoqi@0 808
aoqi@0 809 void CallNode::extract_projections(CallProjections* projs, bool separate_io_proj) {
aoqi@0 810 projs->fallthrough_proj = NULL;
aoqi@0 811 projs->fallthrough_catchproj = NULL;
aoqi@0 812 projs->fallthrough_ioproj = NULL;
aoqi@0 813 projs->catchall_ioproj = NULL;
aoqi@0 814 projs->catchall_catchproj = NULL;
aoqi@0 815 projs->fallthrough_memproj = NULL;
aoqi@0 816 projs->catchall_memproj = NULL;
aoqi@0 817 projs->resproj = NULL;
aoqi@0 818 projs->exobj = NULL;
aoqi@0 819
aoqi@0 820 for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
aoqi@0 821 ProjNode *pn = fast_out(i)->as_Proj();
aoqi@0 822 if (pn->outcnt() == 0) continue;
aoqi@0 823 switch (pn->_con) {
aoqi@0 824 case TypeFunc::Control:
aoqi@0 825 {
aoqi@0 826 // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
aoqi@0 827 projs->fallthrough_proj = pn;
aoqi@0 828 DUIterator_Fast jmax, j = pn->fast_outs(jmax);
aoqi@0 829 const Node *cn = pn->fast_out(j);
aoqi@0 830 if (cn->is_Catch()) {
aoqi@0 831 ProjNode *cpn = NULL;
aoqi@0 832 for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
aoqi@0 833 cpn = cn->fast_out(k)->as_Proj();
aoqi@0 834 assert(cpn->is_CatchProj(), "must be a CatchProjNode");
aoqi@0 835 if (cpn->_con == CatchProjNode::fall_through_index)
aoqi@0 836 projs->fallthrough_catchproj = cpn;
aoqi@0 837 else {
aoqi@0 838 assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
aoqi@0 839 projs->catchall_catchproj = cpn;
aoqi@0 840 }
aoqi@0 841 }
aoqi@0 842 }
aoqi@0 843 break;
aoqi@0 844 }
aoqi@0 845 case TypeFunc::I_O:
aoqi@0 846 if (pn->_is_io_use)
aoqi@0 847 projs->catchall_ioproj = pn;
aoqi@0 848 else
aoqi@0 849 projs->fallthrough_ioproj = pn;
aoqi@0 850 for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
aoqi@0 851 Node* e = pn->out(j);
aoqi@0 852 if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
aoqi@0 853 assert(projs->exobj == NULL, "only one");
aoqi@0 854 projs->exobj = e;
aoqi@0 855 }
aoqi@0 856 }
aoqi@0 857 break;
aoqi@0 858 case TypeFunc::Memory:
aoqi@0 859 if (pn->_is_io_use)
aoqi@0 860 projs->catchall_memproj = pn;
aoqi@0 861 else
aoqi@0 862 projs->fallthrough_memproj = pn;
aoqi@0 863 break;
aoqi@0 864 case TypeFunc::Parms:
aoqi@0 865 projs->resproj = pn;
aoqi@0 866 break;
aoqi@0 867 default:
aoqi@0 868 assert(false, "unexpected projection from allocation node.");
aoqi@0 869 }
aoqi@0 870 }
aoqi@0 871
aoqi@0 872 // The resproj may not exist because the result couuld be ignored
aoqi@0 873 // and the exception object may not exist if an exception handler
aoqi@0 874 // swallows the exception but all the other must exist and be found.
aoqi@0 875 assert(projs->fallthrough_proj != NULL, "must be found");
aoqi@0 876 assert(Compile::current()->inlining_incrementally() || projs->fallthrough_catchproj != NULL, "must be found");
aoqi@0 877 assert(Compile::current()->inlining_incrementally() || projs->fallthrough_memproj != NULL, "must be found");
aoqi@0 878 assert(Compile::current()->inlining_incrementally() || projs->fallthrough_ioproj != NULL, "must be found");
aoqi@0 879 assert(Compile::current()->inlining_incrementally() || projs->catchall_catchproj != NULL, "must be found");
aoqi@0 880 if (separate_io_proj) {
aoqi@0 881 assert(Compile::current()->inlining_incrementally() || projs->catchall_memproj != NULL, "must be found");
aoqi@0 882 assert(Compile::current()->inlining_incrementally() || projs->catchall_ioproj != NULL, "must be found");
aoqi@0 883 }
aoqi@0 884 }
aoqi@0 885
aoqi@0 886 Node *CallNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 887 CallGenerator* cg = generator();
aoqi@0 888 if (can_reshape && cg != NULL && cg->is_mh_late_inline() && !cg->already_attempted()) {
aoqi@0 889 // Check whether this MH handle call becomes a candidate for inlining
aoqi@0 890 ciMethod* callee = cg->method();
aoqi@0 891 vmIntrinsics::ID iid = callee->intrinsic_id();
aoqi@0 892 if (iid == vmIntrinsics::_invokeBasic) {
aoqi@0 893 if (in(TypeFunc::Parms)->Opcode() == Op_ConP) {
aoqi@0 894 phase->C->prepend_late_inline(cg);
aoqi@0 895 set_generator(NULL);
aoqi@0 896 }
aoqi@0 897 } else {
aoqi@0 898 assert(callee->has_member_arg(), "wrong type of call?");
aoqi@0 899 if (in(TypeFunc::Parms + callee->arg_size() - 1)->Opcode() == Op_ConP) {
aoqi@0 900 phase->C->prepend_late_inline(cg);
aoqi@0 901 set_generator(NULL);
aoqi@0 902 }
aoqi@0 903 }
aoqi@0 904 }
aoqi@0 905 return SafePointNode::Ideal(phase, can_reshape);
aoqi@0 906 }
aoqi@0 907
aoqi@0 908
aoqi@0 909 //=============================================================================
aoqi@0 910 uint CallJavaNode::size_of() const { return sizeof(*this); }
aoqi@0 911 uint CallJavaNode::cmp( const Node &n ) const {
aoqi@0 912 CallJavaNode &call = (CallJavaNode&)n;
aoqi@0 913 return CallNode::cmp(call) && _method == call._method;
aoqi@0 914 }
aoqi@0 915 #ifndef PRODUCT
aoqi@0 916 void CallJavaNode::dump_spec(outputStream *st) const {
aoqi@0 917 if( _method ) _method->print_short_name(st);
aoqi@0 918 CallNode::dump_spec(st);
aoqi@0 919 }
aoqi@0 920 #endif
aoqi@0 921
aoqi@0 922 //=============================================================================
aoqi@0 923 uint CallStaticJavaNode::size_of() const { return sizeof(*this); }
aoqi@0 924 uint CallStaticJavaNode::cmp( const Node &n ) const {
aoqi@0 925 CallStaticJavaNode &call = (CallStaticJavaNode&)n;
aoqi@0 926 return CallJavaNode::cmp(call);
aoqi@0 927 }
aoqi@0 928
aoqi@0 929 //----------------------------uncommon_trap_request----------------------------
aoqi@0 930 // If this is an uncommon trap, return the request code, else zero.
aoqi@0 931 int CallStaticJavaNode::uncommon_trap_request() const {
aoqi@0 932 if (_name != NULL && !strcmp(_name, "uncommon_trap")) {
aoqi@0 933 return extract_uncommon_trap_request(this);
aoqi@0 934 }
aoqi@0 935 return 0;
aoqi@0 936 }
aoqi@0 937 int CallStaticJavaNode::extract_uncommon_trap_request(const Node* call) {
aoqi@0 938 #ifndef PRODUCT
aoqi@0 939 if (!(call->req() > TypeFunc::Parms &&
aoqi@0 940 call->in(TypeFunc::Parms) != NULL &&
aoqi@0 941 call->in(TypeFunc::Parms)->is_Con())) {
aoqi@0 942 assert(in_dump() != 0, "OK if dumping");
aoqi@0 943 tty->print("[bad uncommon trap]");
aoqi@0 944 return 0;
aoqi@0 945 }
aoqi@0 946 #endif
aoqi@0 947 return call->in(TypeFunc::Parms)->bottom_type()->is_int()->get_con();
aoqi@0 948 }
aoqi@0 949
aoqi@0 950 #ifndef PRODUCT
aoqi@0 951 void CallStaticJavaNode::dump_spec(outputStream *st) const {
aoqi@0 952 st->print("# Static ");
aoqi@0 953 if (_name != NULL) {
aoqi@0 954 st->print("%s", _name);
aoqi@0 955 int trap_req = uncommon_trap_request();
aoqi@0 956 if (trap_req != 0) {
aoqi@0 957 char buf[100];
aoqi@0 958 st->print("(%s)",
aoqi@0 959 Deoptimization::format_trap_request(buf, sizeof(buf),
aoqi@0 960 trap_req));
aoqi@0 961 }
aoqi@0 962 st->print(" ");
aoqi@0 963 }
aoqi@0 964 CallJavaNode::dump_spec(st);
aoqi@0 965 }
aoqi@0 966 #endif
aoqi@0 967
aoqi@0 968 //=============================================================================
aoqi@0 969 uint CallDynamicJavaNode::size_of() const { return sizeof(*this); }
aoqi@0 970 uint CallDynamicJavaNode::cmp( const Node &n ) const {
aoqi@0 971 CallDynamicJavaNode &call = (CallDynamicJavaNode&)n;
aoqi@0 972 return CallJavaNode::cmp(call);
aoqi@0 973 }
aoqi@0 974 #ifndef PRODUCT
aoqi@0 975 void CallDynamicJavaNode::dump_spec(outputStream *st) const {
aoqi@0 976 st->print("# Dynamic ");
aoqi@0 977 CallJavaNode::dump_spec(st);
aoqi@0 978 }
aoqi@0 979 #endif
aoqi@0 980
aoqi@0 981 //=============================================================================
aoqi@0 982 uint CallRuntimeNode::size_of() const { return sizeof(*this); }
aoqi@0 983 uint CallRuntimeNode::cmp( const Node &n ) const {
aoqi@0 984 CallRuntimeNode &call = (CallRuntimeNode&)n;
aoqi@0 985 return CallNode::cmp(call) && !strcmp(_name,call._name);
aoqi@0 986 }
aoqi@0 987 #ifndef PRODUCT
aoqi@0 988 void CallRuntimeNode::dump_spec(outputStream *st) const {
aoqi@0 989 st->print("# ");
aoqi@0 990 st->print("%s", _name);
aoqi@0 991 CallNode::dump_spec(st);
aoqi@0 992 }
aoqi@0 993 #endif
aoqi@0 994
aoqi@0 995 //------------------------------calling_convention-----------------------------
aoqi@0 996 void CallRuntimeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
aoqi@0 997 Matcher::c_calling_convention( sig_bt, parm_regs, argcnt );
aoqi@0 998 }
aoqi@0 999
aoqi@0 1000 //=============================================================================
aoqi@0 1001 //------------------------------calling_convention-----------------------------
aoqi@0 1002
aoqi@0 1003
aoqi@0 1004 //=============================================================================
aoqi@0 1005 #ifndef PRODUCT
aoqi@0 1006 void CallLeafNode::dump_spec(outputStream *st) const {
aoqi@0 1007 st->print("# ");
aoqi@0 1008 st->print("%s", _name);
aoqi@0 1009 CallNode::dump_spec(st);
aoqi@0 1010 }
aoqi@0 1011 #endif
aoqi@0 1012
aoqi@0 1013 //=============================================================================
aoqi@0 1014
aoqi@0 1015 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
aoqi@0 1016 assert(verify_jvms(jvms), "jvms must match");
aoqi@0 1017 int loc = jvms->locoff() + idx;
aoqi@0 1018 if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
aoqi@0 1019 // If current local idx is top then local idx - 1 could
aoqi@0 1020 // be a long/double that needs to be killed since top could
aoqi@0 1021 // represent the 2nd half ofthe long/double.
aoqi@0 1022 uint ideal = in(loc -1)->ideal_reg();
aoqi@0 1023 if (ideal == Op_RegD || ideal == Op_RegL) {
aoqi@0 1024 // set other (low index) half to top
aoqi@0 1025 set_req(loc - 1, in(loc));
aoqi@0 1026 }
aoqi@0 1027 }
aoqi@0 1028 set_req(loc, c);
aoqi@0 1029 }
aoqi@0 1030
aoqi@0 1031 uint SafePointNode::size_of() const { return sizeof(*this); }
aoqi@0 1032 uint SafePointNode::cmp( const Node &n ) const {
aoqi@0 1033 return (&n == this); // Always fail except on self
aoqi@0 1034 }
aoqi@0 1035
aoqi@0 1036 //-------------------------set_next_exception----------------------------------
aoqi@0 1037 void SafePointNode::set_next_exception(SafePointNode* n) {
aoqi@0 1038 assert(n == NULL || n->Opcode() == Op_SafePoint, "correct value for next_exception");
aoqi@0 1039 if (len() == req()) {
aoqi@0 1040 if (n != NULL) add_prec(n);
aoqi@0 1041 } else {
aoqi@0 1042 set_prec(req(), n);
aoqi@0 1043 }
aoqi@0 1044 }
aoqi@0 1045
aoqi@0 1046
aoqi@0 1047 //----------------------------next_exception-----------------------------------
aoqi@0 1048 SafePointNode* SafePointNode::next_exception() const {
aoqi@0 1049 if (len() == req()) {
aoqi@0 1050 return NULL;
aoqi@0 1051 } else {
aoqi@0 1052 Node* n = in(req());
aoqi@0 1053 assert(n == NULL || n->Opcode() == Op_SafePoint, "no other uses of prec edges");
aoqi@0 1054 return (SafePointNode*) n;
aoqi@0 1055 }
aoqi@0 1056 }
aoqi@0 1057
aoqi@0 1058
aoqi@0 1059 //------------------------------Ideal------------------------------------------
aoqi@0 1060 // Skip over any collapsed Regions
aoqi@0 1061 Node *SafePointNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1062 return remove_dead_region(phase, can_reshape) ? this : NULL;
aoqi@0 1063 }
aoqi@0 1064
aoqi@0 1065 //------------------------------Identity---------------------------------------
aoqi@0 1066 // Remove obviously duplicate safepoints
aoqi@0 1067 Node *SafePointNode::Identity( PhaseTransform *phase ) {
aoqi@0 1068
aoqi@0 1069 // If you have back to back safepoints, remove one
aoqi@0 1070 if( in(TypeFunc::Control)->is_SafePoint() )
aoqi@0 1071 return in(TypeFunc::Control);
aoqi@0 1072
aoqi@0 1073 if( in(0)->is_Proj() ) {
aoqi@0 1074 Node *n0 = in(0)->in(0);
aoqi@0 1075 // Check if he is a call projection (except Leaf Call)
aoqi@0 1076 if( n0->is_Catch() ) {
aoqi@0 1077 n0 = n0->in(0)->in(0);
aoqi@0 1078 assert( n0->is_Call(), "expect a call here" );
aoqi@0 1079 }
aoqi@0 1080 if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) {
aoqi@0 1081 // Useless Safepoint, so remove it
aoqi@0 1082 return in(TypeFunc::Control);
aoqi@0 1083 }
aoqi@0 1084 }
aoqi@0 1085
aoqi@0 1086 return this;
aoqi@0 1087 }
aoqi@0 1088
aoqi@0 1089 //------------------------------Value------------------------------------------
aoqi@0 1090 const Type *SafePointNode::Value( PhaseTransform *phase ) const {
aoqi@0 1091 if( phase->type(in(0)) == Type::TOP ) return Type::TOP;
aoqi@0 1092 if( phase->eqv( in(0), this ) ) return Type::TOP; // Dead infinite loop
aoqi@0 1093 return Type::CONTROL;
aoqi@0 1094 }
aoqi@0 1095
aoqi@0 1096 #ifndef PRODUCT
aoqi@0 1097 void SafePointNode::dump_spec(outputStream *st) const {
aoqi@0 1098 st->print(" SafePoint ");
roland@7041 1099 _replaced_nodes.dump(st);
aoqi@0 1100 }
aoqi@0 1101 #endif
aoqi@0 1102
aoqi@0 1103 const RegMask &SafePointNode::in_RegMask(uint idx) const {
aoqi@0 1104 if( idx < TypeFunc::Parms ) return RegMask::Empty;
aoqi@0 1105 // Values outside the domain represent debug info
aoqi@0 1106 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
aoqi@0 1107 }
aoqi@0 1108 const RegMask &SafePointNode::out_RegMask() const {
aoqi@0 1109 return RegMask::Empty;
aoqi@0 1110 }
aoqi@0 1111
aoqi@0 1112
aoqi@0 1113 void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {
aoqi@0 1114 assert((int)grow_by > 0, "sanity");
aoqi@0 1115 int monoff = jvms->monoff();
aoqi@0 1116 int scloff = jvms->scloff();
aoqi@0 1117 int endoff = jvms->endoff();
aoqi@0 1118 assert(endoff == (int)req(), "no other states or debug info after me");
aoqi@0 1119 Node* top = Compile::current()->top();
aoqi@0 1120 for (uint i = 0; i < grow_by; i++) {
aoqi@0 1121 ins_req(monoff, top);
aoqi@0 1122 }
aoqi@0 1123 jvms->set_monoff(monoff + grow_by);
aoqi@0 1124 jvms->set_scloff(scloff + grow_by);
aoqi@0 1125 jvms->set_endoff(endoff + grow_by);
aoqi@0 1126 }
aoqi@0 1127
aoqi@0 1128 void SafePointNode::push_monitor(const FastLockNode *lock) {
aoqi@0 1129 // Add a LockNode, which points to both the original BoxLockNode (the
aoqi@0 1130 // stack space for the monitor) and the Object being locked.
aoqi@0 1131 const int MonitorEdges = 2;
aoqi@0 1132 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
aoqi@0 1133 assert(req() == jvms()->endoff(), "correct sizing");
aoqi@0 1134 int nextmon = jvms()->scloff();
aoqi@0 1135 if (GenerateSynchronizationCode) {
aoqi@0 1136 ins_req(nextmon, lock->box_node());
aoqi@0 1137 ins_req(nextmon+1, lock->obj_node());
aoqi@0 1138 } else {
aoqi@0 1139 Node* top = Compile::current()->top();
aoqi@0 1140 ins_req(nextmon, top);
aoqi@0 1141 ins_req(nextmon, top);
aoqi@0 1142 }
aoqi@0 1143 jvms()->set_scloff(nextmon + MonitorEdges);
aoqi@0 1144 jvms()->set_endoff(req());
aoqi@0 1145 }
aoqi@0 1146
aoqi@0 1147 void SafePointNode::pop_monitor() {
aoqi@0 1148 // Delete last monitor from debug info
aoqi@0 1149 debug_only(int num_before_pop = jvms()->nof_monitors());
aoqi@0 1150 const int MonitorEdges = 2;
aoqi@0 1151 assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
aoqi@0 1152 int scloff = jvms()->scloff();
aoqi@0 1153 int endoff = jvms()->endoff();
aoqi@0 1154 int new_scloff = scloff - MonitorEdges;
aoqi@0 1155 int new_endoff = endoff - MonitorEdges;
aoqi@0 1156 jvms()->set_scloff(new_scloff);
aoqi@0 1157 jvms()->set_endoff(new_endoff);
aoqi@0 1158 while (scloff > new_scloff) del_req_ordered(--scloff);
aoqi@0 1159 assert(jvms()->nof_monitors() == num_before_pop-1, "");
aoqi@0 1160 }
aoqi@0 1161
aoqi@0 1162 Node *SafePointNode::peek_monitor_box() const {
aoqi@0 1163 int mon = jvms()->nof_monitors() - 1;
aoqi@0 1164 assert(mon >= 0, "most have a monitor");
aoqi@0 1165 return monitor_box(jvms(), mon);
aoqi@0 1166 }
aoqi@0 1167
aoqi@0 1168 Node *SafePointNode::peek_monitor_obj() const {
aoqi@0 1169 int mon = jvms()->nof_monitors() - 1;
aoqi@0 1170 assert(mon >= 0, "most have a monitor");
aoqi@0 1171 return monitor_obj(jvms(), mon);
aoqi@0 1172 }
aoqi@0 1173
aoqi@0 1174 // Do we Match on this edge index or not? Match no edges
aoqi@0 1175 uint SafePointNode::match_edge(uint idx) const {
aoqi@0 1176 if( !needs_polling_address_input() )
aoqi@0 1177 return 0;
aoqi@0 1178
aoqi@0 1179 return (TypeFunc::Parms == idx);
aoqi@0 1180 }
aoqi@0 1181
aoqi@0 1182 //============== SafePointScalarObjectNode ==============
aoqi@0 1183
aoqi@0 1184 SafePointScalarObjectNode::SafePointScalarObjectNode(const TypeOopPtr* tp,
aoqi@0 1185 #ifdef ASSERT
aoqi@0 1186 AllocateNode* alloc,
aoqi@0 1187 #endif
aoqi@0 1188 uint first_index,
aoqi@0 1189 uint n_fields) :
aoqi@0 1190 TypeNode(tp, 1), // 1 control input -- seems required. Get from root.
aoqi@0 1191 #ifdef ASSERT
aoqi@0 1192 _alloc(alloc),
aoqi@0 1193 #endif
aoqi@0 1194 _first_index(first_index),
aoqi@0 1195 _n_fields(n_fields)
aoqi@0 1196 {
aoqi@0 1197 init_class_id(Class_SafePointScalarObject);
aoqi@0 1198 }
aoqi@0 1199
aoqi@0 1200 // Do not allow value-numbering for SafePointScalarObject node.
aoqi@0 1201 uint SafePointScalarObjectNode::hash() const { return NO_HASH; }
aoqi@0 1202 uint SafePointScalarObjectNode::cmp( const Node &n ) const {
aoqi@0 1203 return (&n == this); // Always fail except on self
aoqi@0 1204 }
aoqi@0 1205
aoqi@0 1206 uint SafePointScalarObjectNode::ideal_reg() const {
aoqi@0 1207 return 0; // No matching to machine instruction
aoqi@0 1208 }
aoqi@0 1209
aoqi@0 1210 const RegMask &SafePointScalarObjectNode::in_RegMask(uint idx) const {
aoqi@0 1211 return *(Compile::current()->matcher()->idealreg2debugmask[in(idx)->ideal_reg()]);
aoqi@0 1212 }
aoqi@0 1213
aoqi@0 1214 const RegMask &SafePointScalarObjectNode::out_RegMask() const {
aoqi@0 1215 return RegMask::Empty;
aoqi@0 1216 }
aoqi@0 1217
aoqi@0 1218 uint SafePointScalarObjectNode::match_edge(uint idx) const {
aoqi@0 1219 return 0;
aoqi@0 1220 }
aoqi@0 1221
aoqi@0 1222 SafePointScalarObjectNode*
aoqi@0 1223 SafePointScalarObjectNode::clone(Dict* sosn_map) const {
aoqi@0 1224 void* cached = (*sosn_map)[(void*)this];
aoqi@0 1225 if (cached != NULL) {
aoqi@0 1226 return (SafePointScalarObjectNode*)cached;
aoqi@0 1227 }
aoqi@0 1228 SafePointScalarObjectNode* res = (SafePointScalarObjectNode*)Node::clone();
aoqi@0 1229 sosn_map->Insert((void*)this, (void*)res);
aoqi@0 1230 return res;
aoqi@0 1231 }
aoqi@0 1232
aoqi@0 1233
aoqi@0 1234 #ifndef PRODUCT
aoqi@0 1235 void SafePointScalarObjectNode::dump_spec(outputStream *st) const {
aoqi@0 1236 st->print(" # fields@[%d..%d]", first_index(),
aoqi@0 1237 first_index() + n_fields() - 1);
aoqi@0 1238 }
aoqi@0 1239
aoqi@0 1240 #endif
aoqi@0 1241
aoqi@0 1242 //=============================================================================
aoqi@0 1243 uint AllocateNode::size_of() const { return sizeof(*this); }
aoqi@0 1244
aoqi@0 1245 AllocateNode::AllocateNode(Compile* C, const TypeFunc *atype,
aoqi@0 1246 Node *ctrl, Node *mem, Node *abio,
aoqi@0 1247 Node *size, Node *klass_node, Node *initial_test)
aoqi@0 1248 : CallNode(atype, NULL, TypeRawPtr::BOTTOM)
aoqi@0 1249 {
aoqi@0 1250 init_class_id(Class_Allocate);
aoqi@0 1251 init_flags(Flag_is_macro);
aoqi@0 1252 _is_scalar_replaceable = false;
aoqi@0 1253 _is_non_escaping = false;
aoqi@0 1254 Node *topnode = C->top();
aoqi@0 1255
aoqi@0 1256 init_req( TypeFunc::Control , ctrl );
aoqi@0 1257 init_req( TypeFunc::I_O , abio );
aoqi@0 1258 init_req( TypeFunc::Memory , mem );
aoqi@0 1259 init_req( TypeFunc::ReturnAdr, topnode );
aoqi@0 1260 init_req( TypeFunc::FramePtr , topnode );
aoqi@0 1261 init_req( AllocSize , size);
aoqi@0 1262 init_req( KlassNode , klass_node);
aoqi@0 1263 init_req( InitialTest , initial_test);
aoqi@0 1264 init_req( ALength , topnode);
aoqi@0 1265 C->add_macro_node(this);
aoqi@0 1266 }
aoqi@0 1267
aoqi@0 1268 //=============================================================================
aoqi@0 1269 Node* AllocateArrayNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1270 if (remove_dead_region(phase, can_reshape)) return this;
aoqi@0 1271 // Don't bother trying to transform a dead node
aoqi@0 1272 if (in(0) && in(0)->is_top()) return NULL;
aoqi@0 1273
aoqi@0 1274 const Type* type = phase->type(Ideal_length());
aoqi@0 1275 if (type->isa_int() && type->is_int()->_hi < 0) {
aoqi@0 1276 if (can_reshape) {
aoqi@0 1277 PhaseIterGVN *igvn = phase->is_IterGVN();
aoqi@0 1278 // Unreachable fall through path (negative array length),
aoqi@0 1279 // the allocation can only throw so disconnect it.
aoqi@0 1280 Node* proj = proj_out(TypeFunc::Control);
aoqi@0 1281 Node* catchproj = NULL;
aoqi@0 1282 if (proj != NULL) {
aoqi@0 1283 for (DUIterator_Fast imax, i = proj->fast_outs(imax); i < imax; i++) {
aoqi@0 1284 Node *cn = proj->fast_out(i);
aoqi@0 1285 if (cn->is_Catch()) {
aoqi@0 1286 catchproj = cn->as_Multi()->proj_out(CatchProjNode::fall_through_index);
aoqi@0 1287 break;
aoqi@0 1288 }
aoqi@0 1289 }
aoqi@0 1290 }
aoqi@0 1291 if (catchproj != NULL && catchproj->outcnt() > 0 &&
aoqi@0 1292 (catchproj->outcnt() > 1 ||
aoqi@0 1293 catchproj->unique_out()->Opcode() != Op_Halt)) {
aoqi@0 1294 assert(catchproj->is_CatchProj(), "must be a CatchProjNode");
aoqi@0 1295 Node* nproj = catchproj->clone();
aoqi@0 1296 igvn->register_new_node_with_optimizer(nproj);
aoqi@0 1297
aoqi@0 1298 Node *frame = new (phase->C) ParmNode( phase->C->start(), TypeFunc::FramePtr );
aoqi@0 1299 frame = phase->transform(frame);
aoqi@0 1300 // Halt & Catch Fire
aoqi@0 1301 Node *halt = new (phase->C) HaltNode( nproj, frame );
aoqi@0 1302 phase->C->root()->add_req(halt);
aoqi@0 1303 phase->transform(halt);
aoqi@0 1304
aoqi@0 1305 igvn->replace_node(catchproj, phase->C->top());
aoqi@0 1306 return this;
aoqi@0 1307 }
aoqi@0 1308 } else {
aoqi@0 1309 // Can't correct it during regular GVN so register for IGVN
aoqi@0 1310 phase->C->record_for_igvn(this);
aoqi@0 1311 }
aoqi@0 1312 }
aoqi@0 1313 return NULL;
aoqi@0 1314 }
aoqi@0 1315
aoqi@0 1316 // Retrieve the length from the AllocateArrayNode. Narrow the type with a
aoqi@0 1317 // CastII, if appropriate. If we are not allowed to create new nodes, and
aoqi@0 1318 // a CastII is appropriate, return NULL.
aoqi@0 1319 Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseTransform *phase, bool allow_new_nodes) {
aoqi@0 1320 Node *length = in(AllocateNode::ALength);
aoqi@0 1321 assert(length != NULL, "length is not null");
aoqi@0 1322
aoqi@0 1323 const TypeInt* length_type = phase->find_int_type(length);
aoqi@0 1324 const TypeAryPtr* ary_type = oop_type->isa_aryptr();
aoqi@0 1325
aoqi@0 1326 if (ary_type != NULL && length_type != NULL) {
aoqi@0 1327 const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type);
aoqi@0 1328 if (narrow_length_type != length_type) {
aoqi@0 1329 // Assert one of:
aoqi@0 1330 // - the narrow_length is 0
aoqi@0 1331 // - the narrow_length is not wider than length
aoqi@0 1332 assert(narrow_length_type == TypeInt::ZERO ||
aoqi@0 1333 length_type->is_con() && narrow_length_type->is_con() &&
aoqi@0 1334 (narrow_length_type->_hi <= length_type->_lo) ||
aoqi@0 1335 (narrow_length_type->_hi <= length_type->_hi &&
aoqi@0 1336 narrow_length_type->_lo >= length_type->_lo),
aoqi@0 1337 "narrow type must be narrower than length type");
aoqi@0 1338
aoqi@0 1339 // Return NULL if new nodes are not allowed
aoqi@0 1340 if (!allow_new_nodes) return NULL;
aoqi@0 1341 // Create a cast which is control dependent on the initialization to
aoqi@0 1342 // propagate the fact that the array length must be positive.
aoqi@0 1343 length = new (phase->C) CastIINode(length, narrow_length_type);
aoqi@0 1344 length->set_req(0, initialization()->proj_out(0));
aoqi@0 1345 }
aoqi@0 1346 }
aoqi@0 1347
aoqi@0 1348 return length;
aoqi@0 1349 }
aoqi@0 1350
aoqi@0 1351 //=============================================================================
aoqi@0 1352 uint LockNode::size_of() const { return sizeof(*this); }
aoqi@0 1353
aoqi@0 1354 // Redundant lock elimination
aoqi@0 1355 //
aoqi@0 1356 // There are various patterns of locking where we release and
aoqi@0 1357 // immediately reacquire a lock in a piece of code where no operations
aoqi@0 1358 // occur in between that would be observable. In those cases we can
aoqi@0 1359 // skip releasing and reacquiring the lock without violating any
aoqi@0 1360 // fairness requirements. Doing this around a loop could cause a lock
aoqi@0 1361 // to be held for a very long time so we concentrate on non-looping
aoqi@0 1362 // control flow. We also require that the operations are fully
aoqi@0 1363 // redundant meaning that we don't introduce new lock operations on
aoqi@0 1364 // some paths so to be able to eliminate it on others ala PRE. This
aoqi@0 1365 // would probably require some more extensive graph manipulation to
aoqi@0 1366 // guarantee that the memory edges were all handled correctly.
aoqi@0 1367 //
aoqi@0 1368 // Assuming p is a simple predicate which can't trap in any way and s
aoqi@0 1369 // is a synchronized method consider this code:
aoqi@0 1370 //
aoqi@0 1371 // s();
aoqi@0 1372 // if (p)
aoqi@0 1373 // s();
aoqi@0 1374 // else
aoqi@0 1375 // s();
aoqi@0 1376 // s();
aoqi@0 1377 //
aoqi@0 1378 // 1. The unlocks of the first call to s can be eliminated if the
aoqi@0 1379 // locks inside the then and else branches are eliminated.
aoqi@0 1380 //
aoqi@0 1381 // 2. The unlocks of the then and else branches can be eliminated if
aoqi@0 1382 // the lock of the final call to s is eliminated.
aoqi@0 1383 //
aoqi@0 1384 // Either of these cases subsumes the simple case of sequential control flow
aoqi@0 1385 //
aoqi@0 1386 // Addtionally we can eliminate versions without the else case:
aoqi@0 1387 //
aoqi@0 1388 // s();
aoqi@0 1389 // if (p)
aoqi@0 1390 // s();
aoqi@0 1391 // s();
aoqi@0 1392 //
aoqi@0 1393 // 3. In this case we eliminate the unlock of the first s, the lock
aoqi@0 1394 // and unlock in the then case and the lock in the final s.
aoqi@0 1395 //
aoqi@0 1396 // Note also that in all these cases the then/else pieces don't have
aoqi@0 1397 // to be trivial as long as they begin and end with synchronization
aoqi@0 1398 // operations.
aoqi@0 1399 //
aoqi@0 1400 // s();
aoqi@0 1401 // if (p)
aoqi@0 1402 // s();
aoqi@0 1403 // f();
aoqi@0 1404 // s();
aoqi@0 1405 // s();
aoqi@0 1406 //
aoqi@0 1407 // The code will work properly for this case, leaving in the unlock
aoqi@0 1408 // before the call to f and the relock after it.
aoqi@0 1409 //
aoqi@0 1410 // A potentially interesting case which isn't handled here is when the
aoqi@0 1411 // locking is partially redundant.
aoqi@0 1412 //
aoqi@0 1413 // s();
aoqi@0 1414 // if (p)
aoqi@0 1415 // s();
aoqi@0 1416 //
aoqi@0 1417 // This could be eliminated putting unlocking on the else case and
aoqi@0 1418 // eliminating the first unlock and the lock in the then side.
aoqi@0 1419 // Alternatively the unlock could be moved out of the then side so it
aoqi@0 1420 // was after the merge and the first unlock and second lock
aoqi@0 1421 // eliminated. This might require less manipulation of the memory
aoqi@0 1422 // state to get correct.
aoqi@0 1423 //
aoqi@0 1424 // Additionally we might allow work between a unlock and lock before
aoqi@0 1425 // giving up eliminating the locks. The current code disallows any
aoqi@0 1426 // conditional control flow between these operations. A formulation
aoqi@0 1427 // similar to partial redundancy elimination computing the
aoqi@0 1428 // availability of unlocking and the anticipatability of locking at a
aoqi@0 1429 // program point would allow detection of fully redundant locking with
aoqi@0 1430 // some amount of work in between. I'm not sure how often I really
aoqi@0 1431 // think that would occur though. Most of the cases I've seen
aoqi@0 1432 // indicate it's likely non-trivial work would occur in between.
aoqi@0 1433 // There may be other more complicated constructs where we could
aoqi@0 1434 // eliminate locking but I haven't seen any others appear as hot or
aoqi@0 1435 // interesting.
aoqi@0 1436 //
aoqi@0 1437 // Locking and unlocking have a canonical form in ideal that looks
aoqi@0 1438 // roughly like this:
aoqi@0 1439 //
aoqi@0 1440 // <obj>
aoqi@0 1441 // | \\------+
aoqi@0 1442 // | \ \
aoqi@0 1443 // | BoxLock \
aoqi@0 1444 // | | | \
aoqi@0 1445 // | | \ \
aoqi@0 1446 // | | FastLock
aoqi@0 1447 // | | /
aoqi@0 1448 // | | /
aoqi@0 1449 // | | |
aoqi@0 1450 //
aoqi@0 1451 // Lock
aoqi@0 1452 // |
aoqi@0 1453 // Proj #0
aoqi@0 1454 // |
aoqi@0 1455 // MembarAcquire
aoqi@0 1456 // |
aoqi@0 1457 // Proj #0
aoqi@0 1458 //
aoqi@0 1459 // MembarRelease
aoqi@0 1460 // |
aoqi@0 1461 // Proj #0
aoqi@0 1462 // |
aoqi@0 1463 // Unlock
aoqi@0 1464 // |
aoqi@0 1465 // Proj #0
aoqi@0 1466 //
aoqi@0 1467 //
aoqi@0 1468 // This code proceeds by processing Lock nodes during PhaseIterGVN
aoqi@0 1469 // and searching back through its control for the proper code
aoqi@0 1470 // patterns. Once it finds a set of lock and unlock operations to
aoqi@0 1471 // eliminate they are marked as eliminatable which causes the
aoqi@0 1472 // expansion of the Lock and Unlock macro nodes to make the operation a NOP
aoqi@0 1473 //
aoqi@0 1474 //=============================================================================
aoqi@0 1475
aoqi@0 1476 //
aoqi@0 1477 // Utility function to skip over uninteresting control nodes. Nodes skipped are:
aoqi@0 1478 // - copy regions. (These may not have been optimized away yet.)
aoqi@0 1479 // - eliminated locking nodes
aoqi@0 1480 //
aoqi@0 1481 static Node *next_control(Node *ctrl) {
aoqi@0 1482 if (ctrl == NULL)
aoqi@0 1483 return NULL;
aoqi@0 1484 while (1) {
aoqi@0 1485 if (ctrl->is_Region()) {
aoqi@0 1486 RegionNode *r = ctrl->as_Region();
aoqi@0 1487 Node *n = r->is_copy();
aoqi@0 1488 if (n == NULL)
aoqi@0 1489 break; // hit a region, return it
aoqi@0 1490 else
aoqi@0 1491 ctrl = n;
aoqi@0 1492 } else if (ctrl->is_Proj()) {
aoqi@0 1493 Node *in0 = ctrl->in(0);
aoqi@0 1494 if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {
aoqi@0 1495 ctrl = in0->in(0);
aoqi@0 1496 } else {
aoqi@0 1497 break;
aoqi@0 1498 }
aoqi@0 1499 } else {
aoqi@0 1500 break; // found an interesting control
aoqi@0 1501 }
aoqi@0 1502 }
aoqi@0 1503 return ctrl;
aoqi@0 1504 }
aoqi@0 1505 //
aoqi@0 1506 // Given a control, see if it's the control projection of an Unlock which
aoqi@0 1507 // operating on the same object as lock.
aoqi@0 1508 //
aoqi@0 1509 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
aoqi@0 1510 GrowableArray<AbstractLockNode*> &lock_ops) {
aoqi@0 1511 ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;
aoqi@0 1512 if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
aoqi@0 1513 Node *n = ctrl_proj->in(0);
aoqi@0 1514 if (n != NULL && n->is_Unlock()) {
aoqi@0 1515 UnlockNode *unlock = n->as_Unlock();
aoqi@0 1516 if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&
aoqi@0 1517 BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
aoqi@0 1518 !unlock->is_eliminated()) {
aoqi@0 1519 lock_ops.append(unlock);
aoqi@0 1520 return true;
aoqi@0 1521 }
aoqi@0 1522 }
aoqi@0 1523 }
aoqi@0 1524 return false;
aoqi@0 1525 }
aoqi@0 1526
aoqi@0 1527 //
aoqi@0 1528 // Find the lock matching an unlock. Returns null if a safepoint
aoqi@0 1529 // or complicated control is encountered first.
aoqi@0 1530 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
aoqi@0 1531 LockNode *lock_result = NULL;
aoqi@0 1532 // find the matching lock, or an intervening safepoint
aoqi@0 1533 Node *ctrl = next_control(unlock->in(0));
aoqi@0 1534 while (1) {
aoqi@0 1535 assert(ctrl != NULL, "invalid control graph");
aoqi@0 1536 assert(!ctrl->is_Start(), "missing lock for unlock");
aoqi@0 1537 if (ctrl->is_top()) break; // dead control path
aoqi@0 1538 if (ctrl->is_Proj()) ctrl = ctrl->in(0);
aoqi@0 1539 if (ctrl->is_SafePoint()) {
aoqi@0 1540 break; // found a safepoint (may be the lock we are searching for)
aoqi@0 1541 } else if (ctrl->is_Region()) {
aoqi@0 1542 // Check for a simple diamond pattern. Punt on anything more complicated
aoqi@0 1543 if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
aoqi@0 1544 Node *in1 = next_control(ctrl->in(1));
aoqi@0 1545 Node *in2 = next_control(ctrl->in(2));
aoqi@0 1546 if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
aoqi@0 1547 (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
aoqi@0 1548 ctrl = next_control(in1->in(0)->in(0));
aoqi@0 1549 } else {
aoqi@0 1550 break;
aoqi@0 1551 }
aoqi@0 1552 } else {
aoqi@0 1553 break;
aoqi@0 1554 }
aoqi@0 1555 } else {
aoqi@0 1556 ctrl = next_control(ctrl->in(0)); // keep searching
aoqi@0 1557 }
aoqi@0 1558 }
aoqi@0 1559 if (ctrl->is_Lock()) {
aoqi@0 1560 LockNode *lock = ctrl->as_Lock();
aoqi@0 1561 if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&
aoqi@0 1562 BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
aoqi@0 1563 lock_result = lock;
aoqi@0 1564 }
aoqi@0 1565 }
aoqi@0 1566 return lock_result;
aoqi@0 1567 }
aoqi@0 1568
aoqi@0 1569 // This code corresponds to case 3 above.
aoqi@0 1570
aoqi@0 1571 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
aoqi@0 1572 GrowableArray<AbstractLockNode*> &lock_ops) {
aoqi@0 1573 Node* if_node = node->in(0);
aoqi@0 1574 bool if_true = node->is_IfTrue();
aoqi@0 1575
aoqi@0 1576 if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
aoqi@0 1577 Node *lock_ctrl = next_control(if_node->in(0));
aoqi@0 1578 if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
aoqi@0 1579 Node* lock1_node = NULL;
aoqi@0 1580 ProjNode* proj = if_node->as_If()->proj_out(!if_true);
aoqi@0 1581 if (if_true) {
aoqi@0 1582 if (proj->is_IfFalse() && proj->outcnt() == 1) {
aoqi@0 1583 lock1_node = proj->unique_out();
aoqi@0 1584 }
aoqi@0 1585 } else {
aoqi@0 1586 if (proj->is_IfTrue() && proj->outcnt() == 1) {
aoqi@0 1587 lock1_node = proj->unique_out();
aoqi@0 1588 }
aoqi@0 1589 }
aoqi@0 1590 if (lock1_node != NULL && lock1_node->is_Lock()) {
aoqi@0 1591 LockNode *lock1 = lock1_node->as_Lock();
aoqi@0 1592 if (lock->obj_node()->eqv_uncast(lock1->obj_node()) &&
aoqi@0 1593 BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
aoqi@0 1594 !lock1->is_eliminated()) {
aoqi@0 1595 lock_ops.append(lock1);
aoqi@0 1596 return true;
aoqi@0 1597 }
aoqi@0 1598 }
aoqi@0 1599 }
aoqi@0 1600 }
aoqi@0 1601
aoqi@0 1602 lock_ops.trunc_to(0);
aoqi@0 1603 return false;
aoqi@0 1604 }
aoqi@0 1605
aoqi@0 1606 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
aoqi@0 1607 GrowableArray<AbstractLockNode*> &lock_ops) {
aoqi@0 1608 // check each control merging at this point for a matching unlock.
aoqi@0 1609 // in(0) should be self edge so skip it.
aoqi@0 1610 for (int i = 1; i < (int)region->req(); i++) {
aoqi@0 1611 Node *in_node = next_control(region->in(i));
aoqi@0 1612 if (in_node != NULL) {
aoqi@0 1613 if (find_matching_unlock(in_node, lock, lock_ops)) {
aoqi@0 1614 // found a match so keep on checking.
aoqi@0 1615 continue;
aoqi@0 1616 } else if (find_lock_and_unlock_through_if(in_node, lock, lock_ops)) {
aoqi@0 1617 continue;
aoqi@0 1618 }
aoqi@0 1619
aoqi@0 1620 // If we fall through to here then it was some kind of node we
aoqi@0 1621 // don't understand or there wasn't a matching unlock, so give
aoqi@0 1622 // up trying to merge locks.
aoqi@0 1623 lock_ops.trunc_to(0);
aoqi@0 1624 return false;
aoqi@0 1625 }
aoqi@0 1626 }
aoqi@0 1627 return true;
aoqi@0 1628
aoqi@0 1629 }
aoqi@0 1630
aoqi@0 1631 #ifndef PRODUCT
aoqi@0 1632 //
aoqi@0 1633 // Create a counter which counts the number of times this lock is acquired
aoqi@0 1634 //
aoqi@0 1635 void AbstractLockNode::create_lock_counter(JVMState* state) {
aoqi@0 1636 _counter = OptoRuntime::new_named_counter(state, NamedCounter::LockCounter);
aoqi@0 1637 }
aoqi@0 1638
aoqi@0 1639 void AbstractLockNode::set_eliminated_lock_counter() {
aoqi@0 1640 if (_counter) {
aoqi@0 1641 // Update the counter to indicate that this lock was eliminated.
aoqi@0 1642 // The counter update code will stay around even though the
aoqi@0 1643 // optimizer will eliminate the lock operation itself.
aoqi@0 1644 _counter->set_tag(NamedCounter::EliminatedLockCounter);
aoqi@0 1645 }
aoqi@0 1646 }
aoqi@0 1647 #endif
aoqi@0 1648
aoqi@0 1649 //=============================================================================
aoqi@0 1650 Node *LockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1651
aoqi@0 1652 // perform any generic optimizations first (returns 'this' or NULL)
aoqi@0 1653 Node *result = SafePointNode::Ideal(phase, can_reshape);
aoqi@0 1654 if (result != NULL) return result;
aoqi@0 1655 // Don't bother trying to transform a dead node
aoqi@0 1656 if (in(0) && in(0)->is_top()) return NULL;
aoqi@0 1657
aoqi@0 1658 // Now see if we can optimize away this lock. We don't actually
aoqi@0 1659 // remove the locking here, we simply set the _eliminate flag which
aoqi@0 1660 // prevents macro expansion from expanding the lock. Since we don't
aoqi@0 1661 // modify the graph, the value returned from this function is the
aoqi@0 1662 // one computed above.
aoqi@0 1663 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
aoqi@0 1664 //
aoqi@0 1665 // If we are locking an unescaped object, the lock/unlock is unnecessary
aoqi@0 1666 //
aoqi@0 1667 ConnectionGraph *cgr = phase->C->congraph();
aoqi@0 1668 if (cgr != NULL && cgr->not_global_escape(obj_node())) {
aoqi@0 1669 assert(!is_eliminated() || is_coarsened(), "sanity");
aoqi@0 1670 // The lock could be marked eliminated by lock coarsening
aoqi@0 1671 // code during first IGVN before EA. Replace coarsened flag
aoqi@0 1672 // to eliminate all associated locks/unlocks.
aoqi@0 1673 this->set_non_esc_obj();
aoqi@0 1674 return result;
aoqi@0 1675 }
aoqi@0 1676
aoqi@0 1677 //
aoqi@0 1678 // Try lock coarsening
aoqi@0 1679 //
aoqi@0 1680 PhaseIterGVN* iter = phase->is_IterGVN();
aoqi@0 1681 if (iter != NULL && !is_eliminated()) {
aoqi@0 1682
aoqi@0 1683 GrowableArray<AbstractLockNode*> lock_ops;
aoqi@0 1684
aoqi@0 1685 Node *ctrl = next_control(in(0));
aoqi@0 1686
aoqi@0 1687 // now search back for a matching Unlock
aoqi@0 1688 if (find_matching_unlock(ctrl, this, lock_ops)) {
aoqi@0 1689 // found an unlock directly preceding this lock. This is the
aoqi@0 1690 // case of single unlock directly control dependent on a
aoqi@0 1691 // single lock which is the trivial version of case 1 or 2.
aoqi@0 1692 } else if (ctrl->is_Region() ) {
aoqi@0 1693 if (find_unlocks_for_region(ctrl->as_Region(), this, lock_ops)) {
aoqi@0 1694 // found lock preceded by multiple unlocks along all paths
aoqi@0 1695 // joining at this point which is case 3 in description above.
aoqi@0 1696 }
aoqi@0 1697 } else {
aoqi@0 1698 // see if this lock comes from either half of an if and the
aoqi@0 1699 // predecessors merges unlocks and the other half of the if
aoqi@0 1700 // performs a lock.
aoqi@0 1701 if (find_lock_and_unlock_through_if(ctrl, this, lock_ops)) {
aoqi@0 1702 // found unlock splitting to an if with locks on both branches.
aoqi@0 1703 }
aoqi@0 1704 }
aoqi@0 1705
aoqi@0 1706 if (lock_ops.length() > 0) {
aoqi@0 1707 // add ourselves to the list of locks to be eliminated.
aoqi@0 1708 lock_ops.append(this);
aoqi@0 1709
aoqi@0 1710 #ifndef PRODUCT
aoqi@0 1711 if (PrintEliminateLocks) {
aoqi@0 1712 int locks = 0;
aoqi@0 1713 int unlocks = 0;
aoqi@0 1714 for (int i = 0; i < lock_ops.length(); i++) {
aoqi@0 1715 AbstractLockNode* lock = lock_ops.at(i);
aoqi@0 1716 if (lock->Opcode() == Op_Lock)
aoqi@0 1717 locks++;
aoqi@0 1718 else
aoqi@0 1719 unlocks++;
aoqi@0 1720 if (Verbose) {
aoqi@0 1721 lock->dump(1);
aoqi@0 1722 }
aoqi@0 1723 }
aoqi@0 1724 tty->print_cr("***Eliminated %d unlocks and %d locks", unlocks, locks);
aoqi@0 1725 }
aoqi@0 1726 #endif
aoqi@0 1727
aoqi@0 1728 // for each of the identified locks, mark them
aoqi@0 1729 // as eliminatable
aoqi@0 1730 for (int i = 0; i < lock_ops.length(); i++) {
aoqi@0 1731 AbstractLockNode* lock = lock_ops.at(i);
aoqi@0 1732
aoqi@0 1733 // Mark it eliminated by coarsening and update any counters
aoqi@0 1734 lock->set_coarsened();
aoqi@0 1735 }
aoqi@0 1736 } else if (ctrl->is_Region() &&
aoqi@0 1737 iter->_worklist.member(ctrl)) {
aoqi@0 1738 // We weren't able to find any opportunities but the region this
aoqi@0 1739 // lock is control dependent on hasn't been processed yet so put
aoqi@0 1740 // this lock back on the worklist so we can check again once any
aoqi@0 1741 // region simplification has occurred.
aoqi@0 1742 iter->_worklist.push(this);
aoqi@0 1743 }
aoqi@0 1744 }
aoqi@0 1745 }
aoqi@0 1746
aoqi@0 1747 return result;
aoqi@0 1748 }
aoqi@0 1749
aoqi@0 1750 //=============================================================================
aoqi@0 1751 bool LockNode::is_nested_lock_region() {
aoqi@0 1752 BoxLockNode* box = box_node()->as_BoxLock();
aoqi@0 1753 int stk_slot = box->stack_slot();
aoqi@0 1754 if (stk_slot <= 0)
aoqi@0 1755 return false; // External lock or it is not Box (Phi node).
aoqi@0 1756
aoqi@0 1757 // Ignore complex cases: merged locks or multiple locks.
aoqi@0 1758 Node* obj = obj_node();
aoqi@0 1759 LockNode* unique_lock = NULL;
aoqi@0 1760 if (!box->is_simple_lock_region(&unique_lock, obj) ||
aoqi@0 1761 (unique_lock != this)) {
aoqi@0 1762 return false;
aoqi@0 1763 }
aoqi@0 1764
aoqi@0 1765 // Look for external lock for the same object.
aoqi@0 1766 SafePointNode* sfn = this->as_SafePoint();
aoqi@0 1767 JVMState* youngest_jvms = sfn->jvms();
aoqi@0 1768 int max_depth = youngest_jvms->depth();
aoqi@0 1769 for (int depth = 1; depth <= max_depth; depth++) {
aoqi@0 1770 JVMState* jvms = youngest_jvms->of_depth(depth);
aoqi@0 1771 int num_mon = jvms->nof_monitors();
aoqi@0 1772 // Loop over monitors
aoqi@0 1773 for (int idx = 0; idx < num_mon; idx++) {
aoqi@0 1774 Node* obj_node = sfn->monitor_obj(jvms, idx);
aoqi@0 1775 BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
aoqi@0 1776 if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
aoqi@0 1777 return true;
aoqi@0 1778 }
aoqi@0 1779 }
aoqi@0 1780 }
aoqi@0 1781 return false;
aoqi@0 1782 }
aoqi@0 1783
aoqi@0 1784 //=============================================================================
aoqi@0 1785 uint UnlockNode::size_of() const { return sizeof(*this); }
aoqi@0 1786
aoqi@0 1787 //=============================================================================
aoqi@0 1788 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
aoqi@0 1789
aoqi@0 1790 // perform any generic optimizations first (returns 'this' or NULL)
aoqi@0 1791 Node *result = SafePointNode::Ideal(phase, can_reshape);
aoqi@0 1792 if (result != NULL) return result;
aoqi@0 1793 // Don't bother trying to transform a dead node
aoqi@0 1794 if (in(0) && in(0)->is_top()) return NULL;
aoqi@0 1795
aoqi@0 1796 // Now see if we can optimize away this unlock. We don't actually
aoqi@0 1797 // remove the unlocking here, we simply set the _eliminate flag which
aoqi@0 1798 // prevents macro expansion from expanding the unlock. Since we don't
aoqi@0 1799 // modify the graph, the value returned from this function is the
aoqi@0 1800 // one computed above.
aoqi@0 1801 // Escape state is defined after Parse phase.
aoqi@0 1802 if (can_reshape && EliminateLocks && !is_non_esc_obj()) {
aoqi@0 1803 //
aoqi@0 1804 // If we are unlocking an unescaped object, the lock/unlock is unnecessary.
aoqi@0 1805 //
aoqi@0 1806 ConnectionGraph *cgr = phase->C->congraph();
aoqi@0 1807 if (cgr != NULL && cgr->not_global_escape(obj_node())) {
aoqi@0 1808 assert(!is_eliminated() || is_coarsened(), "sanity");
aoqi@0 1809 // The lock could be marked eliminated by lock coarsening
aoqi@0 1810 // code during first IGVN before EA. Replace coarsened flag
aoqi@0 1811 // to eliminate all associated locks/unlocks.
aoqi@0 1812 this->set_non_esc_obj();
aoqi@0 1813 }
aoqi@0 1814 }
aoqi@0 1815 return result;
aoqi@0 1816 }

mercurial