Tue, 26 Nov 2013 14:35:38 +0100
8027675: Full collections with Serial slower in JDK 8 compared to 7u40
Summary: Reduced the number of calls to follow_class_loader and instead marked and pushed the klass holder directly. Also removed unneeded calls to adjust_klass.
Reviewed-by: coleenp, jmasa, mgerdin, tschatzl
duke@435 | 1 | /* |
acorn@4497 | 2 | * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 27 | #include "interpreter/bytecode.hpp" |
stefank@2314 | 28 | #include "interpreter/bytecodeStream.hpp" |
stefank@2314 | 29 | #include "interpreter/linkResolver.hpp" |
acorn@4497 | 30 | #include "memory/heapInspection.hpp" |
coleenp@4037 | 31 | #include "oops/methodData.hpp" |
coleenp@4037 | 32 | #include "prims/jvmtiRedefineClasses.hpp" |
stefank@2314 | 33 | #include "runtime/compilationPolicy.hpp" |
stefank@2314 | 34 | #include "runtime/deoptimization.hpp" |
stefank@2314 | 35 | #include "runtime/handles.inline.hpp" |
duke@435 | 36 | |
duke@435 | 37 | // ================================================================== |
duke@435 | 38 | // DataLayout |
duke@435 | 39 | // |
duke@435 | 40 | // Overlay for generic profiling data. |
duke@435 | 41 | |
duke@435 | 42 | // Some types of data layouts need a length field. |
duke@435 | 43 | bool DataLayout::needs_array_len(u1 tag) { |
roland@5987 | 44 | return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag) || (tag == parameters_type_data_tag); |
duke@435 | 45 | } |
duke@435 | 46 | |
duke@435 | 47 | // Perform generic initialization of the data. More specific |
duke@435 | 48 | // initialization occurs in overrides of ProfileData::post_initialize. |
duke@435 | 49 | void DataLayout::initialize(u1 tag, u2 bci, int cell_count) { |
duke@435 | 50 | _header._bits = (intptr_t)0; |
duke@435 | 51 | _header._struct._tag = tag; |
duke@435 | 52 | _header._struct._bci = bci; |
duke@435 | 53 | for (int i = 0; i < cell_count; i++) { |
duke@435 | 54 | set_cell_at(i, (intptr_t)0); |
duke@435 | 55 | } |
duke@435 | 56 | if (needs_array_len(tag)) { |
duke@435 | 57 | set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header. |
duke@435 | 58 | } |
roland@5914 | 59 | if (tag == call_type_data_tag) { |
roland@5914 | 60 | CallTypeData::initialize(this, cell_count); |
roland@5914 | 61 | } else if (tag == virtual_call_type_data_tag) { |
roland@5914 | 62 | VirtualCallTypeData::initialize(this, cell_count); |
roland@5914 | 63 | } |
duke@435 | 64 | } |
duke@435 | 65 | |
coleenp@4037 | 66 | void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) { |
ysr@1376 | 67 | ResourceMark m; |
coleenp@4037 | 68 | data_in()->clean_weak_klass_links(cl); |
ysr@1376 | 69 | } |
ysr@1376 | 70 | |
ysr@1376 | 71 | |
duke@435 | 72 | // ================================================================== |
duke@435 | 73 | // ProfileData |
duke@435 | 74 | // |
duke@435 | 75 | // A ProfileData object is created to refer to a section of profiling |
duke@435 | 76 | // data in a structured way. |
duke@435 | 77 | |
duke@435 | 78 | // Constructor for invalid ProfileData. |
duke@435 | 79 | ProfileData::ProfileData() { |
duke@435 | 80 | _data = NULL; |
duke@435 | 81 | } |
duke@435 | 82 | |
duke@435 | 83 | #ifndef PRODUCT |
roland@5914 | 84 | void ProfileData::print_shared(outputStream* st, const char* name) const { |
duke@435 | 85 | st->print("bci: %d", bci()); |
duke@435 | 86 | st->fill_to(tab_width_one); |
duke@435 | 87 | st->print("%s", name); |
duke@435 | 88 | tab(st); |
duke@435 | 89 | int trap = trap_state(); |
duke@435 | 90 | if (trap != 0) { |
duke@435 | 91 | char buf[100]; |
duke@435 | 92 | st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); |
duke@435 | 93 | } |
duke@435 | 94 | int flags = data()->flags(); |
duke@435 | 95 | if (flags != 0) |
duke@435 | 96 | st->print("flags(%d) ", flags); |
duke@435 | 97 | } |
duke@435 | 98 | |
roland@5914 | 99 | void ProfileData::tab(outputStream* st, bool first) const { |
roland@5914 | 100 | st->fill_to(first ? tab_width_one : tab_width_two); |
duke@435 | 101 | } |
duke@435 | 102 | #endif // !PRODUCT |
duke@435 | 103 | |
duke@435 | 104 | // ================================================================== |
duke@435 | 105 | // BitData |
duke@435 | 106 | // |
duke@435 | 107 | // A BitData corresponds to a one-bit flag. This is used to indicate |
duke@435 | 108 | // whether a checkcast bytecode has seen a null value. |
duke@435 | 109 | |
duke@435 | 110 | |
duke@435 | 111 | #ifndef PRODUCT |
roland@5914 | 112 | void BitData::print_data_on(outputStream* st) const { |
duke@435 | 113 | print_shared(st, "BitData"); |
duke@435 | 114 | } |
duke@435 | 115 | #endif // !PRODUCT |
duke@435 | 116 | |
duke@435 | 117 | // ================================================================== |
duke@435 | 118 | // CounterData |
duke@435 | 119 | // |
duke@435 | 120 | // A CounterData corresponds to a simple counter. |
duke@435 | 121 | |
duke@435 | 122 | #ifndef PRODUCT |
roland@5914 | 123 | void CounterData::print_data_on(outputStream* st) const { |
duke@435 | 124 | print_shared(st, "CounterData"); |
duke@435 | 125 | st->print_cr("count(%u)", count()); |
duke@435 | 126 | } |
duke@435 | 127 | #endif // !PRODUCT |
duke@435 | 128 | |
duke@435 | 129 | // ================================================================== |
duke@435 | 130 | // JumpData |
duke@435 | 131 | // |
duke@435 | 132 | // A JumpData is used to access profiling information for a direct |
duke@435 | 133 | // branch. It is a counter, used for counting the number of branches, |
duke@435 | 134 | // plus a data displacement, used for realigning the data pointer to |
duke@435 | 135 | // the corresponding target bci. |
duke@435 | 136 | |
coleenp@4037 | 137 | void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
duke@435 | 138 | assert(stream->bci() == bci(), "wrong pos"); |
duke@435 | 139 | int target; |
duke@435 | 140 | Bytecodes::Code c = stream->code(); |
duke@435 | 141 | if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) { |
duke@435 | 142 | target = stream->dest_w(); |
duke@435 | 143 | } else { |
duke@435 | 144 | target = stream->dest(); |
duke@435 | 145 | } |
duke@435 | 146 | int my_di = mdo->dp_to_di(dp()); |
duke@435 | 147 | int target_di = mdo->bci_to_di(target); |
duke@435 | 148 | int offset = target_di - my_di; |
duke@435 | 149 | set_displacement(offset); |
duke@435 | 150 | } |
duke@435 | 151 | |
duke@435 | 152 | #ifndef PRODUCT |
roland@5914 | 153 | void JumpData::print_data_on(outputStream* st) const { |
duke@435 | 154 | print_shared(st, "JumpData"); |
duke@435 | 155 | st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); |
duke@435 | 156 | } |
duke@435 | 157 | #endif // !PRODUCT |
duke@435 | 158 | |
roland@5987 | 159 | int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { |
roland@5987 | 160 | // Parameter profiling include the receiver |
roland@5987 | 161 | int args_count = include_receiver ? 1 : 0; |
roland@5921 | 162 | ResourceMark rm; |
roland@5921 | 163 | SignatureStream ss(signature); |
roland@5987 | 164 | args_count += ss.reference_parameter_count(); |
roland@5987 | 165 | args_count = MIN2(args_count, max); |
roland@5921 | 166 | return args_count * per_arg_cell_count; |
roland@5921 | 167 | } |
roland@5921 | 168 | |
roland@5921 | 169 | int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) { |
roland@5914 | 170 | assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); |
roland@5921 | 171 | assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken"); |
roland@5914 | 172 | Bytecode_invoke inv(stream->method(), stream->bci()); |
roland@5921 | 173 | int args_cell = 0; |
roland@5921 | 174 | if (arguments_profiling_enabled()) { |
roland@5987 | 175 | args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit); |
roland@5921 | 176 | } |
roland@5921 | 177 | int ret_cell = 0; |
roland@5921 | 178 | if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) { |
roland@5921 | 179 | ret_cell = ReturnTypeEntry::static_cell_count(); |
roland@5921 | 180 | } |
roland@5921 | 181 | int header_cell = 0; |
roland@5921 | 182 | if (args_cell + ret_cell > 0) { |
roland@5921 | 183 | header_cell = header_cell_count(); |
roland@5921 | 184 | } |
roland@5914 | 185 | |
roland@5921 | 186 | return header_cell + args_cell + ret_cell; |
roland@5914 | 187 | } |
roland@5914 | 188 | |
roland@5914 | 189 | class ArgumentOffsetComputer : public SignatureInfo { |
roland@5914 | 190 | private: |
roland@5914 | 191 | int _max; |
roland@5914 | 192 | GrowableArray<int> _offsets; |
roland@5914 | 193 | |
roland@5914 | 194 | void set(int size, BasicType type) { _size += size; } |
roland@5914 | 195 | void do_object(int begin, int end) { |
roland@5914 | 196 | if (_offsets.length() < _max) { |
roland@5914 | 197 | _offsets.push(_size); |
roland@5914 | 198 | } |
roland@5914 | 199 | SignatureInfo::do_object(begin, end); |
roland@5914 | 200 | } |
roland@5914 | 201 | void do_array (int begin, int end) { |
roland@5914 | 202 | if (_offsets.length() < _max) { |
roland@5914 | 203 | _offsets.push(_size); |
roland@5914 | 204 | } |
roland@5914 | 205 | SignatureInfo::do_array(begin, end); |
roland@5914 | 206 | } |
roland@5914 | 207 | |
roland@5914 | 208 | public: |
roland@5914 | 209 | ArgumentOffsetComputer(Symbol* signature, int max) |
roland@5914 | 210 | : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) { |
roland@5914 | 211 | } |
roland@5914 | 212 | |
roland@5914 | 213 | int total() { lazy_iterate_parameters(); return _size; } |
roland@5914 | 214 | |
roland@5914 | 215 | int off_at(int i) const { return _offsets.at(i); } |
roland@5914 | 216 | }; |
roland@5914 | 217 | |
roland@5987 | 218 | void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver, bool include_receiver) { |
roland@5914 | 219 | ResourceMark rm; |
roland@5987 | 220 | int start = 0; |
roland@5987 | 221 | // Parameter profiling include the receiver |
roland@5987 | 222 | if (include_receiver && has_receiver) { |
roland@5987 | 223 | set_stack_slot(0, 0); |
roland@5987 | 224 | set_type(0, type_none()); |
roland@5987 | 225 | start += 1; |
roland@5987 | 226 | } |
roland@5987 | 227 | ArgumentOffsetComputer aos(signature, _number_of_entries-start); |
roland@5921 | 228 | aos.total(); |
roland@5987 | 229 | for (int i = start; i < _number_of_entries; i++) { |
roland@5987 | 230 | set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0)); |
roland@5921 | 231 | set_type(i, type_none()); |
roland@5921 | 232 | } |
roland@5921 | 233 | } |
roland@5914 | 234 | |
roland@5921 | 235 | void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
roland@5914 | 236 | assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); |
roland@5914 | 237 | Bytecode_invoke inv(stream->method(), stream->bci()); |
roland@5914 | 238 | |
roland@5921 | 239 | SignatureStream ss(inv.signature()); |
roland@5921 | 240 | if (has_arguments()) { |
roland@5914 | 241 | #ifdef ASSERT |
roland@5921 | 242 | ResourceMark rm; |
roland@5921 | 243 | int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit); |
roland@5921 | 244 | assert(count > 0, "room for args type but none found?"); |
roland@5921 | 245 | check_number_of_arguments(count); |
roland@5914 | 246 | #endif |
roland@5987 | 247 | _args.post_initialize(inv.signature(), inv.has_receiver(), false); |
roland@5921 | 248 | } |
roland@5914 | 249 | |
roland@5921 | 250 | if (has_return()) { |
roland@5921 | 251 | assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?"); |
roland@5921 | 252 | _ret.post_initialize(); |
roland@5921 | 253 | } |
roland@5921 | 254 | } |
roland@5921 | 255 | |
roland@5921 | 256 | void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
roland@5921 | 257 | assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); |
roland@5921 | 258 | Bytecode_invoke inv(stream->method(), stream->bci()); |
roland@5921 | 259 | |
roland@5921 | 260 | if (has_arguments()) { |
roland@5921 | 261 | #ifdef ASSERT |
roland@5921 | 262 | ResourceMark rm; |
roland@5921 | 263 | SignatureStream ss(inv.signature()); |
roland@5921 | 264 | int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit); |
roland@5921 | 265 | assert(count > 0, "room for args type but none found?"); |
roland@5921 | 266 | check_number_of_arguments(count); |
roland@5921 | 267 | #endif |
roland@5987 | 268 | _args.post_initialize(inv.signature(), inv.has_receiver(), false); |
roland@5921 | 269 | } |
roland@5921 | 270 | |
roland@5921 | 271 | if (has_return()) { |
roland@5921 | 272 | assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?"); |
roland@5921 | 273 | _ret.post_initialize(); |
roland@5914 | 274 | } |
roland@5914 | 275 | } |
roland@5914 | 276 | |
roland@5914 | 277 | bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) { |
roland@6105 | 278 | Klass* k = (Klass*)klass_part(p); |
roland@6105 | 279 | return k != NULL && k->is_loader_alive(is_alive_cl); |
roland@5914 | 280 | } |
roland@5914 | 281 | |
roland@5914 | 282 | void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { |
roland@5921 | 283 | for (int i = 0; i < _number_of_entries; i++) { |
roland@5914 | 284 | intptr_t p = type(i); |
roland@6105 | 285 | if (!is_loader_alive(is_alive_cl, p)) { |
roland@6105 | 286 | set_type(i, with_status((Klass*)NULL, p)); |
roland@5914 | 287 | } |
roland@5914 | 288 | } |
roland@5914 | 289 | } |
roland@5914 | 290 | |
roland@5921 | 291 | void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { |
roland@5921 | 292 | intptr_t p = type(); |
roland@6105 | 293 | if (!is_loader_alive(is_alive_cl, p)) { |
roland@6105 | 294 | set_type(with_status((Klass*)NULL, p)); |
roland@5921 | 295 | } |
roland@5921 | 296 | } |
roland@5921 | 297 | |
roland@5921 | 298 | bool TypeEntriesAtCall::return_profiling_enabled() { |
roland@5921 | 299 | return MethodData::profile_return(); |
roland@5921 | 300 | } |
roland@5921 | 301 | |
roland@5921 | 302 | bool TypeEntriesAtCall::arguments_profiling_enabled() { |
roland@5914 | 303 | return MethodData::profile_arguments(); |
roland@5914 | 304 | } |
roland@5914 | 305 | |
roland@5914 | 306 | #ifndef PRODUCT |
roland@5914 | 307 | void TypeEntries::print_klass(outputStream* st, intptr_t k) { |
roland@5914 | 308 | if (is_type_none(k)) { |
roland@5914 | 309 | st->print("none"); |
roland@5914 | 310 | } else if (is_type_unknown(k)) { |
roland@5914 | 311 | st->print("unknown"); |
roland@5914 | 312 | } else { |
roland@5914 | 313 | valid_klass(k)->print_value_on(st); |
roland@5914 | 314 | } |
roland@5914 | 315 | if (was_null_seen(k)) { |
roland@5914 | 316 | st->print(" (null seen)"); |
roland@5914 | 317 | } |
roland@5914 | 318 | } |
roland@5914 | 319 | |
roland@5914 | 320 | void TypeStackSlotEntries::print_data_on(outputStream* st) const { |
roland@5921 | 321 | for (int i = 0; i < _number_of_entries; i++) { |
roland@5914 | 322 | _pd->tab(st); |
roland@5914 | 323 | st->print("%d: stack(%u) ", i, stack_slot(i)); |
roland@5914 | 324 | print_klass(st, type(i)); |
roland@5914 | 325 | st->cr(); |
roland@5914 | 326 | } |
roland@5914 | 327 | } |
roland@5914 | 328 | |
roland@5921 | 329 | void ReturnTypeEntry::print_data_on(outputStream* st) const { |
roland@5921 | 330 | _pd->tab(st); |
roland@5921 | 331 | print_klass(st, type()); |
roland@5921 | 332 | st->cr(); |
roland@5921 | 333 | } |
roland@5921 | 334 | |
roland@5914 | 335 | void CallTypeData::print_data_on(outputStream* st) const { |
roland@5914 | 336 | CounterData::print_data_on(st); |
roland@5921 | 337 | if (has_arguments()) { |
roland@5921 | 338 | tab(st, true); |
roland@5921 | 339 | st->print("argument types"); |
roland@5921 | 340 | _args.print_data_on(st); |
roland@5921 | 341 | } |
roland@5921 | 342 | if (has_return()) { |
roland@5921 | 343 | tab(st, true); |
roland@5921 | 344 | st->print("return type"); |
roland@5921 | 345 | _ret.print_data_on(st); |
roland@5921 | 346 | } |
roland@5914 | 347 | } |
roland@5914 | 348 | |
roland@5914 | 349 | void VirtualCallTypeData::print_data_on(outputStream* st) const { |
roland@5914 | 350 | VirtualCallData::print_data_on(st); |
roland@5921 | 351 | if (has_arguments()) { |
roland@5921 | 352 | tab(st, true); |
roland@5921 | 353 | st->print("argument types"); |
roland@5921 | 354 | _args.print_data_on(st); |
roland@5921 | 355 | } |
roland@5921 | 356 | if (has_return()) { |
roland@5921 | 357 | tab(st, true); |
roland@5921 | 358 | st->print("return type"); |
roland@5921 | 359 | _ret.print_data_on(st); |
roland@5921 | 360 | } |
roland@5914 | 361 | } |
roland@5914 | 362 | #endif |
roland@5914 | 363 | |
duke@435 | 364 | // ================================================================== |
duke@435 | 365 | // ReceiverTypeData |
duke@435 | 366 | // |
duke@435 | 367 | // A ReceiverTypeData is used to access profiling information about a |
duke@435 | 368 | // dynamic type check. It consists of a counter which counts the total times |
coleenp@4037 | 369 | // that the check is reached, and a series of (Klass*, count) pairs |
duke@435 | 370 | // which are used to store a type profile for the receiver of the check. |
duke@435 | 371 | |
coleenp@4037 | 372 | void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { |
ysr@1376 | 373 | for (uint row = 0; row < row_limit(); row++) { |
coleenp@4037 | 374 | Klass* p = receiver(row); |
coleenp@4037 | 375 | if (p != NULL && !p->is_loader_alive(is_alive_cl)) { |
ysr@1376 | 376 | clear_row(row); |
ysr@1376 | 377 | } |
ysr@1376 | 378 | } |
ysr@1376 | 379 | } |
ysr@1376 | 380 | |
duke@435 | 381 | #ifndef PRODUCT |
roland@5914 | 382 | void ReceiverTypeData::print_receiver_data_on(outputStream* st) const { |
duke@435 | 383 | uint row; |
duke@435 | 384 | int entries = 0; |
duke@435 | 385 | for (row = 0; row < row_limit(); row++) { |
duke@435 | 386 | if (receiver(row) != NULL) entries++; |
duke@435 | 387 | } |
duke@435 | 388 | st->print_cr("count(%u) entries(%u)", count(), entries); |
iveresov@2138 | 389 | int total = count(); |
iveresov@2138 | 390 | for (row = 0; row < row_limit(); row++) { |
iveresov@2138 | 391 | if (receiver(row) != NULL) { |
iveresov@2138 | 392 | total += receiver_count(row); |
iveresov@2138 | 393 | } |
iveresov@2138 | 394 | } |
duke@435 | 395 | for (row = 0; row < row_limit(); row++) { |
duke@435 | 396 | if (receiver(row) != NULL) { |
duke@435 | 397 | tab(st); |
duke@435 | 398 | receiver(row)->print_value_on(st); |
iveresov@2138 | 399 | st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); |
duke@435 | 400 | } |
duke@435 | 401 | } |
duke@435 | 402 | } |
roland@5914 | 403 | void ReceiverTypeData::print_data_on(outputStream* st) const { |
duke@435 | 404 | print_shared(st, "ReceiverTypeData"); |
duke@435 | 405 | print_receiver_data_on(st); |
duke@435 | 406 | } |
roland@5914 | 407 | void VirtualCallData::print_data_on(outputStream* st) const { |
duke@435 | 408 | print_shared(st, "VirtualCallData"); |
duke@435 | 409 | print_receiver_data_on(st); |
duke@435 | 410 | } |
duke@435 | 411 | #endif // !PRODUCT |
duke@435 | 412 | |
duke@435 | 413 | // ================================================================== |
duke@435 | 414 | // RetData |
duke@435 | 415 | // |
duke@435 | 416 | // A RetData is used to access profiling information for a ret bytecode. |
duke@435 | 417 | // It is composed of a count of the number of times that the ret has |
duke@435 | 418 | // been executed, followed by a series of triples of the form |
duke@435 | 419 | // (bci, count, di) which count the number of times that some bci was the |
duke@435 | 420 | // target of the ret and cache a corresponding displacement. |
duke@435 | 421 | |
coleenp@4037 | 422 | void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
duke@435 | 423 | for (uint row = 0; row < row_limit(); row++) { |
duke@435 | 424 | set_bci_displacement(row, -1); |
duke@435 | 425 | set_bci(row, no_bci); |
duke@435 | 426 | } |
duke@435 | 427 | // release so other threads see a consistent state. bci is used as |
duke@435 | 428 | // a valid flag for bci_displacement. |
duke@435 | 429 | OrderAccess::release(); |
duke@435 | 430 | } |
duke@435 | 431 | |
duke@435 | 432 | // This routine needs to atomically update the RetData structure, so the |
duke@435 | 433 | // caller needs to hold the RetData_lock before it gets here. Since taking |
duke@435 | 434 | // the lock can block (and allow GC) and since RetData is a ProfileData is a |
duke@435 | 435 | // wrapper around a derived oop, taking the lock in _this_ method will |
duke@435 | 436 | // basically cause the 'this' pointer's _data field to contain junk after the |
duke@435 | 437 | // lock. We require the caller to take the lock before making the ProfileData |
duke@435 | 438 | // structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret |
coleenp@4037 | 439 | address RetData::fixup_ret(int return_bci, MethodData* h_mdo) { |
duke@435 | 440 | // First find the mdp which corresponds to the return bci. |
duke@435 | 441 | address mdp = h_mdo->bci_to_dp(return_bci); |
duke@435 | 442 | |
duke@435 | 443 | // Now check to see if any of the cache slots are open. |
duke@435 | 444 | for (uint row = 0; row < row_limit(); row++) { |
duke@435 | 445 | if (bci(row) == no_bci) { |
duke@435 | 446 | set_bci_displacement(row, mdp - dp()); |
duke@435 | 447 | set_bci_count(row, DataLayout::counter_increment); |
duke@435 | 448 | // Barrier to ensure displacement is written before the bci; allows |
duke@435 | 449 | // the interpreter to read displacement without fear of race condition. |
duke@435 | 450 | release_set_bci(row, return_bci); |
duke@435 | 451 | break; |
duke@435 | 452 | } |
duke@435 | 453 | } |
duke@435 | 454 | return mdp; |
duke@435 | 455 | } |
duke@435 | 456 | |
duke@435 | 457 | |
duke@435 | 458 | #ifndef PRODUCT |
roland@5914 | 459 | void RetData::print_data_on(outputStream* st) const { |
duke@435 | 460 | print_shared(st, "RetData"); |
duke@435 | 461 | uint row; |
duke@435 | 462 | int entries = 0; |
duke@435 | 463 | for (row = 0; row < row_limit(); row++) { |
duke@435 | 464 | if (bci(row) != no_bci) entries++; |
duke@435 | 465 | } |
duke@435 | 466 | st->print_cr("count(%u) entries(%u)", count(), entries); |
duke@435 | 467 | for (row = 0; row < row_limit(); row++) { |
duke@435 | 468 | if (bci(row) != no_bci) { |
duke@435 | 469 | tab(st); |
duke@435 | 470 | st->print_cr("bci(%d: count(%u) displacement(%d))", |
duke@435 | 471 | bci(row), bci_count(row), bci_displacement(row)); |
duke@435 | 472 | } |
duke@435 | 473 | } |
duke@435 | 474 | } |
duke@435 | 475 | #endif // !PRODUCT |
duke@435 | 476 | |
duke@435 | 477 | // ================================================================== |
duke@435 | 478 | // BranchData |
duke@435 | 479 | // |
duke@435 | 480 | // A BranchData is used to access profiling data for a two-way branch. |
duke@435 | 481 | // It consists of taken and not_taken counts as well as a data displacement |
duke@435 | 482 | // for the taken case. |
duke@435 | 483 | |
coleenp@4037 | 484 | void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
duke@435 | 485 | assert(stream->bci() == bci(), "wrong pos"); |
duke@435 | 486 | int target = stream->dest(); |
duke@435 | 487 | int my_di = mdo->dp_to_di(dp()); |
duke@435 | 488 | int target_di = mdo->bci_to_di(target); |
duke@435 | 489 | int offset = target_di - my_di; |
duke@435 | 490 | set_displacement(offset); |
duke@435 | 491 | } |
duke@435 | 492 | |
duke@435 | 493 | #ifndef PRODUCT |
roland@5914 | 494 | void BranchData::print_data_on(outputStream* st) const { |
duke@435 | 495 | print_shared(st, "BranchData"); |
duke@435 | 496 | st->print_cr("taken(%u) displacement(%d)", |
duke@435 | 497 | taken(), displacement()); |
duke@435 | 498 | tab(st); |
duke@435 | 499 | st->print_cr("not taken(%u)", not_taken()); |
duke@435 | 500 | } |
duke@435 | 501 | #endif |
duke@435 | 502 | |
duke@435 | 503 | // ================================================================== |
duke@435 | 504 | // MultiBranchData |
duke@435 | 505 | // |
duke@435 | 506 | // A MultiBranchData is used to access profiling information for |
duke@435 | 507 | // a multi-way branch (*switch bytecodes). It consists of a series |
duke@435 | 508 | // of (count, displacement) pairs, which count the number of times each |
duke@435 | 509 | // case was taken and specify the data displacment for each branch target. |
duke@435 | 510 | |
duke@435 | 511 | int MultiBranchData::compute_cell_count(BytecodeStream* stream) { |
duke@435 | 512 | int cell_count = 0; |
duke@435 | 513 | if (stream->code() == Bytecodes::_tableswitch) { |
never@2462 | 514 | Bytecode_tableswitch sw(stream->method()(), stream->bcp()); |
never@2462 | 515 | cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default |
duke@435 | 516 | } else { |
never@2462 | 517 | Bytecode_lookupswitch sw(stream->method()(), stream->bcp()); |
never@2462 | 518 | cell_count = 1 + per_case_cell_count * (sw.number_of_pairs() + 1); // 1 for default |
duke@435 | 519 | } |
duke@435 | 520 | return cell_count; |
duke@435 | 521 | } |
duke@435 | 522 | |
duke@435 | 523 | void MultiBranchData::post_initialize(BytecodeStream* stream, |
coleenp@4037 | 524 | MethodData* mdo) { |
duke@435 | 525 | assert(stream->bci() == bci(), "wrong pos"); |
duke@435 | 526 | int target; |
duke@435 | 527 | int my_di; |
duke@435 | 528 | int target_di; |
duke@435 | 529 | int offset; |
duke@435 | 530 | if (stream->code() == Bytecodes::_tableswitch) { |
never@2462 | 531 | Bytecode_tableswitch sw(stream->method()(), stream->bcp()); |
never@2462 | 532 | int len = sw.length(); |
duke@435 | 533 | assert(array_len() == per_case_cell_count * (len + 1), "wrong len"); |
duke@435 | 534 | for (int count = 0; count < len; count++) { |
never@2462 | 535 | target = sw.dest_offset_at(count) + bci(); |
duke@435 | 536 | my_di = mdo->dp_to_di(dp()); |
duke@435 | 537 | target_di = mdo->bci_to_di(target); |
duke@435 | 538 | offset = target_di - my_di; |
duke@435 | 539 | set_displacement_at(count, offset); |
duke@435 | 540 | } |
never@2462 | 541 | target = sw.default_offset() + bci(); |
duke@435 | 542 | my_di = mdo->dp_to_di(dp()); |
duke@435 | 543 | target_di = mdo->bci_to_di(target); |
duke@435 | 544 | offset = target_di - my_di; |
duke@435 | 545 | set_default_displacement(offset); |
duke@435 | 546 | |
duke@435 | 547 | } else { |
never@2462 | 548 | Bytecode_lookupswitch sw(stream->method()(), stream->bcp()); |
never@2462 | 549 | int npairs = sw.number_of_pairs(); |
duke@435 | 550 | assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len"); |
duke@435 | 551 | for (int count = 0; count < npairs; count++) { |
never@2462 | 552 | LookupswitchPair pair = sw.pair_at(count); |
never@2462 | 553 | target = pair.offset() + bci(); |
duke@435 | 554 | my_di = mdo->dp_to_di(dp()); |
duke@435 | 555 | target_di = mdo->bci_to_di(target); |
duke@435 | 556 | offset = target_di - my_di; |
duke@435 | 557 | set_displacement_at(count, offset); |
duke@435 | 558 | } |
never@2462 | 559 | target = sw.default_offset() + bci(); |
duke@435 | 560 | my_di = mdo->dp_to_di(dp()); |
duke@435 | 561 | target_di = mdo->bci_to_di(target); |
duke@435 | 562 | offset = target_di - my_di; |
duke@435 | 563 | set_default_displacement(offset); |
duke@435 | 564 | } |
duke@435 | 565 | } |
duke@435 | 566 | |
duke@435 | 567 | #ifndef PRODUCT |
roland@5914 | 568 | void MultiBranchData::print_data_on(outputStream* st) const { |
duke@435 | 569 | print_shared(st, "MultiBranchData"); |
duke@435 | 570 | st->print_cr("default_count(%u) displacement(%d)", |
duke@435 | 571 | default_count(), default_displacement()); |
duke@435 | 572 | int cases = number_of_cases(); |
duke@435 | 573 | for (int i = 0; i < cases; i++) { |
duke@435 | 574 | tab(st); |
duke@435 | 575 | st->print_cr("count(%u) displacement(%d)", |
duke@435 | 576 | count_at(i), displacement_at(i)); |
duke@435 | 577 | } |
duke@435 | 578 | } |
duke@435 | 579 | #endif |
duke@435 | 580 | |
kvn@480 | 581 | #ifndef PRODUCT |
roland@5914 | 582 | void ArgInfoData::print_data_on(outputStream* st) const { |
kvn@480 | 583 | print_shared(st, "ArgInfoData"); |
kvn@480 | 584 | int nargs = number_of_args(); |
kvn@480 | 585 | for (int i = 0; i < nargs; i++) { |
kvn@480 | 586 | st->print(" 0x%x", arg_modified(i)); |
kvn@480 | 587 | } |
kvn@480 | 588 | st->cr(); |
kvn@480 | 589 | } |
kvn@480 | 590 | |
kvn@480 | 591 | #endif |
roland@5987 | 592 | |
roland@5987 | 593 | int ParametersTypeData::compute_cell_count(Method* m) { |
roland@5987 | 594 | if (!MethodData::profile_parameters_for_method(m)) { |
roland@5987 | 595 | return 0; |
roland@5987 | 596 | } |
roland@5987 | 597 | int max = TypeProfileParmsLimit == -1 ? INT_MAX : TypeProfileParmsLimit; |
roland@5987 | 598 | int obj_args = TypeStackSlotEntries::compute_cell_count(m->signature(), !m->is_static(), max); |
roland@5987 | 599 | if (obj_args > 0) { |
roland@5987 | 600 | return obj_args + 1; // 1 cell for array len |
roland@5987 | 601 | } |
roland@5987 | 602 | return 0; |
roland@5987 | 603 | } |
roland@5987 | 604 | |
roland@5987 | 605 | void ParametersTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
roland@5987 | 606 | _parameters.post_initialize(mdo->method()->signature(), !mdo->method()->is_static(), true); |
roland@5987 | 607 | } |
roland@5987 | 608 | |
roland@5987 | 609 | bool ParametersTypeData::profiling_enabled() { |
roland@5987 | 610 | return MethodData::profile_parameters(); |
roland@5987 | 611 | } |
roland@5987 | 612 | |
roland@5987 | 613 | #ifndef PRODUCT |
roland@5987 | 614 | void ParametersTypeData::print_data_on(outputStream* st) const { |
roland@5987 | 615 | st->print("parameter types"); |
roland@5987 | 616 | _parameters.print_data_on(st); |
roland@5987 | 617 | } |
roland@5987 | 618 | #endif |
roland@5987 | 619 | |
duke@435 | 620 | // ================================================================== |
coleenp@4037 | 621 | // MethodData* |
duke@435 | 622 | // |
coleenp@4037 | 623 | // A MethodData* holds information which has been collected about |
duke@435 | 624 | // a method. |
duke@435 | 625 | |
coleenp@4037 | 626 | MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) { |
coleenp@4037 | 627 | int size = MethodData::compute_allocation_size_in_words(method); |
coleenp@4037 | 628 | |
iklam@5208 | 629 | return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD) |
iklam@5208 | 630 | MethodData(method(), size, CHECK_NULL); |
coleenp@4037 | 631 | } |
coleenp@4037 | 632 | |
coleenp@4037 | 633 | int MethodData::bytecode_cell_count(Bytecodes::Code code) { |
roland@4860 | 634 | #if defined(COMPILER1) && !defined(COMPILER2) |
roland@4860 | 635 | return no_profile_data; |
roland@4860 | 636 | #else |
duke@435 | 637 | switch (code) { |
duke@435 | 638 | case Bytecodes::_checkcast: |
duke@435 | 639 | case Bytecodes::_instanceof: |
duke@435 | 640 | case Bytecodes::_aastore: |
duke@435 | 641 | if (TypeProfileCasts) { |
duke@435 | 642 | return ReceiverTypeData::static_cell_count(); |
duke@435 | 643 | } else { |
duke@435 | 644 | return BitData::static_cell_count(); |
duke@435 | 645 | } |
duke@435 | 646 | case Bytecodes::_invokespecial: |
duke@435 | 647 | case Bytecodes::_invokestatic: |
roland@5921 | 648 | if (MethodData::profile_arguments() || MethodData::profile_return()) { |
roland@5914 | 649 | return variable_cell_count; |
roland@5914 | 650 | } else { |
roland@5914 | 651 | return CounterData::static_cell_count(); |
roland@5914 | 652 | } |
duke@435 | 653 | case Bytecodes::_goto: |
duke@435 | 654 | case Bytecodes::_goto_w: |
duke@435 | 655 | case Bytecodes::_jsr: |
duke@435 | 656 | case Bytecodes::_jsr_w: |
duke@435 | 657 | return JumpData::static_cell_count(); |
duke@435 | 658 | case Bytecodes::_invokevirtual: |
duke@435 | 659 | case Bytecodes::_invokeinterface: |
roland@5921 | 660 | if (MethodData::profile_arguments() || MethodData::profile_return()) { |
roland@5914 | 661 | return variable_cell_count; |
roland@5914 | 662 | } else { |
roland@5914 | 663 | return VirtualCallData::static_cell_count(); |
roland@5914 | 664 | } |
jrose@1161 | 665 | case Bytecodes::_invokedynamic: |
roland@5921 | 666 | if (MethodData::profile_arguments() || MethodData::profile_return()) { |
roland@5914 | 667 | return variable_cell_count; |
roland@5914 | 668 | } else { |
roland@5914 | 669 | return CounterData::static_cell_count(); |
roland@5914 | 670 | } |
duke@435 | 671 | case Bytecodes::_ret: |
duke@435 | 672 | return RetData::static_cell_count(); |
duke@435 | 673 | case Bytecodes::_ifeq: |
duke@435 | 674 | case Bytecodes::_ifne: |
duke@435 | 675 | case Bytecodes::_iflt: |
duke@435 | 676 | case Bytecodes::_ifge: |
duke@435 | 677 | case Bytecodes::_ifgt: |
duke@435 | 678 | case Bytecodes::_ifle: |
duke@435 | 679 | case Bytecodes::_if_icmpeq: |
duke@435 | 680 | case Bytecodes::_if_icmpne: |
duke@435 | 681 | case Bytecodes::_if_icmplt: |
duke@435 | 682 | case Bytecodes::_if_icmpge: |
duke@435 | 683 | case Bytecodes::_if_icmpgt: |
duke@435 | 684 | case Bytecodes::_if_icmple: |
duke@435 | 685 | case Bytecodes::_if_acmpeq: |
duke@435 | 686 | case Bytecodes::_if_acmpne: |
duke@435 | 687 | case Bytecodes::_ifnull: |
duke@435 | 688 | case Bytecodes::_ifnonnull: |
duke@435 | 689 | return BranchData::static_cell_count(); |
duke@435 | 690 | case Bytecodes::_lookupswitch: |
duke@435 | 691 | case Bytecodes::_tableswitch: |
duke@435 | 692 | return variable_cell_count; |
duke@435 | 693 | } |
duke@435 | 694 | return no_profile_data; |
roland@4860 | 695 | #endif |
duke@435 | 696 | } |
duke@435 | 697 | |
duke@435 | 698 | // Compute the size of the profiling information corresponding to |
duke@435 | 699 | // the current bytecode. |
coleenp@4037 | 700 | int MethodData::compute_data_size(BytecodeStream* stream) { |
duke@435 | 701 | int cell_count = bytecode_cell_count(stream->code()); |
duke@435 | 702 | if (cell_count == no_profile_data) { |
duke@435 | 703 | return 0; |
duke@435 | 704 | } |
duke@435 | 705 | if (cell_count == variable_cell_count) { |
roland@5914 | 706 | switch (stream->code()) { |
roland@5914 | 707 | case Bytecodes::_lookupswitch: |
roland@5914 | 708 | case Bytecodes::_tableswitch: |
roland@5914 | 709 | cell_count = MultiBranchData::compute_cell_count(stream); |
roland@5914 | 710 | break; |
roland@5914 | 711 | case Bytecodes::_invokespecial: |
roland@5914 | 712 | case Bytecodes::_invokestatic: |
roland@5914 | 713 | case Bytecodes::_invokedynamic: |
roland@5921 | 714 | assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile"); |
roland@5921 | 715 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 716 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 717 | cell_count = CallTypeData::compute_cell_count(stream); |
roland@5914 | 718 | } else { |
roland@5914 | 719 | cell_count = CounterData::static_cell_count(); |
roland@5914 | 720 | } |
roland@5914 | 721 | break; |
roland@5914 | 722 | case Bytecodes::_invokevirtual: |
roland@5914 | 723 | case Bytecodes::_invokeinterface: { |
roland@5921 | 724 | assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile"); |
roland@5921 | 725 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 726 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 727 | cell_count = VirtualCallTypeData::compute_cell_count(stream); |
roland@5914 | 728 | } else { |
roland@5914 | 729 | cell_count = VirtualCallData::static_cell_count(); |
roland@5914 | 730 | } |
roland@5914 | 731 | break; |
roland@5914 | 732 | } |
roland@5914 | 733 | default: |
roland@5914 | 734 | fatal("unexpected bytecode for var length profile data"); |
roland@5914 | 735 | } |
duke@435 | 736 | } |
duke@435 | 737 | // Note: cell_count might be zero, meaning that there is just |
duke@435 | 738 | // a DataLayout header, with no extra cells. |
duke@435 | 739 | assert(cell_count >= 0, "sanity"); |
duke@435 | 740 | return DataLayout::compute_size_in_bytes(cell_count); |
duke@435 | 741 | } |
duke@435 | 742 | |
coleenp@4037 | 743 | int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) { |
duke@435 | 744 | if (ProfileTraps) { |
duke@435 | 745 | // Assume that up to 3% of BCIs with no MDP will need to allocate one. |
duke@435 | 746 | int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; |
duke@435 | 747 | // If the method is large, let the extra BCIs grow numerous (to ~1%). |
duke@435 | 748 | int one_percent_of_data |
duke@435 | 749 | = (uint)data_size / (DataLayout::header_size_in_bytes()*128); |
duke@435 | 750 | if (extra_data_count < one_percent_of_data) |
duke@435 | 751 | extra_data_count = one_percent_of_data; |
duke@435 | 752 | if (extra_data_count > empty_bc_count) |
duke@435 | 753 | extra_data_count = empty_bc_count; // no need for more |
duke@435 | 754 | return extra_data_count; |
duke@435 | 755 | } else { |
duke@435 | 756 | return 0; |
duke@435 | 757 | } |
duke@435 | 758 | } |
duke@435 | 759 | |
coleenp@4037 | 760 | // Compute the size of the MethodData* necessary to store |
duke@435 | 761 | // profiling information about a given method. Size is in bytes. |
coleenp@4037 | 762 | int MethodData::compute_allocation_size_in_bytes(methodHandle method) { |
duke@435 | 763 | int data_size = 0; |
duke@435 | 764 | BytecodeStream stream(method); |
duke@435 | 765 | Bytecodes::Code c; |
duke@435 | 766 | int empty_bc_count = 0; // number of bytecodes lacking data |
duke@435 | 767 | while ((c = stream.next()) >= 0) { |
duke@435 | 768 | int size_in_bytes = compute_data_size(&stream); |
duke@435 | 769 | data_size += size_in_bytes; |
duke@435 | 770 | if (size_in_bytes == 0) empty_bc_count += 1; |
duke@435 | 771 | } |
duke@435 | 772 | int object_size = in_bytes(data_offset()) + data_size; |
duke@435 | 773 | |
duke@435 | 774 | // Add some extra DataLayout cells (at least one) to track stray traps. |
duke@435 | 775 | int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); |
duke@435 | 776 | object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); |
duke@435 | 777 | |
kvn@480 | 778 | // Add a cell to record information about modified arguments. |
kvn@480 | 779 | int arg_size = method->size_of_parameters(); |
kvn@480 | 780 | object_size += DataLayout::compute_size_in_bytes(arg_size+1); |
roland@5914 | 781 | |
roland@5987 | 782 | // Reserve room for an area of the MDO dedicated to profiling of |
roland@5987 | 783 | // parameters |
roland@5987 | 784 | int args_cell = ParametersTypeData::compute_cell_count(method()); |
roland@5987 | 785 | if (args_cell > 0) { |
roland@5987 | 786 | object_size += DataLayout::compute_size_in_bytes(args_cell); |
roland@5987 | 787 | } |
duke@435 | 788 | return object_size; |
duke@435 | 789 | } |
duke@435 | 790 | |
coleenp@4037 | 791 | // Compute the size of the MethodData* necessary to store |
duke@435 | 792 | // profiling information about a given method. Size is in words |
coleenp@4037 | 793 | int MethodData::compute_allocation_size_in_words(methodHandle method) { |
duke@435 | 794 | int byte_size = compute_allocation_size_in_bytes(method); |
duke@435 | 795 | int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord; |
duke@435 | 796 | return align_object_size(word_size); |
duke@435 | 797 | } |
duke@435 | 798 | |
duke@435 | 799 | // Initialize an individual data segment. Returns the size of |
duke@435 | 800 | // the segment in bytes. |
coleenp@4037 | 801 | int MethodData::initialize_data(BytecodeStream* stream, |
duke@435 | 802 | int data_index) { |
roland@4860 | 803 | #if defined(COMPILER1) && !defined(COMPILER2) |
roland@4860 | 804 | return 0; |
roland@4860 | 805 | #else |
duke@435 | 806 | int cell_count = -1; |
duke@435 | 807 | int tag = DataLayout::no_tag; |
duke@435 | 808 | DataLayout* data_layout = data_layout_at(data_index); |
duke@435 | 809 | Bytecodes::Code c = stream->code(); |
duke@435 | 810 | switch (c) { |
duke@435 | 811 | case Bytecodes::_checkcast: |
duke@435 | 812 | case Bytecodes::_instanceof: |
duke@435 | 813 | case Bytecodes::_aastore: |
duke@435 | 814 | if (TypeProfileCasts) { |
duke@435 | 815 | cell_count = ReceiverTypeData::static_cell_count(); |
duke@435 | 816 | tag = DataLayout::receiver_type_data_tag; |
duke@435 | 817 | } else { |
duke@435 | 818 | cell_count = BitData::static_cell_count(); |
duke@435 | 819 | tag = DataLayout::bit_data_tag; |
duke@435 | 820 | } |
duke@435 | 821 | break; |
duke@435 | 822 | case Bytecodes::_invokespecial: |
roland@5914 | 823 | case Bytecodes::_invokestatic: { |
roland@5914 | 824 | int counter_data_cell_count = CounterData::static_cell_count(); |
roland@5921 | 825 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 826 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 827 | cell_count = CallTypeData::compute_cell_count(stream); |
roland@5914 | 828 | } else { |
roland@5914 | 829 | cell_count = counter_data_cell_count; |
roland@5914 | 830 | } |
roland@5914 | 831 | if (cell_count > counter_data_cell_count) { |
roland@5914 | 832 | tag = DataLayout::call_type_data_tag; |
roland@5914 | 833 | } else { |
roland@5914 | 834 | tag = DataLayout::counter_data_tag; |
roland@5914 | 835 | } |
duke@435 | 836 | break; |
roland@5914 | 837 | } |
duke@435 | 838 | case Bytecodes::_goto: |
duke@435 | 839 | case Bytecodes::_goto_w: |
duke@435 | 840 | case Bytecodes::_jsr: |
duke@435 | 841 | case Bytecodes::_jsr_w: |
duke@435 | 842 | cell_count = JumpData::static_cell_count(); |
duke@435 | 843 | tag = DataLayout::jump_data_tag; |
duke@435 | 844 | break; |
duke@435 | 845 | case Bytecodes::_invokevirtual: |
roland@5914 | 846 | case Bytecodes::_invokeinterface: { |
roland@5914 | 847 | int virtual_call_data_cell_count = VirtualCallData::static_cell_count(); |
roland@5921 | 848 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 849 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 850 | cell_count = VirtualCallTypeData::compute_cell_count(stream); |
roland@5914 | 851 | } else { |
roland@5914 | 852 | cell_count = virtual_call_data_cell_count; |
roland@5914 | 853 | } |
roland@5914 | 854 | if (cell_count > virtual_call_data_cell_count) { |
roland@5914 | 855 | tag = DataLayout::virtual_call_type_data_tag; |
roland@5914 | 856 | } else { |
roland@5914 | 857 | tag = DataLayout::virtual_call_data_tag; |
roland@5914 | 858 | } |
duke@435 | 859 | break; |
roland@5914 | 860 | } |
roland@5914 | 861 | case Bytecodes::_invokedynamic: { |
jrose@1161 | 862 | // %%% should make a type profile for any invokedynamic that takes a ref argument |
roland@5914 | 863 | int counter_data_cell_count = CounterData::static_cell_count(); |
roland@5921 | 864 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 865 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 866 | cell_count = CallTypeData::compute_cell_count(stream); |
roland@5914 | 867 | } else { |
roland@5914 | 868 | cell_count = counter_data_cell_count; |
roland@5914 | 869 | } |
roland@5914 | 870 | if (cell_count > counter_data_cell_count) { |
roland@5914 | 871 | tag = DataLayout::call_type_data_tag; |
roland@5914 | 872 | } else { |
roland@5914 | 873 | tag = DataLayout::counter_data_tag; |
roland@5914 | 874 | } |
jrose@1161 | 875 | break; |
roland@5914 | 876 | } |
duke@435 | 877 | case Bytecodes::_ret: |
duke@435 | 878 | cell_count = RetData::static_cell_count(); |
duke@435 | 879 | tag = DataLayout::ret_data_tag; |
duke@435 | 880 | break; |
duke@435 | 881 | case Bytecodes::_ifeq: |
duke@435 | 882 | case Bytecodes::_ifne: |
duke@435 | 883 | case Bytecodes::_iflt: |
duke@435 | 884 | case Bytecodes::_ifge: |
duke@435 | 885 | case Bytecodes::_ifgt: |
duke@435 | 886 | case Bytecodes::_ifle: |
duke@435 | 887 | case Bytecodes::_if_icmpeq: |
duke@435 | 888 | case Bytecodes::_if_icmpne: |
duke@435 | 889 | case Bytecodes::_if_icmplt: |
duke@435 | 890 | case Bytecodes::_if_icmpge: |
duke@435 | 891 | case Bytecodes::_if_icmpgt: |
duke@435 | 892 | case Bytecodes::_if_icmple: |
duke@435 | 893 | case Bytecodes::_if_acmpeq: |
duke@435 | 894 | case Bytecodes::_if_acmpne: |
duke@435 | 895 | case Bytecodes::_ifnull: |
duke@435 | 896 | case Bytecodes::_ifnonnull: |
duke@435 | 897 | cell_count = BranchData::static_cell_count(); |
duke@435 | 898 | tag = DataLayout::branch_data_tag; |
duke@435 | 899 | break; |
duke@435 | 900 | case Bytecodes::_lookupswitch: |
duke@435 | 901 | case Bytecodes::_tableswitch: |
duke@435 | 902 | cell_count = MultiBranchData::compute_cell_count(stream); |
duke@435 | 903 | tag = DataLayout::multi_branch_data_tag; |
duke@435 | 904 | break; |
duke@435 | 905 | } |
duke@435 | 906 | assert(tag == DataLayout::multi_branch_data_tag || |
roland@5921 | 907 | ((MethodData::profile_arguments() || MethodData::profile_return()) && |
roland@5914 | 908 | (tag == DataLayout::call_type_data_tag || |
roland@5914 | 909 | tag == DataLayout::counter_data_tag || |
roland@5914 | 910 | tag == DataLayout::virtual_call_type_data_tag || |
roland@5914 | 911 | tag == DataLayout::virtual_call_data_tag)) || |
duke@435 | 912 | cell_count == bytecode_cell_count(c), "cell counts must agree"); |
duke@435 | 913 | if (cell_count >= 0) { |
duke@435 | 914 | assert(tag != DataLayout::no_tag, "bad tag"); |
duke@435 | 915 | assert(bytecode_has_profile(c), "agree w/ BHP"); |
duke@435 | 916 | data_layout->initialize(tag, stream->bci(), cell_count); |
duke@435 | 917 | return DataLayout::compute_size_in_bytes(cell_count); |
duke@435 | 918 | } else { |
duke@435 | 919 | assert(!bytecode_has_profile(c), "agree w/ !BHP"); |
duke@435 | 920 | return 0; |
duke@435 | 921 | } |
roland@4860 | 922 | #endif |
duke@435 | 923 | } |
duke@435 | 924 | |
duke@435 | 925 | // Get the data at an arbitrary (sort of) data index. |
coleenp@4037 | 926 | ProfileData* MethodData::data_at(int data_index) const { |
duke@435 | 927 | if (out_of_bounds(data_index)) { |
duke@435 | 928 | return NULL; |
duke@435 | 929 | } |
duke@435 | 930 | DataLayout* data_layout = data_layout_at(data_index); |
ysr@1376 | 931 | return data_layout->data_in(); |
ysr@1376 | 932 | } |
duke@435 | 933 | |
ysr@1376 | 934 | ProfileData* DataLayout::data_in() { |
ysr@1376 | 935 | switch (tag()) { |
duke@435 | 936 | case DataLayout::no_tag: |
duke@435 | 937 | default: |
duke@435 | 938 | ShouldNotReachHere(); |
duke@435 | 939 | return NULL; |
duke@435 | 940 | case DataLayout::bit_data_tag: |
ysr@1376 | 941 | return new BitData(this); |
duke@435 | 942 | case DataLayout::counter_data_tag: |
ysr@1376 | 943 | return new CounterData(this); |
duke@435 | 944 | case DataLayout::jump_data_tag: |
ysr@1376 | 945 | return new JumpData(this); |
duke@435 | 946 | case DataLayout::receiver_type_data_tag: |
ysr@1376 | 947 | return new ReceiverTypeData(this); |
duke@435 | 948 | case DataLayout::virtual_call_data_tag: |
ysr@1376 | 949 | return new VirtualCallData(this); |
duke@435 | 950 | case DataLayout::ret_data_tag: |
ysr@1376 | 951 | return new RetData(this); |
duke@435 | 952 | case DataLayout::branch_data_tag: |
ysr@1376 | 953 | return new BranchData(this); |
duke@435 | 954 | case DataLayout::multi_branch_data_tag: |
ysr@1376 | 955 | return new MultiBranchData(this); |
kvn@480 | 956 | case DataLayout::arg_info_data_tag: |
ysr@1376 | 957 | return new ArgInfoData(this); |
roland@5914 | 958 | case DataLayout::call_type_data_tag: |
roland@5914 | 959 | return new CallTypeData(this); |
roland@5914 | 960 | case DataLayout::virtual_call_type_data_tag: |
roland@5914 | 961 | return new VirtualCallTypeData(this); |
roland@5987 | 962 | case DataLayout::parameters_type_data_tag: |
roland@5987 | 963 | return new ParametersTypeData(this); |
duke@435 | 964 | }; |
duke@435 | 965 | } |
duke@435 | 966 | |
duke@435 | 967 | // Iteration over data. |
coleenp@4037 | 968 | ProfileData* MethodData::next_data(ProfileData* current) const { |
duke@435 | 969 | int current_index = dp_to_di(current->dp()); |
duke@435 | 970 | int next_index = current_index + current->size_in_bytes(); |
duke@435 | 971 | ProfileData* next = data_at(next_index); |
duke@435 | 972 | return next; |
duke@435 | 973 | } |
duke@435 | 974 | |
duke@435 | 975 | // Give each of the data entries a chance to perform specific |
duke@435 | 976 | // data initialization. |
coleenp@4037 | 977 | void MethodData::post_initialize(BytecodeStream* stream) { |
duke@435 | 978 | ResourceMark rm; |
duke@435 | 979 | ProfileData* data; |
duke@435 | 980 | for (data = first_data(); is_valid(data); data = next_data(data)) { |
duke@435 | 981 | stream->set_start(data->bci()); |
duke@435 | 982 | stream->next(); |
duke@435 | 983 | data->post_initialize(stream, this); |
duke@435 | 984 | } |
roland@5987 | 985 | if (_parameters_type_data_di != -1) { |
roland@5987 | 986 | parameters_type_data()->post_initialize(NULL, this); |
roland@5987 | 987 | } |
duke@435 | 988 | } |
duke@435 | 989 | |
coleenp@4037 | 990 | // Initialize the MethodData* corresponding to a given method. |
coleenp@4037 | 991 | MethodData::MethodData(methodHandle method, int size, TRAPS) { |
coleenp@4037 | 992 | No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC |
duke@435 | 993 | ResourceMark rm; |
duke@435 | 994 | // Set the method back-pointer. |
duke@435 | 995 | _method = method(); |
iveresov@2138 | 996 | |
iignatyev@4908 | 997 | init(); |
duke@435 | 998 | set_creation_mileage(mileage_of(method())); |
duke@435 | 999 | |
duke@435 | 1000 | // Go through the bytecodes and allocate and initialize the |
duke@435 | 1001 | // corresponding data cells. |
duke@435 | 1002 | int data_size = 0; |
duke@435 | 1003 | int empty_bc_count = 0; // number of bytecodes lacking data |
coleenp@4712 | 1004 | _data[0] = 0; // apparently not set below. |
duke@435 | 1005 | BytecodeStream stream(method); |
duke@435 | 1006 | Bytecodes::Code c; |
duke@435 | 1007 | while ((c = stream.next()) >= 0) { |
duke@435 | 1008 | int size_in_bytes = initialize_data(&stream, data_size); |
duke@435 | 1009 | data_size += size_in_bytes; |
duke@435 | 1010 | if (size_in_bytes == 0) empty_bc_count += 1; |
duke@435 | 1011 | } |
duke@435 | 1012 | _data_size = data_size; |
duke@435 | 1013 | int object_size = in_bytes(data_offset()) + data_size; |
duke@435 | 1014 | |
duke@435 | 1015 | // Add some extra DataLayout cells (at least one) to track stray traps. |
duke@435 | 1016 | int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); |
kvn@480 | 1017 | int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); |
kvn@480 | 1018 | |
kvn@480 | 1019 | // Add a cell to record information about modified arguments. |
kvn@480 | 1020 | // Set up _args_modified array after traps cells so that |
kvn@480 | 1021 | // the code for traps cells works. |
kvn@480 | 1022 | DataLayout *dp = data_layout_at(data_size + extra_size); |
kvn@480 | 1023 | |
kvn@480 | 1024 | int arg_size = method->size_of_parameters(); |
kvn@480 | 1025 | dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
kvn@480 | 1026 | |
roland@5987 | 1027 | int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); |
roland@5987 | 1028 | object_size += extra_size + arg_data_size; |
roland@5987 | 1029 | |
roland@5987 | 1030 | int args_cell = ParametersTypeData::compute_cell_count(method()); |
roland@5987 | 1031 | // If we are profiling parameters, we reserver an area near the end |
roland@5987 | 1032 | // of the MDO after the slots for bytecodes (because there's no bci |
roland@5987 | 1033 | // for method entry so they don't fit with the framework for the |
roland@5987 | 1034 | // profiling of bytecodes). We store the offset within the MDO of |
roland@5987 | 1035 | // this area (or -1 if no parameter is profiled) |
roland@5987 | 1036 | if (args_cell > 0) { |
roland@5987 | 1037 | object_size += DataLayout::compute_size_in_bytes(args_cell); |
roland@5987 | 1038 | _parameters_type_data_di = data_size + extra_size + arg_data_size; |
roland@5987 | 1039 | DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); |
roland@5987 | 1040 | dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell); |
roland@5987 | 1041 | } else { |
roland@5987 | 1042 | _parameters_type_data_di = -1; |
roland@5987 | 1043 | } |
duke@435 | 1044 | |
duke@435 | 1045 | // Set an initial hint. Don't use set_hint_di() because |
duke@435 | 1046 | // first_di() may be out of bounds if data_size is 0. |
duke@435 | 1047 | // In that situation, _hint_di is never used, but at |
duke@435 | 1048 | // least well-defined. |
duke@435 | 1049 | _hint_di = first_di(); |
duke@435 | 1050 | |
duke@435 | 1051 | post_initialize(&stream); |
duke@435 | 1052 | |
coleenp@4037 | 1053 | set_size(object_size); |
iignatyev@4908 | 1054 | } |
coleenp@4712 | 1055 | |
iignatyev@4908 | 1056 | void MethodData::init() { |
iignatyev@4908 | 1057 | _invocation_counter.init(); |
iignatyev@4908 | 1058 | _backedge_counter.init(); |
iignatyev@4908 | 1059 | _invocation_counter_start = 0; |
iignatyev@4908 | 1060 | _backedge_counter_start = 0; |
iignatyev@4908 | 1061 | _num_loops = 0; |
iignatyev@4908 | 1062 | _num_blocks = 0; |
iignatyev@4908 | 1063 | _highest_comp_level = 0; |
iignatyev@4908 | 1064 | _highest_osr_comp_level = 0; |
iignatyev@4908 | 1065 | _would_profile = true; |
iignatyev@4908 | 1066 | |
iignatyev@4908 | 1067 | // Initialize flags and trap history. |
iignatyev@4908 | 1068 | _nof_decompiles = 0; |
iignatyev@4908 | 1069 | _nof_overflow_recompiles = 0; |
iignatyev@4908 | 1070 | _nof_overflow_traps = 0; |
iignatyev@4908 | 1071 | clear_escape_info(); |
iignatyev@4908 | 1072 | assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align"); |
iignatyev@4908 | 1073 | Copy::zero_to_words((HeapWord*) &_trap_hist, |
iignatyev@4908 | 1074 | sizeof(_trap_hist) / sizeof(HeapWord)); |
duke@435 | 1075 | } |
duke@435 | 1076 | |
duke@435 | 1077 | // Get a measure of how much mileage the method has on it. |
coleenp@4037 | 1078 | int MethodData::mileage_of(Method* method) { |
duke@435 | 1079 | int mileage = 0; |
iveresov@2138 | 1080 | if (TieredCompilation) { |
iveresov@2138 | 1081 | mileage = MAX2(method->invocation_count(), method->backedge_count()); |
iveresov@2138 | 1082 | } else { |
iveresov@2138 | 1083 | int iic = method->interpreter_invocation_count(); |
iveresov@2138 | 1084 | if (mileage < iic) mileage = iic; |
jiangli@4936 | 1085 | MethodCounters* mcs = method->method_counters(); |
jiangli@4936 | 1086 | if (mcs != NULL) { |
jiangli@4936 | 1087 | InvocationCounter* ic = mcs->invocation_counter(); |
jiangli@4936 | 1088 | InvocationCounter* bc = mcs->backedge_counter(); |
jiangli@4936 | 1089 | int icval = ic->count(); |
jiangli@4936 | 1090 | if (ic->carry()) icval += CompileThreshold; |
jiangli@4936 | 1091 | if (mileage < icval) mileage = icval; |
jiangli@4936 | 1092 | int bcval = bc->count(); |
jiangli@4936 | 1093 | if (bc->carry()) bcval += CompileThreshold; |
jiangli@4936 | 1094 | if (mileage < bcval) mileage = bcval; |
jiangli@4936 | 1095 | } |
iveresov@2138 | 1096 | } |
duke@435 | 1097 | return mileage; |
duke@435 | 1098 | } |
duke@435 | 1099 | |
coleenp@4037 | 1100 | bool MethodData::is_mature() const { |
iveresov@2138 | 1101 | return CompilationPolicy::policy()->is_mature(_method); |
duke@435 | 1102 | } |
duke@435 | 1103 | |
duke@435 | 1104 | // Translate a bci to its corresponding data index (di). |
coleenp@4037 | 1105 | address MethodData::bci_to_dp(int bci) { |
duke@435 | 1106 | ResourceMark rm; |
duke@435 | 1107 | ProfileData* data = data_before(bci); |
duke@435 | 1108 | ProfileData* prev = NULL; |
duke@435 | 1109 | for ( ; is_valid(data); data = next_data(data)) { |
duke@435 | 1110 | if (data->bci() >= bci) { |
duke@435 | 1111 | if (data->bci() == bci) set_hint_di(dp_to_di(data->dp())); |
duke@435 | 1112 | else if (prev != NULL) set_hint_di(dp_to_di(prev->dp())); |
duke@435 | 1113 | return data->dp(); |
duke@435 | 1114 | } |
duke@435 | 1115 | prev = data; |
duke@435 | 1116 | } |
duke@435 | 1117 | return (address)limit_data_position(); |
duke@435 | 1118 | } |
duke@435 | 1119 | |
duke@435 | 1120 | // Translate a bci to its corresponding data, or NULL. |
coleenp@4037 | 1121 | ProfileData* MethodData::bci_to_data(int bci) { |
duke@435 | 1122 | ProfileData* data = data_before(bci); |
duke@435 | 1123 | for ( ; is_valid(data); data = next_data(data)) { |
duke@435 | 1124 | if (data->bci() == bci) { |
duke@435 | 1125 | set_hint_di(dp_to_di(data->dp())); |
duke@435 | 1126 | return data; |
duke@435 | 1127 | } else if (data->bci() > bci) { |
duke@435 | 1128 | break; |
duke@435 | 1129 | } |
duke@435 | 1130 | } |
duke@435 | 1131 | return bci_to_extra_data(bci, false); |
duke@435 | 1132 | } |
duke@435 | 1133 | |
duke@435 | 1134 | // Translate a bci to its corresponding extra data, or NULL. |
coleenp@4037 | 1135 | ProfileData* MethodData::bci_to_extra_data(int bci, bool create_if_missing) { |
duke@435 | 1136 | DataLayout* dp = extra_data_base(); |
duke@435 | 1137 | DataLayout* end = extra_data_limit(); |
duke@435 | 1138 | DataLayout* avail = NULL; |
duke@435 | 1139 | for (; dp < end; dp = next_extra(dp)) { |
duke@435 | 1140 | // No need for "OrderAccess::load_acquire" ops, |
duke@435 | 1141 | // since the data structure is monotonic. |
duke@435 | 1142 | if (dp->tag() == DataLayout::no_tag) break; |
kvn@480 | 1143 | if (dp->tag() == DataLayout::arg_info_data_tag) { |
kvn@480 | 1144 | dp = end; // ArgInfoData is at the end of extra data section. |
kvn@480 | 1145 | break; |
kvn@480 | 1146 | } |
duke@435 | 1147 | if (dp->bci() == bci) { |
duke@435 | 1148 | assert(dp->tag() == DataLayout::bit_data_tag, "sane"); |
duke@435 | 1149 | return new BitData(dp); |
duke@435 | 1150 | } |
duke@435 | 1151 | } |
duke@435 | 1152 | if (create_if_missing && dp < end) { |
duke@435 | 1153 | // Allocate this one. There is no mutual exclusion, |
duke@435 | 1154 | // so two threads could allocate different BCIs to the |
duke@435 | 1155 | // same data layout. This means these extra data |
duke@435 | 1156 | // records, like most other MDO contents, must not be |
duke@435 | 1157 | // trusted too much. |
duke@435 | 1158 | DataLayout temp; |
duke@435 | 1159 | temp.initialize(DataLayout::bit_data_tag, bci, 0); |
duke@435 | 1160 | dp->release_set_header(temp.header()); |
duke@435 | 1161 | assert(dp->tag() == DataLayout::bit_data_tag, "sane"); |
duke@435 | 1162 | //NO: assert(dp->bci() == bci, "no concurrent allocation"); |
duke@435 | 1163 | return new BitData(dp); |
duke@435 | 1164 | } |
duke@435 | 1165 | return NULL; |
duke@435 | 1166 | } |
duke@435 | 1167 | |
coleenp@4037 | 1168 | ArgInfoData *MethodData::arg_info() { |
kvn@480 | 1169 | DataLayout* dp = extra_data_base(); |
kvn@480 | 1170 | DataLayout* end = extra_data_limit(); |
kvn@480 | 1171 | for (; dp < end; dp = next_extra(dp)) { |
kvn@480 | 1172 | if (dp->tag() == DataLayout::arg_info_data_tag) |
kvn@480 | 1173 | return new ArgInfoData(dp); |
kvn@480 | 1174 | } |
kvn@480 | 1175 | return NULL; |
kvn@480 | 1176 | } |
kvn@480 | 1177 | |
coleenp@4037 | 1178 | // Printing |
coleenp@4037 | 1179 | |
duke@435 | 1180 | #ifndef PRODUCT |
coleenp@4037 | 1181 | |
coleenp@4037 | 1182 | void MethodData::print_on(outputStream* st) const { |
coleenp@4037 | 1183 | assert(is_methodData(), "should be method data"); |
coleenp@4037 | 1184 | st->print("method data for "); |
coleenp@4037 | 1185 | method()->print_value_on(st); |
coleenp@4037 | 1186 | st->cr(); |
coleenp@4037 | 1187 | print_data_on(st); |
coleenp@4037 | 1188 | } |
coleenp@4037 | 1189 | |
coleenp@4037 | 1190 | #endif //PRODUCT |
coleenp@4037 | 1191 | |
coleenp@4037 | 1192 | void MethodData::print_value_on(outputStream* st) const { |
coleenp@4037 | 1193 | assert(is_methodData(), "should be method data"); |
coleenp@4037 | 1194 | st->print("method data for "); |
coleenp@4037 | 1195 | method()->print_value_on(st); |
coleenp@4037 | 1196 | } |
coleenp@4037 | 1197 | |
coleenp@4037 | 1198 | #ifndef PRODUCT |
coleenp@4037 | 1199 | void MethodData::print_data_on(outputStream* st) const { |
duke@435 | 1200 | ResourceMark rm; |
duke@435 | 1201 | ProfileData* data = first_data(); |
roland@5987 | 1202 | if (_parameters_type_data_di != -1) { |
roland@5987 | 1203 | parameters_type_data()->print_data_on(st); |
roland@5987 | 1204 | } |
duke@435 | 1205 | for ( ; is_valid(data); data = next_data(data)) { |
duke@435 | 1206 | st->print("%d", dp_to_di(data->dp())); |
duke@435 | 1207 | st->fill_to(6); |
duke@435 | 1208 | data->print_data_on(st); |
duke@435 | 1209 | } |
kvn@480 | 1210 | st->print_cr("--- Extra data:"); |
duke@435 | 1211 | DataLayout* dp = extra_data_base(); |
duke@435 | 1212 | DataLayout* end = extra_data_limit(); |
duke@435 | 1213 | for (; dp < end; dp = next_extra(dp)) { |
duke@435 | 1214 | // No need for "OrderAccess::load_acquire" ops, |
duke@435 | 1215 | // since the data structure is monotonic. |
kvn@480 | 1216 | if (dp->tag() == DataLayout::no_tag) continue; |
kvn@480 | 1217 | if (dp->tag() == DataLayout::bit_data_tag) { |
kvn@480 | 1218 | data = new BitData(dp); |
kvn@480 | 1219 | } else { |
kvn@480 | 1220 | assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo"); |
kvn@480 | 1221 | data = new ArgInfoData(dp); |
kvn@480 | 1222 | dp = end; // ArgInfoData is at the end of extra data section. |
kvn@480 | 1223 | } |
duke@435 | 1224 | st->print("%d", dp_to_di(data->dp())); |
duke@435 | 1225 | st->fill_to(6); |
duke@435 | 1226 | data->print_data_on(st); |
duke@435 | 1227 | } |
duke@435 | 1228 | } |
duke@435 | 1229 | #endif |
duke@435 | 1230 | |
acorn@4497 | 1231 | #if INCLUDE_SERVICES |
acorn@4497 | 1232 | // Size Statistics |
acorn@4497 | 1233 | void MethodData::collect_statistics(KlassSizeStats *sz) const { |
acorn@4497 | 1234 | int n = sz->count(this); |
acorn@4497 | 1235 | sz->_method_data_bytes += n; |
acorn@4497 | 1236 | sz->_method_all_bytes += n; |
acorn@4497 | 1237 | sz->_rw_bytes += n; |
acorn@4497 | 1238 | } |
acorn@4497 | 1239 | #endif // INCLUDE_SERVICES |
coleenp@4037 | 1240 | |
coleenp@4037 | 1241 | // Verification |
coleenp@4037 | 1242 | |
coleenp@4037 | 1243 | void MethodData::verify_on(outputStream* st) { |
coleenp@4037 | 1244 | guarantee(is_methodData(), "object must be method data"); |
coleenp@4037 | 1245 | // guarantee(m->is_perm(), "should be in permspace"); |
coleenp@4037 | 1246 | this->verify_data_on(st); |
coleenp@4037 | 1247 | } |
coleenp@4037 | 1248 | |
coleenp@4037 | 1249 | void MethodData::verify_data_on(outputStream* st) { |
duke@435 | 1250 | NEEDS_CLEANUP; |
duke@435 | 1251 | // not yet implemented. |
duke@435 | 1252 | } |
roland@5914 | 1253 | |
roland@5914 | 1254 | bool MethodData::profile_jsr292(methodHandle m, int bci) { |
roland@5914 | 1255 | if (m->is_compiled_lambda_form()) { |
roland@5914 | 1256 | return true; |
roland@5914 | 1257 | } |
roland@5914 | 1258 | |
roland@5914 | 1259 | Bytecode_invoke inv(m , bci); |
roland@5914 | 1260 | return inv.is_invokedynamic() || inv.is_invokehandle(); |
roland@5914 | 1261 | } |
roland@5914 | 1262 | |
roland@5914 | 1263 | int MethodData::profile_arguments_flag() { |
roland@5921 | 1264 | return TypeProfileLevel % 10; |
roland@5914 | 1265 | } |
roland@5914 | 1266 | |
roland@5914 | 1267 | bool MethodData::profile_arguments() { |
roland@5914 | 1268 | return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all; |
roland@5914 | 1269 | } |
roland@5914 | 1270 | |
roland@5914 | 1271 | bool MethodData::profile_arguments_jsr292_only() { |
roland@5914 | 1272 | return profile_arguments_flag() == type_profile_jsr292; |
roland@5914 | 1273 | } |
roland@5914 | 1274 | |
roland@5914 | 1275 | bool MethodData::profile_all_arguments() { |
roland@5914 | 1276 | return profile_arguments_flag() == type_profile_all; |
roland@5914 | 1277 | } |
roland@5914 | 1278 | |
roland@5914 | 1279 | bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) { |
roland@5914 | 1280 | if (!profile_arguments()) { |
roland@5914 | 1281 | return false; |
roland@5914 | 1282 | } |
roland@5914 | 1283 | |
roland@5914 | 1284 | if (profile_all_arguments()) { |
roland@5914 | 1285 | return true; |
roland@5914 | 1286 | } |
roland@5914 | 1287 | |
roland@5914 | 1288 | assert(profile_arguments_jsr292_only(), "inconsistent"); |
roland@5914 | 1289 | return profile_jsr292(m, bci); |
roland@5914 | 1290 | } |
roland@5914 | 1291 | |
roland@5921 | 1292 | int MethodData::profile_return_flag() { |
roland@5987 | 1293 | return (TypeProfileLevel % 100) / 10; |
roland@5921 | 1294 | } |
roland@5921 | 1295 | |
roland@5921 | 1296 | bool MethodData::profile_return() { |
roland@5921 | 1297 | return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all; |
roland@5921 | 1298 | } |
roland@5921 | 1299 | |
roland@5921 | 1300 | bool MethodData::profile_return_jsr292_only() { |
roland@5921 | 1301 | return profile_return_flag() == type_profile_jsr292; |
roland@5921 | 1302 | } |
roland@5921 | 1303 | |
roland@5921 | 1304 | bool MethodData::profile_all_return() { |
roland@5921 | 1305 | return profile_return_flag() == type_profile_all; |
roland@5921 | 1306 | } |
roland@5921 | 1307 | |
roland@5921 | 1308 | bool MethodData::profile_return_for_invoke(methodHandle m, int bci) { |
roland@5921 | 1309 | if (!profile_return()) { |
roland@5921 | 1310 | return false; |
roland@5921 | 1311 | } |
roland@5921 | 1312 | |
roland@5921 | 1313 | if (profile_all_return()) { |
roland@5921 | 1314 | return true; |
roland@5921 | 1315 | } |
roland@5921 | 1316 | |
roland@5921 | 1317 | assert(profile_return_jsr292_only(), "inconsistent"); |
roland@5921 | 1318 | return profile_jsr292(m, bci); |
roland@5921 | 1319 | } |
roland@5987 | 1320 | |
roland@5987 | 1321 | int MethodData::profile_parameters_flag() { |
roland@5987 | 1322 | return TypeProfileLevel / 100; |
roland@5987 | 1323 | } |
roland@5987 | 1324 | |
roland@5987 | 1325 | bool MethodData::profile_parameters() { |
roland@5987 | 1326 | return profile_parameters_flag() > no_type_profile && profile_parameters_flag() <= type_profile_all; |
roland@5987 | 1327 | } |
roland@5987 | 1328 | |
roland@5987 | 1329 | bool MethodData::profile_parameters_jsr292_only() { |
roland@5987 | 1330 | return profile_parameters_flag() == type_profile_jsr292; |
roland@5987 | 1331 | } |
roland@5987 | 1332 | |
roland@5987 | 1333 | bool MethodData::profile_all_parameters() { |
roland@5987 | 1334 | return profile_parameters_flag() == type_profile_all; |
roland@5987 | 1335 | } |
roland@5987 | 1336 | |
roland@5987 | 1337 | bool MethodData::profile_parameters_for_method(methodHandle m) { |
roland@5987 | 1338 | if (!profile_parameters()) { |
roland@5987 | 1339 | return false; |
roland@5987 | 1340 | } |
roland@5987 | 1341 | |
roland@5987 | 1342 | if (profile_all_parameters()) { |
roland@5987 | 1343 | return true; |
roland@5987 | 1344 | } |
roland@5987 | 1345 | |
roland@5987 | 1346 | assert(profile_parameters_jsr292_only(), "inconsistent"); |
roland@5987 | 1347 | return m->is_compiled_lambda_form(); |
roland@5987 | 1348 | } |