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