src/share/vm/opto/callnode.cpp

Fri, 11 Jul 2014 19:51:36 -0400

author
drchase
date
Fri, 11 Jul 2014 19:51:36 -0400
changeset 7161
fc2c88ea11a9
parent 7041
411e30e5fbb8
child 7166
f8afcfbdbf1c
permissions
-rw-r--r--

8036588: VerifyFieldClosure fails instanceKlass:3133
Summary: Changed deopt live-pointer test to use returns-object instead of live-and-returns-object
Reviewed-by: iveresov, kvn, jrose

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

mercurial