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