Mon, 12 Aug 2019 18:30:40 +0300
8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens
duke@435 | 1 | /* |
phh@9507 | 2 | * Copyright (c) 2000, 2018, 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" |
kvn@6429 | 27 | #include "compiler/compilerOracle.hpp" |
stefank@2314 | 28 | #include "interpreter/bytecode.hpp" |
stefank@2314 | 29 | #include "interpreter/bytecodeStream.hpp" |
stefank@2314 | 30 | #include "interpreter/linkResolver.hpp" |
acorn@4497 | 31 | #include "memory/heapInspection.hpp" |
coleenp@4037 | 32 | #include "oops/methodData.hpp" |
coleenp@4037 | 33 | #include "prims/jvmtiRedefineClasses.hpp" |
stefank@2314 | 34 | #include "runtime/compilationPolicy.hpp" |
stefank@2314 | 35 | #include "runtime/deoptimization.hpp" |
stefank@2314 | 36 | #include "runtime/handles.inline.hpp" |
goetz@6911 | 37 | #include "runtime/orderAccess.inline.hpp" |
duke@435 | 38 | |
drchase@6680 | 39 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
drchase@6680 | 40 | |
duke@435 | 41 | // ================================================================== |
duke@435 | 42 | // DataLayout |
duke@435 | 43 | // |
duke@435 | 44 | // Overlay for generic profiling data. |
duke@435 | 45 | |
duke@435 | 46 | // Some types of data layouts need a length field. |
duke@435 | 47 | bool DataLayout::needs_array_len(u1 tag) { |
roland@5987 | 48 | return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag) || (tag == parameters_type_data_tag); |
duke@435 | 49 | } |
duke@435 | 50 | |
duke@435 | 51 | // Perform generic initialization of the data. More specific |
duke@435 | 52 | // initialization occurs in overrides of ProfileData::post_initialize. |
duke@435 | 53 | void DataLayout::initialize(u1 tag, u2 bci, int cell_count) { |
duke@435 | 54 | _header._bits = (intptr_t)0; |
duke@435 | 55 | _header._struct._tag = tag; |
duke@435 | 56 | _header._struct._bci = bci; |
duke@435 | 57 | for (int i = 0; i < cell_count; i++) { |
duke@435 | 58 | set_cell_at(i, (intptr_t)0); |
duke@435 | 59 | } |
duke@435 | 60 | if (needs_array_len(tag)) { |
duke@435 | 61 | set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header. |
duke@435 | 62 | } |
roland@5914 | 63 | if (tag == call_type_data_tag) { |
roland@5914 | 64 | CallTypeData::initialize(this, cell_count); |
roland@5914 | 65 | } else if (tag == virtual_call_type_data_tag) { |
roland@5914 | 66 | VirtualCallTypeData::initialize(this, cell_count); |
roland@5914 | 67 | } |
duke@435 | 68 | } |
duke@435 | 69 | |
coleenp@4037 | 70 | void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) { |
ysr@1376 | 71 | ResourceMark m; |
coleenp@4037 | 72 | data_in()->clean_weak_klass_links(cl); |
ysr@1376 | 73 | } |
ysr@1376 | 74 | |
ysr@1376 | 75 | |
duke@435 | 76 | // ================================================================== |
duke@435 | 77 | // ProfileData |
duke@435 | 78 | // |
duke@435 | 79 | // A ProfileData object is created to refer to a section of profiling |
duke@435 | 80 | // data in a structured way. |
duke@435 | 81 | |
duke@435 | 82 | // Constructor for invalid ProfileData. |
duke@435 | 83 | ProfileData::ProfileData() { |
duke@435 | 84 | _data = NULL; |
duke@435 | 85 | } |
duke@435 | 86 | |
roland@6377 | 87 | char* ProfileData::print_data_on_helper(const MethodData* md) const { |
roland@6377 | 88 | DataLayout* dp = md->extra_data_base(); |
roland@6377 | 89 | DataLayout* end = md->extra_data_limit(); |
roland@6377 | 90 | stringStream ss; |
roland@6377 | 91 | for (;; dp = MethodData::next_extra(dp)) { |
roland@6377 | 92 | assert(dp < end, "moved past end of extra data"); |
roland@6377 | 93 | switch(dp->tag()) { |
roland@6377 | 94 | case DataLayout::speculative_trap_data_tag: |
roland@6377 | 95 | if (dp->bci() == bci()) { |
roland@6377 | 96 | SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
roland@6377 | 97 | int trap = data->trap_state(); |
roland@6377 | 98 | char buf[100]; |
roland@6377 | 99 | ss.print("trap/"); |
roland@6377 | 100 | data->method()->print_short_name(&ss); |
roland@6377 | 101 | ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); |
roland@6377 | 102 | } |
roland@6377 | 103 | break; |
roland@6377 | 104 | case DataLayout::bit_data_tag: |
roland@6377 | 105 | break; |
roland@6377 | 106 | case DataLayout::no_tag: |
roland@6377 | 107 | case DataLayout::arg_info_data_tag: |
roland@6377 | 108 | return ss.as_string(); |
roland@6377 | 109 | break; |
roland@6377 | 110 | default: |
roland@6377 | 111 | fatal(err_msg("unexpected tag %d", dp->tag())); |
roland@6377 | 112 | } |
roland@6377 | 113 | } |
roland@6377 | 114 | return NULL; |
roland@6377 | 115 | } |
roland@6377 | 116 | |
roland@6377 | 117 | void ProfileData::print_data_on(outputStream* st, const MethodData* md) const { |
roland@6377 | 118 | print_data_on(st, print_data_on_helper(md)); |
roland@6377 | 119 | } |
roland@6377 | 120 | |
duke@435 | 121 | #ifndef PRODUCT |
roland@6377 | 122 | void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const { |
duke@435 | 123 | st->print("bci: %d", bci()); |
duke@435 | 124 | st->fill_to(tab_width_one); |
duke@435 | 125 | st->print("%s", name); |
duke@435 | 126 | tab(st); |
duke@435 | 127 | int trap = trap_state(); |
duke@435 | 128 | if (trap != 0) { |
duke@435 | 129 | char buf[100]; |
duke@435 | 130 | st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); |
duke@435 | 131 | } |
roland@6377 | 132 | if (extra != NULL) { |
drchase@6680 | 133 | st->print("%s", extra); |
roland@6377 | 134 | } |
duke@435 | 135 | int flags = data()->flags(); |
roland@6377 | 136 | if (flags != 0) { |
duke@435 | 137 | st->print("flags(%d) ", flags); |
roland@6377 | 138 | } |
duke@435 | 139 | } |
duke@435 | 140 | |
roland@5914 | 141 | void ProfileData::tab(outputStream* st, bool first) const { |
roland@5914 | 142 | st->fill_to(first ? tab_width_one : tab_width_two); |
duke@435 | 143 | } |
duke@435 | 144 | #endif // !PRODUCT |
duke@435 | 145 | |
duke@435 | 146 | // ================================================================== |
duke@435 | 147 | // BitData |
duke@435 | 148 | // |
duke@435 | 149 | // A BitData corresponds to a one-bit flag. This is used to indicate |
duke@435 | 150 | // whether a checkcast bytecode has seen a null value. |
duke@435 | 151 | |
duke@435 | 152 | |
duke@435 | 153 | #ifndef PRODUCT |
roland@6377 | 154 | void BitData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 155 | print_shared(st, "BitData", extra); |
duke@435 | 156 | } |
duke@435 | 157 | #endif // !PRODUCT |
duke@435 | 158 | |
duke@435 | 159 | // ================================================================== |
duke@435 | 160 | // CounterData |
duke@435 | 161 | // |
duke@435 | 162 | // A CounterData corresponds to a simple counter. |
duke@435 | 163 | |
duke@435 | 164 | #ifndef PRODUCT |
roland@6377 | 165 | void CounterData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 166 | print_shared(st, "CounterData", extra); |
duke@435 | 167 | st->print_cr("count(%u)", count()); |
duke@435 | 168 | } |
duke@435 | 169 | #endif // !PRODUCT |
duke@435 | 170 | |
duke@435 | 171 | // ================================================================== |
duke@435 | 172 | // JumpData |
duke@435 | 173 | // |
duke@435 | 174 | // A JumpData is used to access profiling information for a direct |
duke@435 | 175 | // branch. It is a counter, used for counting the number of branches, |
duke@435 | 176 | // plus a data displacement, used for realigning the data pointer to |
duke@435 | 177 | // the corresponding target bci. |
duke@435 | 178 | |
coleenp@4037 | 179 | void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
duke@435 | 180 | assert(stream->bci() == bci(), "wrong pos"); |
duke@435 | 181 | int target; |
duke@435 | 182 | Bytecodes::Code c = stream->code(); |
duke@435 | 183 | if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) { |
duke@435 | 184 | target = stream->dest_w(); |
duke@435 | 185 | } else { |
duke@435 | 186 | target = stream->dest(); |
duke@435 | 187 | } |
duke@435 | 188 | int my_di = mdo->dp_to_di(dp()); |
duke@435 | 189 | int target_di = mdo->bci_to_di(target); |
duke@435 | 190 | int offset = target_di - my_di; |
duke@435 | 191 | set_displacement(offset); |
duke@435 | 192 | } |
duke@435 | 193 | |
duke@435 | 194 | #ifndef PRODUCT |
roland@6377 | 195 | void JumpData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 196 | print_shared(st, "JumpData", extra); |
duke@435 | 197 | st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); |
duke@435 | 198 | } |
duke@435 | 199 | #endif // !PRODUCT |
duke@435 | 200 | |
roland@5987 | 201 | int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { |
roland@5987 | 202 | // Parameter profiling include the receiver |
roland@5987 | 203 | int args_count = include_receiver ? 1 : 0; |
roland@5921 | 204 | ResourceMark rm; |
roland@5921 | 205 | SignatureStream ss(signature); |
roland@5987 | 206 | args_count += ss.reference_parameter_count(); |
roland@5987 | 207 | args_count = MIN2(args_count, max); |
roland@5921 | 208 | return args_count * per_arg_cell_count; |
roland@5921 | 209 | } |
roland@5921 | 210 | |
roland@5921 | 211 | int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) { |
roland@5914 | 212 | assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); |
roland@5921 | 213 | assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken"); |
roland@5914 | 214 | Bytecode_invoke inv(stream->method(), stream->bci()); |
roland@5921 | 215 | int args_cell = 0; |
roland@5921 | 216 | if (arguments_profiling_enabled()) { |
roland@5987 | 217 | args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit); |
roland@5921 | 218 | } |
roland@5921 | 219 | int ret_cell = 0; |
roland@5921 | 220 | if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) { |
roland@5921 | 221 | ret_cell = ReturnTypeEntry::static_cell_count(); |
roland@5921 | 222 | } |
roland@5921 | 223 | int header_cell = 0; |
roland@5921 | 224 | if (args_cell + ret_cell > 0) { |
roland@5921 | 225 | header_cell = header_cell_count(); |
roland@5921 | 226 | } |
roland@5914 | 227 | |
roland@5921 | 228 | return header_cell + args_cell + ret_cell; |
roland@5914 | 229 | } |
roland@5914 | 230 | |
roland@5914 | 231 | class ArgumentOffsetComputer : public SignatureInfo { |
roland@5914 | 232 | private: |
roland@5914 | 233 | int _max; |
roland@5914 | 234 | GrowableArray<int> _offsets; |
roland@5914 | 235 | |
roland@5914 | 236 | void set(int size, BasicType type) { _size += size; } |
roland@5914 | 237 | void do_object(int begin, int end) { |
roland@5914 | 238 | if (_offsets.length() < _max) { |
roland@5914 | 239 | _offsets.push(_size); |
roland@5914 | 240 | } |
roland@5914 | 241 | SignatureInfo::do_object(begin, end); |
roland@5914 | 242 | } |
roland@5914 | 243 | void do_array (int begin, int end) { |
roland@5914 | 244 | if (_offsets.length() < _max) { |
roland@5914 | 245 | _offsets.push(_size); |
roland@5914 | 246 | } |
roland@5914 | 247 | SignatureInfo::do_array(begin, end); |
roland@5914 | 248 | } |
roland@5914 | 249 | |
roland@5914 | 250 | public: |
roland@5914 | 251 | ArgumentOffsetComputer(Symbol* signature, int max) |
roland@5914 | 252 | : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) { |
roland@5914 | 253 | } |
roland@5914 | 254 | |
roland@5914 | 255 | int total() { lazy_iterate_parameters(); return _size; } |
roland@5914 | 256 | |
roland@5914 | 257 | int off_at(int i) const { return _offsets.at(i); } |
roland@5914 | 258 | }; |
roland@5914 | 259 | |
roland@5987 | 260 | void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver, bool include_receiver) { |
roland@5914 | 261 | ResourceMark rm; |
roland@5987 | 262 | int start = 0; |
roland@5987 | 263 | // Parameter profiling include the receiver |
roland@5987 | 264 | if (include_receiver && has_receiver) { |
roland@5987 | 265 | set_stack_slot(0, 0); |
roland@5987 | 266 | set_type(0, type_none()); |
roland@5987 | 267 | start += 1; |
roland@5987 | 268 | } |
roland@5987 | 269 | ArgumentOffsetComputer aos(signature, _number_of_entries-start); |
roland@5921 | 270 | aos.total(); |
roland@5987 | 271 | for (int i = start; i < _number_of_entries; i++) { |
roland@5987 | 272 | set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0)); |
roland@5921 | 273 | set_type(i, type_none()); |
roland@5921 | 274 | } |
roland@5921 | 275 | } |
roland@5914 | 276 | |
roland@5921 | 277 | void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
roland@5914 | 278 | assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); |
roland@5914 | 279 | Bytecode_invoke inv(stream->method(), stream->bci()); |
roland@5914 | 280 | |
roland@5921 | 281 | SignatureStream ss(inv.signature()); |
roland@5921 | 282 | if (has_arguments()) { |
roland@5914 | 283 | #ifdef ASSERT |
roland@5921 | 284 | ResourceMark rm; |
roland@5921 | 285 | int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit); |
roland@5921 | 286 | assert(count > 0, "room for args type but none found?"); |
roland@5921 | 287 | check_number_of_arguments(count); |
roland@5914 | 288 | #endif |
roland@5987 | 289 | _args.post_initialize(inv.signature(), inv.has_receiver(), false); |
roland@5921 | 290 | } |
roland@5914 | 291 | |
roland@5921 | 292 | if (has_return()) { |
roland@5921 | 293 | assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?"); |
roland@5921 | 294 | _ret.post_initialize(); |
roland@5921 | 295 | } |
roland@5921 | 296 | } |
roland@5921 | 297 | |
roland@5921 | 298 | void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
roland@5921 | 299 | assert(Bytecodes::is_invoke(stream->code()), "should be invoke"); |
roland@5921 | 300 | Bytecode_invoke inv(stream->method(), stream->bci()); |
roland@5921 | 301 | |
roland@5921 | 302 | if (has_arguments()) { |
roland@5921 | 303 | #ifdef ASSERT |
roland@5921 | 304 | ResourceMark rm; |
roland@5921 | 305 | SignatureStream ss(inv.signature()); |
roland@5921 | 306 | int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit); |
roland@5921 | 307 | assert(count > 0, "room for args type but none found?"); |
roland@5921 | 308 | check_number_of_arguments(count); |
roland@5921 | 309 | #endif |
roland@5987 | 310 | _args.post_initialize(inv.signature(), inv.has_receiver(), false); |
roland@5921 | 311 | } |
roland@5921 | 312 | |
roland@5921 | 313 | if (has_return()) { |
roland@5921 | 314 | assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?"); |
roland@5921 | 315 | _ret.post_initialize(); |
roland@5914 | 316 | } |
roland@5914 | 317 | } |
roland@5914 | 318 | |
roland@5914 | 319 | bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) { |
roland@6105 | 320 | Klass* k = (Klass*)klass_part(p); |
roland@6105 | 321 | return k != NULL && k->is_loader_alive(is_alive_cl); |
roland@5914 | 322 | } |
roland@5914 | 323 | |
roland@5914 | 324 | void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { |
roland@5921 | 325 | for (int i = 0; i < _number_of_entries; i++) { |
roland@5914 | 326 | intptr_t p = type(i); |
roland@6105 | 327 | if (!is_loader_alive(is_alive_cl, p)) { |
roland@6105 | 328 | set_type(i, with_status((Klass*)NULL, p)); |
roland@5914 | 329 | } |
roland@5914 | 330 | } |
roland@5914 | 331 | } |
roland@5914 | 332 | |
roland@5921 | 333 | void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { |
roland@5921 | 334 | intptr_t p = type(); |
roland@6105 | 335 | if (!is_loader_alive(is_alive_cl, p)) { |
roland@6105 | 336 | set_type(with_status((Klass*)NULL, p)); |
roland@5921 | 337 | } |
roland@5921 | 338 | } |
roland@5921 | 339 | |
roland@5921 | 340 | bool TypeEntriesAtCall::return_profiling_enabled() { |
roland@5921 | 341 | return MethodData::profile_return(); |
roland@5921 | 342 | } |
roland@5921 | 343 | |
roland@5921 | 344 | bool TypeEntriesAtCall::arguments_profiling_enabled() { |
roland@5914 | 345 | return MethodData::profile_arguments(); |
roland@5914 | 346 | } |
roland@5914 | 347 | |
roland@5914 | 348 | #ifndef PRODUCT |
roland@5914 | 349 | void TypeEntries::print_klass(outputStream* st, intptr_t k) { |
roland@5914 | 350 | if (is_type_none(k)) { |
roland@5914 | 351 | st->print("none"); |
roland@5914 | 352 | } else if (is_type_unknown(k)) { |
roland@5914 | 353 | st->print("unknown"); |
roland@5914 | 354 | } else { |
roland@5914 | 355 | valid_klass(k)->print_value_on(st); |
roland@5914 | 356 | } |
roland@5914 | 357 | if (was_null_seen(k)) { |
roland@5914 | 358 | st->print(" (null seen)"); |
roland@5914 | 359 | } |
roland@5914 | 360 | } |
roland@5914 | 361 | |
roland@5914 | 362 | void TypeStackSlotEntries::print_data_on(outputStream* st) const { |
roland@5921 | 363 | for (int i = 0; i < _number_of_entries; i++) { |
roland@5914 | 364 | _pd->tab(st); |
roland@5914 | 365 | st->print("%d: stack(%u) ", i, stack_slot(i)); |
roland@5914 | 366 | print_klass(st, type(i)); |
roland@5914 | 367 | st->cr(); |
roland@5914 | 368 | } |
roland@5914 | 369 | } |
roland@5914 | 370 | |
roland@5921 | 371 | void ReturnTypeEntry::print_data_on(outputStream* st) const { |
roland@5921 | 372 | _pd->tab(st); |
roland@5921 | 373 | print_klass(st, type()); |
roland@5921 | 374 | st->cr(); |
roland@5921 | 375 | } |
roland@5921 | 376 | |
roland@6377 | 377 | void CallTypeData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 378 | CounterData::print_data_on(st, extra); |
roland@5921 | 379 | if (has_arguments()) { |
roland@5921 | 380 | tab(st, true); |
roland@5921 | 381 | st->print("argument types"); |
roland@5921 | 382 | _args.print_data_on(st); |
roland@5921 | 383 | } |
roland@5921 | 384 | if (has_return()) { |
roland@5921 | 385 | tab(st, true); |
roland@5921 | 386 | st->print("return type"); |
roland@5921 | 387 | _ret.print_data_on(st); |
roland@5921 | 388 | } |
roland@5914 | 389 | } |
roland@5914 | 390 | |
roland@6377 | 391 | void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 392 | VirtualCallData::print_data_on(st, extra); |
roland@5921 | 393 | if (has_arguments()) { |
roland@5921 | 394 | tab(st, true); |
roland@5921 | 395 | st->print("argument types"); |
roland@5921 | 396 | _args.print_data_on(st); |
roland@5921 | 397 | } |
roland@5921 | 398 | if (has_return()) { |
roland@5921 | 399 | tab(st, true); |
roland@5921 | 400 | st->print("return type"); |
roland@5921 | 401 | _ret.print_data_on(st); |
roland@5921 | 402 | } |
roland@5914 | 403 | } |
roland@5914 | 404 | #endif |
roland@5914 | 405 | |
duke@435 | 406 | // ================================================================== |
duke@435 | 407 | // ReceiverTypeData |
duke@435 | 408 | // |
duke@435 | 409 | // A ReceiverTypeData is used to access profiling information about a |
duke@435 | 410 | // dynamic type check. It consists of a counter which counts the total times |
coleenp@4037 | 411 | // that the check is reached, and a series of (Klass*, count) pairs |
duke@435 | 412 | // which are used to store a type profile for the receiver of the check. |
duke@435 | 413 | |
coleenp@4037 | 414 | void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) { |
ysr@1376 | 415 | for (uint row = 0; row < row_limit(); row++) { |
coleenp@4037 | 416 | Klass* p = receiver(row); |
coleenp@4037 | 417 | if (p != NULL && !p->is_loader_alive(is_alive_cl)) { |
ysr@1376 | 418 | clear_row(row); |
ysr@1376 | 419 | } |
ysr@1376 | 420 | } |
ysr@1376 | 421 | } |
ysr@1376 | 422 | |
duke@435 | 423 | #ifndef PRODUCT |
roland@5914 | 424 | void ReceiverTypeData::print_receiver_data_on(outputStream* st) const { |
duke@435 | 425 | uint row; |
duke@435 | 426 | int entries = 0; |
duke@435 | 427 | for (row = 0; row < row_limit(); row++) { |
duke@435 | 428 | if (receiver(row) != NULL) entries++; |
duke@435 | 429 | } |
duke@435 | 430 | st->print_cr("count(%u) entries(%u)", count(), entries); |
iveresov@2138 | 431 | int total = count(); |
iveresov@2138 | 432 | for (row = 0; row < row_limit(); row++) { |
iveresov@2138 | 433 | if (receiver(row) != NULL) { |
iveresov@2138 | 434 | total += receiver_count(row); |
iveresov@2138 | 435 | } |
iveresov@2138 | 436 | } |
duke@435 | 437 | for (row = 0; row < row_limit(); row++) { |
duke@435 | 438 | if (receiver(row) != NULL) { |
duke@435 | 439 | tab(st); |
duke@435 | 440 | receiver(row)->print_value_on(st); |
iveresov@2138 | 441 | st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); |
duke@435 | 442 | } |
duke@435 | 443 | } |
duke@435 | 444 | } |
roland@6377 | 445 | void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 446 | print_shared(st, "ReceiverTypeData", extra); |
duke@435 | 447 | print_receiver_data_on(st); |
duke@435 | 448 | } |
roland@6377 | 449 | void VirtualCallData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 450 | print_shared(st, "VirtualCallData", extra); |
duke@435 | 451 | print_receiver_data_on(st); |
duke@435 | 452 | } |
duke@435 | 453 | #endif // !PRODUCT |
duke@435 | 454 | |
duke@435 | 455 | // ================================================================== |
duke@435 | 456 | // RetData |
duke@435 | 457 | // |
duke@435 | 458 | // A RetData is used to access profiling information for a ret bytecode. |
duke@435 | 459 | // It is composed of a count of the number of times that the ret has |
duke@435 | 460 | // been executed, followed by a series of triples of the form |
duke@435 | 461 | // (bci, count, di) which count the number of times that some bci was the |
duke@435 | 462 | // target of the ret and cache a corresponding displacement. |
duke@435 | 463 | |
coleenp@4037 | 464 | void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
duke@435 | 465 | for (uint row = 0; row < row_limit(); row++) { |
duke@435 | 466 | set_bci_displacement(row, -1); |
duke@435 | 467 | set_bci(row, no_bci); |
duke@435 | 468 | } |
duke@435 | 469 | // release so other threads see a consistent state. bci is used as |
duke@435 | 470 | // a valid flag for bci_displacement. |
duke@435 | 471 | OrderAccess::release(); |
duke@435 | 472 | } |
duke@435 | 473 | |
duke@435 | 474 | // This routine needs to atomically update the RetData structure, so the |
duke@435 | 475 | // caller needs to hold the RetData_lock before it gets here. Since taking |
duke@435 | 476 | // the lock can block (and allow GC) and since RetData is a ProfileData is a |
duke@435 | 477 | // wrapper around a derived oop, taking the lock in _this_ method will |
duke@435 | 478 | // basically cause the 'this' pointer's _data field to contain junk after the |
duke@435 | 479 | // lock. We require the caller to take the lock before making the ProfileData |
duke@435 | 480 | // structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret |
coleenp@4037 | 481 | address RetData::fixup_ret(int return_bci, MethodData* h_mdo) { |
duke@435 | 482 | // First find the mdp which corresponds to the return bci. |
duke@435 | 483 | address mdp = h_mdo->bci_to_dp(return_bci); |
duke@435 | 484 | |
duke@435 | 485 | // Now check to see if any of the cache slots are open. |
duke@435 | 486 | for (uint row = 0; row < row_limit(); row++) { |
duke@435 | 487 | if (bci(row) == no_bci) { |
duke@435 | 488 | set_bci_displacement(row, mdp - dp()); |
duke@435 | 489 | set_bci_count(row, DataLayout::counter_increment); |
duke@435 | 490 | // Barrier to ensure displacement is written before the bci; allows |
duke@435 | 491 | // the interpreter to read displacement without fear of race condition. |
duke@435 | 492 | release_set_bci(row, return_bci); |
duke@435 | 493 | break; |
duke@435 | 494 | } |
duke@435 | 495 | } |
duke@435 | 496 | return mdp; |
duke@435 | 497 | } |
duke@435 | 498 | |
goetz@6470 | 499 | #ifdef CC_INTERP |
goetz@6470 | 500 | DataLayout* RetData::advance(MethodData *md, int bci) { |
goetz@6470 | 501 | return (DataLayout*) md->bci_to_dp(bci); |
goetz@6470 | 502 | } |
goetz@6470 | 503 | #endif // CC_INTERP |
duke@435 | 504 | |
duke@435 | 505 | #ifndef PRODUCT |
roland@6377 | 506 | void RetData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 507 | print_shared(st, "RetData", extra); |
duke@435 | 508 | uint row; |
duke@435 | 509 | int entries = 0; |
duke@435 | 510 | for (row = 0; row < row_limit(); row++) { |
duke@435 | 511 | if (bci(row) != no_bci) entries++; |
duke@435 | 512 | } |
duke@435 | 513 | st->print_cr("count(%u) entries(%u)", count(), entries); |
duke@435 | 514 | for (row = 0; row < row_limit(); row++) { |
duke@435 | 515 | if (bci(row) != no_bci) { |
duke@435 | 516 | tab(st); |
duke@435 | 517 | st->print_cr("bci(%d: count(%u) displacement(%d))", |
duke@435 | 518 | bci(row), bci_count(row), bci_displacement(row)); |
duke@435 | 519 | } |
duke@435 | 520 | } |
duke@435 | 521 | } |
duke@435 | 522 | #endif // !PRODUCT |
duke@435 | 523 | |
duke@435 | 524 | // ================================================================== |
duke@435 | 525 | // BranchData |
duke@435 | 526 | // |
duke@435 | 527 | // A BranchData is used to access profiling data for a two-way branch. |
duke@435 | 528 | // It consists of taken and not_taken counts as well as a data displacement |
duke@435 | 529 | // for the taken case. |
duke@435 | 530 | |
coleenp@4037 | 531 | void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
duke@435 | 532 | assert(stream->bci() == bci(), "wrong pos"); |
duke@435 | 533 | int target = stream->dest(); |
duke@435 | 534 | int my_di = mdo->dp_to_di(dp()); |
duke@435 | 535 | int target_di = mdo->bci_to_di(target); |
duke@435 | 536 | int offset = target_di - my_di; |
duke@435 | 537 | set_displacement(offset); |
duke@435 | 538 | } |
duke@435 | 539 | |
duke@435 | 540 | #ifndef PRODUCT |
roland@6377 | 541 | void BranchData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 542 | print_shared(st, "BranchData", extra); |
duke@435 | 543 | st->print_cr("taken(%u) displacement(%d)", |
duke@435 | 544 | taken(), displacement()); |
duke@435 | 545 | tab(st); |
duke@435 | 546 | st->print_cr("not taken(%u)", not_taken()); |
duke@435 | 547 | } |
duke@435 | 548 | #endif |
duke@435 | 549 | |
duke@435 | 550 | // ================================================================== |
duke@435 | 551 | // MultiBranchData |
duke@435 | 552 | // |
duke@435 | 553 | // A MultiBranchData is used to access profiling information for |
duke@435 | 554 | // a multi-way branch (*switch bytecodes). It consists of a series |
duke@435 | 555 | // of (count, displacement) pairs, which count the number of times each |
duke@435 | 556 | // case was taken and specify the data displacment for each branch target. |
duke@435 | 557 | |
duke@435 | 558 | int MultiBranchData::compute_cell_count(BytecodeStream* stream) { |
duke@435 | 559 | int cell_count = 0; |
duke@435 | 560 | if (stream->code() == Bytecodes::_tableswitch) { |
never@2462 | 561 | Bytecode_tableswitch sw(stream->method()(), stream->bcp()); |
never@2462 | 562 | cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default |
duke@435 | 563 | } else { |
never@2462 | 564 | Bytecode_lookupswitch sw(stream->method()(), stream->bcp()); |
never@2462 | 565 | cell_count = 1 + per_case_cell_count * (sw.number_of_pairs() + 1); // 1 for default |
duke@435 | 566 | } |
duke@435 | 567 | return cell_count; |
duke@435 | 568 | } |
duke@435 | 569 | |
duke@435 | 570 | void MultiBranchData::post_initialize(BytecodeStream* stream, |
coleenp@4037 | 571 | MethodData* mdo) { |
duke@435 | 572 | assert(stream->bci() == bci(), "wrong pos"); |
duke@435 | 573 | int target; |
duke@435 | 574 | int my_di; |
duke@435 | 575 | int target_di; |
duke@435 | 576 | int offset; |
duke@435 | 577 | if (stream->code() == Bytecodes::_tableswitch) { |
never@2462 | 578 | Bytecode_tableswitch sw(stream->method()(), stream->bcp()); |
never@2462 | 579 | int len = sw.length(); |
duke@435 | 580 | assert(array_len() == per_case_cell_count * (len + 1), "wrong len"); |
duke@435 | 581 | for (int count = 0; count < len; count++) { |
never@2462 | 582 | target = sw.dest_offset_at(count) + bci(); |
duke@435 | 583 | my_di = mdo->dp_to_di(dp()); |
duke@435 | 584 | target_di = mdo->bci_to_di(target); |
duke@435 | 585 | offset = target_di - my_di; |
duke@435 | 586 | set_displacement_at(count, offset); |
duke@435 | 587 | } |
never@2462 | 588 | target = sw.default_offset() + bci(); |
duke@435 | 589 | my_di = mdo->dp_to_di(dp()); |
duke@435 | 590 | target_di = mdo->bci_to_di(target); |
duke@435 | 591 | offset = target_di - my_di; |
duke@435 | 592 | set_default_displacement(offset); |
duke@435 | 593 | |
duke@435 | 594 | } else { |
never@2462 | 595 | Bytecode_lookupswitch sw(stream->method()(), stream->bcp()); |
never@2462 | 596 | int npairs = sw.number_of_pairs(); |
duke@435 | 597 | assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len"); |
duke@435 | 598 | for (int count = 0; count < npairs; count++) { |
never@2462 | 599 | LookupswitchPair pair = sw.pair_at(count); |
never@2462 | 600 | target = pair.offset() + bci(); |
duke@435 | 601 | my_di = mdo->dp_to_di(dp()); |
duke@435 | 602 | target_di = mdo->bci_to_di(target); |
duke@435 | 603 | offset = target_di - my_di; |
duke@435 | 604 | set_displacement_at(count, offset); |
duke@435 | 605 | } |
never@2462 | 606 | target = sw.default_offset() + bci(); |
duke@435 | 607 | my_di = mdo->dp_to_di(dp()); |
duke@435 | 608 | target_di = mdo->bci_to_di(target); |
duke@435 | 609 | offset = target_di - my_di; |
duke@435 | 610 | set_default_displacement(offset); |
duke@435 | 611 | } |
duke@435 | 612 | } |
duke@435 | 613 | |
duke@435 | 614 | #ifndef PRODUCT |
roland@6377 | 615 | void MultiBranchData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 616 | print_shared(st, "MultiBranchData", extra); |
duke@435 | 617 | st->print_cr("default_count(%u) displacement(%d)", |
duke@435 | 618 | default_count(), default_displacement()); |
duke@435 | 619 | int cases = number_of_cases(); |
duke@435 | 620 | for (int i = 0; i < cases; i++) { |
duke@435 | 621 | tab(st); |
duke@435 | 622 | st->print_cr("count(%u) displacement(%d)", |
duke@435 | 623 | count_at(i), displacement_at(i)); |
duke@435 | 624 | } |
duke@435 | 625 | } |
duke@435 | 626 | #endif |
duke@435 | 627 | |
kvn@480 | 628 | #ifndef PRODUCT |
roland@6377 | 629 | void ArgInfoData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 630 | print_shared(st, "ArgInfoData", extra); |
kvn@480 | 631 | int nargs = number_of_args(); |
kvn@480 | 632 | for (int i = 0; i < nargs; i++) { |
kvn@480 | 633 | st->print(" 0x%x", arg_modified(i)); |
kvn@480 | 634 | } |
kvn@480 | 635 | st->cr(); |
kvn@480 | 636 | } |
kvn@480 | 637 | |
kvn@480 | 638 | #endif |
roland@5987 | 639 | |
roland@5987 | 640 | int ParametersTypeData::compute_cell_count(Method* m) { |
roland@5987 | 641 | if (!MethodData::profile_parameters_for_method(m)) { |
roland@5987 | 642 | return 0; |
roland@5987 | 643 | } |
roland@5987 | 644 | int max = TypeProfileParmsLimit == -1 ? INT_MAX : TypeProfileParmsLimit; |
roland@5987 | 645 | int obj_args = TypeStackSlotEntries::compute_cell_count(m->signature(), !m->is_static(), max); |
roland@5987 | 646 | if (obj_args > 0) { |
roland@5987 | 647 | return obj_args + 1; // 1 cell for array len |
roland@5987 | 648 | } |
roland@5987 | 649 | return 0; |
roland@5987 | 650 | } |
roland@5987 | 651 | |
roland@5987 | 652 | void ParametersTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) { |
roland@5987 | 653 | _parameters.post_initialize(mdo->method()->signature(), !mdo->method()->is_static(), true); |
roland@5987 | 654 | } |
roland@5987 | 655 | |
roland@5987 | 656 | bool ParametersTypeData::profiling_enabled() { |
roland@5987 | 657 | return MethodData::profile_parameters(); |
roland@5987 | 658 | } |
roland@5987 | 659 | |
roland@5987 | 660 | #ifndef PRODUCT |
roland@6377 | 661 | void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const { |
drchase@6680 | 662 | st->print("parameter types"); // FIXME extra ignored? |
roland@5987 | 663 | _parameters.print_data_on(st); |
roland@5987 | 664 | } |
roland@6377 | 665 | |
roland@6377 | 666 | void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const { |
roland@6377 | 667 | print_shared(st, "SpeculativeTrapData", extra); |
roland@6377 | 668 | tab(st); |
roland@6377 | 669 | method()->print_short_name(st); |
roland@6377 | 670 | st->cr(); |
roland@6377 | 671 | } |
roland@5987 | 672 | #endif |
roland@5987 | 673 | |
duke@435 | 674 | // ================================================================== |
coleenp@4037 | 675 | // MethodData* |
duke@435 | 676 | // |
coleenp@4037 | 677 | // A MethodData* holds information which has been collected about |
duke@435 | 678 | // a method. |
duke@435 | 679 | |
coleenp@4037 | 680 | MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) { |
coleenp@4037 | 681 | int size = MethodData::compute_allocation_size_in_words(method); |
coleenp@4037 | 682 | |
iklam@5208 | 683 | return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD) |
phh@9507 | 684 | MethodData(method(), size, THREAD); |
coleenp@4037 | 685 | } |
coleenp@4037 | 686 | |
coleenp@4037 | 687 | int MethodData::bytecode_cell_count(Bytecodes::Code code) { |
roland@4860 | 688 | #if defined(COMPILER1) && !defined(COMPILER2) |
roland@4860 | 689 | return no_profile_data; |
roland@4860 | 690 | #else |
duke@435 | 691 | switch (code) { |
duke@435 | 692 | case Bytecodes::_checkcast: |
duke@435 | 693 | case Bytecodes::_instanceof: |
duke@435 | 694 | case Bytecodes::_aastore: |
duke@435 | 695 | if (TypeProfileCasts) { |
duke@435 | 696 | return ReceiverTypeData::static_cell_count(); |
duke@435 | 697 | } else { |
duke@435 | 698 | return BitData::static_cell_count(); |
duke@435 | 699 | } |
duke@435 | 700 | case Bytecodes::_invokespecial: |
duke@435 | 701 | case Bytecodes::_invokestatic: |
roland@5921 | 702 | if (MethodData::profile_arguments() || MethodData::profile_return()) { |
roland@5914 | 703 | return variable_cell_count; |
roland@5914 | 704 | } else { |
roland@5914 | 705 | return CounterData::static_cell_count(); |
roland@5914 | 706 | } |
duke@435 | 707 | case Bytecodes::_goto: |
duke@435 | 708 | case Bytecodes::_goto_w: |
duke@435 | 709 | case Bytecodes::_jsr: |
duke@435 | 710 | case Bytecodes::_jsr_w: |
duke@435 | 711 | return JumpData::static_cell_count(); |
duke@435 | 712 | case Bytecodes::_invokevirtual: |
duke@435 | 713 | case Bytecodes::_invokeinterface: |
roland@5921 | 714 | if (MethodData::profile_arguments() || MethodData::profile_return()) { |
roland@5914 | 715 | return variable_cell_count; |
roland@5914 | 716 | } else { |
roland@5914 | 717 | return VirtualCallData::static_cell_count(); |
roland@5914 | 718 | } |
jrose@1161 | 719 | case Bytecodes::_invokedynamic: |
roland@5921 | 720 | if (MethodData::profile_arguments() || MethodData::profile_return()) { |
roland@5914 | 721 | return variable_cell_count; |
roland@5914 | 722 | } else { |
roland@5914 | 723 | return CounterData::static_cell_count(); |
roland@5914 | 724 | } |
duke@435 | 725 | case Bytecodes::_ret: |
duke@435 | 726 | return RetData::static_cell_count(); |
duke@435 | 727 | case Bytecodes::_ifeq: |
duke@435 | 728 | case Bytecodes::_ifne: |
duke@435 | 729 | case Bytecodes::_iflt: |
duke@435 | 730 | case Bytecodes::_ifge: |
duke@435 | 731 | case Bytecodes::_ifgt: |
duke@435 | 732 | case Bytecodes::_ifle: |
duke@435 | 733 | case Bytecodes::_if_icmpeq: |
duke@435 | 734 | case Bytecodes::_if_icmpne: |
duke@435 | 735 | case Bytecodes::_if_icmplt: |
duke@435 | 736 | case Bytecodes::_if_icmpge: |
duke@435 | 737 | case Bytecodes::_if_icmpgt: |
duke@435 | 738 | case Bytecodes::_if_icmple: |
duke@435 | 739 | case Bytecodes::_if_acmpeq: |
duke@435 | 740 | case Bytecodes::_if_acmpne: |
duke@435 | 741 | case Bytecodes::_ifnull: |
duke@435 | 742 | case Bytecodes::_ifnonnull: |
duke@435 | 743 | return BranchData::static_cell_count(); |
duke@435 | 744 | case Bytecodes::_lookupswitch: |
duke@435 | 745 | case Bytecodes::_tableswitch: |
duke@435 | 746 | return variable_cell_count; |
duke@435 | 747 | } |
duke@435 | 748 | return no_profile_data; |
roland@4860 | 749 | #endif |
duke@435 | 750 | } |
duke@435 | 751 | |
duke@435 | 752 | // Compute the size of the profiling information corresponding to |
duke@435 | 753 | // the current bytecode. |
coleenp@4037 | 754 | int MethodData::compute_data_size(BytecodeStream* stream) { |
duke@435 | 755 | int cell_count = bytecode_cell_count(stream->code()); |
duke@435 | 756 | if (cell_count == no_profile_data) { |
duke@435 | 757 | return 0; |
duke@435 | 758 | } |
duke@435 | 759 | if (cell_count == variable_cell_count) { |
roland@5914 | 760 | switch (stream->code()) { |
roland@5914 | 761 | case Bytecodes::_lookupswitch: |
roland@5914 | 762 | case Bytecodes::_tableswitch: |
roland@5914 | 763 | cell_count = MultiBranchData::compute_cell_count(stream); |
roland@5914 | 764 | break; |
roland@5914 | 765 | case Bytecodes::_invokespecial: |
roland@5914 | 766 | case Bytecodes::_invokestatic: |
roland@5914 | 767 | case Bytecodes::_invokedynamic: |
roland@5921 | 768 | assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile"); |
roland@5921 | 769 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 770 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 771 | cell_count = CallTypeData::compute_cell_count(stream); |
roland@5914 | 772 | } else { |
roland@5914 | 773 | cell_count = CounterData::static_cell_count(); |
roland@5914 | 774 | } |
roland@5914 | 775 | break; |
roland@5914 | 776 | case Bytecodes::_invokevirtual: |
roland@5914 | 777 | case Bytecodes::_invokeinterface: { |
roland@5921 | 778 | assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile"); |
roland@5921 | 779 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 780 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 781 | cell_count = VirtualCallTypeData::compute_cell_count(stream); |
roland@5914 | 782 | } else { |
roland@5914 | 783 | cell_count = VirtualCallData::static_cell_count(); |
roland@5914 | 784 | } |
roland@5914 | 785 | break; |
roland@5914 | 786 | } |
roland@5914 | 787 | default: |
roland@5914 | 788 | fatal("unexpected bytecode for var length profile data"); |
roland@5914 | 789 | } |
duke@435 | 790 | } |
duke@435 | 791 | // Note: cell_count might be zero, meaning that there is just |
duke@435 | 792 | // a DataLayout header, with no extra cells. |
duke@435 | 793 | assert(cell_count >= 0, "sanity"); |
duke@435 | 794 | return DataLayout::compute_size_in_bytes(cell_count); |
duke@435 | 795 | } |
duke@435 | 796 | |
roland@6377 | 797 | bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) { |
roland@6377 | 798 | // Bytecodes for which we may use speculation |
roland@6377 | 799 | switch (code) { |
roland@6377 | 800 | case Bytecodes::_checkcast: |
roland@6377 | 801 | case Bytecodes::_instanceof: |
roland@6377 | 802 | case Bytecodes::_aastore: |
roland@6377 | 803 | case Bytecodes::_invokevirtual: |
roland@6377 | 804 | case Bytecodes::_invokeinterface: |
roland@6377 | 805 | case Bytecodes::_if_acmpeq: |
roland@6377 | 806 | case Bytecodes::_if_acmpne: |
roland@6377 | 807 | case Bytecodes::_invokestatic: |
roland@6377 | 808 | #ifdef COMPILER2 |
roland@6377 | 809 | return UseTypeSpeculation; |
roland@6377 | 810 | #endif |
roland@6377 | 811 | default: |
roland@6377 | 812 | return false; |
roland@6377 | 813 | } |
roland@6377 | 814 | return false; |
roland@6377 | 815 | } |
roland@6377 | 816 | |
roland@6377 | 817 | int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { |
duke@435 | 818 | if (ProfileTraps) { |
duke@435 | 819 | // Assume that up to 3% of BCIs with no MDP will need to allocate one. |
duke@435 | 820 | int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; |
duke@435 | 821 | // If the method is large, let the extra BCIs grow numerous (to ~1%). |
duke@435 | 822 | int one_percent_of_data |
duke@435 | 823 | = (uint)data_size / (DataLayout::header_size_in_bytes()*128); |
duke@435 | 824 | if (extra_data_count < one_percent_of_data) |
duke@435 | 825 | extra_data_count = one_percent_of_data; |
duke@435 | 826 | if (extra_data_count > empty_bc_count) |
duke@435 | 827 | extra_data_count = empty_bc_count; // no need for more |
roland@6377 | 828 | |
roland@6377 | 829 | // Make sure we have a minimum number of extra data slots to |
roland@6377 | 830 | // allocate SpeculativeTrapData entries. We would want to have one |
roland@6377 | 831 | // entry per compilation that inlines this method and for which |
roland@6377 | 832 | // some type speculation assumption fails. So the room we need for |
roland@6377 | 833 | // the SpeculativeTrapData entries doesn't directly depend on the |
roland@6377 | 834 | // size of the method. Because it's hard to estimate, we reserve |
roland@6377 | 835 | // space for an arbitrary number of entries. |
roland@6377 | 836 | int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) * |
roland@6377 | 837 | (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells()); |
roland@6377 | 838 | |
roland@6377 | 839 | return MAX2(extra_data_count, spec_data_count); |
duke@435 | 840 | } else { |
duke@435 | 841 | return 0; |
duke@435 | 842 | } |
duke@435 | 843 | } |
duke@435 | 844 | |
coleenp@4037 | 845 | // Compute the size of the MethodData* necessary to store |
duke@435 | 846 | // profiling information about a given method. Size is in bytes. |
coleenp@4037 | 847 | int MethodData::compute_allocation_size_in_bytes(methodHandle method) { |
duke@435 | 848 | int data_size = 0; |
duke@435 | 849 | BytecodeStream stream(method); |
duke@435 | 850 | Bytecodes::Code c; |
duke@435 | 851 | int empty_bc_count = 0; // number of bytecodes lacking data |
roland@6377 | 852 | bool needs_speculative_traps = false; |
duke@435 | 853 | while ((c = stream.next()) >= 0) { |
duke@435 | 854 | int size_in_bytes = compute_data_size(&stream); |
duke@435 | 855 | data_size += size_in_bytes; |
duke@435 | 856 | if (size_in_bytes == 0) empty_bc_count += 1; |
roland@6377 | 857 | needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); |
duke@435 | 858 | } |
duke@435 | 859 | int object_size = in_bytes(data_offset()) + data_size; |
duke@435 | 860 | |
duke@435 | 861 | // Add some extra DataLayout cells (at least one) to track stray traps. |
roland@6377 | 862 | int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); |
duke@435 | 863 | object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); |
duke@435 | 864 | |
kvn@480 | 865 | // Add a cell to record information about modified arguments. |
kvn@480 | 866 | int arg_size = method->size_of_parameters(); |
kvn@480 | 867 | object_size += DataLayout::compute_size_in_bytes(arg_size+1); |
roland@5914 | 868 | |
roland@5987 | 869 | // Reserve room for an area of the MDO dedicated to profiling of |
roland@5987 | 870 | // parameters |
roland@5987 | 871 | int args_cell = ParametersTypeData::compute_cell_count(method()); |
roland@5987 | 872 | if (args_cell > 0) { |
roland@5987 | 873 | object_size += DataLayout::compute_size_in_bytes(args_cell); |
roland@5987 | 874 | } |
duke@435 | 875 | return object_size; |
duke@435 | 876 | } |
duke@435 | 877 | |
coleenp@4037 | 878 | // Compute the size of the MethodData* necessary to store |
duke@435 | 879 | // profiling information about a given method. Size is in words |
coleenp@4037 | 880 | int MethodData::compute_allocation_size_in_words(methodHandle method) { |
duke@435 | 881 | int byte_size = compute_allocation_size_in_bytes(method); |
duke@435 | 882 | int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord; |
duke@435 | 883 | return align_object_size(word_size); |
duke@435 | 884 | } |
duke@435 | 885 | |
duke@435 | 886 | // Initialize an individual data segment. Returns the size of |
duke@435 | 887 | // the segment in bytes. |
coleenp@4037 | 888 | int MethodData::initialize_data(BytecodeStream* stream, |
duke@435 | 889 | int data_index) { |
roland@4860 | 890 | #if defined(COMPILER1) && !defined(COMPILER2) |
roland@4860 | 891 | return 0; |
roland@4860 | 892 | #else |
duke@435 | 893 | int cell_count = -1; |
duke@435 | 894 | int tag = DataLayout::no_tag; |
duke@435 | 895 | DataLayout* data_layout = data_layout_at(data_index); |
duke@435 | 896 | Bytecodes::Code c = stream->code(); |
duke@435 | 897 | switch (c) { |
duke@435 | 898 | case Bytecodes::_checkcast: |
duke@435 | 899 | case Bytecodes::_instanceof: |
duke@435 | 900 | case Bytecodes::_aastore: |
duke@435 | 901 | if (TypeProfileCasts) { |
duke@435 | 902 | cell_count = ReceiverTypeData::static_cell_count(); |
duke@435 | 903 | tag = DataLayout::receiver_type_data_tag; |
duke@435 | 904 | } else { |
duke@435 | 905 | cell_count = BitData::static_cell_count(); |
duke@435 | 906 | tag = DataLayout::bit_data_tag; |
duke@435 | 907 | } |
duke@435 | 908 | break; |
duke@435 | 909 | case Bytecodes::_invokespecial: |
roland@5914 | 910 | case Bytecodes::_invokestatic: { |
roland@5914 | 911 | int counter_data_cell_count = CounterData::static_cell_count(); |
roland@5921 | 912 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 913 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 914 | cell_count = CallTypeData::compute_cell_count(stream); |
roland@5914 | 915 | } else { |
roland@5914 | 916 | cell_count = counter_data_cell_count; |
roland@5914 | 917 | } |
roland@5914 | 918 | if (cell_count > counter_data_cell_count) { |
roland@5914 | 919 | tag = DataLayout::call_type_data_tag; |
roland@5914 | 920 | } else { |
roland@5914 | 921 | tag = DataLayout::counter_data_tag; |
roland@5914 | 922 | } |
duke@435 | 923 | break; |
roland@5914 | 924 | } |
duke@435 | 925 | case Bytecodes::_goto: |
duke@435 | 926 | case Bytecodes::_goto_w: |
duke@435 | 927 | case Bytecodes::_jsr: |
duke@435 | 928 | case Bytecodes::_jsr_w: |
duke@435 | 929 | cell_count = JumpData::static_cell_count(); |
duke@435 | 930 | tag = DataLayout::jump_data_tag; |
duke@435 | 931 | break; |
duke@435 | 932 | case Bytecodes::_invokevirtual: |
roland@5914 | 933 | case Bytecodes::_invokeinterface: { |
roland@5914 | 934 | int virtual_call_data_cell_count = VirtualCallData::static_cell_count(); |
roland@5921 | 935 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 936 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 937 | cell_count = VirtualCallTypeData::compute_cell_count(stream); |
roland@5914 | 938 | } else { |
roland@5914 | 939 | cell_count = virtual_call_data_cell_count; |
roland@5914 | 940 | } |
roland@5914 | 941 | if (cell_count > virtual_call_data_cell_count) { |
roland@5914 | 942 | tag = DataLayout::virtual_call_type_data_tag; |
roland@5914 | 943 | } else { |
roland@5914 | 944 | tag = DataLayout::virtual_call_data_tag; |
roland@5914 | 945 | } |
duke@435 | 946 | break; |
roland@5914 | 947 | } |
roland@5914 | 948 | case Bytecodes::_invokedynamic: { |
jrose@1161 | 949 | // %%% should make a type profile for any invokedynamic that takes a ref argument |
roland@5914 | 950 | int counter_data_cell_count = CounterData::static_cell_count(); |
roland@5921 | 951 | if (profile_arguments_for_invoke(stream->method(), stream->bci()) || |
roland@5921 | 952 | profile_return_for_invoke(stream->method(), stream->bci())) { |
roland@5914 | 953 | cell_count = CallTypeData::compute_cell_count(stream); |
roland@5914 | 954 | } else { |
roland@5914 | 955 | cell_count = counter_data_cell_count; |
roland@5914 | 956 | } |
roland@5914 | 957 | if (cell_count > counter_data_cell_count) { |
roland@5914 | 958 | tag = DataLayout::call_type_data_tag; |
roland@5914 | 959 | } else { |
roland@5914 | 960 | tag = DataLayout::counter_data_tag; |
roland@5914 | 961 | } |
jrose@1161 | 962 | break; |
roland@5914 | 963 | } |
duke@435 | 964 | case Bytecodes::_ret: |
duke@435 | 965 | cell_count = RetData::static_cell_count(); |
duke@435 | 966 | tag = DataLayout::ret_data_tag; |
duke@435 | 967 | break; |
duke@435 | 968 | case Bytecodes::_ifeq: |
duke@435 | 969 | case Bytecodes::_ifne: |
duke@435 | 970 | case Bytecodes::_iflt: |
duke@435 | 971 | case Bytecodes::_ifge: |
duke@435 | 972 | case Bytecodes::_ifgt: |
duke@435 | 973 | case Bytecodes::_ifle: |
duke@435 | 974 | case Bytecodes::_if_icmpeq: |
duke@435 | 975 | case Bytecodes::_if_icmpne: |
duke@435 | 976 | case Bytecodes::_if_icmplt: |
duke@435 | 977 | case Bytecodes::_if_icmpge: |
duke@435 | 978 | case Bytecodes::_if_icmpgt: |
duke@435 | 979 | case Bytecodes::_if_icmple: |
duke@435 | 980 | case Bytecodes::_if_acmpeq: |
duke@435 | 981 | case Bytecodes::_if_acmpne: |
duke@435 | 982 | case Bytecodes::_ifnull: |
duke@435 | 983 | case Bytecodes::_ifnonnull: |
duke@435 | 984 | cell_count = BranchData::static_cell_count(); |
duke@435 | 985 | tag = DataLayout::branch_data_tag; |
duke@435 | 986 | break; |
duke@435 | 987 | case Bytecodes::_lookupswitch: |
duke@435 | 988 | case Bytecodes::_tableswitch: |
duke@435 | 989 | cell_count = MultiBranchData::compute_cell_count(stream); |
duke@435 | 990 | tag = DataLayout::multi_branch_data_tag; |
duke@435 | 991 | break; |
duke@435 | 992 | } |
duke@435 | 993 | assert(tag == DataLayout::multi_branch_data_tag || |
roland@5921 | 994 | ((MethodData::profile_arguments() || MethodData::profile_return()) && |
roland@5914 | 995 | (tag == DataLayout::call_type_data_tag || |
roland@5914 | 996 | tag == DataLayout::counter_data_tag || |
roland@5914 | 997 | tag == DataLayout::virtual_call_type_data_tag || |
roland@5914 | 998 | tag == DataLayout::virtual_call_data_tag)) || |
duke@435 | 999 | cell_count == bytecode_cell_count(c), "cell counts must agree"); |
duke@435 | 1000 | if (cell_count >= 0) { |
duke@435 | 1001 | assert(tag != DataLayout::no_tag, "bad tag"); |
duke@435 | 1002 | assert(bytecode_has_profile(c), "agree w/ BHP"); |
duke@435 | 1003 | data_layout->initialize(tag, stream->bci(), cell_count); |
duke@435 | 1004 | return DataLayout::compute_size_in_bytes(cell_count); |
duke@435 | 1005 | } else { |
duke@435 | 1006 | assert(!bytecode_has_profile(c), "agree w/ !BHP"); |
duke@435 | 1007 | return 0; |
duke@435 | 1008 | } |
roland@4860 | 1009 | #endif |
duke@435 | 1010 | } |
duke@435 | 1011 | |
duke@435 | 1012 | // Get the data at an arbitrary (sort of) data index. |
coleenp@4037 | 1013 | ProfileData* MethodData::data_at(int data_index) const { |
duke@435 | 1014 | if (out_of_bounds(data_index)) { |
duke@435 | 1015 | return NULL; |
duke@435 | 1016 | } |
duke@435 | 1017 | DataLayout* data_layout = data_layout_at(data_index); |
ysr@1376 | 1018 | return data_layout->data_in(); |
ysr@1376 | 1019 | } |
duke@435 | 1020 | |
ysr@1376 | 1021 | ProfileData* DataLayout::data_in() { |
ysr@1376 | 1022 | switch (tag()) { |
duke@435 | 1023 | case DataLayout::no_tag: |
duke@435 | 1024 | default: |
duke@435 | 1025 | ShouldNotReachHere(); |
duke@435 | 1026 | return NULL; |
duke@435 | 1027 | case DataLayout::bit_data_tag: |
ysr@1376 | 1028 | return new BitData(this); |
duke@435 | 1029 | case DataLayout::counter_data_tag: |
ysr@1376 | 1030 | return new CounterData(this); |
duke@435 | 1031 | case DataLayout::jump_data_tag: |
ysr@1376 | 1032 | return new JumpData(this); |
duke@435 | 1033 | case DataLayout::receiver_type_data_tag: |
ysr@1376 | 1034 | return new ReceiverTypeData(this); |
duke@435 | 1035 | case DataLayout::virtual_call_data_tag: |
ysr@1376 | 1036 | return new VirtualCallData(this); |
duke@435 | 1037 | case DataLayout::ret_data_tag: |
ysr@1376 | 1038 | return new RetData(this); |
duke@435 | 1039 | case DataLayout::branch_data_tag: |
ysr@1376 | 1040 | return new BranchData(this); |
duke@435 | 1041 | case DataLayout::multi_branch_data_tag: |
ysr@1376 | 1042 | return new MultiBranchData(this); |
kvn@480 | 1043 | case DataLayout::arg_info_data_tag: |
ysr@1376 | 1044 | return new ArgInfoData(this); |
roland@5914 | 1045 | case DataLayout::call_type_data_tag: |
roland@5914 | 1046 | return new CallTypeData(this); |
roland@5914 | 1047 | case DataLayout::virtual_call_type_data_tag: |
roland@5914 | 1048 | return new VirtualCallTypeData(this); |
roland@5987 | 1049 | case DataLayout::parameters_type_data_tag: |
roland@5987 | 1050 | return new ParametersTypeData(this); |
duke@435 | 1051 | }; |
duke@435 | 1052 | } |
duke@435 | 1053 | |
duke@435 | 1054 | // Iteration over data. |
coleenp@4037 | 1055 | ProfileData* MethodData::next_data(ProfileData* current) const { |
duke@435 | 1056 | int current_index = dp_to_di(current->dp()); |
duke@435 | 1057 | int next_index = current_index + current->size_in_bytes(); |
duke@435 | 1058 | ProfileData* next = data_at(next_index); |
duke@435 | 1059 | return next; |
duke@435 | 1060 | } |
duke@435 | 1061 | |
duke@435 | 1062 | // Give each of the data entries a chance to perform specific |
duke@435 | 1063 | // data initialization. |
coleenp@4037 | 1064 | void MethodData::post_initialize(BytecodeStream* stream) { |
duke@435 | 1065 | ResourceMark rm; |
duke@435 | 1066 | ProfileData* data; |
duke@435 | 1067 | for (data = first_data(); is_valid(data); data = next_data(data)) { |
duke@435 | 1068 | stream->set_start(data->bci()); |
duke@435 | 1069 | stream->next(); |
duke@435 | 1070 | data->post_initialize(stream, this); |
duke@435 | 1071 | } |
roland@5987 | 1072 | if (_parameters_type_data_di != -1) { |
roland@5987 | 1073 | parameters_type_data()->post_initialize(NULL, this); |
roland@5987 | 1074 | } |
duke@435 | 1075 | } |
duke@435 | 1076 | |
coleenp@4037 | 1077 | // Initialize the MethodData* corresponding to a given method. |
roland@6382 | 1078 | MethodData::MethodData(methodHandle method, int size, TRAPS) |
roland@6382 | 1079 | : _extra_data_lock(Monitor::leaf, "MDO extra data lock") { |
coleenp@4037 | 1080 | No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC |
duke@435 | 1081 | ResourceMark rm; |
duke@435 | 1082 | // Set the method back-pointer. |
duke@435 | 1083 | _method = method(); |
iveresov@2138 | 1084 | |
iignatyev@4908 | 1085 | init(); |
duke@435 | 1086 | set_creation_mileage(mileage_of(method())); |
duke@435 | 1087 | |
duke@435 | 1088 | // Go through the bytecodes and allocate and initialize the |
duke@435 | 1089 | // corresponding data cells. |
duke@435 | 1090 | int data_size = 0; |
duke@435 | 1091 | int empty_bc_count = 0; // number of bytecodes lacking data |
coleenp@4712 | 1092 | _data[0] = 0; // apparently not set below. |
duke@435 | 1093 | BytecodeStream stream(method); |
duke@435 | 1094 | Bytecodes::Code c; |
roland@6377 | 1095 | bool needs_speculative_traps = false; |
duke@435 | 1096 | while ((c = stream.next()) >= 0) { |
duke@435 | 1097 | int size_in_bytes = initialize_data(&stream, data_size); |
duke@435 | 1098 | data_size += size_in_bytes; |
duke@435 | 1099 | if (size_in_bytes == 0) empty_bc_count += 1; |
roland@6377 | 1100 | needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); |
duke@435 | 1101 | } |
duke@435 | 1102 | _data_size = data_size; |
duke@435 | 1103 | int object_size = in_bytes(data_offset()) + data_size; |
duke@435 | 1104 | |
duke@435 | 1105 | // Add some extra DataLayout cells (at least one) to track stray traps. |
roland@6377 | 1106 | int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); |
kvn@480 | 1107 | int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); |
kvn@480 | 1108 | |
roland@6377 | 1109 | // Let's zero the space for the extra data |
roland@6377 | 1110 | Copy::zero_to_bytes(((address)_data) + data_size, extra_size); |
roland@6377 | 1111 | |
kvn@480 | 1112 | // Add a cell to record information about modified arguments. |
kvn@480 | 1113 | // Set up _args_modified array after traps cells so that |
kvn@480 | 1114 | // the code for traps cells works. |
kvn@480 | 1115 | DataLayout *dp = data_layout_at(data_size + extra_size); |
kvn@480 | 1116 | |
kvn@480 | 1117 | int arg_size = method->size_of_parameters(); |
kvn@480 | 1118 | dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
kvn@480 | 1119 | |
roland@5987 | 1120 | int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); |
roland@5987 | 1121 | object_size += extra_size + arg_data_size; |
roland@5987 | 1122 | |
roland@6377 | 1123 | int parms_cell = ParametersTypeData::compute_cell_count(method()); |
roland@5987 | 1124 | // If we are profiling parameters, we reserver an area near the end |
roland@5987 | 1125 | // of the MDO after the slots for bytecodes (because there's no bci |
roland@5987 | 1126 | // for method entry so they don't fit with the framework for the |
roland@5987 | 1127 | // profiling of bytecodes). We store the offset within the MDO of |
roland@5987 | 1128 | // this area (or -1 if no parameter is profiled) |
roland@6377 | 1129 | if (parms_cell > 0) { |
roland@6377 | 1130 | object_size += DataLayout::compute_size_in_bytes(parms_cell); |
roland@5987 | 1131 | _parameters_type_data_di = data_size + extra_size + arg_data_size; |
roland@5987 | 1132 | DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); |
roland@6377 | 1133 | dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell); |
roland@5987 | 1134 | } else { |
roland@5987 | 1135 | _parameters_type_data_di = -1; |
roland@5987 | 1136 | } |
duke@435 | 1137 | |
duke@435 | 1138 | // Set an initial hint. Don't use set_hint_di() because |
duke@435 | 1139 | // first_di() may be out of bounds if data_size is 0. |
duke@435 | 1140 | // In that situation, _hint_di is never used, but at |
duke@435 | 1141 | // least well-defined. |
duke@435 | 1142 | _hint_di = first_di(); |
duke@435 | 1143 | |
duke@435 | 1144 | post_initialize(&stream); |
duke@435 | 1145 | |
coleenp@4037 | 1146 | set_size(object_size); |
iignatyev@4908 | 1147 | } |
coleenp@4712 | 1148 | |
iignatyev@4908 | 1149 | void MethodData::init() { |
iignatyev@4908 | 1150 | _invocation_counter.init(); |
iignatyev@4908 | 1151 | _backedge_counter.init(); |
iignatyev@4908 | 1152 | _invocation_counter_start = 0; |
iignatyev@4908 | 1153 | _backedge_counter_start = 0; |
iignatyev@4908 | 1154 | _num_loops = 0; |
iignatyev@4908 | 1155 | _num_blocks = 0; |
thartmann@7365 | 1156 | _would_profile = unknown; |
iignatyev@4908 | 1157 | |
kvn@6429 | 1158 | #if INCLUDE_RTM_OPT |
kvn@6429 | 1159 | _rtm_state = NoRTM; // No RTM lock eliding by default |
kvn@6429 | 1160 | if (UseRTMLocking && |
kvn@6429 | 1161 | !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) { |
kvn@6429 | 1162 | if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) { |
kvn@6429 | 1163 | // Generate RTM lock eliding code without abort ratio calculation code. |
kvn@6429 | 1164 | _rtm_state = UseRTM; |
kvn@6429 | 1165 | } else if (UseRTMDeopt) { |
kvn@6429 | 1166 | // Generate RTM lock eliding code and include abort ratio calculation |
kvn@6429 | 1167 | // code if UseRTMDeopt is on. |
kvn@6429 | 1168 | _rtm_state = ProfileRTM; |
kvn@6429 | 1169 | } |
kvn@6429 | 1170 | } |
kvn@6429 | 1171 | #endif |
kvn@6429 | 1172 | |
iignatyev@4908 | 1173 | // Initialize flags and trap history. |
iignatyev@4908 | 1174 | _nof_decompiles = 0; |
iignatyev@4908 | 1175 | _nof_overflow_recompiles = 0; |
iignatyev@4908 | 1176 | _nof_overflow_traps = 0; |
iignatyev@4908 | 1177 | clear_escape_info(); |
iignatyev@4908 | 1178 | assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align"); |
iignatyev@4908 | 1179 | Copy::zero_to_words((HeapWord*) &_trap_hist, |
iignatyev@4908 | 1180 | sizeof(_trap_hist) / sizeof(HeapWord)); |
duke@435 | 1181 | } |
duke@435 | 1182 | |
duke@435 | 1183 | // Get a measure of how much mileage the method has on it. |
coleenp@4037 | 1184 | int MethodData::mileage_of(Method* method) { |
duke@435 | 1185 | int mileage = 0; |
iveresov@2138 | 1186 | if (TieredCompilation) { |
iveresov@2138 | 1187 | mileage = MAX2(method->invocation_count(), method->backedge_count()); |
iveresov@2138 | 1188 | } else { |
iveresov@2138 | 1189 | int iic = method->interpreter_invocation_count(); |
iveresov@2138 | 1190 | if (mileage < iic) mileage = iic; |
jiangli@4936 | 1191 | MethodCounters* mcs = method->method_counters(); |
jiangli@4936 | 1192 | if (mcs != NULL) { |
jiangli@4936 | 1193 | InvocationCounter* ic = mcs->invocation_counter(); |
jiangli@4936 | 1194 | InvocationCounter* bc = mcs->backedge_counter(); |
jiangli@4936 | 1195 | int icval = ic->count(); |
jiangli@4936 | 1196 | if (ic->carry()) icval += CompileThreshold; |
jiangli@4936 | 1197 | if (mileage < icval) mileage = icval; |
jiangli@4936 | 1198 | int bcval = bc->count(); |
jiangli@4936 | 1199 | if (bc->carry()) bcval += CompileThreshold; |
jiangli@4936 | 1200 | if (mileage < bcval) mileage = bcval; |
jiangli@4936 | 1201 | } |
iveresov@2138 | 1202 | } |
duke@435 | 1203 | return mileage; |
duke@435 | 1204 | } |
duke@435 | 1205 | |
coleenp@4037 | 1206 | bool MethodData::is_mature() const { |
iveresov@2138 | 1207 | return CompilationPolicy::policy()->is_mature(_method); |
duke@435 | 1208 | } |
duke@435 | 1209 | |
duke@435 | 1210 | // Translate a bci to its corresponding data index (di). |
coleenp@4037 | 1211 | address MethodData::bci_to_dp(int bci) { |
duke@435 | 1212 | ResourceMark rm; |
duke@435 | 1213 | ProfileData* data = data_before(bci); |
duke@435 | 1214 | ProfileData* prev = NULL; |
duke@435 | 1215 | for ( ; is_valid(data); data = next_data(data)) { |
duke@435 | 1216 | if (data->bci() >= bci) { |
duke@435 | 1217 | if (data->bci() == bci) set_hint_di(dp_to_di(data->dp())); |
duke@435 | 1218 | else if (prev != NULL) set_hint_di(dp_to_di(prev->dp())); |
duke@435 | 1219 | return data->dp(); |
duke@435 | 1220 | } |
duke@435 | 1221 | prev = data; |
duke@435 | 1222 | } |
duke@435 | 1223 | return (address)limit_data_position(); |
duke@435 | 1224 | } |
duke@435 | 1225 | |
duke@435 | 1226 | // Translate a bci to its corresponding data, or NULL. |
coleenp@4037 | 1227 | ProfileData* MethodData::bci_to_data(int bci) { |
duke@435 | 1228 | ProfileData* data = data_before(bci); |
duke@435 | 1229 | for ( ; is_valid(data); data = next_data(data)) { |
duke@435 | 1230 | if (data->bci() == bci) { |
duke@435 | 1231 | set_hint_di(dp_to_di(data->dp())); |
duke@435 | 1232 | return data; |
duke@435 | 1233 | } else if (data->bci() > bci) { |
duke@435 | 1234 | break; |
duke@435 | 1235 | } |
duke@435 | 1236 | } |
roland@6377 | 1237 | return bci_to_extra_data(bci, NULL, false); |
duke@435 | 1238 | } |
duke@435 | 1239 | |
roland@6377 | 1240 | DataLayout* MethodData::next_extra(DataLayout* dp) { |
roland@6377 | 1241 | int nb_cells = 0; |
roland@6377 | 1242 | switch(dp->tag()) { |
roland@6377 | 1243 | case DataLayout::bit_data_tag: |
roland@6377 | 1244 | case DataLayout::no_tag: |
roland@6377 | 1245 | nb_cells = BitData::static_cell_count(); |
roland@6377 | 1246 | break; |
roland@6377 | 1247 | case DataLayout::speculative_trap_data_tag: |
roland@6377 | 1248 | nb_cells = SpeculativeTrapData::static_cell_count(); |
roland@6377 | 1249 | break; |
roland@6377 | 1250 | default: |
roland@6377 | 1251 | fatal(err_msg("unexpected tag %d", dp->tag())); |
roland@6377 | 1252 | } |
roland@6377 | 1253 | return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells)); |
roland@6377 | 1254 | } |
roland@6377 | 1255 | |
roland@6382 | 1256 | ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) { |
roland@6377 | 1257 | DataLayout* end = extra_data_limit(); |
roland@6377 | 1258 | |
roland@6377 | 1259 | for (;; dp = next_extra(dp)) { |
roland@6377 | 1260 | assert(dp < end, "moved past end of extra data"); |
duke@435 | 1261 | // No need for "OrderAccess::load_acquire" ops, |
duke@435 | 1262 | // since the data structure is monotonic. |
roland@6377 | 1263 | switch(dp->tag()) { |
roland@6377 | 1264 | case DataLayout::no_tag: |
roland@6377 | 1265 | return NULL; |
roland@6377 | 1266 | case DataLayout::arg_info_data_tag: |
roland@6377 | 1267 | dp = end; |
roland@6377 | 1268 | return NULL; // ArgInfoData is at the end of extra data section. |
roland@6377 | 1269 | case DataLayout::bit_data_tag: |
roland@6377 | 1270 | if (m == NULL && dp->bci() == bci) { |
roland@6377 | 1271 | return new BitData(dp); |
roland@6377 | 1272 | } |
kvn@480 | 1273 | break; |
roland@6377 | 1274 | case DataLayout::speculative_trap_data_tag: |
roland@6377 | 1275 | if (m != NULL) { |
roland@6377 | 1276 | SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
roland@6377 | 1277 | // data->method() may be null in case of a concurrent |
roland@6382 | 1278 | // allocation. Maybe it's for the same method. Try to use that |
roland@6377 | 1279 | // entry in that case. |
roland@6377 | 1280 | if (dp->bci() == bci) { |
roland@6377 | 1281 | if (data->method() == NULL) { |
roland@6382 | 1282 | assert(concurrent, "impossible because no concurrent allocation"); |
roland@6377 | 1283 | return NULL; |
roland@6377 | 1284 | } else if (data->method() == m) { |
roland@6377 | 1285 | return data; |
roland@6377 | 1286 | } |
roland@6377 | 1287 | } |
roland@6377 | 1288 | } |
roland@6377 | 1289 | break; |
roland@6377 | 1290 | default: |
roland@6377 | 1291 | fatal(err_msg("unexpected tag %d", dp->tag())); |
duke@435 | 1292 | } |
duke@435 | 1293 | } |
roland@6377 | 1294 | return NULL; |
roland@6377 | 1295 | } |
roland@6377 | 1296 | |
roland@6377 | 1297 | |
roland@6377 | 1298 | // Translate a bci to its corresponding extra data, or NULL. |
roland@6377 | 1299 | ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) { |
roland@6377 | 1300 | // This code assumes an entry for a SpeculativeTrapData is 2 cells |
roland@6377 | 1301 | assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) == |
roland@6377 | 1302 | DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()), |
roland@6377 | 1303 | "code needs to be adjusted"); |
roland@6377 | 1304 | |
roland@6377 | 1305 | DataLayout* dp = extra_data_base(); |
roland@6377 | 1306 | DataLayout* end = extra_data_limit(); |
roland@6377 | 1307 | |
roland@6377 | 1308 | // Allocation in the extra data space has to be atomic because not |
roland@6377 | 1309 | // all entries have the same size and non atomic concurrent |
roland@6377 | 1310 | // allocation would result in a corrupted extra data space. |
roland@6382 | 1311 | ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true); |
roland@6382 | 1312 | if (result != NULL) { |
roland@6382 | 1313 | return result; |
roland@6382 | 1314 | } |
roland@6382 | 1315 | |
roland@6382 | 1316 | if (create_if_missing && dp < end) { |
roland@6382 | 1317 | MutexLocker ml(&_extra_data_lock); |
roland@6382 | 1318 | // Check again now that we have the lock. Another thread may |
roland@6382 | 1319 | // have added extra data entries. |
roland@6382 | 1320 | ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false); |
roland@6382 | 1321 | if (result != NULL || dp >= end) { |
roland@6377 | 1322 | return result; |
roland@6377 | 1323 | } |
roland@6377 | 1324 | |
roland@6382 | 1325 | assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free"); |
roland@6382 | 1326 | assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info"); |
roland@6382 | 1327 | u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag; |
roland@6382 | 1328 | // SpeculativeTrapData is 2 slots. Make sure we have room. |
roland@6382 | 1329 | if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) { |
roland@6382 | 1330 | return NULL; |
roland@6377 | 1331 | } |
roland@6382 | 1332 | DataLayout temp; |
roland@6382 | 1333 | temp.initialize(tag, bci, 0); |
roland@6382 | 1334 | |
roland@6382 | 1335 | dp->set_header(temp.header()); |
roland@6382 | 1336 | assert(dp->tag() == tag, "sane"); |
roland@6382 | 1337 | assert(dp->bci() == bci, "no concurrent allocation"); |
roland@6382 | 1338 | if (tag == DataLayout::bit_data_tag) { |
roland@6382 | 1339 | return new BitData(dp); |
roland@6382 | 1340 | } else { |
roland@6382 | 1341 | SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
roland@6382 | 1342 | data->set_method(m); |
roland@6382 | 1343 | return data; |
roland@6382 | 1344 | } |
duke@435 | 1345 | } |
duke@435 | 1346 | return NULL; |
duke@435 | 1347 | } |
duke@435 | 1348 | |
coleenp@4037 | 1349 | ArgInfoData *MethodData::arg_info() { |
kvn@480 | 1350 | DataLayout* dp = extra_data_base(); |
kvn@480 | 1351 | DataLayout* end = extra_data_limit(); |
kvn@480 | 1352 | for (; dp < end; dp = next_extra(dp)) { |
kvn@480 | 1353 | if (dp->tag() == DataLayout::arg_info_data_tag) |
kvn@480 | 1354 | return new ArgInfoData(dp); |
kvn@480 | 1355 | } |
kvn@480 | 1356 | return NULL; |
kvn@480 | 1357 | } |
kvn@480 | 1358 | |
coleenp@4037 | 1359 | // Printing |
coleenp@4037 | 1360 | |
duke@435 | 1361 | #ifndef PRODUCT |
coleenp@4037 | 1362 | |
coleenp@4037 | 1363 | void MethodData::print_on(outputStream* st) const { |
coleenp@4037 | 1364 | assert(is_methodData(), "should be method data"); |
coleenp@4037 | 1365 | st->print("method data for "); |
coleenp@4037 | 1366 | method()->print_value_on(st); |
coleenp@4037 | 1367 | st->cr(); |
coleenp@4037 | 1368 | print_data_on(st); |
coleenp@4037 | 1369 | } |
coleenp@4037 | 1370 | |
coleenp@4037 | 1371 | #endif //PRODUCT |
coleenp@4037 | 1372 | |
coleenp@4037 | 1373 | void MethodData::print_value_on(outputStream* st) const { |
coleenp@4037 | 1374 | assert(is_methodData(), "should be method data"); |
coleenp@4037 | 1375 | st->print("method data for "); |
coleenp@4037 | 1376 | method()->print_value_on(st); |
coleenp@4037 | 1377 | } |
coleenp@4037 | 1378 | |
coleenp@4037 | 1379 | #ifndef PRODUCT |
coleenp@4037 | 1380 | void MethodData::print_data_on(outputStream* st) const { |
duke@435 | 1381 | ResourceMark rm; |
duke@435 | 1382 | ProfileData* data = first_data(); |
roland@5987 | 1383 | if (_parameters_type_data_di != -1) { |
roland@5987 | 1384 | parameters_type_data()->print_data_on(st); |
roland@5987 | 1385 | } |
duke@435 | 1386 | for ( ; is_valid(data); data = next_data(data)) { |
duke@435 | 1387 | st->print("%d", dp_to_di(data->dp())); |
duke@435 | 1388 | st->fill_to(6); |
roland@6377 | 1389 | data->print_data_on(st, this); |
duke@435 | 1390 | } |
kvn@480 | 1391 | st->print_cr("--- Extra data:"); |
duke@435 | 1392 | DataLayout* dp = extra_data_base(); |
duke@435 | 1393 | DataLayout* end = extra_data_limit(); |
roland@6377 | 1394 | for (;; dp = next_extra(dp)) { |
roland@6377 | 1395 | assert(dp < end, "moved past end of extra data"); |
duke@435 | 1396 | // No need for "OrderAccess::load_acquire" ops, |
duke@435 | 1397 | // since the data structure is monotonic. |
roland@6377 | 1398 | switch(dp->tag()) { |
roland@6377 | 1399 | case DataLayout::no_tag: |
roland@6377 | 1400 | continue; |
roland@6377 | 1401 | case DataLayout::bit_data_tag: |
kvn@480 | 1402 | data = new BitData(dp); |
roland@6377 | 1403 | break; |
roland@6377 | 1404 | case DataLayout::speculative_trap_data_tag: |
roland@6377 | 1405 | data = new SpeculativeTrapData(dp); |
roland@6377 | 1406 | break; |
roland@6377 | 1407 | case DataLayout::arg_info_data_tag: |
kvn@480 | 1408 | data = new ArgInfoData(dp); |
kvn@480 | 1409 | dp = end; // ArgInfoData is at the end of extra data section. |
roland@6377 | 1410 | break; |
roland@6377 | 1411 | default: |
roland@6377 | 1412 | fatal(err_msg("unexpected tag %d", dp->tag())); |
kvn@480 | 1413 | } |
duke@435 | 1414 | st->print("%d", dp_to_di(data->dp())); |
duke@435 | 1415 | st->fill_to(6); |
duke@435 | 1416 | data->print_data_on(st); |
roland@6377 | 1417 | if (dp >= end) return; |
duke@435 | 1418 | } |
duke@435 | 1419 | } |
duke@435 | 1420 | #endif |
duke@435 | 1421 | |
acorn@4497 | 1422 | #if INCLUDE_SERVICES |
acorn@4497 | 1423 | // Size Statistics |
acorn@4497 | 1424 | void MethodData::collect_statistics(KlassSizeStats *sz) const { |
acorn@4497 | 1425 | int n = sz->count(this); |
acorn@4497 | 1426 | sz->_method_data_bytes += n; |
acorn@4497 | 1427 | sz->_method_all_bytes += n; |
acorn@4497 | 1428 | sz->_rw_bytes += n; |
acorn@4497 | 1429 | } |
acorn@4497 | 1430 | #endif // INCLUDE_SERVICES |
coleenp@4037 | 1431 | |
coleenp@4037 | 1432 | // Verification |
coleenp@4037 | 1433 | |
coleenp@4037 | 1434 | void MethodData::verify_on(outputStream* st) { |
coleenp@4037 | 1435 | guarantee(is_methodData(), "object must be method data"); |
coleenp@4037 | 1436 | // guarantee(m->is_perm(), "should be in permspace"); |
coleenp@4037 | 1437 | this->verify_data_on(st); |
coleenp@4037 | 1438 | } |
coleenp@4037 | 1439 | |
coleenp@4037 | 1440 | void MethodData::verify_data_on(outputStream* st) { |
duke@435 | 1441 | NEEDS_CLEANUP; |
duke@435 | 1442 | // not yet implemented. |
duke@435 | 1443 | } |
roland@5914 | 1444 | |
roland@5914 | 1445 | bool MethodData::profile_jsr292(methodHandle m, int bci) { |
roland@5914 | 1446 | if (m->is_compiled_lambda_form()) { |
roland@5914 | 1447 | return true; |
roland@5914 | 1448 | } |
roland@5914 | 1449 | |
roland@5914 | 1450 | Bytecode_invoke inv(m , bci); |
roland@5914 | 1451 | return inv.is_invokedynamic() || inv.is_invokehandle(); |
roland@5914 | 1452 | } |
roland@5914 | 1453 | |
roland@5914 | 1454 | int MethodData::profile_arguments_flag() { |
roland@5921 | 1455 | return TypeProfileLevel % 10; |
roland@5914 | 1456 | } |
roland@5914 | 1457 | |
roland@5914 | 1458 | bool MethodData::profile_arguments() { |
roland@5914 | 1459 | return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all; |
roland@5914 | 1460 | } |
roland@5914 | 1461 | |
roland@5914 | 1462 | bool MethodData::profile_arguments_jsr292_only() { |
roland@5914 | 1463 | return profile_arguments_flag() == type_profile_jsr292; |
roland@5914 | 1464 | } |
roland@5914 | 1465 | |
roland@5914 | 1466 | bool MethodData::profile_all_arguments() { |
roland@5914 | 1467 | return profile_arguments_flag() == type_profile_all; |
roland@5914 | 1468 | } |
roland@5914 | 1469 | |
roland@5914 | 1470 | bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) { |
roland@5914 | 1471 | if (!profile_arguments()) { |
roland@5914 | 1472 | return false; |
roland@5914 | 1473 | } |
roland@5914 | 1474 | |
roland@5914 | 1475 | if (profile_all_arguments()) { |
roland@5914 | 1476 | return true; |
roland@5914 | 1477 | } |
roland@5914 | 1478 | |
roland@5914 | 1479 | assert(profile_arguments_jsr292_only(), "inconsistent"); |
roland@5914 | 1480 | return profile_jsr292(m, bci); |
roland@5914 | 1481 | } |
roland@5914 | 1482 | |
roland@5921 | 1483 | int MethodData::profile_return_flag() { |
roland@5987 | 1484 | return (TypeProfileLevel % 100) / 10; |
roland@5921 | 1485 | } |
roland@5921 | 1486 | |
roland@5921 | 1487 | bool MethodData::profile_return() { |
roland@5921 | 1488 | return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all; |
roland@5921 | 1489 | } |
roland@5921 | 1490 | |
roland@5921 | 1491 | bool MethodData::profile_return_jsr292_only() { |
roland@5921 | 1492 | return profile_return_flag() == type_profile_jsr292; |
roland@5921 | 1493 | } |
roland@5921 | 1494 | |
roland@5921 | 1495 | bool MethodData::profile_all_return() { |
roland@5921 | 1496 | return profile_return_flag() == type_profile_all; |
roland@5921 | 1497 | } |
roland@5921 | 1498 | |
roland@5921 | 1499 | bool MethodData::profile_return_for_invoke(methodHandle m, int bci) { |
roland@5921 | 1500 | if (!profile_return()) { |
roland@5921 | 1501 | return false; |
roland@5921 | 1502 | } |
roland@5921 | 1503 | |
roland@5921 | 1504 | if (profile_all_return()) { |
roland@5921 | 1505 | return true; |
roland@5921 | 1506 | } |
roland@5921 | 1507 | |
roland@5921 | 1508 | assert(profile_return_jsr292_only(), "inconsistent"); |
roland@5921 | 1509 | return profile_jsr292(m, bci); |
roland@5921 | 1510 | } |
roland@5987 | 1511 | |
roland@5987 | 1512 | int MethodData::profile_parameters_flag() { |
roland@5987 | 1513 | return TypeProfileLevel / 100; |
roland@5987 | 1514 | } |
roland@5987 | 1515 | |
roland@5987 | 1516 | bool MethodData::profile_parameters() { |
roland@5987 | 1517 | return profile_parameters_flag() > no_type_profile && profile_parameters_flag() <= type_profile_all; |
roland@5987 | 1518 | } |
roland@5987 | 1519 | |
roland@5987 | 1520 | bool MethodData::profile_parameters_jsr292_only() { |
roland@5987 | 1521 | return profile_parameters_flag() == type_profile_jsr292; |
roland@5987 | 1522 | } |
roland@5987 | 1523 | |
roland@5987 | 1524 | bool MethodData::profile_all_parameters() { |
roland@5987 | 1525 | return profile_parameters_flag() == type_profile_all; |
roland@5987 | 1526 | } |
roland@5987 | 1527 | |
roland@5987 | 1528 | bool MethodData::profile_parameters_for_method(methodHandle m) { |
roland@5987 | 1529 | if (!profile_parameters()) { |
roland@5987 | 1530 | return false; |
roland@5987 | 1531 | } |
roland@5987 | 1532 | |
roland@5987 | 1533 | if (profile_all_parameters()) { |
roland@5987 | 1534 | return true; |
roland@5987 | 1535 | } |
roland@5987 | 1536 | |
roland@5987 | 1537 | assert(profile_parameters_jsr292_only(), "inconsistent"); |
roland@5987 | 1538 | return m->is_compiled_lambda_form(); |
roland@5987 | 1539 | } |
roland@6377 | 1540 | |
roland@6377 | 1541 | void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) { |
roland@6377 | 1542 | if (shift == 0) { |
roland@6377 | 1543 | return; |
roland@6377 | 1544 | } |
roland@6377 | 1545 | if (!reset) { |
roland@6377 | 1546 | // Move all cells of trap entry at dp left by "shift" cells |
roland@6377 | 1547 | intptr_t* start = (intptr_t*)dp; |
roland@6377 | 1548 | intptr_t* end = (intptr_t*)next_extra(dp); |
roland@6377 | 1549 | for (intptr_t* ptr = start; ptr < end; ptr++) { |
roland@6377 | 1550 | *(ptr-shift) = *ptr; |
roland@6377 | 1551 | } |
roland@6377 | 1552 | } else { |
roland@6377 | 1553 | // Reset "shift" cells stopping at dp |
roland@6377 | 1554 | intptr_t* start = ((intptr_t*)dp) - shift; |
roland@6377 | 1555 | intptr_t* end = (intptr_t*)dp; |
roland@6377 | 1556 | for (intptr_t* ptr = start; ptr < end; ptr++) { |
roland@6377 | 1557 | *ptr = 0; |
roland@6377 | 1558 | } |
roland@6377 | 1559 | } |
roland@6377 | 1560 | } |
roland@6377 | 1561 | |
roland@9183 | 1562 | class CleanExtraDataClosure : public StackObj { |
roland@9183 | 1563 | public: |
roland@9183 | 1564 | virtual bool is_live(Method* m) = 0; |
roland@9183 | 1565 | }; |
roland@9183 | 1566 | |
roland@9183 | 1567 | // Check for entries that reference an unloaded method |
roland@9183 | 1568 | class CleanExtraDataKlassClosure : public CleanExtraDataClosure { |
roland@9183 | 1569 | private: |
roland@9183 | 1570 | BoolObjectClosure* _is_alive; |
roland@9183 | 1571 | public: |
roland@9183 | 1572 | CleanExtraDataKlassClosure(BoolObjectClosure* is_alive) : _is_alive(is_alive) {} |
roland@9183 | 1573 | bool is_live(Method* m) { |
roland@9183 | 1574 | return m->method_holder()->is_loader_alive(_is_alive); |
roland@9183 | 1575 | } |
roland@9183 | 1576 | }; |
roland@9183 | 1577 | |
roland@9183 | 1578 | // Check for entries that reference a redefined method |
roland@9183 | 1579 | class CleanExtraDataMethodClosure : public CleanExtraDataClosure { |
roland@9183 | 1580 | public: |
roland@9183 | 1581 | CleanExtraDataMethodClosure() {} |
roland@9183 | 1582 | bool is_live(Method* m) { |
roland@9183 | 1583 | return m->on_stack(); |
roland@9183 | 1584 | } |
roland@9183 | 1585 | }; |
roland@9183 | 1586 | |
roland@9183 | 1587 | |
roland@9183 | 1588 | // Remove SpeculativeTrapData entries that reference an unloaded or |
roland@9183 | 1589 | // redefined method |
roland@9183 | 1590 | void MethodData::clean_extra_data(CleanExtraDataClosure* cl) { |
roland@6377 | 1591 | DataLayout* dp = extra_data_base(); |
roland@6377 | 1592 | DataLayout* end = extra_data_limit(); |
roland@6377 | 1593 | |
roland@6377 | 1594 | int shift = 0; |
roland@6377 | 1595 | for (; dp < end; dp = next_extra(dp)) { |
roland@6377 | 1596 | switch(dp->tag()) { |
roland@6377 | 1597 | case DataLayout::speculative_trap_data_tag: { |
roland@6377 | 1598 | SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
roland@6377 | 1599 | Method* m = data->method(); |
roland@6377 | 1600 | assert(m != NULL, "should have a method"); |
roland@9183 | 1601 | if (!cl->is_live(m)) { |
roland@6377 | 1602 | // "shift" accumulates the number of cells for dead |
roland@6377 | 1603 | // SpeculativeTrapData entries that have been seen so |
roland@6377 | 1604 | // far. Following entries must be shifted left by that many |
roland@6377 | 1605 | // cells to remove the dead SpeculativeTrapData entries. |
roland@6377 | 1606 | shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp); |
roland@6377 | 1607 | } else { |
roland@6377 | 1608 | // Shift this entry left if it follows dead |
roland@6377 | 1609 | // SpeculativeTrapData entries |
roland@6377 | 1610 | clean_extra_data_helper(dp, shift); |
roland@6377 | 1611 | } |
roland@6377 | 1612 | break; |
roland@6377 | 1613 | } |
roland@6377 | 1614 | case DataLayout::bit_data_tag: |
roland@6377 | 1615 | // Shift this entry left if it follows dead SpeculativeTrapData |
roland@6377 | 1616 | // entries |
roland@6377 | 1617 | clean_extra_data_helper(dp, shift); |
roland@6377 | 1618 | continue; |
roland@6377 | 1619 | case DataLayout::no_tag: |
roland@6377 | 1620 | case DataLayout::arg_info_data_tag: |
roland@6377 | 1621 | // We are at end of the live trap entries. The previous "shift" |
roland@6377 | 1622 | // cells contain entries that are either dead or were shifted |
roland@6377 | 1623 | // left. They need to be reset to no_tag |
roland@6377 | 1624 | clean_extra_data_helper(dp, shift, true); |
roland@6377 | 1625 | return; |
roland@6377 | 1626 | default: |
roland@6377 | 1627 | fatal(err_msg("unexpected tag %d", dp->tag())); |
roland@6377 | 1628 | } |
roland@6377 | 1629 | } |
roland@6377 | 1630 | } |
roland@6377 | 1631 | |
roland@9183 | 1632 | // Verify there's no unloaded or redefined method referenced by a |
roland@6377 | 1633 | // SpeculativeTrapData entry |
roland@9183 | 1634 | void MethodData::verify_extra_data_clean(CleanExtraDataClosure* cl) { |
roland@6377 | 1635 | #ifdef ASSERT |
roland@6377 | 1636 | DataLayout* dp = extra_data_base(); |
roland@6377 | 1637 | DataLayout* end = extra_data_limit(); |
roland@6377 | 1638 | |
roland@6377 | 1639 | for (; dp < end; dp = next_extra(dp)) { |
roland@6377 | 1640 | switch(dp->tag()) { |
roland@6377 | 1641 | case DataLayout::speculative_trap_data_tag: { |
roland@6377 | 1642 | SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
roland@6377 | 1643 | Method* m = data->method(); |
roland@9183 | 1644 | assert(m != NULL && cl->is_live(m), "Method should exist"); |
roland@6377 | 1645 | break; |
roland@6377 | 1646 | } |
roland@6377 | 1647 | case DataLayout::bit_data_tag: |
roland@6377 | 1648 | continue; |
roland@6377 | 1649 | case DataLayout::no_tag: |
roland@6377 | 1650 | case DataLayout::arg_info_data_tag: |
roland@6377 | 1651 | return; |
roland@6377 | 1652 | default: |
roland@6377 | 1653 | fatal(err_msg("unexpected tag %d", dp->tag())); |
roland@6377 | 1654 | } |
roland@6377 | 1655 | } |
roland@6377 | 1656 | #endif |
roland@6377 | 1657 | } |
roland@6377 | 1658 | |
roland@6377 | 1659 | void MethodData::clean_method_data(BoolObjectClosure* is_alive) { |
roland@6377 | 1660 | for (ProfileData* data = first_data(); |
roland@6377 | 1661 | is_valid(data); |
roland@6377 | 1662 | data = next_data(data)) { |
roland@6377 | 1663 | data->clean_weak_klass_links(is_alive); |
roland@6377 | 1664 | } |
roland@6377 | 1665 | ParametersTypeData* parameters = parameters_type_data(); |
roland@6377 | 1666 | if (parameters != NULL) { |
roland@6377 | 1667 | parameters->clean_weak_klass_links(is_alive); |
roland@6377 | 1668 | } |
roland@6377 | 1669 | |
roland@9183 | 1670 | CleanExtraDataKlassClosure cl(is_alive); |
roland@9183 | 1671 | clean_extra_data(&cl); |
roland@9183 | 1672 | verify_extra_data_clean(&cl); |
roland@6377 | 1673 | } |
roland@9183 | 1674 | |
roland@9183 | 1675 | void MethodData::clean_weak_method_links() { |
roland@9183 | 1676 | for (ProfileData* data = first_data(); |
roland@9183 | 1677 | is_valid(data); |
roland@9183 | 1678 | data = next_data(data)) { |
roland@9183 | 1679 | data->clean_weak_method_links(); |
roland@9183 | 1680 | } |
roland@9183 | 1681 | |
roland@9183 | 1682 | CleanExtraDataMethodClosure cl; |
roland@9183 | 1683 | clean_extra_data(&cl); |
roland@9183 | 1684 | verify_extra_data_clean(&cl); |
roland@9183 | 1685 | } |