duke@435: /* xdono@772: * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_callGenerator.cpp.incl" duke@435: duke@435: CallGenerator::CallGenerator(ciMethod* method) { duke@435: _method = method; duke@435: } duke@435: duke@435: // Utility function. duke@435: const TypeFunc* CallGenerator::tf() const { duke@435: return TypeFunc::make(method()); duke@435: } duke@435: duke@435: //-----------------------------ParseGenerator--------------------------------- duke@435: // Internal class which handles all direct bytecode traversal. duke@435: class ParseGenerator : public InlineCallGenerator { duke@435: private: duke@435: bool _is_osr; duke@435: float _expected_uses; duke@435: duke@435: public: duke@435: ParseGenerator(ciMethod* method, float expected_uses, bool is_osr = false) duke@435: : InlineCallGenerator(method) duke@435: { duke@435: _is_osr = is_osr; duke@435: _expected_uses = expected_uses; duke@435: assert(can_parse(method, is_osr), "parse must be possible"); duke@435: } duke@435: duke@435: // Can we build either an OSR or a regular parser for this method? duke@435: static bool can_parse(ciMethod* method, int is_osr = false); duke@435: duke@435: virtual bool is_parse() const { return true; } duke@435: virtual JVMState* generate(JVMState* jvms); duke@435: int is_osr() { return _is_osr; } duke@435: duke@435: }; duke@435: duke@435: JVMState* ParseGenerator::generate(JVMState* jvms) { duke@435: Compile* C = Compile::current(); duke@435: duke@435: if (is_osr()) { duke@435: // The JVMS for a OSR has a single argument (see its TypeFunc). duke@435: assert(jvms->depth() == 1, "no inline OSR"); duke@435: } duke@435: duke@435: if (C->failing()) { duke@435: return NULL; // bailing out of the compile; do not try to parse duke@435: } duke@435: duke@435: Parse parser(jvms, method(), _expected_uses); duke@435: // Grab signature for matching/allocation duke@435: #ifdef ASSERT duke@435: if (parser.tf() != (parser.depth() == 1 ? C->tf() : tf())) { duke@435: MutexLockerEx ml(Compile_lock, Mutex::_no_safepoint_check_flag); duke@435: assert(C->env()->system_dictionary_modification_counter_changed(), duke@435: "Must invalidate if TypeFuncs differ"); duke@435: } duke@435: #endif duke@435: duke@435: GraphKit& exits = parser.exits(); duke@435: duke@435: if (C->failing()) { duke@435: while (exits.pop_exception_state() != NULL) ; duke@435: return NULL; duke@435: } duke@435: duke@435: assert(exits.jvms()->same_calls_as(jvms), "sanity"); duke@435: duke@435: // Simply return the exit state of the parser, duke@435: // augmented by any exceptional states. duke@435: return exits.transfer_exceptions_into_jvms(); duke@435: } duke@435: duke@435: //---------------------------DirectCallGenerator------------------------------ duke@435: // Internal class which handles all out-of-line calls w/o receiver type checks. duke@435: class DirectCallGenerator : public CallGenerator { never@1515: private: never@1515: CallStaticJavaNode* _call_node; never@1515: // Force separate memory and I/O projections for the exceptional never@1515: // paths to facilitate late inlinig. never@1515: bool _separate_io_proj; never@1515: never@1515: public: never@1515: DirectCallGenerator(ciMethod* method, bool separate_io_proj) never@1515: : CallGenerator(method), never@1515: _separate_io_proj(separate_io_proj) duke@435: { duke@435: } duke@435: virtual JVMState* generate(JVMState* jvms); never@1515: never@1515: CallStaticJavaNode* call_node() const { return _call_node; } duke@435: }; duke@435: duke@435: JVMState* DirectCallGenerator::generate(JVMState* jvms) { duke@435: GraphKit kit(jvms); duke@435: bool is_static = method()->is_static(); duke@435: address target = is_static ? SharedRuntime::get_resolve_static_call_stub() duke@435: : SharedRuntime::get_resolve_opt_virtual_call_stub(); duke@435: duke@435: if (kit.C->log() != NULL) { duke@435: kit.C->log()->elem("direct_call bci='%d'", jvms->bci()); duke@435: } duke@435: duke@435: CallStaticJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallStaticJavaNode(tf(), target, method(), kit.bci()); duke@435: if (!is_static) { duke@435: // Make an explicit receiver null_check as part of this call. duke@435: // Since we share a map with the caller, his JVMS gets adjusted. duke@435: kit.null_check_receiver(method()); duke@435: if (kit.stopped()) { duke@435: // And dump it back to the caller, decorated with any exceptions: duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: // Mark the call node as virtual, sort of: duke@435: call->set_optimized_virtual(true); duke@435: } duke@435: kit.set_arguments_for_java_call(call); never@1515: kit.set_edges_for_java_call(call, false, _separate_io_proj); never@1515: Node* ret = kit.set_results_for_java_call(call, _separate_io_proj); duke@435: kit.push_node(method()->return_type()->basic_type(), ret); never@1515: _call_node = call; // Save the call node in case we need it later duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: duke@435: class VirtualCallGenerator : public CallGenerator { duke@435: private: duke@435: int _vtable_index; duke@435: public: duke@435: VirtualCallGenerator(ciMethod* method, int vtable_index) duke@435: : CallGenerator(method), _vtable_index(vtable_index) duke@435: { duke@435: assert(vtable_index == methodOopDesc::invalid_vtable_index || duke@435: vtable_index >= 0, "either invalid or usable"); duke@435: } duke@435: virtual bool is_virtual() const { return true; } duke@435: virtual JVMState* generate(JVMState* jvms); duke@435: }; duke@435: duke@435: //--------------------------VirtualCallGenerator------------------------------ duke@435: // Internal class which handles all out-of-line calls checking receiver type. duke@435: JVMState* VirtualCallGenerator::generate(JVMState* jvms) { duke@435: GraphKit kit(jvms); duke@435: Node* receiver = kit.argument(0); duke@435: duke@435: if (kit.C->log() != NULL) { duke@435: kit.C->log()->elem("virtual_call bci='%d'", jvms->bci()); duke@435: } duke@435: duke@435: // If the receiver is a constant null, do not torture the system duke@435: // by attempting to call through it. The compile will proceed duke@435: // correctly, but may bail out in final_graph_reshaping, because duke@435: // the call instruction will have a seemingly deficient out-count. duke@435: // (The bailout says something misleading about an "infinite loop".) duke@435: if (kit.gvn().type(receiver)->higher_equal(TypePtr::NULL_PTR)) { duke@435: kit.inc_sp(method()->arg_size()); // restore arguments duke@435: kit.uncommon_trap(Deoptimization::Reason_null_check, duke@435: Deoptimization::Action_none, duke@435: NULL, "null receiver"); duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: duke@435: // Ideally we would unconditionally do a null check here and let it duke@435: // be converted to an implicit check based on profile information. duke@435: // However currently the conversion to implicit null checks in duke@435: // Block::implicit_null_check() only looks for loads and stores, not calls. duke@435: ciMethod *caller = kit.method(); duke@435: ciMethodData *caller_md = (caller == NULL) ? NULL : caller->method_data(); duke@435: if (!UseInlineCaches || !ImplicitNullChecks || duke@435: ((ImplicitNullCheckThreshold > 0) && caller_md && duke@435: (caller_md->trap_count(Deoptimization::Reason_null_check) duke@435: >= (uint)ImplicitNullCheckThreshold))) { duke@435: // Make an explicit receiver null_check as part of this call. duke@435: // Since we share a map with the caller, his JVMS gets adjusted. duke@435: receiver = kit.null_check_receiver(method()); duke@435: if (kit.stopped()) { duke@435: // And dump it back to the caller, decorated with any exceptions: duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: } duke@435: duke@435: assert(!method()->is_static(), "virtual call must not be to static"); duke@435: assert(!method()->is_final(), "virtual call should not be to final"); duke@435: assert(!method()->is_private(), "virtual call should not be to private"); duke@435: assert(_vtable_index == methodOopDesc::invalid_vtable_index || !UseInlineCaches, duke@435: "no vtable calls if +UseInlineCaches "); duke@435: address target = SharedRuntime::get_resolve_virtual_call_stub(); duke@435: // Normal inline cache used for call duke@435: CallDynamicJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallDynamicJavaNode(tf(), target, method(), _vtable_index, kit.bci()); duke@435: kit.set_arguments_for_java_call(call); duke@435: kit.set_edges_for_java_call(call); duke@435: Node* ret = kit.set_results_for_java_call(call); duke@435: kit.push_node(method()->return_type()->basic_type(), ret); duke@435: duke@435: // Represent the effect of an implicit receiver null_check duke@435: // as part of this call. Since we share a map with the caller, duke@435: // his JVMS gets adjusted. duke@435: kit.cast_not_null(receiver); duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: duke@435: bool ParseGenerator::can_parse(ciMethod* m, int entry_bci) { duke@435: // Certain methods cannot be parsed at all: duke@435: if (!m->can_be_compiled()) return false; duke@435: if (!m->has_balanced_monitors()) return false; duke@435: if (m->get_flow_analysis()->failing()) return false; duke@435: duke@435: // (Methods may bail out for other reasons, after the parser is run. duke@435: // We try to avoid this, but if forced, we must return (Node*)NULL. duke@435: // The user of the CallGenerator must check for this condition.) duke@435: return true; duke@435: } duke@435: duke@435: CallGenerator* CallGenerator::for_inline(ciMethod* m, float expected_uses) { duke@435: if (!ParseGenerator::can_parse(m)) return NULL; duke@435: return new ParseGenerator(m, expected_uses); duke@435: } duke@435: duke@435: // As a special case, the JVMS passed to this CallGenerator is duke@435: // for the method execution already in progress, not just the JVMS duke@435: // of the caller. Thus, this CallGenerator cannot be mixed with others! duke@435: CallGenerator* CallGenerator::for_osr(ciMethod* m, int osr_bci) { duke@435: if (!ParseGenerator::can_parse(m, true)) return NULL; duke@435: float past_uses = m->interpreter_invocation_count(); duke@435: float expected_uses = past_uses; duke@435: return new ParseGenerator(m, expected_uses, true); duke@435: } duke@435: never@1515: CallGenerator* CallGenerator::for_direct_call(ciMethod* m, bool separate_io_proj) { duke@435: assert(!m->is_abstract(), "for_direct_call mismatch"); never@1515: return new DirectCallGenerator(m, separate_io_proj); duke@435: } duke@435: duke@435: CallGenerator* CallGenerator::for_virtual_call(ciMethod* m, int vtable_index) { duke@435: assert(!m->is_static(), "for_virtual_call mismatch"); duke@435: return new VirtualCallGenerator(m, vtable_index); duke@435: } duke@435: never@1515: // Allow inlining decisions to be delayed never@1515: class LateInlineCallGenerator : public DirectCallGenerator { never@1515: CallGenerator* _inline_cg; never@1515: never@1515: public: never@1515: LateInlineCallGenerator(ciMethod* method, CallGenerator* inline_cg) : never@1515: DirectCallGenerator(method, true), _inline_cg(inline_cg) {} never@1515: never@1515: virtual bool is_late_inline() const { return true; } never@1515: never@1515: // Convert the CallStaticJava into an inline never@1515: virtual void do_late_inline(); never@1515: never@1515: JVMState* generate(JVMState* jvms) { never@1515: // Record that this call site should be revisited once the main never@1515: // parse is finished. never@1515: Compile::current()->add_late_inline(this); never@1515: never@1515: // Emit the CallStaticJava and request separate projections so never@1515: // that the late inlining logic can distinguish between fall never@1515: // through and exceptional uses of the memory and io projections never@1515: // as is done for allocations and macro expansion. never@1515: return DirectCallGenerator::generate(jvms); never@1515: } never@1515: never@1515: }; never@1515: never@1515: never@1515: void LateInlineCallGenerator::do_late_inline() { never@1515: // Can't inline it never@1515: if (call_node() == NULL || call_node()->outcnt() == 0 || never@1515: call_node()->in(0) == NULL || call_node()->in(0)->is_top()) never@1515: return; never@1515: never@1515: CallStaticJavaNode* call = call_node(); never@1515: never@1515: // Make a clone of the JVMState that appropriate to use for driving a parse never@1515: Compile* C = Compile::current(); never@1515: JVMState* jvms = call->jvms()->clone_shallow(C); never@1515: uint size = call->req(); never@1515: SafePointNode* map = new (C, size) SafePointNode(size, jvms); never@1515: for (uint i1 = 0; i1 < size; i1++) { never@1515: map->init_req(i1, call->in(i1)); never@1515: } never@1515: never@1515: // Make sure the state is a MergeMem for parsing. never@1515: if (!map->in(TypeFunc::Memory)->is_MergeMem()) { never@1515: map->set_req(TypeFunc::Memory, MergeMemNode::make(C, map->in(TypeFunc::Memory))); never@1515: } never@1515: never@1515: // Make enough space for the expression stack and transfer the incoming arguments never@1515: int nargs = method()->arg_size(); never@1515: jvms->set_map(map); never@1515: map->ensure_stack(jvms, jvms->method()->max_stack()); never@1515: if (nargs > 0) { never@1515: for (int i1 = 0; i1 < nargs; i1++) { never@1515: map->set_req(i1 + jvms->argoff(), call->in(TypeFunc::Parms + i1)); never@1515: } never@1515: } never@1515: never@1515: CompileLog* log = C->log(); never@1515: if (log != NULL) { never@1515: log->head("late_inline method='%d'", log->identify(method())); never@1515: JVMState* p = jvms; never@1515: while (p != NULL) { never@1515: log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method())); never@1515: p = p->caller(); never@1515: } never@1515: log->tail("late_inline"); never@1515: } never@1515: never@1515: // Setup default node notes to be picked up by the inlining never@1515: Node_Notes* old_nn = C->default_node_notes(); never@1515: if (old_nn != NULL) { never@1515: Node_Notes* entry_nn = old_nn->clone(C); never@1515: entry_nn->set_jvms(jvms); never@1515: C->set_default_node_notes(entry_nn); never@1515: } never@1515: never@1515: // Now perform the inling using the synthesized JVMState never@1515: JVMState* new_jvms = _inline_cg->generate(jvms); never@1515: if (new_jvms == NULL) return; // no change never@1515: if (C->failing()) return; never@1515: never@1515: // Capture any exceptional control flow never@1515: GraphKit kit(new_jvms); never@1515: never@1515: // Find the result object never@1515: Node* result = C->top(); never@1515: int result_size = method()->return_type()->size(); never@1515: if (result_size != 0 && !kit.stopped()) { never@1515: result = (result_size == 1) ? kit.pop() : kit.pop_pair(); never@1515: } never@1515: never@1515: kit.replace_call(call, result); never@1515: } never@1515: never@1515: never@1515: CallGenerator* CallGenerator::for_late_inline(ciMethod* method, CallGenerator* inline_cg) { never@1515: return new LateInlineCallGenerator(method, inline_cg); never@1515: } never@1515: duke@435: duke@435: //---------------------------WarmCallGenerator-------------------------------- duke@435: // Internal class which handles initial deferral of inlining decisions. duke@435: class WarmCallGenerator : public CallGenerator { duke@435: WarmCallInfo* _call_info; duke@435: CallGenerator* _if_cold; duke@435: CallGenerator* _if_hot; duke@435: bool _is_virtual; // caches virtuality of if_cold duke@435: bool _is_inline; // caches inline-ness of if_hot duke@435: duke@435: public: duke@435: WarmCallGenerator(WarmCallInfo* ci, duke@435: CallGenerator* if_cold, duke@435: CallGenerator* if_hot) duke@435: : CallGenerator(if_cold->method()) duke@435: { duke@435: assert(method() == if_hot->method(), "consistent choices"); duke@435: _call_info = ci; duke@435: _if_cold = if_cold; duke@435: _if_hot = if_hot; duke@435: _is_virtual = if_cold->is_virtual(); duke@435: _is_inline = if_hot->is_inline(); duke@435: } duke@435: duke@435: virtual bool is_inline() const { return _is_inline; } duke@435: virtual bool is_virtual() const { return _is_virtual; } duke@435: virtual bool is_deferred() const { return true; } duke@435: duke@435: virtual JVMState* generate(JVMState* jvms); duke@435: }; duke@435: duke@435: duke@435: CallGenerator* CallGenerator::for_warm_call(WarmCallInfo* ci, duke@435: CallGenerator* if_cold, duke@435: CallGenerator* if_hot) { duke@435: return new WarmCallGenerator(ci, if_cold, if_hot); duke@435: } duke@435: duke@435: JVMState* WarmCallGenerator::generate(JVMState* jvms) { duke@435: Compile* C = Compile::current(); duke@435: if (C->log() != NULL) { duke@435: C->log()->elem("warm_call bci='%d'", jvms->bci()); duke@435: } duke@435: jvms = _if_cold->generate(jvms); duke@435: if (jvms != NULL) { duke@435: Node* m = jvms->map()->control(); duke@435: if (m->is_CatchProj()) m = m->in(0); else m = C->top(); duke@435: if (m->is_Catch()) m = m->in(0); else m = C->top(); duke@435: if (m->is_Proj()) m = m->in(0); else m = C->top(); duke@435: if (m->is_CallJava()) { duke@435: _call_info->set_call(m->as_Call()); duke@435: _call_info->set_hot_cg(_if_hot); duke@435: #ifndef PRODUCT duke@435: if (PrintOpto || PrintOptoInlining) { duke@435: tty->print_cr("Queueing for warm inlining at bci %d:", jvms->bci()); duke@435: tty->print("WCI: "); duke@435: _call_info->print(); duke@435: } duke@435: #endif duke@435: _call_info->set_heat(_call_info->compute_heat()); duke@435: C->set_warm_calls(_call_info->insert_into(C->warm_calls())); duke@435: } duke@435: } duke@435: return jvms; duke@435: } duke@435: duke@435: void WarmCallInfo::make_hot() { never@1515: Unimplemented(); duke@435: } duke@435: duke@435: void WarmCallInfo::make_cold() { duke@435: // No action: Just dequeue. duke@435: } duke@435: duke@435: duke@435: //------------------------PredictedCallGenerator------------------------------ duke@435: // Internal class which handles all out-of-line calls checking receiver type. duke@435: class PredictedCallGenerator : public CallGenerator { duke@435: ciKlass* _predicted_receiver; duke@435: CallGenerator* _if_missed; duke@435: CallGenerator* _if_hit; duke@435: float _hit_prob; duke@435: duke@435: public: duke@435: PredictedCallGenerator(ciKlass* predicted_receiver, duke@435: CallGenerator* if_missed, duke@435: CallGenerator* if_hit, float hit_prob) duke@435: : CallGenerator(if_missed->method()) duke@435: { duke@435: // The call profile data may predict the hit_prob as extreme as 0 or 1. duke@435: // Remove the extremes values from the range. duke@435: if (hit_prob > PROB_MAX) hit_prob = PROB_MAX; duke@435: if (hit_prob < PROB_MIN) hit_prob = PROB_MIN; duke@435: duke@435: _predicted_receiver = predicted_receiver; duke@435: _if_missed = if_missed; duke@435: _if_hit = if_hit; duke@435: _hit_prob = hit_prob; duke@435: } duke@435: duke@435: virtual bool is_virtual() const { return true; } duke@435: virtual bool is_inline() const { return _if_hit->is_inline(); } duke@435: virtual bool is_deferred() const { return _if_hit->is_deferred(); } duke@435: duke@435: virtual JVMState* generate(JVMState* jvms); duke@435: }; duke@435: duke@435: duke@435: CallGenerator* CallGenerator::for_predicted_call(ciKlass* predicted_receiver, duke@435: CallGenerator* if_missed, duke@435: CallGenerator* if_hit, duke@435: float hit_prob) { duke@435: return new PredictedCallGenerator(predicted_receiver, if_missed, if_hit, hit_prob); duke@435: } duke@435: duke@435: duke@435: JVMState* PredictedCallGenerator::generate(JVMState* jvms) { duke@435: GraphKit kit(jvms); duke@435: PhaseGVN& gvn = kit.gvn(); duke@435: // We need an explicit receiver null_check before checking its type. duke@435: // We share a map with the caller, so his JVMS gets adjusted. duke@435: Node* receiver = kit.argument(0); duke@435: duke@435: CompileLog* log = kit.C->log(); duke@435: if (log != NULL) { duke@435: log->elem("predicted_call bci='%d' klass='%d'", duke@435: jvms->bci(), log->identify(_predicted_receiver)); duke@435: } duke@435: duke@435: receiver = kit.null_check_receiver(method()); duke@435: if (kit.stopped()) { duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: duke@435: Node* exact_receiver = receiver; // will get updated in place... duke@435: Node* slow_ctl = kit.type_check_receiver(receiver, duke@435: _predicted_receiver, _hit_prob, duke@435: &exact_receiver); duke@435: duke@435: SafePointNode* slow_map = NULL; duke@435: JVMState* slow_jvms; duke@435: { PreserveJVMState pjvms(&kit); duke@435: kit.set_control(slow_ctl); duke@435: if (!kit.stopped()) { duke@435: slow_jvms = _if_missed->generate(kit.sync_jvms()); duke@435: assert(slow_jvms != NULL, "miss path must not fail to generate"); duke@435: kit.add_exception_states_from(slow_jvms); duke@435: kit.set_map(slow_jvms->map()); duke@435: if (!kit.stopped()) duke@435: slow_map = kit.stop(); duke@435: } duke@435: } duke@435: kvn@728: if (kit.stopped()) { kvn@728: // Instance exactly does not matches the desired type. kvn@728: kit.set_jvms(slow_jvms); kvn@728: return kit.transfer_exceptions_into_jvms(); kvn@728: } kvn@728: duke@435: // fall through if the instance exactly matches the desired type duke@435: kit.replace_in_map(receiver, exact_receiver); duke@435: duke@435: // Make the hot call: duke@435: JVMState* new_jvms = _if_hit->generate(kit.sync_jvms()); duke@435: if (new_jvms == NULL) { duke@435: // Inline failed, so make a direct call. duke@435: assert(_if_hit->is_inline(), "must have been a failed inline"); duke@435: CallGenerator* cg = CallGenerator::for_direct_call(_if_hit->method()); duke@435: new_jvms = cg->generate(kit.sync_jvms()); duke@435: } duke@435: kit.add_exception_states_from(new_jvms); duke@435: kit.set_jvms(new_jvms); duke@435: duke@435: // Need to merge slow and fast? duke@435: if (slow_map == NULL) { duke@435: // The fast path is the only path remaining. duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: duke@435: if (kit.stopped()) { duke@435: // Inlined method threw an exception, so it's just the slow path after all. duke@435: kit.set_jvms(slow_jvms); duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: duke@435: // Finish the diamond. duke@435: kit.C->set_has_split_ifs(true); // Has chance for split-if optimization duke@435: RegionNode* region = new (kit.C, 3) RegionNode(3); duke@435: region->init_req(1, kit.control()); duke@435: region->init_req(2, slow_map->control()); duke@435: kit.set_control(gvn.transform(region)); duke@435: Node* iophi = PhiNode::make(region, kit.i_o(), Type::ABIO); duke@435: iophi->set_req(2, slow_map->i_o()); duke@435: kit.set_i_o(gvn.transform(iophi)); duke@435: kit.merge_memory(slow_map->merged_memory(), region, 2); duke@435: uint tos = kit.jvms()->stkoff() + kit.sp(); duke@435: uint limit = slow_map->req(); duke@435: for (uint i = TypeFunc::Parms; i < limit; i++) { duke@435: // Skip unused stack slots; fast forward to monoff(); duke@435: if (i == tos) { duke@435: i = kit.jvms()->monoff(); duke@435: if( i >= limit ) break; duke@435: } duke@435: Node* m = kit.map()->in(i); duke@435: Node* n = slow_map->in(i); duke@435: if (m != n) { duke@435: const Type* t = gvn.type(m)->meet(gvn.type(n)); duke@435: Node* phi = PhiNode::make(region, m, t); duke@435: phi->set_req(2, n); duke@435: kit.map()->set_req(i, gvn.transform(phi)); duke@435: } duke@435: } duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: duke@435: duke@435: //-------------------------UncommonTrapCallGenerator----------------------------- duke@435: // Internal class which handles all out-of-line calls checking receiver type. duke@435: class UncommonTrapCallGenerator : public CallGenerator { duke@435: Deoptimization::DeoptReason _reason; duke@435: Deoptimization::DeoptAction _action; duke@435: duke@435: public: duke@435: UncommonTrapCallGenerator(ciMethod* m, duke@435: Deoptimization::DeoptReason reason, duke@435: Deoptimization::DeoptAction action) duke@435: : CallGenerator(m) duke@435: { duke@435: _reason = reason; duke@435: _action = action; duke@435: } duke@435: duke@435: virtual bool is_virtual() const { ShouldNotReachHere(); return false; } duke@435: virtual bool is_trap() const { return true; } duke@435: duke@435: virtual JVMState* generate(JVMState* jvms); duke@435: }; duke@435: duke@435: duke@435: CallGenerator* duke@435: CallGenerator::for_uncommon_trap(ciMethod* m, duke@435: Deoptimization::DeoptReason reason, duke@435: Deoptimization::DeoptAction action) { duke@435: return new UncommonTrapCallGenerator(m, reason, action); duke@435: } duke@435: duke@435: duke@435: JVMState* UncommonTrapCallGenerator::generate(JVMState* jvms) { duke@435: GraphKit kit(jvms); duke@435: // Take the trap with arguments pushed on the stack. (Cf. null_check_receiver). duke@435: int nargs = method()->arg_size(); duke@435: kit.inc_sp(nargs); duke@435: assert(nargs <= kit.sp() && kit.sp() <= jvms->stk_size(), "sane sp w/ args pushed"); duke@435: if (_reason == Deoptimization::Reason_class_check && duke@435: _action == Deoptimization::Action_maybe_recompile) { duke@435: // Temp fix for 6529811 duke@435: // Don't allow uncommon_trap to override our decision to recompile in the event duke@435: // of a class cast failure for a monomorphic call as it will never let us convert duke@435: // the call to either bi-morphic or megamorphic and can lead to unc-trap loops duke@435: bool keep_exact_action = true; duke@435: kit.uncommon_trap(_reason, _action, NULL, "monomorphic vcall checkcast", false, keep_exact_action); duke@435: } else { duke@435: kit.uncommon_trap(_reason, _action); duke@435: } duke@435: return kit.transfer_exceptions_into_jvms(); duke@435: } duke@435: duke@435: // (Note: Moved hook_up_call to GraphKit::set_edges_for_java_call.) duke@435: duke@435: // (Node: Merged hook_up_exits into ParseGenerator::generate.) duke@435: duke@435: #define NODES_OVERHEAD_PER_METHOD (30.0) duke@435: #define NODES_PER_BYTECODE (9.5) duke@435: duke@435: void WarmCallInfo::init(JVMState* call_site, ciMethod* call_method, ciCallProfile& profile, float prof_factor) { duke@435: int call_count = profile.count(); duke@435: int code_size = call_method->code_size(); duke@435: duke@435: // Expected execution count is based on the historical count: duke@435: _count = call_count < 0 ? 1 : call_site->method()->scale_count(call_count, prof_factor); duke@435: duke@435: // Expected profit from inlining, in units of simple call-overheads. duke@435: _profit = 1.0; duke@435: duke@435: // Expected work performed by the call in units of call-overheads. duke@435: // %%% need an empirical curve fit for "work" (time in call) duke@435: float bytecodes_per_call = 3; duke@435: _work = 1.0 + code_size / bytecodes_per_call; duke@435: duke@435: // Expected size of compilation graph: duke@435: // -XX:+PrintParseStatistics once reported: duke@435: // Methods seen: 9184 Methods parsed: 9184 Nodes created: 1582391 duke@435: // Histogram of 144298 parsed bytecodes: duke@435: // %%% Need an better predictor for graph size. duke@435: _size = NODES_OVERHEAD_PER_METHOD + (NODES_PER_BYTECODE * code_size); duke@435: } duke@435: duke@435: // is_cold: Return true if the node should never be inlined. duke@435: // This is true if any of the key metrics are extreme. duke@435: bool WarmCallInfo::is_cold() const { duke@435: if (count() < WarmCallMinCount) return true; duke@435: if (profit() < WarmCallMinProfit) return true; duke@435: if (work() > WarmCallMaxWork) return true; duke@435: if (size() > WarmCallMaxSize) return true; duke@435: return false; duke@435: } duke@435: duke@435: // is_hot: Return true if the node should be inlined immediately. duke@435: // This is true if any of the key metrics are extreme. duke@435: bool WarmCallInfo::is_hot() const { duke@435: assert(!is_cold(), "eliminate is_cold cases before testing is_hot"); duke@435: if (count() >= HotCallCountThreshold) return true; duke@435: if (profit() >= HotCallProfitThreshold) return true; duke@435: if (work() <= HotCallTrivialWork) return true; duke@435: if (size() <= HotCallTrivialSize) return true; duke@435: return false; duke@435: } duke@435: duke@435: // compute_heat: duke@435: float WarmCallInfo::compute_heat() const { duke@435: assert(!is_cold(), "compute heat only on warm nodes"); duke@435: assert(!is_hot(), "compute heat only on warm nodes"); duke@435: int min_size = MAX2(0, (int)HotCallTrivialSize); duke@435: int max_size = MIN2(500, (int)WarmCallMaxSize); duke@435: float method_size = (size() - min_size) / MAX2(1, max_size - min_size); duke@435: float size_factor; duke@435: if (method_size < 0.05) size_factor = 4; // 2 sigmas better than avg. duke@435: else if (method_size < 0.15) size_factor = 2; // 1 sigma better than avg. duke@435: else if (method_size < 0.5) size_factor = 1; // better than avg. duke@435: else size_factor = 0.5; // worse than avg. duke@435: return (count() * profit() * size_factor); duke@435: } duke@435: duke@435: bool WarmCallInfo::warmer_than(WarmCallInfo* that) { duke@435: assert(this != that, "compare only different WCIs"); duke@435: assert(this->heat() != 0 && that->heat() != 0, "call compute_heat 1st"); duke@435: if (this->heat() > that->heat()) return true; duke@435: if (this->heat() < that->heat()) return false; duke@435: assert(this->heat() == that->heat(), "no NaN heat allowed"); duke@435: // Equal heat. Break the tie some other way. duke@435: if (!this->call() || !that->call()) return (address)this > (address)that; duke@435: return this->call()->_idx > that->call()->_idx; duke@435: } duke@435: duke@435: //#define UNINIT_NEXT ((WarmCallInfo*)badAddress) duke@435: #define UNINIT_NEXT ((WarmCallInfo*)NULL) duke@435: duke@435: WarmCallInfo* WarmCallInfo::insert_into(WarmCallInfo* head) { duke@435: assert(next() == UNINIT_NEXT, "not yet on any list"); duke@435: WarmCallInfo* prev_p = NULL; duke@435: WarmCallInfo* next_p = head; duke@435: while (next_p != NULL && next_p->warmer_than(this)) { duke@435: prev_p = next_p; duke@435: next_p = prev_p->next(); duke@435: } duke@435: // Install this between prev_p and next_p. duke@435: this->set_next(next_p); duke@435: if (prev_p == NULL) duke@435: head = this; duke@435: else duke@435: prev_p->set_next(this); duke@435: return head; duke@435: } duke@435: duke@435: WarmCallInfo* WarmCallInfo::remove_from(WarmCallInfo* head) { duke@435: WarmCallInfo* prev_p = NULL; duke@435: WarmCallInfo* next_p = head; duke@435: while (next_p != this) { duke@435: assert(next_p != NULL, "this must be in the list somewhere"); duke@435: prev_p = next_p; duke@435: next_p = prev_p->next(); duke@435: } duke@435: next_p = this->next(); duke@435: debug_only(this->set_next(UNINIT_NEXT)); duke@435: // Remove this from between prev_p and next_p. duke@435: if (prev_p == NULL) duke@435: head = next_p; duke@435: else duke@435: prev_p->set_next(next_p); duke@435: return head; duke@435: } duke@435: duke@435: WarmCallInfo* WarmCallInfo::_always_hot = NULL; duke@435: WarmCallInfo* WarmCallInfo::_always_cold = NULL; duke@435: duke@435: WarmCallInfo* WarmCallInfo::always_hot() { duke@435: if (_always_hot == NULL) { duke@435: static double bits[sizeof(WarmCallInfo) / sizeof(double) + 1] = {0}; duke@435: WarmCallInfo* ci = (WarmCallInfo*) bits; duke@435: ci->_profit = ci->_count = MAX_VALUE(); duke@435: ci->_work = ci->_size = MIN_VALUE(); duke@435: _always_hot = ci; duke@435: } duke@435: assert(_always_hot->is_hot(), "must always be hot"); duke@435: return _always_hot; duke@435: } duke@435: duke@435: WarmCallInfo* WarmCallInfo::always_cold() { duke@435: if (_always_cold == NULL) { duke@435: static double bits[sizeof(WarmCallInfo) / sizeof(double) + 1] = {0}; duke@435: WarmCallInfo* ci = (WarmCallInfo*) bits; duke@435: ci->_profit = ci->_count = MIN_VALUE(); duke@435: ci->_work = ci->_size = MAX_VALUE(); duke@435: _always_cold = ci; duke@435: } duke@435: assert(_always_cold->is_cold(), "must always be cold"); duke@435: return _always_cold; duke@435: } duke@435: duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: void WarmCallInfo::print() const { duke@435: tty->print("%s : C=%6.1f P=%6.1f W=%6.1f S=%6.1f H=%6.1f -> %p", duke@435: is_cold() ? "cold" : is_hot() ? "hot " : "warm", duke@435: count(), profit(), work(), size(), compute_heat(), next()); duke@435: tty->cr(); duke@435: if (call() != NULL) call()->dump(); duke@435: } duke@435: duke@435: void print_wci(WarmCallInfo* ci) { duke@435: ci->print(); duke@435: } duke@435: duke@435: void WarmCallInfo::print_all() const { duke@435: for (const WarmCallInfo* p = this; p != NULL; p = p->next()) duke@435: p->print(); duke@435: } duke@435: duke@435: int WarmCallInfo::count_all() const { duke@435: int cnt = 0; duke@435: for (const WarmCallInfo* p = this; p != NULL; p = p->next()) duke@435: cnt++; duke@435: return cnt; duke@435: } duke@435: duke@435: #endif //PRODUCT