Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
coleenp@7358 | 2 | * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. |
coleenp@7358 | 3 | * Copyright 2012, 2014 SAP AG. All rights reserved. |
aoqi@0 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 5 | * |
aoqi@0 | 6 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 7 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 8 | * published by the Free Software Foundation. |
aoqi@0 | 9 | * |
aoqi@0 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 14 | * accompanied this code). |
aoqi@0 | 15 | * |
aoqi@0 | 16 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 19 | * |
aoqi@0 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 21 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 22 | * questions. |
aoqi@0 | 23 | * |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | // This file defines a set of macros which are used by the c++-interpreter |
aoqi@0 | 27 | // for updating a method's methodData object. |
aoqi@0 | 28 | |
aoqi@0 | 29 | |
aoqi@0 | 30 | #ifndef SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP |
aoqi@0 | 31 | #define SHARE_VM_INTERPRETER_BYTECODEINTERPRETERPROFILING_HPP |
aoqi@0 | 32 | |
aoqi@0 | 33 | |
aoqi@0 | 34 | // Global settings ///////////////////////////////////////////////////////////// |
aoqi@0 | 35 | |
aoqi@0 | 36 | |
aoqi@0 | 37 | // Enables profiling support. |
aoqi@0 | 38 | #if defined(COMPILER2) |
aoqi@0 | 39 | #define CC_INTERP_PROFILE |
aoqi@0 | 40 | #endif |
aoqi@0 | 41 | |
aoqi@0 | 42 | // Enables assertions for profiling code (also works in product-builds). |
aoqi@0 | 43 | // #define CC_INTERP_PROFILE_WITH_ASSERTIONS |
aoqi@0 | 44 | |
aoqi@0 | 45 | |
aoqi@0 | 46 | #ifdef CC_INTERP |
aoqi@0 | 47 | |
aoqi@0 | 48 | // Empty dummy implementations if profiling code is switched off. ////////////// |
aoqi@0 | 49 | |
aoqi@0 | 50 | #ifndef CC_INTERP_PROFILE |
aoqi@0 | 51 | |
aoqi@0 | 52 | #define SET_MDX(mdx) |
aoqi@0 | 53 | |
aoqi@0 | 54 | #define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler) \ |
aoqi@0 | 55 | if (ProfileInterpreter) { \ |
aoqi@0 | 56 | ShouldNotReachHere(); \ |
aoqi@0 | 57 | } |
aoqi@0 | 58 | |
aoqi@0 | 59 | #define BI_PROFILE_ALIGN_TO_CURRENT_BCI() |
aoqi@0 | 60 | |
aoqi@0 | 61 | #define BI_PROFILE_UPDATE_JUMP() |
aoqi@0 | 62 | #define BI_PROFILE_UPDATE_BRANCH(is_taken) |
aoqi@0 | 63 | #define BI_PROFILE_UPDATE_RET(bci) |
aoqi@0 | 64 | #define BI_PROFILE_SUBTYPECHECK_FAILED(receiver) |
aoqi@0 | 65 | #define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver) |
aoqi@0 | 66 | #define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver) |
aoqi@0 | 67 | #define BI_PROFILE_UPDATE_CALL() |
aoqi@0 | 68 | #define BI_PROFILE_UPDATE_FINALCALL() |
aoqi@0 | 69 | #define BI_PROFILE_UPDATE_VIRTUALCALL(receiver) |
aoqi@0 | 70 | #define BI_PROFILE_UPDATE_SWITCH(switch_index) |
aoqi@0 | 71 | |
aoqi@0 | 72 | |
aoqi@0 | 73 | #else |
aoqi@0 | 74 | |
aoqi@0 | 75 | |
aoqi@0 | 76 | // Non-dummy implementations /////////////////////////////////////////////////// |
aoqi@0 | 77 | |
aoqi@0 | 78 | // Accessors for the current method data pointer 'mdx'. |
aoqi@0 | 79 | #define MDX() (istate->mdx()) |
aoqi@0 | 80 | #define SET_MDX(mdx) \ |
aoqi@0 | 81 | if (TraceProfileInterpreter) { \ |
aoqi@0 | 82 | /* Let it look like TraceBytecodes' format. */ \ |
aoqi@0 | 83 | tty->print_cr("[%d] %4d " \ |
aoqi@0 | 84 | "mdx " PTR_FORMAT "(%d)" \ |
aoqi@0 | 85 | " " \ |
aoqi@0 | 86 | " \t-> " PTR_FORMAT "(%d)", \ |
aoqi@0 | 87 | (int) THREAD->osthread()->thread_id(), \ |
aoqi@0 | 88 | BCI(), \ |
coleenp@7358 | 89 | p2i(MDX()), \ |
aoqi@0 | 90 | (MDX() == NULL \ |
aoqi@0 | 91 | ? 0 \ |
aoqi@0 | 92 | : istate->method()->method_data()->dp_to_di((address)MDX())), \ |
coleenp@7358 | 93 | p2i(mdx), \ |
aoqi@0 | 94 | istate->method()->method_data()->dp_to_di((address)mdx) \ |
aoqi@0 | 95 | ); \ |
aoqi@0 | 96 | }; \ |
aoqi@0 | 97 | istate->set_mdx(mdx); |
aoqi@0 | 98 | |
aoqi@0 | 99 | |
aoqi@0 | 100 | // Dumps the profiling method data for the current method. |
aoqi@0 | 101 | #ifdef PRODUCT |
aoqi@0 | 102 | #define BI_PROFILE_PRINT_METHOD_DATA() |
aoqi@0 | 103 | #else // PRODUCT |
aoqi@0 | 104 | #define BI_PROFILE_PRINT_METHOD_DATA() \ |
aoqi@0 | 105 | { \ |
aoqi@0 | 106 | ttyLocker ttyl; \ |
aoqi@0 | 107 | MethodData *md = istate->method()->method_data(); \ |
aoqi@0 | 108 | tty->cr(); \ |
aoqi@0 | 109 | tty->print("method data at mdx " PTR_FORMAT "(0) for", \ |
coleenp@7358 | 110 | p2i(md->data_layout_at(md->bci_to_di(0)))); \ |
aoqi@0 | 111 | istate->method()->print_short_name(tty); \ |
aoqi@0 | 112 | tty->cr(); \ |
aoqi@0 | 113 | if (md != NULL) { \ |
aoqi@0 | 114 | md->print_data_on(tty); \ |
aoqi@0 | 115 | address mdx = (address) MDX(); \ |
aoqi@0 | 116 | if (mdx != NULL) { \ |
aoqi@0 | 117 | tty->print_cr("current mdx " PTR_FORMAT "(%d)", \ |
coleenp@7358 | 118 | p2i(mdx), \ |
aoqi@0 | 119 | istate->method()->method_data()->dp_to_di(mdx)); \ |
aoqi@0 | 120 | } \ |
aoqi@0 | 121 | } else { \ |
aoqi@0 | 122 | tty->print_cr("no method data"); \ |
aoqi@0 | 123 | } \ |
aoqi@0 | 124 | } |
aoqi@0 | 125 | #endif // PRODUCT |
aoqi@0 | 126 | |
aoqi@0 | 127 | |
aoqi@0 | 128 | // Gets or creates the profiling method data and initializes mdx. |
aoqi@0 | 129 | #define BI_PROFILE_GET_OR_CREATE_METHOD_DATA(exception_handler) \ |
aoqi@0 | 130 | if (ProfileInterpreter && MDX() == NULL) { \ |
aoqi@0 | 131 | /* Mdx is not yet initialized for this activation. */ \ |
aoqi@0 | 132 | MethodData *md = istate->method()->method_data(); \ |
aoqi@0 | 133 | if (md == NULL) { \ |
aoqi@0 | 134 | MethodCounters* mcs; \ |
aoqi@0 | 135 | GET_METHOD_COUNTERS(mcs); \ |
aoqi@0 | 136 | /* The profiling method data doesn't exist for this method, */ \ |
aoqi@0 | 137 | /* create it if the counters have overflowed. */ \ |
aoqi@0 | 138 | if (mcs->invocation_counter() \ |
aoqi@0 | 139 | ->reached_ProfileLimit(mcs->backedge_counter())) { \ |
aoqi@0 | 140 | /* Must use CALL_VM, because an async exception may be pending. */ \ |
aoqi@0 | 141 | CALL_VM((InterpreterRuntime::profile_method(THREAD)), \ |
aoqi@0 | 142 | exception_handler); \ |
aoqi@0 | 143 | md = istate->method()->method_data(); \ |
aoqi@0 | 144 | if (md != NULL) { \ |
aoqi@0 | 145 | if (TraceProfileInterpreter) { \ |
aoqi@0 | 146 | BI_PROFILE_PRINT_METHOD_DATA(); \ |
aoqi@0 | 147 | } \ |
aoqi@0 | 148 | Method *m = istate->method(); \ |
aoqi@0 | 149 | int bci = m->bci_from(pc); \ |
aoqi@0 | 150 | jint di = md->bci_to_di(bci); \ |
aoqi@0 | 151 | SET_MDX(md->data_layout_at(di)); \ |
aoqi@0 | 152 | } \ |
aoqi@0 | 153 | } \ |
aoqi@0 | 154 | } else { \ |
aoqi@0 | 155 | /* The profiling method data exists, align the method data pointer */ \ |
aoqi@0 | 156 | /* mdx to the current bytecode index. */ \ |
aoqi@0 | 157 | if (TraceProfileInterpreter) { \ |
aoqi@0 | 158 | BI_PROFILE_PRINT_METHOD_DATA(); \ |
aoqi@0 | 159 | } \ |
aoqi@0 | 160 | SET_MDX(md->data_layout_at(md->bci_to_di(BCI()))); \ |
aoqi@0 | 161 | } \ |
aoqi@0 | 162 | } |
aoqi@0 | 163 | |
aoqi@0 | 164 | |
aoqi@0 | 165 | // Asserts that the current method data pointer mdx corresponds |
aoqi@0 | 166 | // to the current bytecode. |
aoqi@0 | 167 | #if defined(CC_INTERP_PROFILE_WITH_ASSERTIONS) |
aoqi@0 | 168 | #define BI_PROFILE_CHECK_MDX() \ |
aoqi@0 | 169 | { \ |
aoqi@0 | 170 | MethodData *md = istate->method()->method_data(); \ |
aoqi@0 | 171 | address mdx = (address) MDX(); \ |
aoqi@0 | 172 | address mdx2 = (address) md->data_layout_at(md->bci_to_di(BCI())); \ |
aoqi@0 | 173 | guarantee(md != NULL, "1"); \ |
aoqi@0 | 174 | guarantee(mdx != NULL, "2"); \ |
aoqi@0 | 175 | guarantee(mdx2 != NULL, "3"); \ |
aoqi@0 | 176 | if (mdx != mdx2) { \ |
aoqi@0 | 177 | BI_PROFILE_PRINT_METHOD_DATA(); \ |
aoqi@0 | 178 | fatal3("invalid mdx at bci %d:" \ |
aoqi@0 | 179 | " was " PTR_FORMAT \ |
aoqi@0 | 180 | " but expected " PTR_FORMAT, \ |
aoqi@0 | 181 | BCI(), \ |
aoqi@0 | 182 | mdx, \ |
aoqi@0 | 183 | mdx2); \ |
aoqi@0 | 184 | } \ |
aoqi@0 | 185 | } |
aoqi@0 | 186 | #else |
aoqi@0 | 187 | #define BI_PROFILE_CHECK_MDX() |
aoqi@0 | 188 | #endif |
aoqi@0 | 189 | |
aoqi@0 | 190 | |
aoqi@0 | 191 | // Aligns the method data pointer mdx to the current bytecode index. |
aoqi@0 | 192 | #define BI_PROFILE_ALIGN_TO_CURRENT_BCI() \ |
aoqi@0 | 193 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 194 | MethodData *md = istate->method()->method_data(); \ |
aoqi@0 | 195 | SET_MDX(md->data_layout_at(md->bci_to_di(BCI()))); \ |
aoqi@0 | 196 | } |
aoqi@0 | 197 | |
aoqi@0 | 198 | |
aoqi@0 | 199 | // Updates profiling data for a jump. |
aoqi@0 | 200 | #define BI_PROFILE_UPDATE_JUMP() \ |
aoqi@0 | 201 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 202 | BI_PROFILE_CHECK_MDX(); \ |
aoqi@0 | 203 | JumpData::increment_taken_count_no_overflow(MDX()); \ |
aoqi@0 | 204 | /* Remember last branch taken count. */ \ |
aoqi@0 | 205 | mdo_last_branch_taken_count = JumpData::taken_count(MDX()); \ |
aoqi@0 | 206 | SET_MDX(JumpData::advance_taken(MDX())); \ |
aoqi@0 | 207 | } |
aoqi@0 | 208 | |
aoqi@0 | 209 | |
aoqi@0 | 210 | // Updates profiling data for a taken/not taken branch. |
aoqi@0 | 211 | #define BI_PROFILE_UPDATE_BRANCH(is_taken) \ |
aoqi@0 | 212 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 213 | BI_PROFILE_CHECK_MDX(); \ |
aoqi@0 | 214 | if (is_taken) { \ |
aoqi@0 | 215 | BranchData::increment_taken_count_no_overflow(MDX()); \ |
aoqi@0 | 216 | /* Remember last branch taken count. */ \ |
aoqi@0 | 217 | mdo_last_branch_taken_count = BranchData::taken_count(MDX()); \ |
aoqi@0 | 218 | SET_MDX(BranchData::advance_taken(MDX())); \ |
aoqi@0 | 219 | } else { \ |
aoqi@0 | 220 | BranchData::increment_not_taken_count_no_overflow(MDX()); \ |
aoqi@0 | 221 | SET_MDX(BranchData::advance_not_taken(MDX())); \ |
aoqi@0 | 222 | } \ |
aoqi@0 | 223 | } |
aoqi@0 | 224 | |
aoqi@0 | 225 | |
aoqi@0 | 226 | // Updates profiling data for a ret with given bci. |
aoqi@0 | 227 | #define BI_PROFILE_UPDATE_RET(bci) \ |
aoqi@0 | 228 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 229 | BI_PROFILE_CHECK_MDX(); \ |
aoqi@0 | 230 | MethodData *md = istate->method()->method_data(); \ |
aoqi@0 | 231 | /* FIXME: there is more to do here than increment and advance(mdx)! */ \ |
aoqi@0 | 232 | CounterData::increment_count_no_overflow(MDX()); \ |
aoqi@0 | 233 | SET_MDX(RetData::advance(md, bci)); \ |
aoqi@0 | 234 | } |
aoqi@0 | 235 | |
aoqi@0 | 236 | // Decrement counter at checkcast if the subtype check fails (as template |
aoqi@0 | 237 | // interpreter does!). |
aoqi@0 | 238 | #define BI_PROFILE_SUBTYPECHECK_FAILED(receiver) \ |
aoqi@0 | 239 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 240 | BI_PROFILE_CHECK_MDX(); \ |
aoqi@0 | 241 | ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver); \ |
aoqi@0 | 242 | ReceiverTypeData::decrement_count(MDX()); \ |
aoqi@0 | 243 | } |
aoqi@0 | 244 | |
aoqi@0 | 245 | // Updates profiling data for a checkcast (was a null seen? which receiver?). |
aoqi@0 | 246 | #define BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver) \ |
aoqi@0 | 247 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 248 | BI_PROFILE_CHECK_MDX(); \ |
aoqi@0 | 249 | if (null_seen) { \ |
aoqi@0 | 250 | ReceiverTypeData::set_null_seen(MDX()); \ |
aoqi@0 | 251 | } else { \ |
aoqi@0 | 252 | /* Template interpreter doesn't increment count. */ \ |
aoqi@0 | 253 | /* ReceiverTypeData::increment_count_no_overflow(MDX()); */ \ |
aoqi@0 | 254 | ReceiverTypeData::increment_receiver_count_no_overflow(MDX(), receiver); \ |
aoqi@0 | 255 | } \ |
aoqi@0 | 256 | SET_MDX(ReceiverTypeData::advance(MDX())); \ |
aoqi@0 | 257 | } |
aoqi@0 | 258 | |
aoqi@0 | 259 | |
aoqi@0 | 260 | // Updates profiling data for an instanceof (was a null seen? which receiver?). |
aoqi@0 | 261 | #define BI_PROFILE_UPDATE_INSTANCEOF(null_seen, receiver) \ |
aoqi@0 | 262 | BI_PROFILE_UPDATE_CHECKCAST(null_seen, receiver) |
aoqi@0 | 263 | |
aoqi@0 | 264 | |
aoqi@0 | 265 | // Updates profiling data for a call. |
aoqi@0 | 266 | #define BI_PROFILE_UPDATE_CALL() \ |
aoqi@0 | 267 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 268 | BI_PROFILE_CHECK_MDX(); \ |
aoqi@0 | 269 | CounterData::increment_count_no_overflow(MDX()); \ |
aoqi@0 | 270 | SET_MDX(CounterData::advance(MDX())); \ |
aoqi@0 | 271 | } |
aoqi@0 | 272 | |
aoqi@0 | 273 | |
aoqi@0 | 274 | // Updates profiling data for a final call. |
aoqi@0 | 275 | #define BI_PROFILE_UPDATE_FINALCALL() \ |
aoqi@0 | 276 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 277 | BI_PROFILE_CHECK_MDX(); \ |
aoqi@0 | 278 | VirtualCallData::increment_count_no_overflow(MDX()); \ |
aoqi@0 | 279 | SET_MDX(VirtualCallData::advance(MDX())); \ |
aoqi@0 | 280 | } |
aoqi@0 | 281 | |
aoqi@0 | 282 | |
aoqi@0 | 283 | // Updates profiling data for a virtual call with given receiver Klass. |
aoqi@0 | 284 | #define BI_PROFILE_UPDATE_VIRTUALCALL(receiver) \ |
aoqi@0 | 285 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 286 | BI_PROFILE_CHECK_MDX(); \ |
aoqi@0 | 287 | VirtualCallData::increment_receiver_count_no_overflow(MDX(), receiver); \ |
aoqi@0 | 288 | SET_MDX(VirtualCallData::advance(MDX())); \ |
aoqi@0 | 289 | } |
aoqi@0 | 290 | |
aoqi@0 | 291 | |
aoqi@0 | 292 | // Updates profiling data for a switch (tabelswitch or lookupswitch) with |
aoqi@0 | 293 | // given taken index (-1 means default case was taken). |
aoqi@0 | 294 | #define BI_PROFILE_UPDATE_SWITCH(switch_index) \ |
aoqi@0 | 295 | if (ProfileInterpreter && MDX() != NULL) { \ |
aoqi@0 | 296 | BI_PROFILE_CHECK_MDX(); \ |
aoqi@0 | 297 | MultiBranchData::increment_count_no_overflow(MDX(), switch_index); \ |
aoqi@0 | 298 | SET_MDX(MultiBranchData::advance(MDX(), switch_index)); \ |
aoqi@0 | 299 | } |
aoqi@0 | 300 | |
aoqi@0 | 301 | |
aoqi@0 | 302 | // The end ///////////////////////////////////////////////////////////////////// |
aoqi@0 | 303 | |
aoqi@0 | 304 | #endif // CC_INTERP_PROFILE |
aoqi@0 | 305 | |
aoqi@0 | 306 | #endif // CC_INTERP |
aoqi@0 | 307 | |
aoqi@0 | 308 | #endif // SHARE_VM_INTERPRETER_BYTECODECINTERPRETERPROFILING_HPP |