Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/interpreter/bytecodeInterpreterProfiling.hpp
32285 views
/*1* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.2* Copyright 2012, 2014 SAP AG. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425// This file defines a set of macros which are used by the c++-interpreter26// for updating a method's methodData object.272829#ifndef SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP30#define SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP313233// Global settings /////////////////////////////////////////////////////////////343536// Enables profiling support.37#if defined(COMPILER2)38#define CC_INTERP_PROFILE39#endif4041// Enables assertions for profiling code (also works in product-builds).42// #define CC_INTERP_PROFILE_WITH_ASSERTIONS434445#ifdef CC_INTERP4647// Empty dummy implementations if profiling code is switched off. //////////////4849#ifndef CC_INTERP_PROFILE5051#define SET_MDX(mdx)5253#define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler) \54if (ProfileInterpreter) { \55ShouldNotReachHere(); \56}5758#define BI_PROFILE_ALIGN_TO_CURRENT_BCI()5960#define BI_PROFILE_UPDATE_JUMP()61#define BI_PROFILE_UPDATE_BRANCH(is_taken)62#define BI_PROFILE_UPDATE_RET(bci)63#define BI_PROFILE_SUBTYPECHECK_FAILED(receiver)64#define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver)65#define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver)66#define BI_PROFILE_UPDATE_CALL()67#define BI_PROFILE_UPDATE_FINALCALL()68#define BI_PROFILE_UPDATE_VIRTUALCALL(receiver)69#define BI_PROFILE_UPDATE_SWITCH(switch_index)707172#else737475// Non-dummy implementations ///////////////////////////////////////////////////7677// Accessors for the current method data pointer 'mdx'.78#define MDX() (istate->mdx())79#define SET_MDX(mdx) \80if (TraceProfileInterpreter) { \81/* Let it look like TraceBytecodes' format. */ \82tty->print_cr("[%d] %4d " \83"mdx " PTR_FORMAT "(%d)" \84" " \85" \t-> " PTR_FORMAT "(%d)", \86(int) THREAD->osthread()->thread_id(), \87BCI(), \88p2i(MDX()), \89(MDX() == NULL \90? 0 \91: istate->method()->method_data()->dp_to_di((address)MDX())), \92p2i(mdx), \93istate->method()->method_data()->dp_to_di((address)mdx) \94); \95}; \96istate->set_mdx(mdx);979899// Dumps the profiling method data for the current method.100#ifdef PRODUCT101#define BI_PROFILE_PRINT_METHOD_DATA()102#else // PRODUCT103#define BI_PROFILE_PRINT_METHOD_DATA() \104{ \105ttyLocker ttyl; \106MethodData *md = istate->method()->method_data(); \107tty->cr(); \108tty->print("method data at mdx " PTR_FORMAT "(0) for", \109p2i(md->data_layout_at(md->bci_to_di(0)))); \110istate->method()->print_short_name(tty); \111tty->cr(); \112if (md != NULL) { \113md->print_data_on(tty); \114address mdx = (address) MDX(); \115if (mdx != NULL) { \116tty->print_cr("current mdx " PTR_FORMAT "(%d)", \117p2i(mdx), \118istate->method()->method_data()->dp_to_di(mdx)); \119} \120} else { \121tty->print_cr("no method data"); \122} \123}124#endif // PRODUCT125126127// Gets or creates the profiling method data and initializes mdx.128#define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler) \129if (ProfileInterpreter && MDX() == NULL) { \130/* Mdx is not yet initialized for this activation. */ \131MethodData *md = istate->method()->method_data(); \132if (md == NULL) { \133MethodCounters* mcs; \134GET_METHOD_COUNTERS(mcs); \135/* The profiling method data doesn't exist for this method, */ \136/* create it if the counters have overflowed. */ \137if (mcs->invocation_counter() \138->reached_ProfileLimit(mcs->backedge_counter())) { \139/* Must use CALL_VM, because an async exception may be pending. */ \140CALL_VM((InterpreterRuntime::profile_method(THREAD)), \141exception_handler); \142md = istate->method()->method_data(); \143if (md != NULL) { \144if (TraceProfileInterpreter) { \145BI_PROFILE_PRINT_METHOD_DATA(); \146} \147Method *m = istate->method(); \148int bci = m->bci_from(pc); \149jint di = md->bci_to_di(bci); \150SET_MDX(md->data_layout_at(di)); \151} \152} \153} else { \154/* The profiling method data exists, align the method data pointer */ \155/* mdx to the current bytecode index. */ \156if (TraceProfileInterpreter) { \157BI_PROFILE_PRINT_METHOD_DATA(); \158} \159SET_MDX(md->data_layout_at(md->bci_to_di(BCI()))); \160} \161}162163164// Asserts that the current method data pointer mdx corresponds165// to the current bytecode.166#if defined(CC_INTERP_PROFILE_WITH_ASSERTIONS)167#define BI_PROFILE_CHECK_MDX() \168{ \169MethodData *md = istate->method()->method_data(); \170address mdx = (address) MDX(); \171address mdx2 = (address) md->data_layout_at(md->bci_to_di(BCI())); \172guarantee(md != NULL, "1"); \173guarantee(mdx != NULL, "2"); \174guarantee(mdx2 != NULL, "3"); \175if (mdx != mdx2) { \176BI_PROFILE_PRINT_METHOD_DATA(); \177fatal3("invalid mdx at bci %d:" \178" was " PTR_FORMAT \179" but expected " PTR_FORMAT, \180BCI(), \181mdx, \182mdx2); \183} \184}185#else186#define BI_PROFILE_CHECK_MDX()187#endif188189190// Aligns the method data pointer mdx to the current bytecode index.191#define BI_PROFILE_ALIGN_TO_CURRENT_BCI() \192if (ProfileInterpreter && MDX() != NULL) { \193MethodData *md = istate->method()->method_data(); \194SET_MDX(md->data_layout_at(md->bci_to_di(BCI()))); \195}196197198// Updates profiling data for a jump.199#define BI_PROFILE_UPDATE_JUMP() \200if (ProfileInterpreter && MDX() != NULL) { \201BI_PROFILE_CHECK_MDX(); \202JumpData::increment_taken_count_no_overflow(MDX()); \203/* Remember last branch taken count. */ \204mdo_last_branch_taken_count = JumpData::taken_count(MDX()); \205SET_MDX(JumpData::advance_taken(MDX())); \206}207208209// Updates profiling data for a taken/not taken branch.210#define BI_PROFILE_UPDATE_BRANCH(is_taken) \211if (ProfileInterpreter && MDX() != NULL) { \212BI_PROFILE_CHECK_MDX(); \213if (is_taken) { \214BranchData::increment_taken_count_no_overflow(MDX()); \215/* Remember last branch taken count. */ \216mdo_last_branch_taken_count = BranchData::taken_count(MDX()); \217SET_MDX(BranchData::advance_taken(MDX())); \218} else { \219BranchData::increment_not_taken_count_no_overflow(MDX()); \220SET_MDX(BranchData::advance_not_taken(MDX())); \221} \222}223224225// Updates profiling data for a ret with given bci.226#define BI_PROFILE_UPDATE_RET(bci) \227if (ProfileInterpreter && MDX() != NULL) { \228BI_PROFILE_CHECK_MDX(); \229MethodData *md = istate->method()->method_data(); \230/* FIXME: there is more to do here than increment and advance(mdx)! */ \231CounterData::increment_count_no_overflow(MDX()); \232SET_MDX(RetData::advance(md, bci)); \233}234235// Decrement counter at checkcast if the subtype check fails (as template236// interpreter does!).237#define BI_PROFILE_SUBTYPECHECK_FAILED(receiver) \238if (ProfileInterpreter && MDX() != NULL) { \239BI_PROFILE_CHECK_MDX(); \240ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver); \241ReceiverTypeData::decrement_count(MDX()); \242}243244// Updates profiling data for a checkcast (was a null seen? which receiver?).245#define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver) \246if (ProfileInterpreter && MDX() != NULL) { \247BI_PROFILE_CHECK_MDX(); \248if (null_seen) { \249ReceiverTypeData::set_null_seen(MDX()); \250} else { \251/* Template interpreter doesn't increment count. */ \252/* ReceiverTypeData::increment_count_no_overflow(MDX()); */ \253ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver); \254} \255SET_MDX(ReceiverTypeData::advance(MDX())); \256}257258259// Updates profiling data for an instanceof (was a null seen? which receiver?).260#define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver) \261BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver)262263264// Updates profiling data for a call.265#define BI_PROFILE_UPDATE_CALL() \266if (ProfileInterpreter && MDX() != NULL) { \267BI_PROFILE_CHECK_MDX(); \268CounterData::increment_count_no_overflow(MDX()); \269SET_MDX(CounterData::advance(MDX())); \270}271272273// Updates profiling data for a final call.274#define BI_PROFILE_UPDATE_FINALCALL() \275if (ProfileInterpreter && MDX() != NULL) { \276BI_PROFILE_CHECK_MDX(); \277VirtualCallData::increment_count_no_overflow(MDX()); \278SET_MDX(VirtualCallData::advance(MDX())); \279}280281282// Updates profiling data for a virtual call with given receiver Klass.283#define BI_PROFILE_UPDATE_VIRTUALCALL(receiver) \284if (ProfileInterpreter && MDX() != NULL) { \285BI_PROFILE_CHECK_MDX(); \286VirtualCallData::increment_receiver_count_no_overflow(MDX(), receiver); \287SET_MDX(VirtualCallData::advance(MDX())); \288}289290291// Updates profiling data for a switch (tabelswitch or lookupswitch) with292// given taken index (-1 means default case was taken).293#define BI_PROFILE_UPDATE_SWITCH(switch_index) \294if (ProfileInterpreter && MDX() != NULL) { \295BI_PROFILE_CHECK_MDX(); \296MultiBranchData::increment_count_no_overflow(MDX(), switch_index); \297SET_MDX(MultiBranchData::advance(MDX(), switch_index)); \298}299300301// The end /////////////////////////////////////////////////////////////////////302303#endif // CC_INTERP_PROFILE304305#endif // CC_INTERP306307#endif // SHARE_VM_INTERPRETER_BYTECODECINTERPRETERPROFILING_HPP308309310