aoqi@0: /* aoqi@0: * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * Copyright 2012, 2013 SAP AG. 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: // This file defines a set of macros which are used by the c++-interpreter aoqi@0: // for updating a method's methodData object. aoqi@0: aoqi@0: aoqi@0: #ifndef SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP aoqi@0: #define SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP aoqi@0: aoqi@0: aoqi@0: // Global settings ///////////////////////////////////////////////////////////// aoqi@0: aoqi@0: aoqi@0: // Enables profiling support. aoqi@0: #if defined(COMPILER2) aoqi@0: #define CC_INTERP_PROFILE aoqi@0: #endif aoqi@0: aoqi@0: // Enables assertions for profiling code (also works in product-builds). aoqi@0: // #define CC_INTERP_PROFILE_WITH_ASSERTIONS aoqi@0: aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: aoqi@0: // Empty dummy implementations if profiling code is switched off. ////////////// aoqi@0: aoqi@0: #ifndef CC_INTERP_PROFILE aoqi@0: aoqi@0: #define SET_MDX(mdx) aoqi@0: aoqi@0: #define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler) \ aoqi@0: if (ProfileInterpreter) { \ aoqi@0: ShouldNotReachHere(); \ aoqi@0: } aoqi@0: aoqi@0: #define BI_PROFILE_ALIGN_TO_CURRENT_BCI() aoqi@0: aoqi@0: #define BI_PROFILE_UPDATE_JUMP() aoqi@0: #define BI_PROFILE_UPDATE_BRANCH(is_taken) aoqi@0: #define BI_PROFILE_UPDATE_RET(bci) aoqi@0: #define BI_PROFILE_SUBTYPECHECK_FAILED(receiver) aoqi@0: #define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver) aoqi@0: #define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver) aoqi@0: #define BI_PROFILE_UPDATE_CALL() aoqi@0: #define BI_PROFILE_UPDATE_FINALCALL() aoqi@0: #define BI_PROFILE_UPDATE_VIRTUALCALL(receiver) aoqi@0: #define BI_PROFILE_UPDATE_SWITCH(switch_index) aoqi@0: aoqi@0: aoqi@0: #else aoqi@0: aoqi@0: aoqi@0: // Non-dummy implementations /////////////////////////////////////////////////// aoqi@0: aoqi@0: // Accessors for the current method data pointer 'mdx'. aoqi@0: #define MDX() (istate->mdx()) aoqi@0: #define SET_MDX(mdx) \ aoqi@0: if (TraceProfileInterpreter) { \ aoqi@0: /* Let it look like TraceBytecodes' format. */ \ aoqi@0: tty->print_cr("[%d] %4d " \ aoqi@0: "mdx " PTR_FORMAT "(%d)" \ aoqi@0: " " \ aoqi@0: " \t-> " PTR_FORMAT "(%d)", \ aoqi@0: (int) THREAD->osthread()->thread_id(), \ aoqi@0: BCI(), \ aoqi@0: MDX(), \ aoqi@0: (MDX() == NULL \ aoqi@0: ? 0 \ aoqi@0: : istate->method()->method_data()->dp_to_di((address)MDX())), \ aoqi@0: mdx, \ aoqi@0: istate->method()->method_data()->dp_to_di((address)mdx) \ aoqi@0: ); \ aoqi@0: }; \ aoqi@0: istate->set_mdx(mdx); aoqi@0: aoqi@0: aoqi@0: // Dumps the profiling method data for the current method. aoqi@0: #ifdef PRODUCT aoqi@0: #define BI_PROFILE_PRINT_METHOD_DATA() aoqi@0: #else // PRODUCT aoqi@0: #define BI_PROFILE_PRINT_METHOD_DATA() \ aoqi@0: { \ aoqi@0: ttyLocker ttyl; \ aoqi@0: MethodData *md = istate->method()->method_data(); \ aoqi@0: tty->cr(); \ aoqi@0: tty->print("method data at mdx " PTR_FORMAT "(0) for", \ aoqi@0: md->data_layout_at(md->bci_to_di(0))); \ aoqi@0: istate->method()->print_short_name(tty); \ aoqi@0: tty->cr(); \ aoqi@0: if (md != NULL) { \ aoqi@0: md->print_data_on(tty); \ aoqi@0: address mdx = (address) MDX(); \ aoqi@0: if (mdx != NULL) { \ aoqi@0: tty->print_cr("current mdx " PTR_FORMAT "(%d)", \ aoqi@0: mdx, \ aoqi@0: istate->method()->method_data()->dp_to_di(mdx)); \ aoqi@0: } \ aoqi@0: } else { \ aoqi@0: tty->print_cr("no method data"); \ aoqi@0: } \ aoqi@0: } aoqi@0: #endif // PRODUCT aoqi@0: aoqi@0: aoqi@0: // Gets or creates the profiling method data and initializes mdx. aoqi@0: #define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler) \ aoqi@0: if (ProfileInterpreter && MDX() == NULL) { \ aoqi@0: /* Mdx is not yet initialized for this activation. */ \ aoqi@0: MethodData *md = istate->method()->method_data(); \ aoqi@0: if (md == NULL) { \ aoqi@0: MethodCounters* mcs; \ aoqi@0: GET_METHOD_COUNTERS(mcs); \ aoqi@0: /* The profiling method data doesn't exist for this method, */ \ aoqi@0: /* create it if the counters have overflowed. */ \ aoqi@0: if (mcs->invocation_counter() \ aoqi@0: ->reached_ProfileLimit(mcs->backedge_counter())) { \ aoqi@0: /* Must use CALL_VM, because an async exception may be pending. */ \ aoqi@0: CALL_VM((InterpreterRuntime::profile_method(THREAD)), \ aoqi@0: exception_handler); \ aoqi@0: md = istate->method()->method_data(); \ aoqi@0: if (md != NULL) { \ aoqi@0: if (TraceProfileInterpreter) { \ aoqi@0: BI_PROFILE_PRINT_METHOD_DATA(); \ aoqi@0: } \ aoqi@0: Method *m = istate->method(); \ aoqi@0: int bci = m->bci_from(pc); \ aoqi@0: jint di = md->bci_to_di(bci); \ aoqi@0: SET_MDX(md->data_layout_at(di)); \ aoqi@0: } \ aoqi@0: } \ aoqi@0: } else { \ aoqi@0: /* The profiling method data exists, align the method data pointer */ \ aoqi@0: /* mdx to the current bytecode index. */ \ aoqi@0: if (TraceProfileInterpreter) { \ aoqi@0: BI_PROFILE_PRINT_METHOD_DATA(); \ aoqi@0: } \ aoqi@0: SET_MDX(md->data_layout_at(md->bci_to_di(BCI()))); \ aoqi@0: } \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Asserts that the current method data pointer mdx corresponds aoqi@0: // to the current bytecode. aoqi@0: #if defined(CC_INTERP_PROFILE_WITH_ASSERTIONS) aoqi@0: #define BI_PROFILE_CHECK_MDX() \ aoqi@0: { \ aoqi@0: MethodData *md = istate->method()->method_data(); \ aoqi@0: address mdx = (address) MDX(); \ aoqi@0: address mdx2 = (address) md->data_layout_at(md->bci_to_di(BCI())); \ aoqi@0: guarantee(md != NULL, "1"); \ aoqi@0: guarantee(mdx != NULL, "2"); \ aoqi@0: guarantee(mdx2 != NULL, "3"); \ aoqi@0: if (mdx != mdx2) { \ aoqi@0: BI_PROFILE_PRINT_METHOD_DATA(); \ aoqi@0: fatal3("invalid mdx at bci %d:" \ aoqi@0: " was " PTR_FORMAT \ aoqi@0: " but expected " PTR_FORMAT, \ aoqi@0: BCI(), \ aoqi@0: mdx, \ aoqi@0: mdx2); \ aoqi@0: } \ aoqi@0: } aoqi@0: #else aoqi@0: #define BI_PROFILE_CHECK_MDX() aoqi@0: #endif aoqi@0: aoqi@0: aoqi@0: // Aligns the method data pointer mdx to the current bytecode index. aoqi@0: #define BI_PROFILE_ALIGN_TO_CURRENT_BCI() \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: MethodData *md = istate->method()->method_data(); \ aoqi@0: SET_MDX(md->data_layout_at(md->bci_to_di(BCI()))); \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Updates profiling data for a jump. aoqi@0: #define BI_PROFILE_UPDATE_JUMP() \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: BI_PROFILE_CHECK_MDX(); \ aoqi@0: JumpData::increment_taken_count_no_overflow(MDX()); \ aoqi@0: /* Remember last branch taken count. */ \ aoqi@0: mdo_last_branch_taken_count = JumpData::taken_count(MDX()); \ aoqi@0: SET_MDX(JumpData::advance_taken(MDX())); \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Updates profiling data for a taken/not taken branch. aoqi@0: #define BI_PROFILE_UPDATE_BRANCH(is_taken) \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: BI_PROFILE_CHECK_MDX(); \ aoqi@0: if (is_taken) { \ aoqi@0: BranchData::increment_taken_count_no_overflow(MDX()); \ aoqi@0: /* Remember last branch taken count. */ \ aoqi@0: mdo_last_branch_taken_count = BranchData::taken_count(MDX()); \ aoqi@0: SET_MDX(BranchData::advance_taken(MDX())); \ aoqi@0: } else { \ aoqi@0: BranchData::increment_not_taken_count_no_overflow(MDX()); \ aoqi@0: SET_MDX(BranchData::advance_not_taken(MDX())); \ aoqi@0: } \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Updates profiling data for a ret with given bci. aoqi@0: #define BI_PROFILE_UPDATE_RET(bci) \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: BI_PROFILE_CHECK_MDX(); \ aoqi@0: MethodData *md = istate->method()->method_data(); \ aoqi@0: /* FIXME: there is more to do here than increment and advance(mdx)! */ \ aoqi@0: CounterData::increment_count_no_overflow(MDX()); \ aoqi@0: SET_MDX(RetData::advance(md, bci)); \ aoqi@0: } aoqi@0: aoqi@0: // Decrement counter at checkcast if the subtype check fails (as template aoqi@0: // interpreter does!). aoqi@0: #define BI_PROFILE_SUBTYPECHECK_FAILED(receiver) \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: BI_PROFILE_CHECK_MDX(); \ aoqi@0: ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver); \ aoqi@0: ReceiverTypeData::decrement_count(MDX()); \ aoqi@0: } aoqi@0: aoqi@0: // Updates profiling data for a checkcast (was a null seen? which receiver?). aoqi@0: #define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver) \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: BI_PROFILE_CHECK_MDX(); \ aoqi@0: if (null_seen) { \ aoqi@0: ReceiverTypeData::set_null_seen(MDX()); \ aoqi@0: } else { \ aoqi@0: /* Template interpreter doesn't increment count. */ \ aoqi@0: /* ReceiverTypeData::increment_count_no_overflow(MDX()); */ \ aoqi@0: ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver); \ aoqi@0: } \ aoqi@0: SET_MDX(ReceiverTypeData::advance(MDX())); \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Updates profiling data for an instanceof (was a null seen? which receiver?). aoqi@0: #define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver) \ aoqi@0: BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver) aoqi@0: aoqi@0: aoqi@0: // Updates profiling data for a call. aoqi@0: #define BI_PROFILE_UPDATE_CALL() \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: BI_PROFILE_CHECK_MDX(); \ aoqi@0: CounterData::increment_count_no_overflow(MDX()); \ aoqi@0: SET_MDX(CounterData::advance(MDX())); \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Updates profiling data for a final call. aoqi@0: #define BI_PROFILE_UPDATE_FINALCALL() \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: BI_PROFILE_CHECK_MDX(); \ aoqi@0: VirtualCallData::increment_count_no_overflow(MDX()); \ aoqi@0: SET_MDX(VirtualCallData::advance(MDX())); \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Updates profiling data for a virtual call with given receiver Klass. aoqi@0: #define BI_PROFILE_UPDATE_VIRTUALCALL(receiver) \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: BI_PROFILE_CHECK_MDX(); \ aoqi@0: VirtualCallData::increment_receiver_count_no_overflow(MDX(), receiver); \ aoqi@0: SET_MDX(VirtualCallData::advance(MDX())); \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Updates profiling data for a switch (tabelswitch or lookupswitch) with aoqi@0: // given taken index (-1 means default case was taken). aoqi@0: #define BI_PROFILE_UPDATE_SWITCH(switch_index) \ aoqi@0: if (ProfileInterpreter && MDX() != NULL) { \ aoqi@0: BI_PROFILE_CHECK_MDX(); \ aoqi@0: MultiBranchData::increment_count_no_overflow(MDX(), switch_index); \ aoqi@0: SET_MDX(MultiBranchData::advance(MDX(), switch_index)); \ aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // The end ///////////////////////////////////////////////////////////////////// aoqi@0: aoqi@0: #endif // CC_INTERP_PROFILE aoqi@0: aoqi@0: #endif // CC_INTERP aoqi@0: aoqi@0: #endif // SHARE_VM_INTERPRETER_BYTECODECINTERPRETERPROFILING_HPP