src/share/vm/interpreter/bytecodeInterpreterProfiling.hpp

changeset 6470
abe03600372a
parent 0
f90c822e73f8
child 7358
327e7269f90d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/interpreter/bytecodeInterpreterProfiling.hpp	Sun Sep 15 15:28:58 2013 +0200
     1.3 @@ -0,0 +1,308 @@
     1.4 +/*
     1.5 + * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright 2012, 2013 SAP AG. All rights reserved.
     1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8 + *
     1.9 + * This code is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License version 2 only, as
    1.11 + * published by the Free Software Foundation.
    1.12 + *
    1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 + * version 2 for more details (a copy is included in the LICENSE file that
    1.17 + * accompanied this code).
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License version
    1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 + *
    1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 + * or visit www.oracle.com if you need additional information or have any
    1.25 + * questions.
    1.26 + *
    1.27 + */
    1.28 +
    1.29 +// This file defines a set of macros which are used by the c++-interpreter
    1.30 +// for updating a method's methodData object.
    1.31 +
    1.32 +
    1.33 +#ifndef SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP
    1.34 +#define SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP
    1.35 +
    1.36 +
    1.37 +// Global settings /////////////////////////////////////////////////////////////
    1.38 +
    1.39 +
    1.40 +// Enables profiling support.
    1.41 +#if defined(COMPILER2)
    1.42 +#define CC_INTERP_PROFILE
    1.43 +#endif
    1.44 +
    1.45 +// Enables assertions for profiling code (also works in product-builds).
    1.46 +// #define CC_INTERP_PROFILE_WITH_ASSERTIONS
    1.47 +
    1.48 +
    1.49 +#ifdef CC_INTERP
    1.50 +
    1.51 +// Empty dummy implementations if profiling code is switched off. //////////////
    1.52 +
    1.53 +#ifndef CC_INTERP_PROFILE
    1.54 +
    1.55 +#define SET_MDX(mdx)
    1.56 +
    1.57 +#define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler)                \
    1.58 +  if (ProfileInterpreter) {                                                    \
    1.59 +    ShouldNotReachHere();                                                      \
    1.60 +  }
    1.61 +
    1.62 +#define BI_PROFILE_ALIGN_TO_CURRENT_BCI()
    1.63 +
    1.64 +#define BI_PROFILE_UPDATE_JUMP()
    1.65 +#define BI_PROFILE_UPDATE_BRANCH(is_taken)
    1.66 +#define BI_PROFILE_UPDATE_RET(bci)
    1.67 +#define BI_PROFILE_SUBTYPECHECK_FAILED(receiver)
    1.68 +#define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver)
    1.69 +#define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver)
    1.70 +#define BI_PROFILE_UPDATE_CALL()
    1.71 +#define BI_PROFILE_UPDATE_FINALCALL()
    1.72 +#define BI_PROFILE_UPDATE_VIRTUALCALL(receiver)
    1.73 +#define BI_PROFILE_UPDATE_SWITCH(switch_index)
    1.74 +
    1.75 +
    1.76 +#else
    1.77 +
    1.78 +
    1.79 +// Non-dummy implementations ///////////////////////////////////////////////////
    1.80 +
    1.81 +// Accessors for the current method data pointer 'mdx'.
    1.82 +#define MDX()        (istate->mdx())
    1.83 +#define SET_MDX(mdx)                                                           \
    1.84 +  if (TraceProfileInterpreter) {                                               \
    1.85 +    /* Let it look like TraceBytecodes' format. */                             \
    1.86 +    tty->print_cr("[%d]           %4d  "                                       \
    1.87 +                  "mdx " PTR_FORMAT "(%d)"                                     \
    1.88 +                  "  "                                                         \
    1.89 +                  " \t-> " PTR_FORMAT "(%d)",                                  \
    1.90 +                (int) THREAD->osthread()->thread_id(),                         \
    1.91 +                BCI(),                                                         \
    1.92 +                MDX(),                                                         \
    1.93 +                (MDX() == NULL                                                 \
    1.94 +                 ? 0                                                           \
    1.95 +                 : istate->method()->method_data()->dp_to_di((address)MDX())), \
    1.96 +                mdx,                                                           \
    1.97 +                istate->method()->method_data()->dp_to_di((address)mdx)        \
    1.98 +                );                                                             \
    1.99 +  };                                                                           \
   1.100 +  istate->set_mdx(mdx);
   1.101 +
   1.102 +
   1.103 +// Dumps the profiling method data for the current method.
   1.104 +#ifdef PRODUCT
   1.105 +#define BI_PROFILE_PRINT_METHOD_DATA()
   1.106 +#else  // PRODUCT
   1.107 +#define BI_PROFILE_PRINT_METHOD_DATA()                                         \
   1.108 +  {                                                                            \
   1.109 +    ttyLocker ttyl;                                                            \
   1.110 +    MethodData *md = istate->method()->method_data();                          \
   1.111 +    tty->cr();                                                                 \
   1.112 +    tty->print("method data at mdx " PTR_FORMAT "(0) for",                     \
   1.113 +               md->data_layout_at(md->bci_to_di(0)));                          \
   1.114 +    istate->method()->print_short_name(tty);                                   \
   1.115 +    tty->cr();                                                                 \
   1.116 +    if (md != NULL) {                                                          \
   1.117 +      md->print_data_on(tty);                                                  \
   1.118 +      address mdx = (address) MDX();                                           \
   1.119 +      if (mdx != NULL) {                                                       \
   1.120 +        tty->print_cr("current mdx " PTR_FORMAT "(%d)",                        \
   1.121 +                      mdx,                                                     \
   1.122 +                      istate->method()->method_data()->dp_to_di(mdx));         \
   1.123 +      }                                                                        \
   1.124 +    } else {                                                                   \
   1.125 +      tty->print_cr("no method data");                                         \
   1.126 +    }                                                                          \
   1.127 +  }
   1.128 +#endif // PRODUCT
   1.129 +
   1.130 +
   1.131 +// Gets or creates the profiling method data and initializes mdx.
   1.132 +#define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler)                \
   1.133 +  if (ProfileInterpreter && MDX() == NULL) {                                   \
   1.134 +    /* Mdx is not yet initialized for this activation. */                      \
   1.135 +    MethodData *md = istate->method()->method_data();                          \
   1.136 +    if (md == NULL) {                                                          \
   1.137 +      MethodCounters* mcs;                                                     \
   1.138 +      GET_METHOD_COUNTERS(mcs);                                                \
   1.139 +      /* The profiling method data doesn't exist for this method, */           \
   1.140 +      /* create it if the counters have overflowed. */                         \
   1.141 +      if (mcs->invocation_counter()                                            \
   1.142 +                         ->reached_ProfileLimit(mcs->backedge_counter())) {    \
   1.143 +        /* Must use CALL_VM, because an async exception may be pending. */     \
   1.144 +        CALL_VM((InterpreterRuntime::profile_method(THREAD)),                  \
   1.145 +                exception_handler);                                            \
   1.146 +        md = istate->method()->method_data();                                  \
   1.147 +        if (md != NULL) {                                                      \
   1.148 +          if (TraceProfileInterpreter) {                                       \
   1.149 +            BI_PROFILE_PRINT_METHOD_DATA();                                    \
   1.150 +          }                                                                    \
   1.151 +          Method *m = istate->method();                                        \
   1.152 +          int bci = m->bci_from(pc);                                           \
   1.153 +          jint di = md->bci_to_di(bci);                                        \
   1.154 +          SET_MDX(md->data_layout_at(di));                                     \
   1.155 +        }                                                                      \
   1.156 +      }                                                                        \
   1.157 +    } else {                                                                   \
   1.158 +      /* The profiling method data exists, align the method data pointer */    \
   1.159 +      /* mdx to the current bytecode index. */                                 \
   1.160 +      if (TraceProfileInterpreter) {                                           \
   1.161 +        BI_PROFILE_PRINT_METHOD_DATA();                                        \
   1.162 +      }                                                                        \
   1.163 +      SET_MDX(md->data_layout_at(md->bci_to_di(BCI())));                       \
   1.164 +    }                                                                          \
   1.165 +  }
   1.166 +
   1.167 +
   1.168 +// Asserts that the current method data pointer mdx corresponds
   1.169 +// to the current bytecode.
   1.170 +#if defined(CC_INTERP_PROFILE_WITH_ASSERTIONS)
   1.171 +#define BI_PROFILE_CHECK_MDX()                                                 \
   1.172 +  {                                                                            \
   1.173 +    MethodData *md = istate->method()->method_data();                          \
   1.174 +    address mdx  = (address) MDX();                                            \
   1.175 +    address mdx2 = (address) md->data_layout_at(md->bci_to_di(BCI()));         \
   1.176 +    guarantee(md   != NULL, "1");                                              \
   1.177 +    guarantee(mdx  != NULL, "2");                                              \
   1.178 +    guarantee(mdx2 != NULL, "3");                                              \
   1.179 +    if (mdx != mdx2) {                                                         \
   1.180 +      BI_PROFILE_PRINT_METHOD_DATA();                                          \
   1.181 +      fatal3("invalid mdx at bci %d:"                                          \
   1.182 +             " was " PTR_FORMAT                                                \
   1.183 +             " but expected " PTR_FORMAT,                                      \
   1.184 +             BCI(),                                                            \
   1.185 +             mdx,                                                              \
   1.186 +             mdx2);                                                            \
   1.187 +    }                                                                          \
   1.188 +  }
   1.189 +#else
   1.190 +#define BI_PROFILE_CHECK_MDX()
   1.191 +#endif
   1.192 +
   1.193 +
   1.194 +// Aligns the method data pointer mdx to the current bytecode index.
   1.195 +#define BI_PROFILE_ALIGN_TO_CURRENT_BCI()                                      \
   1.196 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.197 +    MethodData *md = istate->method()->method_data();                          \
   1.198 +    SET_MDX(md->data_layout_at(md->bci_to_di(BCI())));                         \
   1.199 +  }
   1.200 +
   1.201 +
   1.202 +// Updates profiling data for a jump.
   1.203 +#define BI_PROFILE_UPDATE_JUMP()                                               \
   1.204 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.205 +    BI_PROFILE_CHECK_MDX();                                                    \
   1.206 +    JumpData::increment_taken_count_no_overflow(MDX());                        \
   1.207 +    /* Remember last branch taken count. */                                    \
   1.208 +    mdo_last_branch_taken_count = JumpData::taken_count(MDX());                \
   1.209 +    SET_MDX(JumpData::advance_taken(MDX()));                                   \
   1.210 +  }
   1.211 +
   1.212 +
   1.213 +// Updates profiling data for a taken/not taken branch.
   1.214 +#define BI_PROFILE_UPDATE_BRANCH(is_taken)                                     \
   1.215 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.216 +    BI_PROFILE_CHECK_MDX();                                                    \
   1.217 +    if (is_taken) {                                                            \
   1.218 +      BranchData::increment_taken_count_no_overflow(MDX());                    \
   1.219 +      /* Remember last branch taken count. */                                  \
   1.220 +      mdo_last_branch_taken_count = BranchData::taken_count(MDX());            \
   1.221 +      SET_MDX(BranchData::advance_taken(MDX()));                               \
   1.222 +    } else {                                                                   \
   1.223 +      BranchData::increment_not_taken_count_no_overflow(MDX());                \
   1.224 +      SET_MDX(BranchData::advance_not_taken(MDX()));                           \
   1.225 +    }                                                                          \
   1.226 +  }
   1.227 +
   1.228 +
   1.229 +// Updates profiling data for a ret with given bci.
   1.230 +#define BI_PROFILE_UPDATE_RET(bci)                                             \
   1.231 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.232 +    BI_PROFILE_CHECK_MDX();                                                    \
   1.233 +    MethodData *md = istate->method()->method_data();                          \
   1.234 +/* FIXME: there is more to do here than increment and advance(mdx)! */         \
   1.235 +    CounterData::increment_count_no_overflow(MDX());                           \
   1.236 +    SET_MDX(RetData::advance(md, bci));                                        \
   1.237 +  }
   1.238 +
   1.239 +// Decrement counter at checkcast if the subtype check fails (as template
   1.240 +// interpreter does!).
   1.241 +#define BI_PROFILE_SUBTYPECHECK_FAILED(receiver)                               \
   1.242 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.243 +    BI_PROFILE_CHECK_MDX();                                                    \
   1.244 +    ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver);   \
   1.245 +    ReceiverTypeData::decrement_count(MDX());                                  \
   1.246 +  }
   1.247 +
   1.248 +// Updates profiling data for a checkcast (was a null seen? which receiver?).
   1.249 +#define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver)                       \
   1.250 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.251 +    BI_PROFILE_CHECK_MDX();                                                    \
   1.252 +    if (null_seen) {                                                           \
   1.253 +      ReceiverTypeData::set_null_seen(MDX());                                  \
   1.254 +    } else {                                                                   \
   1.255 +      /* Template interpreter doesn't increment count. */                      \
   1.256 +      /* ReceiverTypeData::increment_count_no_overflow(MDX()); */              \
   1.257 +      ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver); \
   1.258 +    }                                                                          \
   1.259 +    SET_MDX(ReceiverTypeData::advance(MDX()));                                 \
   1.260 +  }
   1.261 +
   1.262 +
   1.263 +// Updates profiling data for an instanceof (was a null seen? which receiver?).
   1.264 +#define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver)                      \
   1.265 +  BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver)
   1.266 +
   1.267 +
   1.268 +// Updates profiling data for a call.
   1.269 +#define BI_PROFILE_UPDATE_CALL()                                               \
   1.270 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.271 +    BI_PROFILE_CHECK_MDX();                                                    \
   1.272 +    CounterData::increment_count_no_overflow(MDX());                           \
   1.273 +    SET_MDX(CounterData::advance(MDX()));                                      \
   1.274 +  }
   1.275 +
   1.276 +
   1.277 +// Updates profiling data for a final call.
   1.278 +#define BI_PROFILE_UPDATE_FINALCALL()                                          \
   1.279 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.280 +    BI_PROFILE_CHECK_MDX();                                                    \
   1.281 +    VirtualCallData::increment_count_no_overflow(MDX());                       \
   1.282 +    SET_MDX(VirtualCallData::advance(MDX()));                                  \
   1.283 +  }
   1.284 +
   1.285 +
   1.286 +// Updates profiling data for a virtual call with given receiver Klass.
   1.287 +#define BI_PROFILE_UPDATE_VIRTUALCALL(receiver)                                \
   1.288 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.289 +    BI_PROFILE_CHECK_MDX();                                                    \
   1.290 +    VirtualCallData::increment_receiver_count_no_overflow(MDX(), receiver);    \
   1.291 +    SET_MDX(VirtualCallData::advance(MDX()));                                  \
   1.292 +  }
   1.293 +
   1.294 +
   1.295 +// Updates profiling data for a switch (tabelswitch or lookupswitch) with
   1.296 +// given taken index (-1 means default case was taken).
   1.297 +#define BI_PROFILE_UPDATE_SWITCH(switch_index)                                 \
   1.298 +  if (ProfileInterpreter && MDX() != NULL) {                                   \
   1.299 +    BI_PROFILE_CHECK_MDX();                                                    \
   1.300 +    MultiBranchData::increment_count_no_overflow(MDX(), switch_index);         \
   1.301 +    SET_MDX(MultiBranchData::advance(MDX(), switch_index));                    \
   1.302 +  }
   1.303 +
   1.304 +
   1.305 +// The end /////////////////////////////////////////////////////////////////////
   1.306 +
   1.307 +#endif // CC_INTERP_PROFILE
   1.308 +
   1.309 +#endif // CC_INTERP
   1.310 +
   1.311 +#endif // SHARE_VM_INTERPRETER_BYTECODECINTERPRETERPROFILING_HPP

mercurial