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