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