src/share/vm/opto/callnode.cpp

Wed, 22 Jan 2014 17:42:23 -0800

author
kvn
date
Wed, 22 Jan 2014 17:42:23 -0800
changeset 6503
a9becfeecd1b
parent 6499
ad3b94907eed
parent 6198
55fb97c4c58d
child 6680
78bbf4d43a14
permissions
-rw-r--r--

Merge

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

mercurial