src/share/vm/oops/methodData.cpp

Tue, 05 Nov 2013 17:38:04 -0800

author
kvn
date
Tue, 05 Nov 2013 17:38:04 -0800
changeset 6472
2b8e28fdf503
parent 6470
abe03600372a
parent 5987
5ccbab1c69f3
child 6485
da862781b584
permissions
-rw-r--r--

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

mercurial