1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/parse1.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,2166 @@ 1.4 +/* 1.5 + * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "incls/_precompiled.incl" 1.29 +#include "incls/_parse1.cpp.incl" 1.30 + 1.31 +// Static array so we can figure out which bytecodes stop us from compiling 1.32 +// the most. Some of the non-static variables are needed in bytecodeInfo.cpp 1.33 +// and eventually should be encapsulated in a proper class (gri 8/18/98). 1.34 + 1.35 +int nodes_created = 0; int nodes_created_old = 0; 1.36 +int methods_parsed = 0; int methods_parsed_old = 0; 1.37 +int methods_seen = 0; int methods_seen_old = 0; 1.38 + 1.39 +int explicit_null_checks_inserted = 0, explicit_null_checks_inserted_old = 0; 1.40 +int explicit_null_checks_elided = 0, explicit_null_checks_elided_old = 0; 1.41 +int all_null_checks_found = 0, implicit_null_checks = 0; 1.42 +int implicit_null_throws = 0; 1.43 + 1.44 +int parse_idx = 0; 1.45 +size_t parse_arena = 0; 1.46 +int reclaim_idx = 0; 1.47 +int reclaim_in = 0; 1.48 +int reclaim_node = 0; 1.49 + 1.50 +#ifndef PRODUCT 1.51 +bool Parse::BytecodeParseHistogram::_initialized = false; 1.52 +uint Parse::BytecodeParseHistogram::_bytecodes_parsed [Bytecodes::number_of_codes]; 1.53 +uint Parse::BytecodeParseHistogram::_nodes_constructed[Bytecodes::number_of_codes]; 1.54 +uint Parse::BytecodeParseHistogram::_nodes_transformed[Bytecodes::number_of_codes]; 1.55 +uint Parse::BytecodeParseHistogram::_new_values [Bytecodes::number_of_codes]; 1.56 +#endif 1.57 + 1.58 +//------------------------------print_statistics------------------------------- 1.59 +#ifndef PRODUCT 1.60 +void Parse::print_statistics() { 1.61 + tty->print_cr("--- Compiler Statistics ---"); 1.62 + tty->print("Methods seen: %d Methods parsed: %d", methods_seen, methods_parsed); 1.63 + tty->print(" Nodes created: %d", nodes_created); 1.64 + tty->cr(); 1.65 + if (methods_seen != methods_parsed) 1.66 + tty->print_cr("Reasons for parse failures (NOT cumulative):"); 1.67 + 1.68 + if( explicit_null_checks_inserted ) 1.69 + tty->print_cr("%d original NULL checks - %d elided (%2d%%); optimizer leaves %d,", explicit_null_checks_inserted, explicit_null_checks_elided, (100*explicit_null_checks_elided)/explicit_null_checks_inserted, all_null_checks_found); 1.70 + if( all_null_checks_found ) 1.71 + tty->print_cr("%d made implicit (%2d%%)", implicit_null_checks, 1.72 + (100*implicit_null_checks)/all_null_checks_found); 1.73 + if( implicit_null_throws ) 1.74 + tty->print_cr("%d implicit null exceptions at runtime", 1.75 + implicit_null_throws); 1.76 + 1.77 + if( PrintParseStatistics && BytecodeParseHistogram::initialized() ) { 1.78 + BytecodeParseHistogram::print(); 1.79 + } 1.80 +} 1.81 +#endif 1.82 + 1.83 +//------------------------------ON STACK REPLACEMENT--------------------------- 1.84 + 1.85 +// Construct a node which can be used to get incoming state for 1.86 +// on stack replacement. 1.87 +Node *Parse::fetch_interpreter_state(int index, 1.88 + BasicType bt, 1.89 + Node *local_addrs, 1.90 + Node *local_addrs_base) { 1.91 + Node *mem = memory(Compile::AliasIdxRaw); 1.92 + Node *adr = basic_plus_adr( local_addrs_base, local_addrs, -index*wordSize ); 1.93 + 1.94 + // Very similar to LoadNode::make, except we handle un-aligned longs and 1.95 + // doubles on Sparc. Intel can handle them just fine directly. 1.96 + Node *l; 1.97 + switch( bt ) { // Signature is flattened 1.98 + case T_INT: l = new (C, 3) LoadINode( 0, mem, adr, TypeRawPtr::BOTTOM ); break; 1.99 + case T_FLOAT: l = new (C, 3) LoadFNode( 0, mem, adr, TypeRawPtr::BOTTOM ); break; 1.100 + case T_ADDRESS: 1.101 + case T_OBJECT: l = new (C, 3) LoadPNode( 0, mem, adr, TypeRawPtr::BOTTOM, TypeInstPtr::BOTTOM ); break; 1.102 + case T_LONG: 1.103 + case T_DOUBLE: { 1.104 + // Since arguments are in reverse order, the argument address 'adr' 1.105 + // refers to the back half of the long/double. Recompute adr. 1.106 + adr = basic_plus_adr( local_addrs_base, local_addrs, -(index+1)*wordSize ); 1.107 + if( Matcher::misaligned_doubles_ok ) { 1.108 + l = (bt == T_DOUBLE) 1.109 + ? (Node*)new (C, 3) LoadDNode( 0, mem, adr, TypeRawPtr::BOTTOM ) 1.110 + : (Node*)new (C, 3) LoadLNode( 0, mem, adr, TypeRawPtr::BOTTOM ); 1.111 + } else { 1.112 + l = (bt == T_DOUBLE) 1.113 + ? (Node*)new (C, 3) LoadD_unalignedNode( 0, mem, adr, TypeRawPtr::BOTTOM ) 1.114 + : (Node*)new (C, 3) LoadL_unalignedNode( 0, mem, adr, TypeRawPtr::BOTTOM ); 1.115 + } 1.116 + break; 1.117 + } 1.118 + default: ShouldNotReachHere(); 1.119 + } 1.120 + return _gvn.transform(l); 1.121 +} 1.122 + 1.123 +// Helper routine to prevent the interpreter from handing 1.124 +// unexpected typestate to an OSR method. 1.125 +// The Node l is a value newly dug out of the interpreter frame. 1.126 +// The type is the type predicted by ciTypeFlow. Note that it is 1.127 +// not a general type, but can only come from Type::get_typeflow_type. 1.128 +// The safepoint is a map which will feed an uncommon trap. 1.129 +Node* Parse::check_interpreter_type(Node* l, const Type* type, 1.130 + SafePointNode* &bad_type_exit) { 1.131 + 1.132 + const TypeOopPtr* tp = type->isa_oopptr(); 1.133 + 1.134 + // TypeFlow may assert null-ness if a type appears unloaded. 1.135 + if (type == TypePtr::NULL_PTR || 1.136 + (tp != NULL && !tp->klass()->is_loaded())) { 1.137 + // Value must be null, not a real oop. 1.138 + Node* chk = _gvn.transform( new (C, 3) CmpPNode(l, null()) ); 1.139 + Node* tst = _gvn.transform( new (C, 2) BoolNode(chk, BoolTest::eq) ); 1.140 + IfNode* iff = create_and_map_if(control(), tst, PROB_MAX, COUNT_UNKNOWN); 1.141 + set_control(_gvn.transform( new (C, 1) IfTrueNode(iff) )); 1.142 + Node* bad_type = _gvn.transform( new (C, 1) IfFalseNode(iff) ); 1.143 + bad_type_exit->control()->add_req(bad_type); 1.144 + l = null(); 1.145 + } 1.146 + 1.147 + // Typeflow can also cut off paths from the CFG, based on 1.148 + // types which appear unloaded, or call sites which appear unlinked. 1.149 + // When paths are cut off, values at later merge points can rise 1.150 + // toward more specific classes. Make sure these specific classes 1.151 + // are still in effect. 1.152 + if (tp != NULL && tp->klass() != C->env()->Object_klass()) { 1.153 + // TypeFlow asserted a specific object type. Value must have that type. 1.154 + Node* bad_type_ctrl = NULL; 1.155 + l = gen_checkcast(l, makecon(TypeKlassPtr::make(tp->klass())), &bad_type_ctrl); 1.156 + bad_type_exit->control()->add_req(bad_type_ctrl); 1.157 + } 1.158 + 1.159 + BasicType bt_l = _gvn.type(l)->basic_type(); 1.160 + BasicType bt_t = type->basic_type(); 1.161 + assert(_gvn.type(l)->higher_equal(type), "must constrain OSR typestate"); 1.162 + return l; 1.163 +} 1.164 + 1.165 +// Helper routine which sets up elements of the initial parser map when 1.166 +// performing a parse for on stack replacement. Add values into map. 1.167 +// The only parameter contains the address of a interpreter arguments. 1.168 +void Parse::load_interpreter_state(Node* osr_buf) { 1.169 + int index; 1.170 + int max_locals = jvms()->loc_size(); 1.171 + int max_stack = jvms()->stk_size(); 1.172 + 1.173 + 1.174 + // Mismatch between method and jvms can occur since map briefly held 1.175 + // an OSR entry state (which takes up one RawPtr word). 1.176 + assert(max_locals == method()->max_locals(), "sanity"); 1.177 + assert(max_stack >= method()->max_stack(), "sanity"); 1.178 + assert((int)jvms()->endoff() == TypeFunc::Parms + max_locals + max_stack, "sanity"); 1.179 + assert((int)jvms()->endoff() == (int)map()->req(), "sanity"); 1.180 + 1.181 + // Find the start block. 1.182 + Block* osr_block = start_block(); 1.183 + assert(osr_block->start() == osr_bci(), "sanity"); 1.184 + 1.185 + // Set initial BCI. 1.186 + set_parse_bci(osr_block->start()); 1.187 + 1.188 + // Set initial stack depth. 1.189 + set_sp(osr_block->start_sp()); 1.190 + 1.191 + // Check bailouts. We currently do not perform on stack replacement 1.192 + // of loops in catch blocks or loops which branch with a non-empty stack. 1.193 + if (sp() != 0) { 1.194 + C->record_method_not_compilable("OSR starts with non-empty stack"); 1.195 + return; 1.196 + } 1.197 + // Do not OSR inside finally clauses: 1.198 + if (osr_block->has_trap_at(osr_block->start())) { 1.199 + C->record_method_not_compilable("OSR starts with an immediate trap"); 1.200 + return; 1.201 + } 1.202 + 1.203 + // Commute monitors from interpreter frame to compiler frame. 1.204 + assert(jvms()->monitor_depth() == 0, "should be no active locks at beginning of osr"); 1.205 + int mcnt = osr_block->flow()->monitor_count(); 1.206 + Node *monitors_addr = basic_plus_adr(osr_buf, osr_buf, (max_locals+mcnt*2-1)*wordSize); 1.207 + for (index = 0; index < mcnt; index++) { 1.208 + // Make a BoxLockNode for the monitor. 1.209 + Node *box = _gvn.transform(new (C, 1) BoxLockNode(next_monitor())); 1.210 + 1.211 + 1.212 + // Displaced headers and locked objects are interleaved in the 1.213 + // temp OSR buffer. We only copy the locked objects out here. 1.214 + // Fetch the locked object from the OSR temp buffer and copy to our fastlock node. 1.215 + Node *lock_object = fetch_interpreter_state(index*2, T_OBJECT, monitors_addr, osr_buf); 1.216 + // Try and copy the displaced header to the BoxNode 1.217 + Node *displaced_hdr = fetch_interpreter_state((index*2) + 1, T_ADDRESS, monitors_addr, osr_buf); 1.218 + 1.219 + 1.220 + store_to_memory(control(), box, displaced_hdr, T_ADDRESS, Compile::AliasIdxRaw); 1.221 + 1.222 + // Build a bogus FastLockNode (no code will be generated) and push the 1.223 + // monitor into our debug info. 1.224 + const FastLockNode *flock = _gvn.transform(new (C, 3) FastLockNode( 0, lock_object, box ))->as_FastLock(); 1.225 + map()->push_monitor(flock); 1.226 + 1.227 + // If the lock is our method synchronization lock, tuck it away in 1.228 + // _sync_lock for return and rethrow exit paths. 1.229 + if (index == 0 && method()->is_synchronized()) { 1.230 + _synch_lock = flock; 1.231 + } 1.232 + } 1.233 + 1.234 + MethodLivenessResult live_locals = method()->liveness_at_bci(osr_bci()); 1.235 + if (!live_locals.is_valid()) { 1.236 + // Degenerate or breakpointed method. 1.237 + C->record_method_not_compilable("OSR in empty or breakpointed method"); 1.238 + return; 1.239 + } 1.240 + 1.241 + // Extract the needed locals from the interpreter frame. 1.242 + Node *locals_addr = basic_plus_adr(osr_buf, osr_buf, (max_locals-1)*wordSize); 1.243 + 1.244 + // find all the locals that the interpreter thinks contain live oops 1.245 + const BitMap live_oops = method()->live_local_oops_at_bci(osr_bci()); 1.246 + for (index = 0; index < max_locals; index++) { 1.247 + 1.248 + if (!live_locals.at(index)) { 1.249 + continue; 1.250 + } 1.251 + 1.252 + const Type *type = osr_block->local_type_at(index); 1.253 + 1.254 + if (type->isa_oopptr() != NULL) { 1.255 + 1.256 + // 6403625: Verify that the interpreter oopMap thinks that the oop is live 1.257 + // else we might load a stale oop if the MethodLiveness disagrees with the 1.258 + // result of the interpreter. If the interpreter says it is dead we agree 1.259 + // by making the value go to top. 1.260 + // 1.261 + 1.262 + if (!live_oops.at(index)) { 1.263 + if (C->log() != NULL) { 1.264 + C->log()->elem("OSR_mismatch local_index='%d'",index); 1.265 + } 1.266 + set_local(index, null()); 1.267 + // and ignore it for the loads 1.268 + continue; 1.269 + } 1.270 + } 1.271 + 1.272 + // Filter out TOP, HALF, and BOTTOM. (Cf. ensure_phi.) 1.273 + if (type == Type::TOP || type == Type::HALF) { 1.274 + continue; 1.275 + } 1.276 + // If the type falls to bottom, then this must be a local that 1.277 + // is mixing ints and oops or some such. Forcing it to top 1.278 + // makes it go dead. 1.279 + if (type == Type::BOTTOM) { 1.280 + continue; 1.281 + } 1.282 + // Construct code to access the appropriate local. 1.283 + Node *value = fetch_interpreter_state(index, type->basic_type(), locals_addr, osr_buf); 1.284 + set_local(index, value); 1.285 + } 1.286 + 1.287 + // Extract the needed stack entries from the interpreter frame. 1.288 + for (index = 0; index < sp(); index++) { 1.289 + const Type *type = osr_block->stack_type_at(index); 1.290 + if (type != Type::TOP) { 1.291 + // Currently the compiler bails out when attempting to on stack replace 1.292 + // at a bci with a non-empty stack. We should not reach here. 1.293 + ShouldNotReachHere(); 1.294 + } 1.295 + } 1.296 + 1.297 + // End the OSR migration 1.298 + make_runtime_call(RC_LEAF, OptoRuntime::osr_end_Type(), 1.299 + CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_end), 1.300 + "OSR_migration_end", TypeRawPtr::BOTTOM, 1.301 + osr_buf); 1.302 + 1.303 + // Now that the interpreter state is loaded, make sure it will match 1.304 + // at execution time what the compiler is expecting now: 1.305 + SafePointNode* bad_type_exit = clone_map(); 1.306 + bad_type_exit->set_control(new (C, 1) RegionNode(1)); 1.307 + 1.308 + for (index = 0; index < max_locals; index++) { 1.309 + if (stopped()) break; 1.310 + Node* l = local(index); 1.311 + if (l->is_top()) continue; // nothing here 1.312 + const Type *type = osr_block->local_type_at(index); 1.313 + if (type->isa_oopptr() != NULL) { 1.314 + if (!live_oops.at(index)) { 1.315 + // skip type check for dead oops 1.316 + continue; 1.317 + } 1.318 + } 1.319 + set_local(index, check_interpreter_type(l, type, bad_type_exit)); 1.320 + } 1.321 + 1.322 + for (index = 0; index < sp(); index++) { 1.323 + if (stopped()) break; 1.324 + Node* l = stack(index); 1.325 + if (l->is_top()) continue; // nothing here 1.326 + const Type *type = osr_block->stack_type_at(index); 1.327 + set_stack(index, check_interpreter_type(l, type, bad_type_exit)); 1.328 + } 1.329 + 1.330 + if (bad_type_exit->control()->req() > 1) { 1.331 + // Build an uncommon trap here, if any inputs can be unexpected. 1.332 + bad_type_exit->set_control(_gvn.transform( bad_type_exit->control() )); 1.333 + record_for_igvn(bad_type_exit->control()); 1.334 + SafePointNode* types_are_good = map(); 1.335 + set_map(bad_type_exit); 1.336 + // The unexpected type happens because a new edge is active 1.337 + // in the CFG, which typeflow had previously ignored. 1.338 + // E.g., Object x = coldAtFirst() && notReached()? "str": new Integer(123). 1.339 + // This x will be typed as Integer if notReached is not yet linked. 1.340 + uncommon_trap(Deoptimization::Reason_unreached, 1.341 + Deoptimization::Action_reinterpret); 1.342 + set_map(types_are_good); 1.343 + } 1.344 +} 1.345 + 1.346 +//------------------------------Parse------------------------------------------ 1.347 +// Main parser constructor. 1.348 +Parse::Parse(JVMState* caller, ciMethod* parse_method, float expected_uses) 1.349 + : _exits(caller) 1.350 +{ 1.351 + // Init some variables 1.352 + _caller = caller; 1.353 + _method = parse_method; 1.354 + _expected_uses = expected_uses; 1.355 + _depth = 1 + (caller->has_method() ? caller->depth() : 0); 1.356 + _wrote_final = false; 1.357 + _entry_bci = InvocationEntryBci; 1.358 + _tf = NULL; 1.359 + _block = NULL; 1.360 + debug_only(_block_count = -1); 1.361 + debug_only(_blocks = (Block*)-1); 1.362 +#ifndef PRODUCT 1.363 + if (PrintCompilation || PrintOpto) { 1.364 + // Make sure I have an inline tree, so I can print messages about it. 1.365 + JVMState* ilt_caller = is_osr_parse() ? caller->caller() : caller; 1.366 + InlineTree::find_subtree_from_root(C->ilt(), ilt_caller, parse_method, true); 1.367 + } 1.368 + _max_switch_depth = 0; 1.369 + _est_switch_depth = 0; 1.370 +#endif 1.371 + 1.372 + _tf = TypeFunc::make(method()); 1.373 + _iter.reset_to_method(method()); 1.374 + _flow = method()->get_flow_analysis(); 1.375 + if (_flow->failing()) { 1.376 + C->record_method_not_compilable_all_tiers(_flow->failure_reason()); 1.377 + } 1.378 + 1.379 + if (_expected_uses <= 0) { 1.380 + _prof_factor = 1; 1.381 + } else { 1.382 + float prof_total = parse_method->interpreter_invocation_count(); 1.383 + if (prof_total <= _expected_uses) { 1.384 + _prof_factor = 1; 1.385 + } else { 1.386 + _prof_factor = _expected_uses / prof_total; 1.387 + } 1.388 + } 1.389 + 1.390 + CompileLog* log = C->log(); 1.391 + if (log != NULL) { 1.392 + log->begin_head("parse method='%d' uses='%g'", 1.393 + log->identify(parse_method), expected_uses); 1.394 + if (depth() == 1 && C->is_osr_compilation()) { 1.395 + log->print(" osr_bci='%d'", C->entry_bci()); 1.396 + } 1.397 + log->stamp(); 1.398 + log->end_head(); 1.399 + } 1.400 + 1.401 + // Accumulate deoptimization counts. 1.402 + // (The range_check and store_check counts are checked elsewhere.) 1.403 + ciMethodData* md = method()->method_data(); 1.404 + for (uint reason = 0; reason < md->trap_reason_limit(); reason++) { 1.405 + uint md_count = md->trap_count(reason); 1.406 + if (md_count != 0) { 1.407 + if (md_count == md->trap_count_limit()) 1.408 + md_count += md->overflow_trap_count(); 1.409 + uint total_count = C->trap_count(reason); 1.410 + uint old_count = total_count; 1.411 + total_count += md_count; 1.412 + // Saturate the add if it overflows. 1.413 + if (total_count < old_count || total_count < md_count) 1.414 + total_count = (uint)-1; 1.415 + C->set_trap_count(reason, total_count); 1.416 + if (log != NULL) 1.417 + log->elem("observe trap='%s' count='%d' total='%d'", 1.418 + Deoptimization::trap_reason_name(reason), 1.419 + md_count, total_count); 1.420 + } 1.421 + } 1.422 + // Accumulate total sum of decompilations, also. 1.423 + C->set_decompile_count(C->decompile_count() + md->decompile_count()); 1.424 + 1.425 + _count_invocations = C->do_count_invocations(); 1.426 + _method_data_update = C->do_method_data_update(); 1.427 + 1.428 + if (log != NULL && method()->has_exception_handlers()) { 1.429 + log->elem("observe that='has_exception_handlers'"); 1.430 + } 1.431 + 1.432 + assert(method()->can_be_compiled(), "Can not parse this method, cutout earlier"); 1.433 + assert(method()->has_balanced_monitors(), "Can not parse unbalanced monitors, cutout earlier"); 1.434 + 1.435 + // Always register dependence if JVMTI is enabled, because 1.436 + // either breakpoint setting or hotswapping of methods may 1.437 + // cause deoptimization. 1.438 + if (JvmtiExport::can_hotswap_or_post_breakpoint()) { 1.439 + C->dependencies()->assert_evol_method(method()); 1.440 + } 1.441 + 1.442 + methods_seen++; 1.443 + 1.444 + // Do some special top-level things. 1.445 + if (depth() == 1 && C->is_osr_compilation()) { 1.446 + _entry_bci = C->entry_bci(); 1.447 + _flow = method()->get_osr_flow_analysis(osr_bci()); 1.448 + if (_flow->failing()) { 1.449 + C->record_method_not_compilable(_flow->failure_reason()); 1.450 +#ifndef PRODUCT 1.451 + if (PrintOpto && (Verbose || WizardMode)) { 1.452 + tty->print_cr("OSR @%d type flow bailout: %s", _entry_bci, _flow->failure_reason()); 1.453 + if (Verbose) { 1.454 + method()->print_oop(); 1.455 + method()->print_codes(); 1.456 + _flow->print(); 1.457 + } 1.458 + } 1.459 +#endif 1.460 + } 1.461 + _tf = C->tf(); // the OSR entry type is different 1.462 + } 1.463 + 1.464 +#ifdef ASSERT 1.465 + if (depth() == 1) { 1.466 + assert(C->is_osr_compilation() == this->is_osr_parse(), "OSR in sync"); 1.467 + if (C->tf() != tf()) { 1.468 + MutexLockerEx ml(Compile_lock, Mutex::_no_safepoint_check_flag); 1.469 + assert(C->env()->system_dictionary_modification_counter_changed(), 1.470 + "Must invalidate if TypeFuncs differ"); 1.471 + } 1.472 + } else { 1.473 + assert(!this->is_osr_parse(), "no recursive OSR"); 1.474 + } 1.475 +#endif 1.476 + 1.477 + methods_parsed++; 1.478 +#ifndef PRODUCT 1.479 + // add method size here to guarantee that inlined methods are added too 1.480 + if (TimeCompiler) 1.481 + _total_bytes_compiled += method()->code_size(); 1.482 + 1.483 + show_parse_info(); 1.484 +#endif 1.485 + 1.486 + if (failing()) { 1.487 + if (log) log->done("parse"); 1.488 + return; 1.489 + } 1.490 + 1.491 + gvn().set_type(root(), root()->bottom_type()); 1.492 + gvn().transform(top()); 1.493 + 1.494 + // Import the results of the ciTypeFlow. 1.495 + init_blocks(); 1.496 + 1.497 + // Merge point for all normal exits 1.498 + build_exits(); 1.499 + 1.500 + // Setup the initial JVM state map. 1.501 + SafePointNode* entry_map = create_entry_map(); 1.502 + 1.503 + // Check for bailouts during map initialization 1.504 + if (failing() || entry_map == NULL) { 1.505 + if (log) log->done("parse"); 1.506 + return; 1.507 + } 1.508 + 1.509 + Node_Notes* caller_nn = C->default_node_notes(); 1.510 + // Collect debug info for inlined calls unless -XX:-DebugInlinedCalls. 1.511 + if (DebugInlinedCalls || depth() == 1) { 1.512 + C->set_default_node_notes(make_node_notes(caller_nn)); 1.513 + } 1.514 + 1.515 + if (is_osr_parse()) { 1.516 + Node* osr_buf = entry_map->in(TypeFunc::Parms+0); 1.517 + entry_map->set_req(TypeFunc::Parms+0, top()); 1.518 + set_map(entry_map); 1.519 + load_interpreter_state(osr_buf); 1.520 + } else { 1.521 + set_map(entry_map); 1.522 + do_method_entry(); 1.523 + } 1.524 + 1.525 + // Check for bailouts during method entry. 1.526 + if (failing()) { 1.527 + if (log) log->done("parse"); 1.528 + C->set_default_node_notes(caller_nn); 1.529 + return; 1.530 + } 1.531 + 1.532 + entry_map = map(); // capture any changes performed by method setup code 1.533 + assert(jvms()->endoff() == map()->req(), "map matches JVMS layout"); 1.534 + 1.535 + // We begin parsing as if we have just encountered a jump to the 1.536 + // method entry. 1.537 + Block* entry_block = start_block(); 1.538 + assert(entry_block->start() == (is_osr_parse() ? osr_bci() : 0), ""); 1.539 + set_map_clone(entry_map); 1.540 + merge_common(entry_block, entry_block->next_path_num()); 1.541 + 1.542 +#ifndef PRODUCT 1.543 + BytecodeParseHistogram *parse_histogram_obj = new (C->env()->arena()) BytecodeParseHistogram(this, C); 1.544 + set_parse_histogram( parse_histogram_obj ); 1.545 +#endif 1.546 + 1.547 + // Parse all the basic blocks. 1.548 + do_all_blocks(); 1.549 + 1.550 + C->set_default_node_notes(caller_nn); 1.551 + 1.552 + // Check for bailouts during conversion to graph 1.553 + if (failing()) { 1.554 + if (log) log->done("parse"); 1.555 + return; 1.556 + } 1.557 + 1.558 + // Fix up all exiting control flow. 1.559 + set_map(entry_map); 1.560 + do_exits(); 1.561 + 1.562 + // Collect a few more statistics. 1.563 + parse_idx += C->unique(); 1.564 + parse_arena += C->node_arena()->used(); 1.565 + 1.566 + if (log) log->done("parse nodes='%d' memory='%d'", 1.567 + C->unique(), C->node_arena()->used()); 1.568 +} 1.569 + 1.570 +//---------------------------do_all_blocks------------------------------------- 1.571 +void Parse::do_all_blocks() { 1.572 + _blocks_merged = 0; 1.573 + _blocks_parsed = 0; 1.574 + 1.575 + int old_blocks_merged = -1; 1.576 + int old_blocks_parsed = -1; 1.577 + 1.578 + for (int tries = 0; ; tries++) { 1.579 + visit_blocks(); 1.580 + if (failing()) return; // Check for bailout 1.581 + 1.582 + // No need for a work list. The outer loop is hardly ever repeated. 1.583 + // The following loop traverses the blocks in a reasonable pre-order, 1.584 + // as produced by the ciTypeFlow pass. 1.585 + 1.586 + // This loop can be taken more than once if there are two entries to 1.587 + // a loop (irreduceable CFG), and the edge which ciTypeFlow chose 1.588 + // as the first predecessor to the loop goes dead in the parser, 1.589 + // due to parse-time optimization. (Could happen with obfuscated code.) 1.590 + 1.591 + // Look for progress, or the lack of it: 1.592 + if (_blocks_parsed == block_count()) { 1.593 + // That's all, folks. 1.594 + if (TraceOptoParse) { 1.595 + tty->print_cr("All blocks parsed."); 1.596 + } 1.597 + break; 1.598 + } 1.599 + 1.600 + // How much work was done this time around? 1.601 + int new_blocks_merged = _blocks_merged - old_blocks_merged; 1.602 + int new_blocks_parsed = _blocks_parsed - old_blocks_parsed; 1.603 + if (new_blocks_merged == 0) { 1.604 + if (TraceOptoParse) { 1.605 + tty->print_cr("All live blocks parsed; %d dead blocks.", block_count() - _blocks_parsed); 1.606 + } 1.607 + // No new blocks have become parseable. Some blocks are just dead. 1.608 + break; 1.609 + } 1.610 + assert(new_blocks_parsed > 0, "must make progress"); 1.611 + assert(tries < block_count(), "the pre-order cannot be this bad!"); 1.612 + 1.613 + old_blocks_merged = _blocks_merged; 1.614 + old_blocks_parsed = _blocks_parsed; 1.615 + } 1.616 + 1.617 +#ifndef PRODUCT 1.618 + // Make sure there are no half-processed blocks remaining. 1.619 + // Every remaining unprocessed block is dead and may be ignored now. 1.620 + for (int po = 0; po < block_count(); po++) { 1.621 + Block* block = pre_order_at(po); 1.622 + if (!block->is_parsed()) { 1.623 + if (TraceOptoParse) { 1.624 + tty->print("Skipped dead block %d at bci:%d", po, block->start()); 1.625 + assert(!block->is_merged(), "no half-processed blocks"); 1.626 + } 1.627 + } 1.628 + } 1.629 +#endif 1.630 +} 1.631 + 1.632 +//---------------------------visit_blocks-------------------------------------- 1.633 +void Parse::visit_blocks() { 1.634 + // Walk over all blocks, parsing every one that has been reached (merged). 1.635 + for (int po = 0; po < block_count(); po++) { 1.636 + Block* block = pre_order_at(po); 1.637 + 1.638 + if (block->is_parsed()) { 1.639 + // Do not parse twice. 1.640 + continue; 1.641 + } 1.642 + 1.643 + if (!block->is_merged()) { 1.644 + // No state on this block. It had not yet been reached. 1.645 + // Delay reaching it until later. 1.646 + continue; 1.647 + } 1.648 + 1.649 + // Prepare to parse this block. 1.650 + load_state_from(block); 1.651 + 1.652 + if (stopped()) { 1.653 + // Block is dead. 1.654 + continue; 1.655 + } 1.656 + 1.657 + if (!block->is_ready() || block->is_handler()) { 1.658 + // Not all preds have been parsed. We must build phis everywhere. 1.659 + // (Note that dead locals do not get phis built, ever.) 1.660 + ensure_phis_everywhere(); 1.661 + 1.662 + // Leave behind an undisturbed copy of the map, for future merges. 1.663 + set_map(clone_map()); 1.664 + } 1.665 + 1.666 + // Ready or not, parse the block. 1.667 + do_one_block(); 1.668 + 1.669 + // Check for bailouts. 1.670 + if (failing()) return; 1.671 + } 1.672 +} 1.673 + 1.674 +//-------------------------------build_exits---------------------------------- 1.675 +// Build normal and exceptional exit merge points. 1.676 +void Parse::build_exits() { 1.677 + // make a clone of caller to prevent sharing of side-effects 1.678 + _exits.set_map(_exits.clone_map()); 1.679 + _exits.clean_stack(_exits.sp()); 1.680 + _exits.sync_jvms(); 1.681 + 1.682 + RegionNode* region = new (C, 1) RegionNode(1); 1.683 + record_for_igvn(region); 1.684 + gvn().set_type_bottom(region); 1.685 + _exits.set_control(region); 1.686 + 1.687 + // Note: iophi and memphi are not transformed until do_exits. 1.688 + Node* iophi = new (C, region->req()) PhiNode(region, Type::ABIO); 1.689 + Node* memphi = new (C, region->req()) PhiNode(region, Type::MEMORY, TypePtr::BOTTOM); 1.690 + _exits.set_i_o(iophi); 1.691 + _exits.set_all_memory(memphi); 1.692 + 1.693 + // Add a return value to the exit state. (Do not push it yet.) 1.694 + if (tf()->range()->cnt() > TypeFunc::Parms) { 1.695 + const Type* ret_type = tf()->range()->field_at(TypeFunc::Parms); 1.696 + // Don't "bind" an unloaded return klass to the ret_phi. If the klass 1.697 + // becomes loaded during the subsequent parsing, the loaded and unloaded 1.698 + // types will not join when we transform and push in do_exits(). 1.699 + const TypeOopPtr* ret_oop_type = ret_type->isa_oopptr(); 1.700 + if (ret_oop_type && !ret_oop_type->klass()->is_loaded()) { 1.701 + ret_type = TypeOopPtr::BOTTOM; 1.702 + } 1.703 + int ret_size = type2size[ret_type->basic_type()]; 1.704 + Node* ret_phi = new (C, region->req()) PhiNode(region, ret_type); 1.705 + _exits.ensure_stack(ret_size); 1.706 + assert((int)(tf()->range()->cnt() - TypeFunc::Parms) == ret_size, "good tf range"); 1.707 + assert(method()->return_type()->size() == ret_size, "tf agrees w/ method"); 1.708 + _exits.set_argument(0, ret_phi); // here is where the parser finds it 1.709 + // Note: ret_phi is not yet pushed, until do_exits. 1.710 + } 1.711 +} 1.712 + 1.713 + 1.714 +//----------------------------build_start_state------------------------------- 1.715 +// Construct a state which contains only the incoming arguments from an 1.716 +// unknown caller. The method & bci will be NULL & InvocationEntryBci. 1.717 +JVMState* Compile::build_start_state(StartNode* start, const TypeFunc* tf) { 1.718 + int arg_size = tf->domain()->cnt(); 1.719 + int max_size = MAX2(arg_size, (int)tf->range()->cnt()); 1.720 + JVMState* jvms = new (this) JVMState(max_size - TypeFunc::Parms); 1.721 + SafePointNode* map = new (this, max_size) SafePointNode(max_size, NULL); 1.722 + record_for_igvn(map); 1.723 + assert(arg_size == TypeFunc::Parms + (is_osr_compilation() ? 1 : method()->arg_size()), "correct arg_size"); 1.724 + Node_Notes* old_nn = default_node_notes(); 1.725 + if (old_nn != NULL && has_method()) { 1.726 + Node_Notes* entry_nn = old_nn->clone(this); 1.727 + JVMState* entry_jvms = new(this) JVMState(method(), old_nn->jvms()); 1.728 + entry_jvms->set_offsets(0); 1.729 + entry_jvms->set_bci(entry_bci()); 1.730 + entry_nn->set_jvms(entry_jvms); 1.731 + set_default_node_notes(entry_nn); 1.732 + } 1.733 + uint i; 1.734 + for (i = 0; i < (uint)arg_size; i++) { 1.735 + Node* parm = initial_gvn()->transform(new (this, 1) ParmNode(start, i)); 1.736 + map->init_req(i, parm); 1.737 + // Record all these guys for later GVN. 1.738 + record_for_igvn(parm); 1.739 + } 1.740 + for (; i < map->req(); i++) { 1.741 + map->init_req(i, top()); 1.742 + } 1.743 + assert(jvms->argoff() == TypeFunc::Parms, "parser gets arguments here"); 1.744 + set_default_node_notes(old_nn); 1.745 + map->set_jvms(jvms); 1.746 + jvms->set_map(map); 1.747 + return jvms; 1.748 +} 1.749 + 1.750 +//-----------------------------make_node_notes--------------------------------- 1.751 +Node_Notes* Parse::make_node_notes(Node_Notes* caller_nn) { 1.752 + if (caller_nn == NULL) return NULL; 1.753 + Node_Notes* nn = caller_nn->clone(C); 1.754 + JVMState* caller_jvms = nn->jvms(); 1.755 + JVMState* jvms = new (C) JVMState(method(), caller_jvms); 1.756 + jvms->set_offsets(0); 1.757 + jvms->set_bci(_entry_bci); 1.758 + nn->set_jvms(jvms); 1.759 + return nn; 1.760 +} 1.761 + 1.762 + 1.763 +//--------------------------return_values-------------------------------------- 1.764 +void Compile::return_values(JVMState* jvms) { 1.765 + GraphKit kit(jvms); 1.766 + Node* ret = new (this, TypeFunc::Parms) ReturnNode(TypeFunc::Parms, 1.767 + kit.control(), 1.768 + kit.i_o(), 1.769 + kit.reset_memory(), 1.770 + kit.frameptr(), 1.771 + kit.returnadr()); 1.772 + // Add zero or 1 return values 1.773 + int ret_size = tf()->range()->cnt() - TypeFunc::Parms; 1.774 + if (ret_size > 0) { 1.775 + kit.inc_sp(-ret_size); // pop the return value(s) 1.776 + kit.sync_jvms(); 1.777 + ret->add_req(kit.argument(0)); 1.778 + // Note: The second dummy edge is not needed by a ReturnNode. 1.779 + } 1.780 + // bind it to root 1.781 + root()->add_req(ret); 1.782 + record_for_igvn(ret); 1.783 + initial_gvn()->transform_no_reclaim(ret); 1.784 +} 1.785 + 1.786 +//------------------------rethrow_exceptions----------------------------------- 1.787 +// Bind all exception states in the list into a single RethrowNode. 1.788 +void Compile::rethrow_exceptions(JVMState* jvms) { 1.789 + GraphKit kit(jvms); 1.790 + if (!kit.has_exceptions()) return; // nothing to generate 1.791 + // Load my combined exception state into the kit, with all phis transformed: 1.792 + SafePointNode* ex_map = kit.combine_and_pop_all_exception_states(); 1.793 + Node* ex_oop = kit.use_exception_state(ex_map); 1.794 + RethrowNode* exit = new (this, TypeFunc::Parms + 1) RethrowNode(kit.control(), 1.795 + kit.i_o(), kit.reset_memory(), 1.796 + kit.frameptr(), kit.returnadr(), 1.797 + // like a return but with exception input 1.798 + ex_oop); 1.799 + // bind to root 1.800 + root()->add_req(exit); 1.801 + record_for_igvn(exit); 1.802 + initial_gvn()->transform_no_reclaim(exit); 1.803 +} 1.804 + 1.805 +bool Parse::can_rerun_bytecode() { 1.806 + switch (bc()) { 1.807 + case Bytecodes::_ldc: 1.808 + case Bytecodes::_ldc_w: 1.809 + case Bytecodes::_ldc2_w: 1.810 + case Bytecodes::_getfield: 1.811 + case Bytecodes::_putfield: 1.812 + case Bytecodes::_getstatic: 1.813 + case Bytecodes::_putstatic: 1.814 + case Bytecodes::_arraylength: 1.815 + case Bytecodes::_baload: 1.816 + case Bytecodes::_caload: 1.817 + case Bytecodes::_iaload: 1.818 + case Bytecodes::_saload: 1.819 + case Bytecodes::_faload: 1.820 + case Bytecodes::_aaload: 1.821 + case Bytecodes::_laload: 1.822 + case Bytecodes::_daload: 1.823 + case Bytecodes::_bastore: 1.824 + case Bytecodes::_castore: 1.825 + case Bytecodes::_iastore: 1.826 + case Bytecodes::_sastore: 1.827 + case Bytecodes::_fastore: 1.828 + case Bytecodes::_aastore: 1.829 + case Bytecodes::_lastore: 1.830 + case Bytecodes::_dastore: 1.831 + case Bytecodes::_irem: 1.832 + case Bytecodes::_idiv: 1.833 + case Bytecodes::_lrem: 1.834 + case Bytecodes::_ldiv: 1.835 + case Bytecodes::_frem: 1.836 + case Bytecodes::_fdiv: 1.837 + case Bytecodes::_drem: 1.838 + case Bytecodes::_ddiv: 1.839 + case Bytecodes::_checkcast: 1.840 + case Bytecodes::_instanceof: 1.841 + case Bytecodes::_athrow: 1.842 + case Bytecodes::_anewarray: 1.843 + case Bytecodes::_newarray: 1.844 + case Bytecodes::_multianewarray: 1.845 + case Bytecodes::_new: 1.846 + case Bytecodes::_monitorenter: // can re-run initial null check, only 1.847 + case Bytecodes::_return: 1.848 + return true; 1.849 + break; 1.850 + 1.851 + case Bytecodes::_invokestatic: 1.852 + case Bytecodes::_invokespecial: 1.853 + case Bytecodes::_invokevirtual: 1.854 + case Bytecodes::_invokeinterface: 1.855 + return false; 1.856 + break; 1.857 + 1.858 + default: 1.859 + assert(false, "unexpected bytecode produced an exception"); 1.860 + return true; 1.861 + } 1.862 +} 1.863 + 1.864 +//---------------------------do_exceptions------------------------------------- 1.865 +// Process exceptions arising from the current bytecode. 1.866 +// Send caught exceptions to the proper handler within this method. 1.867 +// Unhandled exceptions feed into _exit. 1.868 +void Parse::do_exceptions() { 1.869 + if (!has_exceptions()) return; 1.870 + 1.871 + if (failing()) { 1.872 + // Pop them all off and throw them away. 1.873 + while (pop_exception_state() != NULL) ; 1.874 + return; 1.875 + } 1.876 + 1.877 + // Make sure we can classify this bytecode if we need to. 1.878 + debug_only(can_rerun_bytecode()); 1.879 + 1.880 + PreserveJVMState pjvms(this, false); 1.881 + 1.882 + SafePointNode* ex_map; 1.883 + while ((ex_map = pop_exception_state()) != NULL) { 1.884 + if (!method()->has_exception_handlers()) { 1.885 + // Common case: Transfer control outward. 1.886 + // Doing it this early allows the exceptions to common up 1.887 + // even between adjacent method calls. 1.888 + throw_to_exit(ex_map); 1.889 + } else { 1.890 + // Have to look at the exception first. 1.891 + assert(stopped(), "catch_inline_exceptions trashes the map"); 1.892 + catch_inline_exceptions(ex_map); 1.893 + stop_and_kill_map(); // we used up this exception state; kill it 1.894 + } 1.895 + } 1.896 + 1.897 + // We now return to our regularly scheduled program: 1.898 +} 1.899 + 1.900 +//---------------------------throw_to_exit------------------------------------- 1.901 +// Merge the given map into an exception exit from this method. 1.902 +// The exception exit will handle any unlocking of receiver. 1.903 +// The ex_oop must be saved within the ex_map, unlike merge_exception. 1.904 +void Parse::throw_to_exit(SafePointNode* ex_map) { 1.905 + // Pop the JVMS to (a copy of) the caller. 1.906 + GraphKit caller; 1.907 + caller.set_map_clone(_caller->map()); 1.908 + caller.set_bci(_caller->bci()); 1.909 + caller.set_sp(_caller->sp()); 1.910 + // Copy out the standard machine state: 1.911 + for (uint i = 0; i < TypeFunc::Parms; i++) { 1.912 + caller.map()->set_req(i, ex_map->in(i)); 1.913 + } 1.914 + // ...and the exception: 1.915 + Node* ex_oop = saved_ex_oop(ex_map); 1.916 + SafePointNode* caller_ex_map = caller.make_exception_state(ex_oop); 1.917 + // Finally, collect the new exception state in my exits: 1.918 + _exits.add_exception_state(caller_ex_map); 1.919 +} 1.920 + 1.921 +//------------------------------do_exits--------------------------------------- 1.922 +void Parse::do_exits() { 1.923 + set_parse_bci(InvocationEntryBci); 1.924 + 1.925 + // Now peephole on the return bits 1.926 + Node* region = _exits.control(); 1.927 + _exits.set_control(gvn().transform(region)); 1.928 + 1.929 + Node* iophi = _exits.i_o(); 1.930 + _exits.set_i_o(gvn().transform(iophi)); 1.931 + 1.932 + if (wrote_final()) { 1.933 + // This method (which must be a constructor by the rules of Java) 1.934 + // wrote a final. The effects of all initializations must be 1.935 + // committed to memory before any code after the constructor 1.936 + // publishes the reference to the newly constructor object. 1.937 + // Rather than wait for the publication, we simply block the 1.938 + // writes here. Rather than put a barrier on only those writes 1.939 + // which are required to complete, we force all writes to complete. 1.940 + // 1.941 + // "All bets are off" unless the first publication occurs after a 1.942 + // normal return from the constructor. We do not attempt to detect 1.943 + // such unusual early publications. But no barrier is needed on 1.944 + // exceptional returns, since they cannot publish normally. 1.945 + // 1.946 + _exits.insert_mem_bar(Op_MemBarRelease); 1.947 +#ifndef PRODUCT 1.948 + if (PrintOpto && (Verbose || WizardMode)) { 1.949 + method()->print_name(); 1.950 + tty->print_cr(" writes finals and needs a memory barrier"); 1.951 + } 1.952 +#endif 1.953 + } 1.954 + 1.955 + for (MergeMemStream mms(_exits.merged_memory()); mms.next_non_empty(); ) { 1.956 + // transform each slice of the original memphi: 1.957 + mms.set_memory(_gvn.transform(mms.memory())); 1.958 + } 1.959 + 1.960 + if (tf()->range()->cnt() > TypeFunc::Parms) { 1.961 + const Type* ret_type = tf()->range()->field_at(TypeFunc::Parms); 1.962 + Node* ret_phi = _gvn.transform( _exits.argument(0) ); 1.963 + assert(_exits.control()->is_top() || !_gvn.type(ret_phi)->empty(), "return value must be well defined"); 1.964 + _exits.push_node(ret_type->basic_type(), ret_phi); 1.965 + } 1.966 + 1.967 + // Note: Logic for creating and optimizing the ReturnNode is in Compile. 1.968 + 1.969 + // Unlock along the exceptional paths. 1.970 + // This is done late so that we can common up equivalent exceptions 1.971 + // (e.g., null checks) arising from multiple points within this method. 1.972 + // See GraphKit::add_exception_state, which performs the commoning. 1.973 + bool do_synch = method()->is_synchronized() && GenerateSynchronizationCode; 1.974 + 1.975 + // record exit from a method if compiled while Dtrace is turned on. 1.976 + if (do_synch || DTraceMethodProbes) { 1.977 + // First move the exception list out of _exits: 1.978 + GraphKit kit(_exits.transfer_exceptions_into_jvms()); 1.979 + SafePointNode* normal_map = kit.map(); // keep this guy safe 1.980 + // Now re-collect the exceptions into _exits: 1.981 + SafePointNode* ex_map; 1.982 + while ((ex_map = kit.pop_exception_state()) != NULL) { 1.983 + Node* ex_oop = kit.use_exception_state(ex_map); 1.984 + // Force the exiting JVM state to have this method at InvocationEntryBci. 1.985 + // The exiting JVM state is otherwise a copy of the calling JVMS. 1.986 + JVMState* caller = kit.jvms(); 1.987 + JVMState* ex_jvms = caller->clone_shallow(C); 1.988 + ex_jvms->set_map(kit.clone_map()); 1.989 + ex_jvms->map()->set_jvms(ex_jvms); 1.990 + ex_jvms->set_bci( InvocationEntryBci); 1.991 + kit.set_jvms(ex_jvms); 1.992 + if (do_synch) { 1.993 + // Add on the synchronized-method box/object combo 1.994 + kit.map()->push_monitor(_synch_lock); 1.995 + // Unlock! 1.996 + kit.shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node()); 1.997 + } 1.998 + if (DTraceMethodProbes) { 1.999 + kit.make_dtrace_method_exit(method()); 1.1000 + } 1.1001 + // Done with exception-path processing. 1.1002 + ex_map = kit.make_exception_state(ex_oop); 1.1003 + assert(ex_jvms->same_calls_as(ex_map->jvms()), "sanity"); 1.1004 + // Pop the last vestige of this method: 1.1005 + ex_map->set_jvms(caller->clone_shallow(C)); 1.1006 + ex_map->jvms()->set_map(ex_map); 1.1007 + _exits.push_exception_state(ex_map); 1.1008 + } 1.1009 + assert(_exits.map() == normal_map, "keep the same return state"); 1.1010 + } 1.1011 + 1.1012 + { 1.1013 + // Capture very early exceptions (receiver null checks) from caller JVMS 1.1014 + GraphKit caller(_caller); 1.1015 + SafePointNode* ex_map; 1.1016 + while ((ex_map = caller.pop_exception_state()) != NULL) { 1.1017 + _exits.add_exception_state(ex_map); 1.1018 + } 1.1019 + } 1.1020 +} 1.1021 + 1.1022 +//-----------------------------create_entry_map------------------------------- 1.1023 +// Initialize our parser map to contain the types at method entry. 1.1024 +// For OSR, the map contains a single RawPtr parameter. 1.1025 +// Initial monitor locking for sync. methods is performed by do_method_entry. 1.1026 +SafePointNode* Parse::create_entry_map() { 1.1027 + // Check for really stupid bail-out cases. 1.1028 + uint len = TypeFunc::Parms + method()->max_locals() + method()->max_stack(); 1.1029 + if (len >= 32760) { 1.1030 + C->record_method_not_compilable_all_tiers("too many local variables"); 1.1031 + return NULL; 1.1032 + } 1.1033 + 1.1034 + // If this is an inlined method, we may have to do a receiver null check. 1.1035 + if (_caller->has_method() && is_normal_parse() && !method()->is_static()) { 1.1036 + GraphKit kit(_caller); 1.1037 + kit.null_check_receiver(method()); 1.1038 + _caller = kit.transfer_exceptions_into_jvms(); 1.1039 + if (kit.stopped()) { 1.1040 + _exits.add_exception_states_from(_caller); 1.1041 + _exits.set_jvms(_caller); 1.1042 + return NULL; 1.1043 + } 1.1044 + } 1.1045 + 1.1046 + assert(method() != NULL, "parser must have a method"); 1.1047 + 1.1048 + // Create an initial safepoint to hold JVM state during parsing 1.1049 + JVMState* jvms = new (C) JVMState(method(), _caller->has_method() ? _caller : NULL); 1.1050 + set_map(new (C, len) SafePointNode(len, jvms)); 1.1051 + jvms->set_map(map()); 1.1052 + record_for_igvn(map()); 1.1053 + assert(jvms->endoff() == len, "correct jvms sizing"); 1.1054 + 1.1055 + SafePointNode* inmap = _caller->map(); 1.1056 + assert(inmap != NULL, "must have inmap"); 1.1057 + 1.1058 + uint i; 1.1059 + 1.1060 + // Pass thru the predefined input parameters. 1.1061 + for (i = 0; i < TypeFunc::Parms; i++) { 1.1062 + map()->init_req(i, inmap->in(i)); 1.1063 + } 1.1064 + 1.1065 + if (depth() == 1) { 1.1066 + assert(map()->memory()->Opcode() == Op_Parm, ""); 1.1067 + // Insert the memory aliasing node 1.1068 + set_all_memory(reset_memory()); 1.1069 + } 1.1070 + assert(merged_memory(), ""); 1.1071 + 1.1072 + // Now add the locals which are initially bound to arguments: 1.1073 + uint arg_size = tf()->domain()->cnt(); 1.1074 + ensure_stack(arg_size - TypeFunc::Parms); // OSR methods have funny args 1.1075 + for (i = TypeFunc::Parms; i < arg_size; i++) { 1.1076 + map()->init_req(i, inmap->argument(_caller, i - TypeFunc::Parms)); 1.1077 + } 1.1078 + 1.1079 + // Clear out the rest of the map (locals and stack) 1.1080 + for (i = arg_size; i < len; i++) { 1.1081 + map()->init_req(i, top()); 1.1082 + } 1.1083 + 1.1084 + SafePointNode* entry_map = stop(); 1.1085 + return entry_map; 1.1086 +} 1.1087 + 1.1088 +//-----------------------------do_method_entry-------------------------------- 1.1089 +// Emit any code needed in the pseudo-block before BCI zero. 1.1090 +// The main thing to do is lock the receiver of a synchronized method. 1.1091 +void Parse::do_method_entry() { 1.1092 + set_parse_bci(InvocationEntryBci); // Pseudo-BCP 1.1093 + set_sp(0); // Java Stack Pointer 1.1094 + 1.1095 + NOT_PRODUCT( count_compiled_calls(true/*at_method_entry*/, false/*is_inline*/); ) 1.1096 + 1.1097 + if (DTraceMethodProbes) { 1.1098 + make_dtrace_method_entry(method()); 1.1099 + } 1.1100 + 1.1101 + // If the method is synchronized, we need to construct a lock node, attach 1.1102 + // it to the Start node, and pin it there. 1.1103 + if (method()->is_synchronized()) { 1.1104 + // Insert a FastLockNode right after the Start which takes as arguments 1.1105 + // the current thread pointer, the "this" pointer & the address of the 1.1106 + // stack slot pair used for the lock. The "this" pointer is a projection 1.1107 + // off the start node, but the locking spot has to be constructed by 1.1108 + // creating a ConLNode of 0, and boxing it with a BoxLockNode. The BoxLockNode 1.1109 + // becomes the second argument to the FastLockNode call. The 1.1110 + // FastLockNode becomes the new control parent to pin it to the start. 1.1111 + 1.1112 + // Setup Object Pointer 1.1113 + Node *lock_obj = NULL; 1.1114 + if(method()->is_static()) { 1.1115 + ciInstance* mirror = _method->holder()->java_mirror(); 1.1116 + const TypeInstPtr *t_lock = TypeInstPtr::make(mirror); 1.1117 + lock_obj = makecon(t_lock); 1.1118 + } else { // Else pass the "this" pointer, 1.1119 + lock_obj = local(0); // which is Parm0 from StartNode 1.1120 + } 1.1121 + // Clear out dead values from the debug info. 1.1122 + kill_dead_locals(); 1.1123 + // Build the FastLockNode 1.1124 + _synch_lock = shared_lock(lock_obj); 1.1125 + } 1.1126 + 1.1127 + if (depth() == 1) { 1.1128 + increment_and_test_invocation_counter(Tier2CompileThreshold); 1.1129 + } 1.1130 +} 1.1131 + 1.1132 +//------------------------------init_blocks------------------------------------ 1.1133 +// Initialize our parser map to contain the types/monitors at method entry. 1.1134 +void Parse::init_blocks() { 1.1135 + // Create the blocks. 1.1136 + _block_count = flow()->block_count(); 1.1137 + _blocks = NEW_RESOURCE_ARRAY(Block, _block_count); 1.1138 + Copy::zero_to_bytes(_blocks, sizeof(Block)*_block_count); 1.1139 + 1.1140 + int po; 1.1141 + 1.1142 + // Initialize the structs. 1.1143 + for (po = 0; po < block_count(); po++) { 1.1144 + Block* block = pre_order_at(po); 1.1145 + block->init_node(this, po); 1.1146 + } 1.1147 + 1.1148 + // Collect predecessor and successor information. 1.1149 + for (po = 0; po < block_count(); po++) { 1.1150 + Block* block = pre_order_at(po); 1.1151 + block->init_graph(this); 1.1152 + } 1.1153 +} 1.1154 + 1.1155 +//-------------------------------init_node------------------------------------- 1.1156 +void Parse::Block::init_node(Parse* outer, int po) { 1.1157 + _flow = outer->flow()->pre_order_at(po); 1.1158 + _pred_count = 0; 1.1159 + _preds_parsed = 0; 1.1160 + _count = 0; 1.1161 + assert(pred_count() == 0 && preds_parsed() == 0, "sanity"); 1.1162 + assert(!(is_merged() || is_parsed() || is_handler()), "sanity"); 1.1163 + assert(_live_locals.size() == 0, "sanity"); 1.1164 + 1.1165 + // entry point has additional predecessor 1.1166 + if (flow()->is_start()) _pred_count++; 1.1167 + assert(flow()->is_start() == (this == outer->start_block()), ""); 1.1168 +} 1.1169 + 1.1170 +//-------------------------------init_graph------------------------------------ 1.1171 +void Parse::Block::init_graph(Parse* outer) { 1.1172 + // Create the successor list for this parser block. 1.1173 + GrowableArray<ciTypeFlow::Block*>* tfs = flow()->successors(); 1.1174 + GrowableArray<ciTypeFlow::Block*>* tfe = flow()->exceptions(); 1.1175 + int ns = tfs->length(); 1.1176 + int ne = tfe->length(); 1.1177 + _num_successors = ns; 1.1178 + _all_successors = ns+ne; 1.1179 + _successors = (ns+ne == 0) ? NULL : NEW_RESOURCE_ARRAY(Block*, ns+ne); 1.1180 + int p = 0; 1.1181 + for (int i = 0; i < ns+ne; i++) { 1.1182 + ciTypeFlow::Block* tf2 = (i < ns) ? tfs->at(i) : tfe->at(i-ns); 1.1183 + Block* block2 = outer->pre_order_at(tf2->pre_order()); 1.1184 + _successors[i] = block2; 1.1185 + 1.1186 + // Accumulate pred info for the other block, too. 1.1187 + if (i < ns) { 1.1188 + block2->_pred_count++; 1.1189 + } else { 1.1190 + block2->_is_handler = true; 1.1191 + } 1.1192 + 1.1193 + #ifdef ASSERT 1.1194 + // A block's successors must be distinguishable by BCI. 1.1195 + // That is, no bytecode is allowed to branch to two different 1.1196 + // clones of the same code location. 1.1197 + for (int j = 0; j < i; j++) { 1.1198 + Block* block1 = _successors[j]; 1.1199 + if (block1 == block2) continue; // duplicates are OK 1.1200 + assert(block1->start() != block2->start(), "successors have unique bcis"); 1.1201 + } 1.1202 + #endif 1.1203 + } 1.1204 + 1.1205 + // Note: We never call next_path_num along exception paths, so they 1.1206 + // never get processed as "ready". Also, the input phis of exception 1.1207 + // handlers get specially processed, so that 1.1208 +} 1.1209 + 1.1210 +//---------------------------successor_for_bci--------------------------------- 1.1211 +Parse::Block* Parse::Block::successor_for_bci(int bci) { 1.1212 + for (int i = 0; i < all_successors(); i++) { 1.1213 + Block* block2 = successor_at(i); 1.1214 + if (block2->start() == bci) return block2; 1.1215 + } 1.1216 + // We can actually reach here if ciTypeFlow traps out a block 1.1217 + // due to an unloaded class, and concurrently with compilation the 1.1218 + // class is then loaded, so that a later phase of the parser is 1.1219 + // able to see more of the bytecode CFG. Or, the flow pass and 1.1220 + // the parser can have a minor difference of opinion about executability 1.1221 + // of bytecodes. For example, "obj.field = null" is executable even 1.1222 + // if the field's type is an unloaded class; the flow pass used to 1.1223 + // make a trap for such code. 1.1224 + return NULL; 1.1225 +} 1.1226 + 1.1227 + 1.1228 +//-----------------------------stack_type_at----------------------------------- 1.1229 +const Type* Parse::Block::stack_type_at(int i) const { 1.1230 + return get_type(flow()->stack_type_at(i)); 1.1231 +} 1.1232 + 1.1233 + 1.1234 +//-----------------------------local_type_at----------------------------------- 1.1235 +const Type* Parse::Block::local_type_at(int i) const { 1.1236 + // Make dead locals fall to bottom. 1.1237 + if (_live_locals.size() == 0) { 1.1238 + MethodLivenessResult live_locals = flow()->outer()->method()->liveness_at_bci(start()); 1.1239 + // This bitmap can be zero length if we saw a breakpoint. 1.1240 + // In such cases, pretend they are all live. 1.1241 + ((Block*)this)->_live_locals = live_locals; 1.1242 + } 1.1243 + if (_live_locals.size() > 0 && !_live_locals.at(i)) 1.1244 + return Type::BOTTOM; 1.1245 + 1.1246 + return get_type(flow()->local_type_at(i)); 1.1247 +} 1.1248 + 1.1249 + 1.1250 +#ifndef PRODUCT 1.1251 + 1.1252 +//----------------------------name_for_bc-------------------------------------- 1.1253 +// helper method for BytecodeParseHistogram 1.1254 +static const char* name_for_bc(int i) { 1.1255 + return Bytecodes::is_defined(i) ? Bytecodes::name(Bytecodes::cast(i)) : "xxxunusedxxx"; 1.1256 +} 1.1257 + 1.1258 +//----------------------------BytecodeParseHistogram------------------------------------ 1.1259 +Parse::BytecodeParseHistogram::BytecodeParseHistogram(Parse *p, Compile *c) { 1.1260 + _parser = p; 1.1261 + _compiler = c; 1.1262 + if( ! _initialized ) { _initialized = true; reset(); } 1.1263 +} 1.1264 + 1.1265 +//----------------------------current_count------------------------------------ 1.1266 +int Parse::BytecodeParseHistogram::current_count(BPHType bph_type) { 1.1267 + switch( bph_type ) { 1.1268 + case BPH_transforms: { return _parser->gvn().made_progress(); } 1.1269 + case BPH_values: { return _parser->gvn().made_new_values(); } 1.1270 + default: { ShouldNotReachHere(); return 0; } 1.1271 + } 1.1272 +} 1.1273 + 1.1274 +//----------------------------initialized-------------------------------------- 1.1275 +bool Parse::BytecodeParseHistogram::initialized() { return _initialized; } 1.1276 + 1.1277 +//----------------------------reset-------------------------------------------- 1.1278 +void Parse::BytecodeParseHistogram::reset() { 1.1279 + int i = Bytecodes::number_of_codes; 1.1280 + while (i-- > 0) { _bytecodes_parsed[i] = 0; _nodes_constructed[i] = 0; _nodes_transformed[i] = 0; _new_values[i] = 0; } 1.1281 +} 1.1282 + 1.1283 +//----------------------------set_initial_state-------------------------------- 1.1284 +// Record info when starting to parse one bytecode 1.1285 +void Parse::BytecodeParseHistogram::set_initial_state( Bytecodes::Code bc ) { 1.1286 + if( PrintParseStatistics && !_parser->is_osr_parse() ) { 1.1287 + _initial_bytecode = bc; 1.1288 + _initial_node_count = _compiler->unique(); 1.1289 + _initial_transforms = current_count(BPH_transforms); 1.1290 + _initial_values = current_count(BPH_values); 1.1291 + } 1.1292 +} 1.1293 + 1.1294 +//----------------------------record_change-------------------------------- 1.1295 +// Record results of parsing one bytecode 1.1296 +void Parse::BytecodeParseHistogram::record_change() { 1.1297 + if( PrintParseStatistics && !_parser->is_osr_parse() ) { 1.1298 + ++_bytecodes_parsed[_initial_bytecode]; 1.1299 + _nodes_constructed [_initial_bytecode] += (_compiler->unique() - _initial_node_count); 1.1300 + _nodes_transformed [_initial_bytecode] += (current_count(BPH_transforms) - _initial_transforms); 1.1301 + _new_values [_initial_bytecode] += (current_count(BPH_values) - _initial_values); 1.1302 + } 1.1303 +} 1.1304 + 1.1305 + 1.1306 +//----------------------------print-------------------------------------------- 1.1307 +void Parse::BytecodeParseHistogram::print(float cutoff) { 1.1308 + ResourceMark rm; 1.1309 + // print profile 1.1310 + int total = 0; 1.1311 + int i = 0; 1.1312 + for( i = 0; i < Bytecodes::number_of_codes; ++i ) { total += _bytecodes_parsed[i]; } 1.1313 + int abs_sum = 0; 1.1314 + tty->cr(); //0123456789012345678901234567890123456789012345678901234567890123456789 1.1315 + tty->print_cr("Histogram of %d parsed bytecodes:", total); 1.1316 + if( total == 0 ) { return; } 1.1317 + tty->cr(); 1.1318 + tty->print_cr("absolute: count of compiled bytecodes of this type"); 1.1319 + tty->print_cr("relative: percentage contribution to compiled nodes"); 1.1320 + tty->print_cr("nodes : Average number of nodes constructed per bytecode"); 1.1321 + tty->print_cr("rnodes : Significance towards total nodes constructed, (nodes*relative)"); 1.1322 + tty->print_cr("transforms: Average amount of tranform progress per bytecode compiled"); 1.1323 + tty->print_cr("values : Average number of node values improved per bytecode"); 1.1324 + tty->print_cr("name : Bytecode name"); 1.1325 + tty->cr(); 1.1326 + tty->print_cr(" absolute relative nodes rnodes transforms values name"); 1.1327 + tty->print_cr("----------------------------------------------------------------------"); 1.1328 + while (--i > 0) { 1.1329 + int abs = _bytecodes_parsed[i]; 1.1330 + float rel = abs * 100.0F / total; 1.1331 + float nodes = _bytecodes_parsed[i] == 0 ? 0 : (1.0F * _nodes_constructed[i])/_bytecodes_parsed[i]; 1.1332 + float rnodes = _bytecodes_parsed[i] == 0 ? 0 : rel * nodes; 1.1333 + float xforms = _bytecodes_parsed[i] == 0 ? 0 : (1.0F * _nodes_transformed[i])/_bytecodes_parsed[i]; 1.1334 + float values = _bytecodes_parsed[i] == 0 ? 0 : (1.0F * _new_values [i])/_bytecodes_parsed[i]; 1.1335 + if (cutoff <= rel) { 1.1336 + tty->print_cr("%10d %7.2f%% %6.1f %6.2f %6.1f %6.1f %s", abs, rel, nodes, rnodes, xforms, values, name_for_bc(i)); 1.1337 + abs_sum += abs; 1.1338 + } 1.1339 + } 1.1340 + tty->print_cr("----------------------------------------------------------------------"); 1.1341 + float rel_sum = abs_sum * 100.0F / total; 1.1342 + tty->print_cr("%10d %7.2f%% (cutoff = %.2f%%)", abs_sum, rel_sum, cutoff); 1.1343 + tty->print_cr("----------------------------------------------------------------------"); 1.1344 + tty->cr(); 1.1345 +} 1.1346 +#endif 1.1347 + 1.1348 +//----------------------------load_state_from---------------------------------- 1.1349 +// Load block/map/sp. But not do not touch iter/bci. 1.1350 +void Parse::load_state_from(Block* block) { 1.1351 + set_block(block); 1.1352 + // load the block's JVM state: 1.1353 + set_map(block->start_map()); 1.1354 + set_sp( block->start_sp()); 1.1355 +} 1.1356 + 1.1357 + 1.1358 +//-----------------------------record_state------------------------------------ 1.1359 +void Parse::Block::record_state(Parse* p) { 1.1360 + assert(!is_merged(), "can only record state once, on 1st inflow"); 1.1361 + assert(start_sp() == p->sp(), "stack pointer must agree with ciTypeFlow"); 1.1362 + set_start_map(p->stop()); 1.1363 +} 1.1364 + 1.1365 + 1.1366 +//------------------------------do_one_block----------------------------------- 1.1367 +void Parse::do_one_block() { 1.1368 + if (TraceOptoParse) { 1.1369 + Block *b = block(); 1.1370 + int ns = b->num_successors(); 1.1371 + int nt = b->all_successors(); 1.1372 + 1.1373 + tty->print("Parsing block #%d at bci [%d,%d), successors: ", 1.1374 + block()->pre_order(), block()->start(), block()->limit()); 1.1375 + for (int i = 0; i < nt; i++) { 1.1376 + tty->print((( i < ns) ? " %d" : " %d(e)"), b->successor_at(i)->pre_order()); 1.1377 + } 1.1378 + tty->print_cr(""); 1.1379 + } 1.1380 + 1.1381 + assert(block()->is_merged(), "must be merged before being parsed"); 1.1382 + block()->mark_parsed(); 1.1383 + ++_blocks_parsed; 1.1384 + 1.1385 + // Set iterator to start of block. 1.1386 + iter().reset_to_bci(block()->start()); 1.1387 + 1.1388 + CompileLog* log = C->log(); 1.1389 + 1.1390 + // Parse bytecodes 1.1391 + while (!stopped() && !failing()) { 1.1392 + iter().next(); 1.1393 + 1.1394 + // Learn the current bci from the iterator: 1.1395 + set_parse_bci(iter().cur_bci()); 1.1396 + 1.1397 + if (bci() == block()->limit()) { 1.1398 + // Do not walk into the next block until directed by do_all_blocks. 1.1399 + merge(bci()); 1.1400 + break; 1.1401 + } 1.1402 + assert(bci() < block()->limit(), "bci still in block"); 1.1403 + 1.1404 + if (log != NULL) { 1.1405 + // Output an optional context marker, to help place actions 1.1406 + // that occur during parsing of this BC. If there is no log 1.1407 + // output until the next context string, this context string 1.1408 + // will be silently ignored. 1.1409 + log->context()->reset(); 1.1410 + log->context()->print_cr("<bc code='%d' bci='%d'/>", (int)bc(), bci()); 1.1411 + } 1.1412 + 1.1413 + if (block()->has_trap_at(bci())) { 1.1414 + // We must respect the flow pass's traps, because it will refuse 1.1415 + // to produce successors for trapping blocks. 1.1416 + int trap_index = block()->flow()->trap_index(); 1.1417 + assert(trap_index != 0, "trap index must be valid"); 1.1418 + uncommon_trap(trap_index); 1.1419 + break; 1.1420 + } 1.1421 + 1.1422 + NOT_PRODUCT( parse_histogram()->set_initial_state(bc()); ); 1.1423 + 1.1424 +#ifdef ASSERT 1.1425 + int pre_bc_sp = sp(); 1.1426 + int inputs, depth; 1.1427 + bool have_se = !stopped() && compute_stack_effects(inputs, depth); 1.1428 + assert(!have_se || pre_bc_sp >= inputs, "have enough stack to execute this BC"); 1.1429 +#endif //ASSERT 1.1430 + 1.1431 + do_one_bytecode(); 1.1432 + 1.1433 + assert(!have_se || stopped() || failing() || (sp() - pre_bc_sp) == depth, "correct depth prediction"); 1.1434 + 1.1435 + do_exceptions(); 1.1436 + 1.1437 + NOT_PRODUCT( parse_histogram()->record_change(); ); 1.1438 + 1.1439 + if (log != NULL) log->context()->reset(); // done w/ this one 1.1440 + 1.1441 + // Fall into next bytecode. Each bytecode normally has 1 sequential 1.1442 + // successor which is typically made ready by visiting this bytecode. 1.1443 + // If the successor has several predecessors, then it is a merge 1.1444 + // point, starts a new basic block, and is handled like other basic blocks. 1.1445 + } 1.1446 +} 1.1447 + 1.1448 + 1.1449 +//------------------------------merge------------------------------------------ 1.1450 +void Parse::set_parse_bci(int bci) { 1.1451 + set_bci(bci); 1.1452 + Node_Notes* nn = C->default_node_notes(); 1.1453 + if (nn == NULL) return; 1.1454 + 1.1455 + // Collect debug info for inlined calls unless -XX:-DebugInlinedCalls. 1.1456 + if (!DebugInlinedCalls && depth() > 1) { 1.1457 + return; 1.1458 + } 1.1459 + 1.1460 + // Update the JVMS annotation, if present. 1.1461 + JVMState* jvms = nn->jvms(); 1.1462 + if (jvms != NULL && jvms->bci() != bci) { 1.1463 + // Update the JVMS. 1.1464 + jvms = jvms->clone_shallow(C); 1.1465 + jvms->set_bci(bci); 1.1466 + nn->set_jvms(jvms); 1.1467 + } 1.1468 +} 1.1469 + 1.1470 +//------------------------------merge------------------------------------------ 1.1471 +// Merge the current mapping into the basic block starting at bci 1.1472 +void Parse::merge(int target_bci) { 1.1473 + Block* target = successor_for_bci(target_bci); 1.1474 + if (target == NULL) { handle_missing_successor(target_bci); return; } 1.1475 + assert(!target->is_ready(), "our arrival must be expected"); 1.1476 + int pnum = target->next_path_num(); 1.1477 + merge_common(target, pnum); 1.1478 +} 1.1479 + 1.1480 +//-------------------------merge_new_path-------------------------------------- 1.1481 +// Merge the current mapping into the basic block, using a new path 1.1482 +void Parse::merge_new_path(int target_bci) { 1.1483 + Block* target = successor_for_bci(target_bci); 1.1484 + if (target == NULL) { handle_missing_successor(target_bci); return; } 1.1485 + assert(!target->is_ready(), "new path into frozen graph"); 1.1486 + int pnum = target->add_new_path(); 1.1487 + merge_common(target, pnum); 1.1488 +} 1.1489 + 1.1490 +//-------------------------merge_exception------------------------------------- 1.1491 +// Merge the current mapping into the basic block starting at bci 1.1492 +// The ex_oop must be pushed on the stack, unlike throw_to_exit. 1.1493 +void Parse::merge_exception(int target_bci) { 1.1494 + assert(sp() == 1, "must have only the throw exception on the stack"); 1.1495 + Block* target = successor_for_bci(target_bci); 1.1496 + if (target == NULL) { handle_missing_successor(target_bci); return; } 1.1497 + assert(target->is_handler(), "exceptions are handled by special blocks"); 1.1498 + int pnum = target->add_new_path(); 1.1499 + merge_common(target, pnum); 1.1500 +} 1.1501 + 1.1502 +//--------------------handle_missing_successor--------------------------------- 1.1503 +void Parse::handle_missing_successor(int target_bci) { 1.1504 +#ifndef PRODUCT 1.1505 + Block* b = block(); 1.1506 + int trap_bci = b->flow()->has_trap()? b->flow()->trap_bci(): -1; 1.1507 + tty->print_cr("### Missing successor at bci:%d for block #%d (trap_bci:%d)", target_bci, b->pre_order(), trap_bci); 1.1508 +#endif 1.1509 + ShouldNotReachHere(); 1.1510 +} 1.1511 + 1.1512 +//--------------------------merge_common--------------------------------------- 1.1513 +void Parse::merge_common(Parse::Block* target, int pnum) { 1.1514 + if (TraceOptoParse) { 1.1515 + tty->print("Merging state at block #%d bci:%d", target->pre_order(), target->start()); 1.1516 + } 1.1517 + 1.1518 + // Zap extra stack slots to top 1.1519 + assert(sp() == target->start_sp(), ""); 1.1520 + clean_stack(sp()); 1.1521 + 1.1522 + if (!target->is_merged()) { // No prior mapping at this bci 1.1523 + if (TraceOptoParse) { tty->print(" with empty state"); } 1.1524 + 1.1525 + // If this path is dead, do not bother capturing it as a merge. 1.1526 + // It is "as if" we had 1 fewer predecessors from the beginning. 1.1527 + if (stopped()) { 1.1528 + if (TraceOptoParse) tty->print_cr(", but path is dead and doesn't count"); 1.1529 + return; 1.1530 + } 1.1531 + 1.1532 + // Record that a new block has been merged. 1.1533 + ++_blocks_merged; 1.1534 + 1.1535 + // Make a region if we know there are multiple or unpredictable inputs. 1.1536 + // (Also, if this is a plain fall-through, we might see another region, 1.1537 + // which must not be allowed into this block's map.) 1.1538 + if (pnum > PhiNode::Input // Known multiple inputs. 1.1539 + || target->is_handler() // These have unpredictable inputs. 1.1540 + || control()->is_Region()) { // We must hide this guy. 1.1541 + // Add a Region to start the new basic block. Phis will be added 1.1542 + // later lazily. 1.1543 + int edges = target->pred_count(); 1.1544 + if (edges < pnum) edges = pnum; // might be a new path! 1.1545 + Node *r = new (C, edges+1) RegionNode(edges+1); 1.1546 + gvn().set_type(r, Type::CONTROL); 1.1547 + record_for_igvn(r); 1.1548 + // zap all inputs to NULL for debugging (done in Node(uint) constructor) 1.1549 + // for (int j = 1; j < edges+1; j++) { r->init_req(j, NULL); } 1.1550 + r->init_req(pnum, control()); 1.1551 + set_control(r); 1.1552 + } 1.1553 + 1.1554 + // Convert the existing Parser mapping into a mapping at this bci. 1.1555 + store_state_to(target); 1.1556 + assert(target->is_merged(), "do not come here twice"); 1.1557 + 1.1558 + } else { // Prior mapping at this bci 1.1559 + if (TraceOptoParse) { tty->print(" with previous state"); } 1.1560 + 1.1561 + // We must not manufacture more phis if the target is already parsed. 1.1562 + bool nophi = target->is_parsed(); 1.1563 + 1.1564 + SafePointNode* newin = map();// Hang on to incoming mapping 1.1565 + Block* save_block = block(); // Hang on to incoming block; 1.1566 + load_state_from(target); // Get prior mapping 1.1567 + 1.1568 + assert(newin->jvms()->locoff() == jvms()->locoff(), "JVMS layouts agree"); 1.1569 + assert(newin->jvms()->stkoff() == jvms()->stkoff(), "JVMS layouts agree"); 1.1570 + assert(newin->jvms()->monoff() == jvms()->monoff(), "JVMS layouts agree"); 1.1571 + assert(newin->jvms()->endoff() == jvms()->endoff(), "JVMS layouts agree"); 1.1572 + 1.1573 + // Iterate over my current mapping and the old mapping. 1.1574 + // Where different, insert Phi functions. 1.1575 + // Use any existing Phi functions. 1.1576 + assert(control()->is_Region(), "must be merging to a region"); 1.1577 + RegionNode* r = control()->as_Region(); 1.1578 + 1.1579 + // Compute where to merge into 1.1580 + // Merge incoming control path 1.1581 + r->set_req(pnum, newin->control()); 1.1582 + 1.1583 + if (pnum == 1) { // Last merge for this Region? 1.1584 + _gvn.transform_no_reclaim(r); 1.1585 + record_for_igvn(r); 1.1586 + } 1.1587 + 1.1588 + // Update all the non-control inputs to map: 1.1589 + assert(TypeFunc::Parms == newin->jvms()->locoff(), "parser map should contain only youngest jvms"); 1.1590 + for (uint j = 1; j < newin->req(); j++) { 1.1591 + Node* m = map()->in(j); // Current state of target. 1.1592 + Node* n = newin->in(j); // Incoming change to target state. 1.1593 + PhiNode* phi; 1.1594 + if (m->is_Phi() && m->as_Phi()->region() == r) 1.1595 + phi = m->as_Phi(); 1.1596 + else 1.1597 + phi = NULL; 1.1598 + if (m != n) { // Different; must merge 1.1599 + switch (j) { 1.1600 + // Frame pointer and Return Address never changes 1.1601 + case TypeFunc::FramePtr:// Drop m, use the original value 1.1602 + case TypeFunc::ReturnAdr: 1.1603 + break; 1.1604 + case TypeFunc::Memory: // Merge inputs to the MergeMem node 1.1605 + assert(phi == NULL, "the merge contains phis, not vice versa"); 1.1606 + merge_memory_edges(n->as_MergeMem(), pnum, nophi); 1.1607 + continue; 1.1608 + default: // All normal stuff 1.1609 + if (phi == NULL) phi = ensure_phi(j, nophi); 1.1610 + break; 1.1611 + } 1.1612 + } 1.1613 + // At this point, n might be top if: 1.1614 + // - there is no phi (because TypeFlow detected a conflict), or 1.1615 + // - the corresponding control edges is top (a dead incoming path) 1.1616 + // It is a bug if we create a phi which sees a garbage value on a live path. 1.1617 + 1.1618 + if (phi != NULL) { 1.1619 + assert(n != top() || r->in(pnum) == top(), "live value must not be garbage"); 1.1620 + assert(phi->region() == r, ""); 1.1621 + phi->set_req(pnum, n); // Then add 'n' to the merge 1.1622 + if (pnum == PhiNode::Input) { 1.1623 + // Last merge for this Phi. 1.1624 + // So far, Phis have had a reasonable type from ciTypeFlow. 1.1625 + // Now _gvn will join that with the meet of current inputs. 1.1626 + // BOTTOM is never permissible here, 'cause pessimistically 1.1627 + // Phis of pointers cannot lose the basic pointer type. 1.1628 + debug_only(const Type* bt1 = phi->bottom_type()); 1.1629 + assert(bt1 != Type::BOTTOM, "should not be building conflict phis"); 1.1630 + map()->set_req(j, _gvn.transform_no_reclaim(phi)); 1.1631 + debug_only(const Type* bt2 = phi->bottom_type()); 1.1632 + assert(bt2->higher_equal(bt1), "must be consistent with type-flow"); 1.1633 + record_for_igvn(phi); 1.1634 + } 1.1635 + } 1.1636 + } // End of for all values to be merged 1.1637 + 1.1638 + if (pnum == PhiNode::Input && 1.1639 + !r->in(0)) { // The occasional useless Region 1.1640 + assert(control() == r, ""); 1.1641 + set_control(r->nonnull_req()); 1.1642 + } 1.1643 + 1.1644 + // newin has been subsumed into the lazy merge, and is now dead. 1.1645 + set_block(save_block); 1.1646 + 1.1647 + stop(); // done with this guy, for now 1.1648 + } 1.1649 + 1.1650 + if (TraceOptoParse) { 1.1651 + tty->print_cr(" on path %d", pnum); 1.1652 + } 1.1653 + 1.1654 + // Done with this parser state. 1.1655 + assert(stopped(), ""); 1.1656 +} 1.1657 + 1.1658 + 1.1659 +//--------------------------merge_memory_edges--------------------------------- 1.1660 +void Parse::merge_memory_edges(MergeMemNode* n, int pnum, bool nophi) { 1.1661 + // (nophi means we must not create phis, because we already parsed here) 1.1662 + assert(n != NULL, ""); 1.1663 + // Merge the inputs to the MergeMems 1.1664 + MergeMemNode* m = merged_memory(); 1.1665 + 1.1666 + assert(control()->is_Region(), "must be merging to a region"); 1.1667 + RegionNode* r = control()->as_Region(); 1.1668 + 1.1669 + PhiNode* base = NULL; 1.1670 + MergeMemNode* remerge = NULL; 1.1671 + for (MergeMemStream mms(m, n); mms.next_non_empty2(); ) { 1.1672 + Node *p = mms.force_memory(); 1.1673 + Node *q = mms.memory2(); 1.1674 + if (mms.is_empty() && nophi) { 1.1675 + // Trouble: No new splits allowed after a loop body is parsed. 1.1676 + // Instead, wire the new split into a MergeMem on the backedge. 1.1677 + // The optimizer will sort it out, slicing the phi. 1.1678 + if (remerge == NULL) { 1.1679 + assert(base != NULL, ""); 1.1680 + assert(base->in(0) != NULL, "should not be xformed away"); 1.1681 + remerge = MergeMemNode::make(C, base->in(pnum)); 1.1682 + gvn().set_type(remerge, Type::MEMORY); 1.1683 + base->set_req(pnum, remerge); 1.1684 + } 1.1685 + remerge->set_memory_at(mms.alias_idx(), q); 1.1686 + continue; 1.1687 + } 1.1688 + assert(!q->is_MergeMem(), ""); 1.1689 + PhiNode* phi; 1.1690 + if (p != q) { 1.1691 + phi = ensure_memory_phi(mms.alias_idx(), nophi); 1.1692 + } else { 1.1693 + if (p->is_Phi() && p->as_Phi()->region() == r) 1.1694 + phi = p->as_Phi(); 1.1695 + else 1.1696 + phi = NULL; 1.1697 + } 1.1698 + // Insert q into local phi 1.1699 + if (phi != NULL) { 1.1700 + assert(phi->region() == r, ""); 1.1701 + p = phi; 1.1702 + phi->set_req(pnum, q); 1.1703 + if (mms.at_base_memory()) { 1.1704 + base = phi; // delay transforming it 1.1705 + } else if (pnum == 1) { 1.1706 + record_for_igvn(phi); 1.1707 + p = _gvn.transform_no_reclaim(phi); 1.1708 + } 1.1709 + mms.set_memory(p);// store back through the iterator 1.1710 + } 1.1711 + } 1.1712 + // Transform base last, in case we must fiddle with remerging. 1.1713 + if (base != NULL && pnum == 1) { 1.1714 + record_for_igvn(base); 1.1715 + m->set_base_memory( _gvn.transform_no_reclaim(base) ); 1.1716 + } 1.1717 +} 1.1718 + 1.1719 + 1.1720 +//------------------------ensure_phis_everywhere------------------------------- 1.1721 +void Parse::ensure_phis_everywhere() { 1.1722 + ensure_phi(TypeFunc::I_O); 1.1723 + 1.1724 + // Ensure a phi on all currently known memories. 1.1725 + for (MergeMemStream mms(merged_memory()); mms.next_non_empty(); ) { 1.1726 + ensure_memory_phi(mms.alias_idx()); 1.1727 + debug_only(mms.set_memory()); // keep the iterator happy 1.1728 + } 1.1729 + 1.1730 + // Note: This is our only chance to create phis for memory slices. 1.1731 + // If we miss a slice that crops up later, it will have to be 1.1732 + // merged into the base-memory phi that we are building here. 1.1733 + // Later, the optimizer will comb out the knot, and build separate 1.1734 + // phi-loops for each memory slice that matters. 1.1735 + 1.1736 + // Monitors must nest nicely and not get confused amongst themselves. 1.1737 + // Phi-ify everything up to the monitors, though. 1.1738 + uint monoff = map()->jvms()->monoff(); 1.1739 + uint nof_monitors = map()->jvms()->nof_monitors(); 1.1740 + 1.1741 + assert(TypeFunc::Parms == map()->jvms()->locoff(), "parser map should contain only youngest jvms"); 1.1742 + for (uint i = TypeFunc::Parms; i < monoff; i++) { 1.1743 + ensure_phi(i); 1.1744 + } 1.1745 + // Even monitors need Phis, though they are well-structured. 1.1746 + // This is true for OSR methods, and also for the rare cases where 1.1747 + // a monitor object is the subject of a replace_in_map operation. 1.1748 + // See bugs 4426707 and 5043395. 1.1749 + for (uint m = 0; m < nof_monitors; m++) { 1.1750 + ensure_phi(map()->jvms()->monitor_obj_offset(m)); 1.1751 + } 1.1752 +} 1.1753 + 1.1754 + 1.1755 +//-----------------------------add_new_path------------------------------------ 1.1756 +// Add a previously unaccounted predecessor to this block. 1.1757 +int Parse::Block::add_new_path() { 1.1758 + // If there is no map, return the lowest unused path number. 1.1759 + if (!is_merged()) return pred_count()+1; // there will be a map shortly 1.1760 + 1.1761 + SafePointNode* map = start_map(); 1.1762 + if (!map->control()->is_Region()) 1.1763 + return pred_count()+1; // there may be a region some day 1.1764 + RegionNode* r = map->control()->as_Region(); 1.1765 + 1.1766 + // Add new path to the region. 1.1767 + uint pnum = r->req(); 1.1768 + r->add_req(NULL); 1.1769 + 1.1770 + for (uint i = 1; i < map->req(); i++) { 1.1771 + Node* n = map->in(i); 1.1772 + if (i == TypeFunc::Memory) { 1.1773 + // Ensure a phi on all currently known memories. 1.1774 + for (MergeMemStream mms(n->as_MergeMem()); mms.next_non_empty(); ) { 1.1775 + Node* phi = mms.memory(); 1.1776 + if (phi->is_Phi() && phi->as_Phi()->region() == r) { 1.1777 + assert(phi->req() == pnum, "must be same size as region"); 1.1778 + phi->add_req(NULL); 1.1779 + } 1.1780 + } 1.1781 + } else { 1.1782 + if (n->is_Phi() && n->as_Phi()->region() == r) { 1.1783 + assert(n->req() == pnum, "must be same size as region"); 1.1784 + n->add_req(NULL); 1.1785 + } 1.1786 + } 1.1787 + } 1.1788 + 1.1789 + return pnum; 1.1790 +} 1.1791 + 1.1792 +//------------------------------ensure_phi------------------------------------- 1.1793 +// Turn the idx'th entry of the current map into a Phi 1.1794 +PhiNode *Parse::ensure_phi(int idx, bool nocreate) { 1.1795 + SafePointNode* map = this->map(); 1.1796 + Node* region = map->control(); 1.1797 + assert(region->is_Region(), ""); 1.1798 + 1.1799 + Node* o = map->in(idx); 1.1800 + assert(o != NULL, ""); 1.1801 + 1.1802 + if (o == top()) return NULL; // TOP always merges into TOP 1.1803 + 1.1804 + if (o->is_Phi() && o->as_Phi()->region() == region) { 1.1805 + return o->as_Phi(); 1.1806 + } 1.1807 + 1.1808 + // Now use a Phi here for merging 1.1809 + assert(!nocreate, "Cannot build a phi for a block already parsed."); 1.1810 + const JVMState* jvms = map->jvms(); 1.1811 + const Type* t; 1.1812 + if (jvms->is_loc(idx)) { 1.1813 + t = block()->local_type_at(idx - jvms->locoff()); 1.1814 + } else if (jvms->is_stk(idx)) { 1.1815 + t = block()->stack_type_at(idx - jvms->stkoff()); 1.1816 + } else if (jvms->is_mon(idx)) { 1.1817 + assert(!jvms->is_monitor_box(idx), "no phis for boxes"); 1.1818 + t = TypeInstPtr::BOTTOM; // this is sufficient for a lock object 1.1819 + } else if ((uint)idx < TypeFunc::Parms) { 1.1820 + t = o->bottom_type(); // Type::RETURN_ADDRESS or such-like. 1.1821 + } else { 1.1822 + assert(false, "no type information for this phi"); 1.1823 + } 1.1824 + 1.1825 + // If the type falls to bottom, then this must be a local that 1.1826 + // is mixing ints and oops or some such. Forcing it to top 1.1827 + // makes it go dead. 1.1828 + if (t == Type::BOTTOM) { 1.1829 + map->set_req(idx, top()); 1.1830 + return NULL; 1.1831 + } 1.1832 + 1.1833 + // Do not create phis for top either. 1.1834 + // A top on a non-null control flow must be an unused even after the.phi. 1.1835 + if (t == Type::TOP || t == Type::HALF) { 1.1836 + map->set_req(idx, top()); 1.1837 + return NULL; 1.1838 + } 1.1839 + 1.1840 + PhiNode* phi = PhiNode::make(region, o, t); 1.1841 + gvn().set_type(phi, t); 1.1842 + if (DoEscapeAnalysis) record_for_igvn(phi); 1.1843 + map->set_req(idx, phi); 1.1844 + return phi; 1.1845 +} 1.1846 + 1.1847 +//--------------------------ensure_memory_phi---------------------------------- 1.1848 +// Turn the idx'th slice of the current memory into a Phi 1.1849 +PhiNode *Parse::ensure_memory_phi(int idx, bool nocreate) { 1.1850 + MergeMemNode* mem = merged_memory(); 1.1851 + Node* region = control(); 1.1852 + assert(region->is_Region(), ""); 1.1853 + 1.1854 + Node *o = (idx == Compile::AliasIdxBot)? mem->base_memory(): mem->memory_at(idx); 1.1855 + assert(o != NULL && o != top(), ""); 1.1856 + 1.1857 + PhiNode* phi; 1.1858 + if (o->is_Phi() && o->as_Phi()->region() == region) { 1.1859 + phi = o->as_Phi(); 1.1860 + if (phi == mem->base_memory() && idx >= Compile::AliasIdxRaw) { 1.1861 + // clone the shared base memory phi to make a new memory split 1.1862 + assert(!nocreate, "Cannot build a phi for a block already parsed."); 1.1863 + const Type* t = phi->bottom_type(); 1.1864 + const TypePtr* adr_type = C->get_adr_type(idx); 1.1865 + phi = phi->slice_memory(adr_type); 1.1866 + gvn().set_type(phi, t); 1.1867 + } 1.1868 + return phi; 1.1869 + } 1.1870 + 1.1871 + // Now use a Phi here for merging 1.1872 + assert(!nocreate, "Cannot build a phi for a block already parsed."); 1.1873 + const Type* t = o->bottom_type(); 1.1874 + const TypePtr* adr_type = C->get_adr_type(idx); 1.1875 + phi = PhiNode::make(region, o, t, adr_type); 1.1876 + gvn().set_type(phi, t); 1.1877 + if (idx == Compile::AliasIdxBot) 1.1878 + mem->set_base_memory(phi); 1.1879 + else 1.1880 + mem->set_memory_at(idx, phi); 1.1881 + return phi; 1.1882 +} 1.1883 + 1.1884 +//------------------------------call_register_finalizer----------------------- 1.1885 +// Check the klass of the receiver and call register_finalizer if the 1.1886 +// class need finalization. 1.1887 +void Parse::call_register_finalizer() { 1.1888 + Node* receiver = local(0); 1.1889 + assert(receiver != NULL && receiver->bottom_type()->isa_instptr() != NULL, 1.1890 + "must have non-null instance type"); 1.1891 + 1.1892 + const TypeInstPtr *tinst = receiver->bottom_type()->isa_instptr(); 1.1893 + if (tinst != NULL && tinst->klass()->is_loaded() && !tinst->klass_is_exact()) { 1.1894 + // The type isn't known exactly so see if CHA tells us anything. 1.1895 + ciInstanceKlass* ik = tinst->klass()->as_instance_klass(); 1.1896 + if (!Dependencies::has_finalizable_subclass(ik)) { 1.1897 + // No finalizable subclasses so skip the dynamic check. 1.1898 + C->dependencies()->assert_has_no_finalizable_subclasses(ik); 1.1899 + return; 1.1900 + } 1.1901 + } 1.1902 + 1.1903 + // Insert a dynamic test for whether the instance needs 1.1904 + // finalization. In general this will fold up since the concrete 1.1905 + // class is often visible so the access flags are constant. 1.1906 + Node* klass_addr = basic_plus_adr( receiver, receiver, oopDesc::klass_offset_in_bytes() ); 1.1907 + Node* klass = _gvn.transform(new (C, 3) LoadKlassNode(NULL, immutable_memory(), klass_addr, TypeInstPtr::KLASS)); 1.1908 + 1.1909 + Node* access_flags_addr = basic_plus_adr(klass, klass, Klass::access_flags_offset_in_bytes() + sizeof(oopDesc)); 1.1910 + Node* access_flags = make_load(NULL, access_flags_addr, TypeInt::INT, T_INT); 1.1911 + 1.1912 + Node* mask = _gvn.transform(new (C, 3) AndINode(access_flags, intcon(JVM_ACC_HAS_FINALIZER))); 1.1913 + Node* check = _gvn.transform(new (C, 3) CmpINode(mask, intcon(0))); 1.1914 + Node* test = _gvn.transform(new (C, 2) BoolNode(check, BoolTest::ne)); 1.1915 + 1.1916 + IfNode* iff = create_and_map_if(control(), test, PROB_MAX, COUNT_UNKNOWN); 1.1917 + 1.1918 + RegionNode* result_rgn = new (C, 3) RegionNode(3); 1.1919 + record_for_igvn(result_rgn); 1.1920 + 1.1921 + Node *skip_register = _gvn.transform(new (C, 1) IfFalseNode(iff)); 1.1922 + result_rgn->init_req(1, skip_register); 1.1923 + 1.1924 + Node *needs_register = _gvn.transform(new (C, 1) IfTrueNode(iff)); 1.1925 + set_control(needs_register); 1.1926 + if (stopped()) { 1.1927 + // There is no slow path. 1.1928 + result_rgn->init_req(2, top()); 1.1929 + } else { 1.1930 + Node *call = make_runtime_call(RC_NO_LEAF, 1.1931 + OptoRuntime::register_finalizer_Type(), 1.1932 + OptoRuntime::register_finalizer_Java(), 1.1933 + NULL, TypePtr::BOTTOM, 1.1934 + receiver); 1.1935 + make_slow_call_ex(call, env()->Throwable_klass(), true); 1.1936 + 1.1937 + Node* fast_io = call->in(TypeFunc::I_O); 1.1938 + Node* fast_mem = call->in(TypeFunc::Memory); 1.1939 + // These two phis are pre-filled with copies of of the fast IO and Memory 1.1940 + Node* io_phi = PhiNode::make(result_rgn, fast_io, Type::ABIO); 1.1941 + Node* mem_phi = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM); 1.1942 + 1.1943 + result_rgn->init_req(2, control()); 1.1944 + io_phi ->init_req(2, i_o()); 1.1945 + mem_phi ->init_req(2, reset_memory()); 1.1946 + 1.1947 + set_all_memory( _gvn.transform(mem_phi) ); 1.1948 + set_i_o( _gvn.transform(io_phi) ); 1.1949 + } 1.1950 + 1.1951 + set_control( _gvn.transform(result_rgn) ); 1.1952 +} 1.1953 + 1.1954 +//------------------------------return_current--------------------------------- 1.1955 +// Append current _map to _exit_return 1.1956 +void Parse::return_current(Node* value) { 1.1957 + if (RegisterFinalizersAtInit && 1.1958 + method()->intrinsic_id() == vmIntrinsics::_Object_init) { 1.1959 + call_register_finalizer(); 1.1960 + } 1.1961 + 1.1962 + // Do not set_parse_bci, so that return goo is credited to the return insn. 1.1963 + set_bci(InvocationEntryBci); 1.1964 + if (method()->is_synchronized() && GenerateSynchronizationCode) { 1.1965 + shared_unlock(_synch_lock->box_node(), _synch_lock->obj_node()); 1.1966 + } 1.1967 + if (DTraceMethodProbes) { 1.1968 + make_dtrace_method_exit(method()); 1.1969 + } 1.1970 + SafePointNode* exit_return = _exits.map(); 1.1971 + exit_return->in( TypeFunc::Control )->add_req( control() ); 1.1972 + exit_return->in( TypeFunc::I_O )->add_req( i_o () ); 1.1973 + Node *mem = exit_return->in( TypeFunc::Memory ); 1.1974 + for (MergeMemStream mms(mem->as_MergeMem(), merged_memory()); mms.next_non_empty2(); ) { 1.1975 + if (mms.is_empty()) { 1.1976 + // get a copy of the base memory, and patch just this one input 1.1977 + const TypePtr* adr_type = mms.adr_type(C); 1.1978 + Node* phi = mms.force_memory()->as_Phi()->slice_memory(adr_type); 1.1979 + assert(phi->as_Phi()->region() == mms.base_memory()->in(0), ""); 1.1980 + gvn().set_type_bottom(phi); 1.1981 + phi->del_req(phi->req()-1); // prepare to re-patch 1.1982 + mms.set_memory(phi); 1.1983 + } 1.1984 + mms.memory()->add_req(mms.memory2()); 1.1985 + } 1.1986 + 1.1987 + // frame pointer is always same, already captured 1.1988 + if (value != NULL) { 1.1989 + // If returning oops to an interface-return, there is a silent free 1.1990 + // cast from oop to interface allowed by the Verifier. Make it explicit 1.1991 + // here. 1.1992 + Node* phi = _exits.argument(0); 1.1993 + const TypeInstPtr *tr = phi->bottom_type()->isa_instptr(); 1.1994 + if( tr && tr->klass()->is_loaded() && 1.1995 + tr->klass()->is_interface() ) { 1.1996 + const TypeInstPtr *tp = value->bottom_type()->isa_instptr(); 1.1997 + if (tp && tp->klass()->is_loaded() && 1.1998 + !tp->klass()->is_interface()) { 1.1999 + // sharpen the type eagerly; this eases certain assert checking 1.2000 + if (tp->higher_equal(TypeInstPtr::NOTNULL)) 1.2001 + tr = tr->join(TypeInstPtr::NOTNULL)->is_instptr(); 1.2002 + value = _gvn.transform(new (C, 2) CheckCastPPNode(0,value,tr)); 1.2003 + } 1.2004 + } 1.2005 + phi->add_req(value); 1.2006 + } 1.2007 + 1.2008 + stop_and_kill_map(); // This CFG path dies here 1.2009 +} 1.2010 + 1.2011 + 1.2012 +//------------------------------add_safepoint---------------------------------- 1.2013 +void Parse::add_safepoint() { 1.2014 + // See if we can avoid this safepoint. No need for a SafePoint immediately 1.2015 + // after a Call (except Leaf Call) or another SafePoint. 1.2016 + Node *proj = control(); 1.2017 + bool add_poll_param = SafePointNode::needs_polling_address_input(); 1.2018 + uint parms = add_poll_param ? TypeFunc::Parms+1 : TypeFunc::Parms; 1.2019 + if( proj->is_Proj() ) { 1.2020 + Node *n0 = proj->in(0); 1.2021 + if( n0->is_Catch() ) { 1.2022 + n0 = n0->in(0)->in(0); 1.2023 + assert( n0->is_Call(), "expect a call here" ); 1.2024 + } 1.2025 + if( n0->is_Call() ) { 1.2026 + if( n0->as_Call()->guaranteed_safepoint() ) 1.2027 + return; 1.2028 + } else if( n0->is_SafePoint() && n0->req() >= parms ) { 1.2029 + return; 1.2030 + } 1.2031 + } 1.2032 + 1.2033 + // Clear out dead values from the debug info. 1.2034 + kill_dead_locals(); 1.2035 + 1.2036 + // Clone the JVM State 1.2037 + SafePointNode *sfpnt = new (C, parms) SafePointNode(parms, NULL); 1.2038 + 1.2039 + // Capture memory state BEFORE a SafePoint. Since we can block at a 1.2040 + // SafePoint we need our GC state to be safe; i.e. we need all our current 1.2041 + // write barriers (card marks) to not float down after the SafePoint so we 1.2042 + // must read raw memory. Likewise we need all oop stores to match the card 1.2043 + // marks. If deopt can happen, we need ALL stores (we need the correct JVM 1.2044 + // state on a deopt). 1.2045 + 1.2046 + // We do not need to WRITE the memory state after a SafePoint. The control 1.2047 + // edge will keep card-marks and oop-stores from floating up from below a 1.2048 + // SafePoint and our true dependency added here will keep them from floating 1.2049 + // down below a SafePoint. 1.2050 + 1.2051 + // Clone the current memory state 1.2052 + Node* mem = MergeMemNode::make(C, map()->memory()); 1.2053 + 1.2054 + mem = _gvn.transform(mem); 1.2055 + 1.2056 + // Pass control through the safepoint 1.2057 + sfpnt->init_req(TypeFunc::Control , control()); 1.2058 + // Fix edges normally used by a call 1.2059 + sfpnt->init_req(TypeFunc::I_O , top() ); 1.2060 + sfpnt->init_req(TypeFunc::Memory , mem ); 1.2061 + sfpnt->init_req(TypeFunc::ReturnAdr, top() ); 1.2062 + sfpnt->init_req(TypeFunc::FramePtr , top() ); 1.2063 + 1.2064 + // Create a node for the polling address 1.2065 + if( add_poll_param ) { 1.2066 + Node *polladr = ConPNode::make(C, (address)os::get_polling_page()); 1.2067 + sfpnt->init_req(TypeFunc::Parms+0, _gvn.transform(polladr)); 1.2068 + } 1.2069 + 1.2070 + // Fix up the JVM State edges 1.2071 + add_safepoint_edges(sfpnt); 1.2072 + Node *transformed_sfpnt = _gvn.transform(sfpnt); 1.2073 + set_control(transformed_sfpnt); 1.2074 + 1.2075 + // Provide an edge from root to safepoint. This makes the safepoint 1.2076 + // appear useful until the parse has completed. 1.2077 + if( OptoRemoveUseless && transformed_sfpnt->is_SafePoint() ) { 1.2078 + assert(C->root() != NULL, "Expect parse is still valid"); 1.2079 + C->root()->add_prec(transformed_sfpnt); 1.2080 + } 1.2081 +} 1.2082 + 1.2083 +#ifndef PRODUCT 1.2084 +//------------------------show_parse_info-------------------------------------- 1.2085 +void Parse::show_parse_info() { 1.2086 + InlineTree* ilt = NULL; 1.2087 + if (C->ilt() != NULL) { 1.2088 + JVMState* caller_jvms = is_osr_parse() ? caller()->caller() : caller(); 1.2089 + ilt = InlineTree::find_subtree_from_root(C->ilt(), caller_jvms, method()); 1.2090 + } 1.2091 + if (PrintCompilation && Verbose) { 1.2092 + if (depth() == 1) { 1.2093 + if( ilt->count_inlines() ) { 1.2094 + tty->print(" __inlined %d (%d bytes)", ilt->count_inlines(), 1.2095 + ilt->count_inline_bcs()); 1.2096 + tty->cr(); 1.2097 + } 1.2098 + } else { 1.2099 + if (method()->is_synchronized()) tty->print("s"); 1.2100 + if (method()->has_exception_handlers()) tty->print("!"); 1.2101 + // Check this is not the final compiled version 1.2102 + if (C->trap_can_recompile()) { 1.2103 + tty->print("-"); 1.2104 + } else { 1.2105 + tty->print(" "); 1.2106 + } 1.2107 + method()->print_short_name(); 1.2108 + if (is_osr_parse()) { 1.2109 + tty->print(" @ %d", osr_bci()); 1.2110 + } 1.2111 + tty->print(" (%d bytes)",method()->code_size()); 1.2112 + if (ilt->count_inlines()) { 1.2113 + tty->print(" __inlined %d (%d bytes)", ilt->count_inlines(), 1.2114 + ilt->count_inline_bcs()); 1.2115 + } 1.2116 + tty->cr(); 1.2117 + } 1.2118 + } 1.2119 + if (PrintOpto && (depth() == 1 || PrintOptoInlining)) { 1.2120 + // Print that we succeeded; suppress this message on the first osr parse. 1.2121 + 1.2122 + if (method()->is_synchronized()) tty->print("s"); 1.2123 + if (method()->has_exception_handlers()) tty->print("!"); 1.2124 + // Check this is not the final compiled version 1.2125 + if (C->trap_can_recompile() && depth() == 1) { 1.2126 + tty->print("-"); 1.2127 + } else { 1.2128 + tty->print(" "); 1.2129 + } 1.2130 + if( depth() != 1 ) { tty->print(" "); } // missing compile count 1.2131 + for (int i = 1; i < depth(); ++i) { tty->print(" "); } 1.2132 + method()->print_short_name(); 1.2133 + if (is_osr_parse()) { 1.2134 + tty->print(" @ %d", osr_bci()); 1.2135 + } 1.2136 + if (ilt->caller_bci() != -1) { 1.2137 + tty->print(" @ %d", ilt->caller_bci()); 1.2138 + } 1.2139 + tty->print(" (%d bytes)",method()->code_size()); 1.2140 + if (ilt->count_inlines()) { 1.2141 + tty->print(" __inlined %d (%d bytes)", ilt->count_inlines(), 1.2142 + ilt->count_inline_bcs()); 1.2143 + } 1.2144 + tty->cr(); 1.2145 + } 1.2146 +} 1.2147 + 1.2148 + 1.2149 +//------------------------------dump------------------------------------------- 1.2150 +// Dump information associated with the bytecodes of current _method 1.2151 +void Parse::dump() { 1.2152 + if( method() != NULL ) { 1.2153 + // Iterate over bytecodes 1.2154 + ciBytecodeStream iter(method()); 1.2155 + for( Bytecodes::Code bc = iter.next(); bc != ciBytecodeStream::EOBC() ; bc = iter.next() ) { 1.2156 + dump_bci( iter.cur_bci() ); 1.2157 + tty->cr(); 1.2158 + } 1.2159 + } 1.2160 +} 1.2161 + 1.2162 +// Dump information associated with a byte code index, 'bci' 1.2163 +void Parse::dump_bci(int bci) { 1.2164 + // Output info on merge-points, cloning, and within _jsr..._ret 1.2165 + // NYI 1.2166 + tty->print(" bci:%d", bci); 1.2167 +} 1.2168 + 1.2169 +#endif