aoqi@0: /* aoqi@0: * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "classfile/systemDictionary.hpp" aoqi@0: #include "compiler/compileLog.hpp" aoqi@0: #include "oops/objArrayKlass.hpp" aoqi@0: #include "opto/addnode.hpp" aoqi@0: #include "opto/memnode.hpp" aoqi@0: #include "opto/mulnode.hpp" aoqi@0: #include "opto/parse.hpp" aoqi@0: #include "opto/rootnode.hpp" aoqi@0: #include "opto/runtime.hpp" aoqi@0: #include "runtime/sharedRuntime.hpp" aoqi@0: aoqi@0: //------------------------------make_dtrace_method_entry_exit ---------------- aoqi@0: // Dtrace -- record entry or exit of a method if compiled with dtrace support aoqi@0: void GraphKit::make_dtrace_method_entry_exit(ciMethod* method, bool is_entry) { aoqi@0: const TypeFunc *call_type = OptoRuntime::dtrace_method_entry_exit_Type(); aoqi@0: address call_address = is_entry ? CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry) : aoqi@0: CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit); aoqi@0: const char *call_name = is_entry ? "dtrace_method_entry" : "dtrace_method_exit"; aoqi@0: aoqi@0: // Get base of thread-local storage area aoqi@0: Node* thread = _gvn.transform( new (C) ThreadLocalNode() ); aoqi@0: aoqi@0: // Get method aoqi@0: const TypePtr* method_type = TypeMetadataPtr::make(method); aoqi@0: Node *method_node = _gvn.transform( ConNode::make(C, method_type) ); aoqi@0: aoqi@0: kill_dead_locals(); aoqi@0: aoqi@0: // For some reason, this call reads only raw memory. aoqi@0: const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; aoqi@0: make_runtime_call(RC_LEAF | RC_NARROW_MEM, aoqi@0: call_type, call_address, aoqi@0: call_name, raw_adr_type, aoqi@0: thread, method_node); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: //============================================================================= aoqi@0: //------------------------------do_checkcast----------------------------------- aoqi@0: void Parse::do_checkcast() { aoqi@0: bool will_link; aoqi@0: ciKlass* klass = iter().get_klass(will_link); aoqi@0: aoqi@0: Node *obj = peek(); aoqi@0: aoqi@0: // Throw uncommon trap if class is not loaded or the value we are casting aoqi@0: // _from_ is not loaded, and value is not null. If the value _is_ NULL, aoqi@0: // then the checkcast does nothing. aoqi@0: const TypeOopPtr *tp = _gvn.type(obj)->isa_oopptr(); aoqi@0: if (!will_link || (tp && tp->klass() && !tp->klass()->is_loaded())) { aoqi@0: if (C->log() != NULL) { aoqi@0: if (!will_link) { aoqi@0: C->log()->elem("assert_null reason='checkcast' klass='%d'", aoqi@0: C->log()->identify(klass)); aoqi@0: } aoqi@0: if (tp && tp->klass() && !tp->klass()->is_loaded()) { aoqi@0: // %%% Cannot happen? aoqi@0: C->log()->elem("assert_null reason='checkcast source' klass='%d'", aoqi@0: C->log()->identify(tp->klass())); aoqi@0: } aoqi@0: } aoqi@0: null_assert(obj); aoqi@0: assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" ); aoqi@0: if (!stopped()) { aoqi@0: profile_null_checkcast(); aoqi@0: } aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: Node *res = gen_checkcast(obj, makecon(TypeKlassPtr::make(klass)) ); aoqi@0: aoqi@0: // Pop from stack AFTER gen_checkcast because it can uncommon trap and aoqi@0: // the debug info has to be correct. aoqi@0: pop(); aoqi@0: push(res); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: //------------------------------do_instanceof---------------------------------- aoqi@0: void Parse::do_instanceof() { aoqi@0: if (stopped()) return; aoqi@0: // We would like to return false if class is not loaded, emitting a aoqi@0: // dependency, but Java requires instanceof to load its operand. aoqi@0: aoqi@0: // Throw uncommon trap if class is not loaded aoqi@0: bool will_link; aoqi@0: ciKlass* klass = iter().get_klass(will_link); aoqi@0: aoqi@0: if (!will_link) { aoqi@0: if (C->log() != NULL) { aoqi@0: C->log()->elem("assert_null reason='instanceof' klass='%d'", aoqi@0: C->log()->identify(klass)); aoqi@0: } aoqi@0: null_assert(peek()); aoqi@0: assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" ); aoqi@0: if (!stopped()) { aoqi@0: // The object is now known to be null. aoqi@0: // Shortcut the effect of gen_instanceof and return "false" directly. aoqi@0: pop(); // pop the null aoqi@0: push(_gvn.intcon(0)); // push false answer aoqi@0: } aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Push the bool result back on stack aoqi@0: Node* res = gen_instanceof(peek(), makecon(TypeKlassPtr::make(klass)), true); aoqi@0: aoqi@0: // Pop from stack AFTER gen_instanceof because it can uncommon trap. aoqi@0: pop(); aoqi@0: push(res); aoqi@0: } aoqi@0: aoqi@0: //------------------------------array_store_check------------------------------ aoqi@0: // pull array from stack and check that the store is valid aoqi@0: void Parse::array_store_check() { aoqi@0: aoqi@0: // Shorthand access to array store elements without popping them. aoqi@0: Node *obj = peek(0); aoqi@0: Node *idx = peek(1); aoqi@0: Node *ary = peek(2); aoqi@0: aoqi@0: if (_gvn.type(obj) == TypePtr::NULL_PTR) { aoqi@0: // There's never a type check on null values. aoqi@0: // This cutout lets us avoid the uncommon_trap(Reason_array_check) aoqi@0: // below, which turns into a performance liability if the aoqi@0: // gen_checkcast folds up completely. aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Extract the array klass type aoqi@0: int klass_offset = oopDesc::klass_offset_in_bytes(); aoqi@0: Node* p = basic_plus_adr( ary, ary, klass_offset ); aoqi@0: // p's type is array-of-OOPS plus klass_offset aoqi@0: Node* array_klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS) ); aoqi@0: // Get the array klass aoqi@0: const TypeKlassPtr *tak = _gvn.type(array_klass)->is_klassptr(); aoqi@0: aoqi@0: // array_klass's type is generally INexact array-of-oop. Heroically aoqi@0: // cast the array klass to EXACT array and uncommon-trap if the cast aoqi@0: // fails. aoqi@0: bool always_see_exact_class = false; aoqi@0: if (MonomorphicArrayCheck aoqi@0: && !too_many_traps(Deoptimization::Reason_array_check)) { aoqi@0: always_see_exact_class = true; aoqi@0: // (If no MDO at all, hope for the best, until a trap actually occurs.) aoqi@0: } aoqi@0: aoqi@0: // Is the array klass is exactly its defined type? aoqi@0: if (always_see_exact_class && !tak->klass_is_exact()) { aoqi@0: // Make a constant out of the inexact array klass aoqi@0: const TypeKlassPtr *extak = tak->cast_to_exactness(true)->is_klassptr(); aoqi@0: Node* con = makecon(extak); aoqi@0: Node* cmp = _gvn.transform(new (C) CmpPNode( array_klass, con )); aoqi@0: Node* bol = _gvn.transform(new (C) BoolNode( cmp, BoolTest::eq )); aoqi@0: Node* ctrl= control(); aoqi@0: { BuildCutout unless(this, bol, PROB_MAX); aoqi@0: uncommon_trap(Deoptimization::Reason_array_check, aoqi@0: Deoptimization::Action_maybe_recompile, aoqi@0: tak->klass()); aoqi@0: } aoqi@0: if (stopped()) { // MUST uncommon-trap? aoqi@0: set_control(ctrl); // Then Don't Do It, just fall into the normal checking aoqi@0: } else { // Cast array klass to exactness: aoqi@0: // Use the exact constant value we know it is. aoqi@0: replace_in_map(array_klass,con); aoqi@0: CompileLog* log = C->log(); aoqi@0: if (log != NULL) { aoqi@0: log->elem("cast_up reason='monomorphic_array' from='%d' to='(exact)'", aoqi@0: log->identify(tak->klass())); aoqi@0: } aoqi@0: array_klass = con; // Use cast value moving forward aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Come here for polymorphic array klasses aoqi@0: aoqi@0: // Extract the array element class aoqi@0: int element_klass_offset = in_bytes(ObjArrayKlass::element_klass_offset()); aoqi@0: Node *p2 = basic_plus_adr(array_klass, array_klass, element_klass_offset); aoqi@0: Node *a_e_klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p2, tak) ); aoqi@0: aoqi@0: // Check (the hard way) and throw if not a subklass. aoqi@0: // Result is ignored, we just need the CFG effects. aoqi@0: gen_checkcast( obj, a_e_klass ); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void Parse::emit_guard_for_new(ciInstanceKlass* klass) { aoqi@0: // Emit guarded new aoqi@0: // if (klass->_init_thread != current_thread || aoqi@0: // klass->_init_state != being_initialized) aoqi@0: // uncommon_trap aoqi@0: Node* cur_thread = _gvn.transform( new (C) ThreadLocalNode() ); aoqi@0: Node* merge = new (C) RegionNode(3); aoqi@0: _gvn.set_type(merge, Type::CONTROL); aoqi@0: Node* kls = makecon(TypeKlassPtr::make(klass)); aoqi@0: aoqi@0: Node* init_thread_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_thread_offset())); aoqi@0: Node* adr_node = basic_plus_adr(kls, kls, init_thread_offset); aoqi@0: Node* init_thread = make_load(NULL, adr_node, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered); aoqi@0: Node *tst = Bool( CmpP( init_thread, cur_thread), BoolTest::eq); aoqi@0: IfNode* iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN); aoqi@0: set_control(IfTrue(iff)); aoqi@0: merge->set_req(1, IfFalse(iff)); aoqi@0: aoqi@0: Node* init_state_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_state_offset())); aoqi@0: adr_node = basic_plus_adr(kls, kls, init_state_offset); aoqi@0: // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler aoqi@0: // can generate code to load it as unsigned byte. aoqi@0: Node* init_state = make_load(NULL, adr_node, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered); aoqi@0: Node* being_init = _gvn.intcon(InstanceKlass::being_initialized); aoqi@0: tst = Bool( CmpI( init_state, being_init), BoolTest::eq); aoqi@0: iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN); aoqi@0: set_control(IfTrue(iff)); aoqi@0: merge->set_req(2, IfFalse(iff)); aoqi@0: aoqi@0: PreserveJVMState pjvms(this); aoqi@0: record_for_igvn(merge); aoqi@0: set_control(merge); aoqi@0: aoqi@0: uncommon_trap(Deoptimization::Reason_uninitialized, aoqi@0: Deoptimization::Action_reinterpret, aoqi@0: klass); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: //------------------------------do_new----------------------------------------- aoqi@0: void Parse::do_new() { aoqi@0: kill_dead_locals(); aoqi@0: aoqi@0: bool will_link; aoqi@0: ciInstanceKlass* klass = iter().get_klass(will_link)->as_instance_klass(); aoqi@0: assert(will_link, "_new: typeflow responsibility"); aoqi@0: aoqi@0: // Should initialize, or throw an InstantiationError? aoqi@0: if (!klass->is_initialized() && !klass->is_being_initialized() || aoqi@0: klass->is_abstract() || klass->is_interface() || aoqi@0: klass->name() == ciSymbol::java_lang_Class() || aoqi@0: iter().is_unresolved_klass()) { aoqi@0: uncommon_trap(Deoptimization::Reason_uninitialized, aoqi@0: Deoptimization::Action_reinterpret, aoqi@0: klass); aoqi@0: return; aoqi@0: } aoqi@0: if (klass->is_being_initialized()) { aoqi@0: emit_guard_for_new(klass); aoqi@0: } aoqi@0: aoqi@0: Node* kls = makecon(TypeKlassPtr::make(klass)); aoqi@0: Node* obj = new_instance(kls); aoqi@0: aoqi@0: // Push resultant oop onto stack aoqi@0: push(obj); aoqi@0: aoqi@0: // Keep track of whether opportunities exist for StringBuilder aoqi@0: // optimizations. aoqi@0: if (OptimizeStringConcat && aoqi@0: (klass == C->env()->StringBuilder_klass() || aoqi@0: klass == C->env()->StringBuffer_klass())) { aoqi@0: C->set_has_stringbuilder(true); aoqi@0: } aoqi@0: aoqi@0: // Keep track of boxed values for EliminateAutoBox optimizations. aoqi@0: if (C->eliminate_boxing() && klass->is_box_klass()) { aoqi@0: C->set_has_boxed_value(true); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: //------------------------------dump_map_adr_mem------------------------------- aoqi@0: // Debug dump of the mapping from address types to MergeMemNode indices. aoqi@0: void Parse::dump_map_adr_mem() const { aoqi@0: tty->print_cr("--- Mapping from address types to memory Nodes ---"); aoqi@0: MergeMemNode *mem = map() == NULL ? NULL : (map()->memory()->is_MergeMem() ? aoqi@0: map()->memory()->as_MergeMem() : NULL); aoqi@0: for (uint i = 0; i < (uint)C->num_alias_types(); i++) { aoqi@0: C->alias_type(i)->print_on(tty); aoqi@0: tty->print("\t"); aoqi@0: // Node mapping, if any aoqi@0: if (mem && i < mem->req() && mem->in(i) && mem->in(i) != mem->empty_memory()) { aoqi@0: mem->in(i)->dump(); aoqi@0: } else { aoqi@0: tty->cr(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: #endif aoqi@0: aoqi@0: aoqi@0: //============================================================================= aoqi@0: // aoqi@0: // parser methods for profiling aoqi@0: aoqi@0: aoqi@0: //----------------------test_counter_against_threshold ------------------------ aoqi@0: void Parse::test_counter_against_threshold(Node* cnt, int limit) { aoqi@0: // Test the counter against the limit and uncommon trap if greater. aoqi@0: aoqi@0: // This code is largely copied from the range check code in aoqi@0: // array_addressing() aoqi@0: aoqi@0: // Test invocation count vs threshold aoqi@0: Node *threshold = makecon(TypeInt::make(limit)); aoqi@0: Node *chk = _gvn.transform( new (C) CmpUNode( cnt, threshold) ); aoqi@0: BoolTest::mask btest = BoolTest::lt; aoqi@0: Node *tst = _gvn.transform( new (C) BoolNode( chk, btest) ); aoqi@0: // Branch to failure if threshold exceeded aoqi@0: { BuildCutout unless(this, tst, PROB_ALWAYS); aoqi@0: uncommon_trap(Deoptimization::Reason_age, aoqi@0: Deoptimization::Action_maybe_recompile); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: //----------------------increment_and_test_invocation_counter------------------- aoqi@0: void Parse::increment_and_test_invocation_counter(int limit) { aoqi@0: if (!count_invocations()) return; aoqi@0: aoqi@0: // Get the Method* node. aoqi@0: ciMethod* m = method(); aoqi@0: MethodCounters* counters_adr = m->ensure_method_counters(); aoqi@0: if (counters_adr == NULL) { aoqi@0: C->record_failure("method counters allocation failed"); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: Node* ctrl = control(); aoqi@0: const TypePtr* adr_type = TypeRawPtr::make((address) counters_adr); aoqi@0: Node *counters_node = makecon(adr_type); aoqi@0: Node* adr_iic_node = basic_plus_adr(counters_node, counters_node, aoqi@0: MethodCounters::interpreter_invocation_counter_offset_in_bytes()); aoqi@0: Node* cnt = make_load(ctrl, adr_iic_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered); aoqi@0: aoqi@0: test_counter_against_threshold(cnt, limit); aoqi@0: aoqi@0: // Add one to the counter and store aoqi@0: Node* incr = _gvn.transform(new (C) AddINode(cnt, _gvn.intcon(1))); aoqi@0: store_to_memory(ctrl, adr_iic_node, incr, T_INT, adr_type, MemNode::unordered); aoqi@0: } aoqi@0: aoqi@0: //----------------------------method_data_addressing--------------------------- aoqi@0: Node* Parse::method_data_addressing(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) { aoqi@0: // Get offset within MethodData* of the data array aoqi@0: ByteSize data_offset = MethodData::data_offset(); aoqi@0: aoqi@0: // Get cell offset of the ProfileData within data array aoqi@0: int cell_offset = md->dp_to_di(data->dp()); aoqi@0: aoqi@0: // Add in counter_offset, the # of bytes into the ProfileData of counter or flag aoqi@0: int offset = in_bytes(data_offset) + cell_offset + in_bytes(counter_offset); aoqi@0: aoqi@0: const TypePtr* adr_type = TypeMetadataPtr::make(md); aoqi@0: Node* mdo = makecon(adr_type); aoqi@0: Node* ptr = basic_plus_adr(mdo, mdo, offset); aoqi@0: aoqi@0: if (stride != 0) { aoqi@0: Node* str = _gvn.MakeConX(stride); aoqi@0: Node* scale = _gvn.transform( new (C) MulXNode( idx, str ) ); aoqi@0: ptr = _gvn.transform( new (C) AddPNode( mdo, ptr, scale ) ); aoqi@0: } aoqi@0: aoqi@0: return ptr; aoqi@0: } aoqi@0: aoqi@0: //--------------------------increment_md_counter_at---------------------------- aoqi@0: void Parse::increment_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) { aoqi@0: Node* adr_node = method_data_addressing(md, data, counter_offset, idx, stride); aoqi@0: aoqi@0: const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr(); aoqi@0: Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered); aoqi@0: Node* incr = _gvn.transform(new (C) AddINode(cnt, _gvn.intcon(DataLayout::counter_increment))); aoqi@0: store_to_memory(NULL, adr_node, incr, T_INT, adr_type, MemNode::unordered); aoqi@0: } aoqi@0: aoqi@0: //--------------------------test_for_osr_md_counter_at------------------------- aoqi@0: void Parse::test_for_osr_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, int limit) { aoqi@0: Node* adr_node = method_data_addressing(md, data, counter_offset); aoqi@0: aoqi@0: const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr(); aoqi@0: Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered); aoqi@0: aoqi@0: test_counter_against_threshold(cnt, limit); aoqi@0: } aoqi@0: aoqi@0: //-------------------------------set_md_flag_at-------------------------------- aoqi@0: void Parse::set_md_flag_at(ciMethodData* md, ciProfileData* data, int flag_constant) { aoqi@0: Node* adr_node = method_data_addressing(md, data, DataLayout::flags_offset()); aoqi@0: aoqi@0: const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr(); aoqi@0: Node* flags = make_load(NULL, adr_node, TypeInt::BYTE, T_BYTE, adr_type, MemNode::unordered); aoqi@0: Node* incr = _gvn.transform(new (C) OrINode(flags, _gvn.intcon(flag_constant))); aoqi@0: store_to_memory(NULL, adr_node, incr, T_BYTE, adr_type, MemNode::unordered); aoqi@0: } aoqi@0: aoqi@0: //----------------------------profile_taken_branch----------------------------- aoqi@0: void Parse::profile_taken_branch(int target_bci, bool force_update) { aoqi@0: // This is a potential osr_site if we have a backedge. aoqi@0: int cur_bci = bci(); aoqi@0: bool osr_site = aoqi@0: (target_bci <= cur_bci) && count_invocations() && UseOnStackReplacement; aoqi@0: aoqi@0: // If we are going to OSR, restart at the target bytecode. aoqi@0: set_bci(target_bci); aoqi@0: aoqi@0: // To do: factor out the the limit calculations below. These duplicate aoqi@0: // the similar limit calculations in the interpreter. aoqi@0: aoqi@0: if (method_data_update() || force_update) { aoqi@0: ciMethodData* md = method()->method_data(); aoqi@0: assert(md != NULL, "expected valid ciMethodData"); aoqi@0: ciProfileData* data = md->bci_to_data(cur_bci); aoqi@0: assert(data->is_JumpData(), "need JumpData for taken branch"); aoqi@0: increment_md_counter_at(md, data, JumpData::taken_offset()); aoqi@0: } aoqi@0: aoqi@0: // In the new tiered system this is all we need to do. In the old aoqi@0: // (c2 based) tiered sytem we must do the code below. aoqi@0: #ifndef TIERED aoqi@0: if (method_data_update()) { aoqi@0: ciMethodData* md = method()->method_data(); aoqi@0: if (osr_site) { aoqi@0: ciProfileData* data = md->bci_to_data(cur_bci); aoqi@0: int limit = (CompileThreshold aoqi@0: * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100; aoqi@0: test_for_osr_md_counter_at(md, data, JumpData::taken_offset(), limit); aoqi@0: } aoqi@0: } else { aoqi@0: // With method data update off, use the invocation counter to trigger an aoqi@0: // OSR compilation, as done in the interpreter. aoqi@0: if (osr_site) { aoqi@0: int limit = (CompileThreshold * OnStackReplacePercentage) / 100; aoqi@0: increment_and_test_invocation_counter(limit); aoqi@0: } aoqi@0: } aoqi@0: #endif // TIERED aoqi@0: aoqi@0: // Restore the original bytecode. aoqi@0: set_bci(cur_bci); aoqi@0: } aoqi@0: aoqi@0: //--------------------------profile_not_taken_branch--------------------------- aoqi@0: void Parse::profile_not_taken_branch(bool force_update) { aoqi@0: aoqi@0: if (method_data_update() || force_update) { aoqi@0: ciMethodData* md = method()->method_data(); aoqi@0: assert(md != NULL, "expected valid ciMethodData"); aoqi@0: ciProfileData* data = md->bci_to_data(bci()); aoqi@0: assert(data->is_BranchData(), "need BranchData for not taken branch"); aoqi@0: increment_md_counter_at(md, data, BranchData::not_taken_offset()); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: //---------------------------------profile_call-------------------------------- aoqi@0: void Parse::profile_call(Node* receiver) { aoqi@0: if (!method_data_update()) return; aoqi@0: aoqi@0: switch (bc()) { aoqi@0: case Bytecodes::_invokevirtual: aoqi@0: case Bytecodes::_invokeinterface: aoqi@0: profile_receiver_type(receiver); aoqi@0: break; aoqi@0: case Bytecodes::_invokestatic: aoqi@0: case Bytecodes::_invokedynamic: aoqi@0: case Bytecodes::_invokespecial: aoqi@0: profile_generic_call(); aoqi@0: break; aoqi@0: default: fatal("unexpected call bytecode"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: //------------------------------profile_generic_call--------------------------- aoqi@0: void Parse::profile_generic_call() { aoqi@0: assert(method_data_update(), "must be generating profile code"); aoqi@0: aoqi@0: ciMethodData* md = method()->method_data(); aoqi@0: assert(md != NULL, "expected valid ciMethodData"); aoqi@0: ciProfileData* data = md->bci_to_data(bci()); aoqi@0: assert(data->is_CounterData(), "need CounterData for not taken branch"); aoqi@0: increment_md_counter_at(md, data, CounterData::count_offset()); aoqi@0: } aoqi@0: aoqi@0: //-----------------------------profile_receiver_type--------------------------- aoqi@0: void Parse::profile_receiver_type(Node* receiver) { aoqi@0: assert(method_data_update(), "must be generating profile code"); aoqi@0: aoqi@0: ciMethodData* md = method()->method_data(); aoqi@0: assert(md != NULL, "expected valid ciMethodData"); aoqi@0: ciProfileData* data = md->bci_to_data(bci()); aoqi@0: assert(data->is_ReceiverTypeData(), "need ReceiverTypeData here"); aoqi@0: aoqi@0: // Skip if we aren't tracking receivers aoqi@0: if (TypeProfileWidth < 1) { aoqi@0: increment_md_counter_at(md, data, CounterData::count_offset()); aoqi@0: return; aoqi@0: } aoqi@0: ciReceiverTypeData* rdata = (ciReceiverTypeData*)data->as_ReceiverTypeData(); aoqi@0: aoqi@0: Node* method_data = method_data_addressing(md, rdata, in_ByteSize(0)); aoqi@0: aoqi@0: // Using an adr_type of TypePtr::BOTTOM to work around anti-dep problems. aoqi@0: // A better solution might be to use TypeRawPtr::BOTTOM with RC_NARROW_MEM. aoqi@0: make_runtime_call(RC_LEAF, OptoRuntime::profile_receiver_type_Type(), aoqi@0: CAST_FROM_FN_PTR(address, aoqi@0: OptoRuntime::profile_receiver_type_C), aoqi@0: "profile_receiver_type_C", aoqi@0: TypePtr::BOTTOM, aoqi@0: method_data, receiver); aoqi@0: } aoqi@0: aoqi@0: //---------------------------------profile_ret--------------------------------- aoqi@0: void Parse::profile_ret(int target_bci) { aoqi@0: if (!method_data_update()) return; aoqi@0: aoqi@0: // Skip if we aren't tracking ret targets aoqi@0: if (TypeProfileWidth < 1) return; aoqi@0: aoqi@0: ciMethodData* md = method()->method_data(); aoqi@0: assert(md != NULL, "expected valid ciMethodData"); aoqi@0: ciProfileData* data = md->bci_to_data(bci()); aoqi@0: assert(data->is_RetData(), "need RetData for ret"); aoqi@0: ciRetData* ret_data = (ciRetData*)data->as_RetData(); aoqi@0: aoqi@0: // Look for the target_bci is already in the table aoqi@0: uint row; aoqi@0: bool table_full = true; aoqi@0: for (row = 0; row < ret_data->row_limit(); row++) { aoqi@0: int key = ret_data->bci(row); aoqi@0: table_full &= (key != RetData::no_bci); aoqi@0: if (key == target_bci) break; aoqi@0: } aoqi@0: aoqi@0: if (row >= ret_data->row_limit()) { aoqi@0: // The target_bci was not found in the table. aoqi@0: if (!table_full) { aoqi@0: // XXX: Make slow call to update RetData aoqi@0: } aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // the target_bci is already in the table aoqi@0: increment_md_counter_at(md, data, RetData::bci_count_offset(row)); aoqi@0: } aoqi@0: aoqi@0: //--------------------------profile_null_checkcast---------------------------- aoqi@0: void Parse::profile_null_checkcast() { aoqi@0: // Set the null-seen flag, done in conjunction with the usual null check. We aoqi@0: // never unset the flag, so this is a one-way switch. aoqi@0: if (!method_data_update()) return; aoqi@0: aoqi@0: ciMethodData* md = method()->method_data(); aoqi@0: assert(md != NULL, "expected valid ciMethodData"); aoqi@0: ciProfileData* data = md->bci_to_data(bci()); aoqi@0: assert(data->is_BitData(), "need BitData for checkcast"); aoqi@0: set_md_flag_at(md, data, BitData::null_seen_byte_constant()); aoqi@0: } aoqi@0: aoqi@0: //-----------------------------profile_switch_case----------------------------- aoqi@0: void Parse::profile_switch_case(int table_index) { aoqi@0: if (!method_data_update()) return; aoqi@0: aoqi@0: ciMethodData* md = method()->method_data(); aoqi@0: assert(md != NULL, "expected valid ciMethodData"); aoqi@0: aoqi@0: ciProfileData* data = md->bci_to_data(bci()); aoqi@0: assert(data->is_MultiBranchData(), "need MultiBranchData for switch case"); aoqi@0: if (table_index >= 0) { aoqi@0: increment_md_counter_at(md, data, MultiBranchData::case_count_offset(table_index)); aoqi@0: } else { aoqi@0: increment_md_counter_at(md, data, MultiBranchData::default_count_offset()); aoqi@0: } aoqi@0: }