src/share/vm/opto/callnode.cpp

Tue, 24 Dec 2013 11:48:39 -0800

author
mikael
date
Tue, 24 Dec 2013 11:48:39 -0800
changeset 6198
55fb97c4c58d
parent 5626
766fac3395d6
child 6503
a9becfeecd1b
permissions
-rw-r--r--

8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
Summary: Copyright year updated for files modified during 2013
Reviewed-by: twisti, iveresov

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

mercurial