src/share/vm/opto/callnode.cpp

Sun, 23 Dec 2012 17:08:22 +0100

author
roland
date
Sun, 23 Dec 2012 17:08:22 +0100
changeset 4409
d092d1b31229
parent 4357
ad5dd04754ee
child 4478
a7114d3d712e
permissions
-rw-r--r--

8005071: Incremental inlining for JSR 292
Summary: post parse inlining driven by number of live nodes.
Reviewed-by: twisti, kvn, jrose

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

mercurial