src/share/vm/oops/methodDataOop.cpp

Wed, 05 Dec 2007 09:00:00 -0800

author
dcubed
date
Wed, 05 Dec 2007 09:00:00 -0800
changeset 451
f8236e79048a
parent 435
a61af66fc99e
child 480
48a3fa21394b
permissions
-rw-r--r--

6664627: Merge changes made only in hotspot 11 forward to jdk 7
Reviewed-by: jcoomes

duke@435 1 /*
duke@435 2 * Copyright 2000-2007 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_methodDataOop.cpp.incl"
duke@435 27
duke@435 28 // ==================================================================
duke@435 29 // DataLayout
duke@435 30 //
duke@435 31 // Overlay for generic profiling data.
duke@435 32
duke@435 33 // Some types of data layouts need a length field.
duke@435 34 bool DataLayout::needs_array_len(u1 tag) {
duke@435 35 return (tag == multi_branch_data_tag);
duke@435 36 }
duke@435 37
duke@435 38 // Perform generic initialization of the data. More specific
duke@435 39 // initialization occurs in overrides of ProfileData::post_initialize.
duke@435 40 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
duke@435 41 _header._bits = (intptr_t)0;
duke@435 42 _header._struct._tag = tag;
duke@435 43 _header._struct._bci = bci;
duke@435 44 for (int i = 0; i < cell_count; i++) {
duke@435 45 set_cell_at(i, (intptr_t)0);
duke@435 46 }
duke@435 47 if (needs_array_len(tag)) {
duke@435 48 set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
duke@435 49 }
duke@435 50 }
duke@435 51
duke@435 52 // ==================================================================
duke@435 53 // ProfileData
duke@435 54 //
duke@435 55 // A ProfileData object is created to refer to a section of profiling
duke@435 56 // data in a structured way.
duke@435 57
duke@435 58 // Constructor for invalid ProfileData.
duke@435 59 ProfileData::ProfileData() {
duke@435 60 _data = NULL;
duke@435 61 }
duke@435 62
duke@435 63 #ifndef PRODUCT
duke@435 64 void ProfileData::print_shared(outputStream* st, const char* name) {
duke@435 65 st->print("bci: %d", bci());
duke@435 66 st->fill_to(tab_width_one);
duke@435 67 st->print("%s", name);
duke@435 68 tab(st);
duke@435 69 int trap = trap_state();
duke@435 70 if (trap != 0) {
duke@435 71 char buf[100];
duke@435 72 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
duke@435 73 }
duke@435 74 int flags = data()->flags();
duke@435 75 if (flags != 0)
duke@435 76 st->print("flags(%d) ", flags);
duke@435 77 }
duke@435 78
duke@435 79 void ProfileData::tab(outputStream* st) {
duke@435 80 st->fill_to(tab_width_two);
duke@435 81 }
duke@435 82 #endif // !PRODUCT
duke@435 83
duke@435 84 // ==================================================================
duke@435 85 // BitData
duke@435 86 //
duke@435 87 // A BitData corresponds to a one-bit flag. This is used to indicate
duke@435 88 // whether a checkcast bytecode has seen a null value.
duke@435 89
duke@435 90
duke@435 91 #ifndef PRODUCT
duke@435 92 void BitData::print_data_on(outputStream* st) {
duke@435 93 print_shared(st, "BitData");
duke@435 94 }
duke@435 95 #endif // !PRODUCT
duke@435 96
duke@435 97 // ==================================================================
duke@435 98 // CounterData
duke@435 99 //
duke@435 100 // A CounterData corresponds to a simple counter.
duke@435 101
duke@435 102 #ifndef PRODUCT
duke@435 103 void CounterData::print_data_on(outputStream* st) {
duke@435 104 print_shared(st, "CounterData");
duke@435 105 st->print_cr("count(%u)", count());
duke@435 106 }
duke@435 107 #endif // !PRODUCT
duke@435 108
duke@435 109 // ==================================================================
duke@435 110 // JumpData
duke@435 111 //
duke@435 112 // A JumpData is used to access profiling information for a direct
duke@435 113 // branch. It is a counter, used for counting the number of branches,
duke@435 114 // plus a data displacement, used for realigning the data pointer to
duke@435 115 // the corresponding target bci.
duke@435 116
duke@435 117 void JumpData::post_initialize(BytecodeStream* stream, methodDataOop mdo) {
duke@435 118 assert(stream->bci() == bci(), "wrong pos");
duke@435 119 int target;
duke@435 120 Bytecodes::Code c = stream->code();
duke@435 121 if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
duke@435 122 target = stream->dest_w();
duke@435 123 } else {
duke@435 124 target = stream->dest();
duke@435 125 }
duke@435 126 int my_di = mdo->dp_to_di(dp());
duke@435 127 int target_di = mdo->bci_to_di(target);
duke@435 128 int offset = target_di - my_di;
duke@435 129 set_displacement(offset);
duke@435 130 }
duke@435 131
duke@435 132 #ifndef PRODUCT
duke@435 133 void JumpData::print_data_on(outputStream* st) {
duke@435 134 print_shared(st, "JumpData");
duke@435 135 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
duke@435 136 }
duke@435 137 #endif // !PRODUCT
duke@435 138
duke@435 139 // ==================================================================
duke@435 140 // ReceiverTypeData
duke@435 141 //
duke@435 142 // A ReceiverTypeData is used to access profiling information about a
duke@435 143 // dynamic type check. It consists of a counter which counts the total times
duke@435 144 // that the check is reached, and a series of (klassOop, count) pairs
duke@435 145 // which are used to store a type profile for the receiver of the check.
duke@435 146
duke@435 147 void ReceiverTypeData::follow_contents() {
duke@435 148 for (uint row = 0; row < row_limit(); row++) {
duke@435 149 if (receiver(row) != NULL) {
duke@435 150 MarkSweep::mark_and_push(adr_receiver(row));
duke@435 151 }
duke@435 152 }
duke@435 153 }
duke@435 154
duke@435 155 #ifndef SERIALGC
duke@435 156 void ReceiverTypeData::follow_contents(ParCompactionManager* cm) {
duke@435 157 for (uint row = 0; row < row_limit(); row++) {
duke@435 158 if (receiver(row) != NULL) {
duke@435 159 PSParallelCompact::mark_and_push(cm, adr_receiver(row));
duke@435 160 }
duke@435 161 }
duke@435 162 }
duke@435 163 #endif // SERIALGC
duke@435 164
duke@435 165 void ReceiverTypeData::oop_iterate(OopClosure* blk) {
duke@435 166 for (uint row = 0; row < row_limit(); row++) {
duke@435 167 if (receiver(row) != NULL) {
duke@435 168 blk->do_oop(adr_receiver(row));
duke@435 169 }
duke@435 170 }
duke@435 171 }
duke@435 172
duke@435 173 void ReceiverTypeData::oop_iterate_m(OopClosure* blk, MemRegion mr) {
duke@435 174 for (uint row = 0; row < row_limit(); row++) {
duke@435 175 if (receiver(row) != NULL) {
duke@435 176 oop* adr = adr_receiver(row);
duke@435 177 if (mr.contains(adr)) {
duke@435 178 blk->do_oop(adr);
duke@435 179 }
duke@435 180 }
duke@435 181 }
duke@435 182 }
duke@435 183
duke@435 184 void ReceiverTypeData::adjust_pointers() {
duke@435 185 for (uint row = 0; row < row_limit(); row++) {
duke@435 186 if (receiver(row) != NULL) {
duke@435 187 MarkSweep::adjust_pointer(adr_receiver(row));
duke@435 188 }
duke@435 189 }
duke@435 190 }
duke@435 191
duke@435 192 #ifndef SERIALGC
duke@435 193 void ReceiverTypeData::update_pointers() {
duke@435 194 for (uint row = 0; row < row_limit(); row++) {
duke@435 195 if (receiver_unchecked(row) != NULL) {
duke@435 196 PSParallelCompact::adjust_pointer(adr_receiver(row));
duke@435 197 }
duke@435 198 }
duke@435 199 }
duke@435 200
duke@435 201 void ReceiverTypeData::update_pointers(HeapWord* beg_addr, HeapWord* end_addr) {
duke@435 202 // The loop bounds could be computed based on beg_addr/end_addr and the
duke@435 203 // boundary test hoisted outside the loop (see klassVTable for an example);
duke@435 204 // however, row_limit() is small enough (2) to make that less efficient.
duke@435 205 for (uint row = 0; row < row_limit(); row++) {
duke@435 206 if (receiver_unchecked(row) != NULL) {
duke@435 207 PSParallelCompact::adjust_pointer(adr_receiver(row), beg_addr, end_addr);
duke@435 208 }
duke@435 209 }
duke@435 210 }
duke@435 211 #endif // SERIALGC
duke@435 212
duke@435 213 #ifndef PRODUCT
duke@435 214 void ReceiverTypeData::print_receiver_data_on(outputStream* st) {
duke@435 215 uint row;
duke@435 216 int entries = 0;
duke@435 217 for (row = 0; row < row_limit(); row++) {
duke@435 218 if (receiver(row) != NULL) entries++;
duke@435 219 }
duke@435 220 st->print_cr("count(%u) entries(%u)", count(), entries);
duke@435 221 for (row = 0; row < row_limit(); row++) {
duke@435 222 if (receiver(row) != NULL) {
duke@435 223 tab(st);
duke@435 224 receiver(row)->print_value_on(st);
duke@435 225 st->print_cr("(%u)", receiver_count(row));
duke@435 226 }
duke@435 227 }
duke@435 228 }
duke@435 229 void ReceiverTypeData::print_data_on(outputStream* st) {
duke@435 230 print_shared(st, "ReceiverTypeData");
duke@435 231 print_receiver_data_on(st);
duke@435 232 }
duke@435 233 void VirtualCallData::print_data_on(outputStream* st) {
duke@435 234 print_shared(st, "VirtualCallData");
duke@435 235 print_receiver_data_on(st);
duke@435 236 }
duke@435 237 #endif // !PRODUCT
duke@435 238
duke@435 239 // ==================================================================
duke@435 240 // RetData
duke@435 241 //
duke@435 242 // A RetData is used to access profiling information for a ret bytecode.
duke@435 243 // It is composed of a count of the number of times that the ret has
duke@435 244 // been executed, followed by a series of triples of the form
duke@435 245 // (bci, count, di) which count the number of times that some bci was the
duke@435 246 // target of the ret and cache a corresponding displacement.
duke@435 247
duke@435 248 void RetData::post_initialize(BytecodeStream* stream, methodDataOop mdo) {
duke@435 249 for (uint row = 0; row < row_limit(); row++) {
duke@435 250 set_bci_displacement(row, -1);
duke@435 251 set_bci(row, no_bci);
duke@435 252 }
duke@435 253 // release so other threads see a consistent state. bci is used as
duke@435 254 // a valid flag for bci_displacement.
duke@435 255 OrderAccess::release();
duke@435 256 }
duke@435 257
duke@435 258 // This routine needs to atomically update the RetData structure, so the
duke@435 259 // caller needs to hold the RetData_lock before it gets here. Since taking
duke@435 260 // the lock can block (and allow GC) and since RetData is a ProfileData is a
duke@435 261 // wrapper around a derived oop, taking the lock in _this_ method will
duke@435 262 // basically cause the 'this' pointer's _data field to contain junk after the
duke@435 263 // lock. We require the caller to take the lock before making the ProfileData
duke@435 264 // structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret
duke@435 265 address RetData::fixup_ret(int return_bci, methodDataHandle h_mdo) {
duke@435 266 // First find the mdp which corresponds to the return bci.
duke@435 267 address mdp = h_mdo->bci_to_dp(return_bci);
duke@435 268
duke@435 269 // Now check to see if any of the cache slots are open.
duke@435 270 for (uint row = 0; row < row_limit(); row++) {
duke@435 271 if (bci(row) == no_bci) {
duke@435 272 set_bci_displacement(row, mdp - dp());
duke@435 273 set_bci_count(row, DataLayout::counter_increment);
duke@435 274 // Barrier to ensure displacement is written before the bci; allows
duke@435 275 // the interpreter to read displacement without fear of race condition.
duke@435 276 release_set_bci(row, return_bci);
duke@435 277 break;
duke@435 278 }
duke@435 279 }
duke@435 280 return mdp;
duke@435 281 }
duke@435 282
duke@435 283
duke@435 284 #ifndef PRODUCT
duke@435 285 void RetData::print_data_on(outputStream* st) {
duke@435 286 print_shared(st, "RetData");
duke@435 287 uint row;
duke@435 288 int entries = 0;
duke@435 289 for (row = 0; row < row_limit(); row++) {
duke@435 290 if (bci(row) != no_bci) entries++;
duke@435 291 }
duke@435 292 st->print_cr("count(%u) entries(%u)", count(), entries);
duke@435 293 for (row = 0; row < row_limit(); row++) {
duke@435 294 if (bci(row) != no_bci) {
duke@435 295 tab(st);
duke@435 296 st->print_cr("bci(%d: count(%u) displacement(%d))",
duke@435 297 bci(row), bci_count(row), bci_displacement(row));
duke@435 298 }
duke@435 299 }
duke@435 300 }
duke@435 301 #endif // !PRODUCT
duke@435 302
duke@435 303 // ==================================================================
duke@435 304 // BranchData
duke@435 305 //
duke@435 306 // A BranchData is used to access profiling data for a two-way branch.
duke@435 307 // It consists of taken and not_taken counts as well as a data displacement
duke@435 308 // for the taken case.
duke@435 309
duke@435 310 void BranchData::post_initialize(BytecodeStream* stream, methodDataOop mdo) {
duke@435 311 assert(stream->bci() == bci(), "wrong pos");
duke@435 312 int target = stream->dest();
duke@435 313 int my_di = mdo->dp_to_di(dp());
duke@435 314 int target_di = mdo->bci_to_di(target);
duke@435 315 int offset = target_di - my_di;
duke@435 316 set_displacement(offset);
duke@435 317 }
duke@435 318
duke@435 319 #ifndef PRODUCT
duke@435 320 void BranchData::print_data_on(outputStream* st) {
duke@435 321 print_shared(st, "BranchData");
duke@435 322 st->print_cr("taken(%u) displacement(%d)",
duke@435 323 taken(), displacement());
duke@435 324 tab(st);
duke@435 325 st->print_cr("not taken(%u)", not_taken());
duke@435 326 }
duke@435 327 #endif
duke@435 328
duke@435 329 // ==================================================================
duke@435 330 // MultiBranchData
duke@435 331 //
duke@435 332 // A MultiBranchData is used to access profiling information for
duke@435 333 // a multi-way branch (*switch bytecodes). It consists of a series
duke@435 334 // of (count, displacement) pairs, which count the number of times each
duke@435 335 // case was taken and specify the data displacment for each branch target.
duke@435 336
duke@435 337 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
duke@435 338 int cell_count = 0;
duke@435 339 if (stream->code() == Bytecodes::_tableswitch) {
duke@435 340 Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp());
duke@435 341 cell_count = 1 + per_case_cell_count * (1 + sw->length()); // 1 for default
duke@435 342 } else {
duke@435 343 Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp());
duke@435 344 cell_count = 1 + per_case_cell_count * (sw->number_of_pairs() + 1); // 1 for default
duke@435 345 }
duke@435 346 return cell_count;
duke@435 347 }
duke@435 348
duke@435 349 void MultiBranchData::post_initialize(BytecodeStream* stream,
duke@435 350 methodDataOop mdo) {
duke@435 351 assert(stream->bci() == bci(), "wrong pos");
duke@435 352 int target;
duke@435 353 int my_di;
duke@435 354 int target_di;
duke@435 355 int offset;
duke@435 356 if (stream->code() == Bytecodes::_tableswitch) {
duke@435 357 Bytecode_tableswitch* sw = Bytecode_tableswitch_at(stream->bcp());
duke@435 358 int len = sw->length();
duke@435 359 assert(array_len() == per_case_cell_count * (len + 1), "wrong len");
duke@435 360 for (int count = 0; count < len; count++) {
duke@435 361 target = sw->dest_offset_at(count) + bci();
duke@435 362 my_di = mdo->dp_to_di(dp());
duke@435 363 target_di = mdo->bci_to_di(target);
duke@435 364 offset = target_di - my_di;
duke@435 365 set_displacement_at(count, offset);
duke@435 366 }
duke@435 367 target = sw->default_offset() + bci();
duke@435 368 my_di = mdo->dp_to_di(dp());
duke@435 369 target_di = mdo->bci_to_di(target);
duke@435 370 offset = target_di - my_di;
duke@435 371 set_default_displacement(offset);
duke@435 372
duke@435 373 } else {
duke@435 374 Bytecode_lookupswitch* sw = Bytecode_lookupswitch_at(stream->bcp());
duke@435 375 int npairs = sw->number_of_pairs();
duke@435 376 assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
duke@435 377 for (int count = 0; count < npairs; count++) {
duke@435 378 LookupswitchPair *pair = sw->pair_at(count);
duke@435 379 target = pair->offset() + bci();
duke@435 380 my_di = mdo->dp_to_di(dp());
duke@435 381 target_di = mdo->bci_to_di(target);
duke@435 382 offset = target_di - my_di;
duke@435 383 set_displacement_at(count, offset);
duke@435 384 }
duke@435 385 target = sw->default_offset() + bci();
duke@435 386 my_di = mdo->dp_to_di(dp());
duke@435 387 target_di = mdo->bci_to_di(target);
duke@435 388 offset = target_di - my_di;
duke@435 389 set_default_displacement(offset);
duke@435 390 }
duke@435 391 }
duke@435 392
duke@435 393 #ifndef PRODUCT
duke@435 394 void MultiBranchData::print_data_on(outputStream* st) {
duke@435 395 print_shared(st, "MultiBranchData");
duke@435 396 st->print_cr("default_count(%u) displacement(%d)",
duke@435 397 default_count(), default_displacement());
duke@435 398 int cases = number_of_cases();
duke@435 399 for (int i = 0; i < cases; i++) {
duke@435 400 tab(st);
duke@435 401 st->print_cr("count(%u) displacement(%d)",
duke@435 402 count_at(i), displacement_at(i));
duke@435 403 }
duke@435 404 }
duke@435 405 #endif
duke@435 406
duke@435 407 // ==================================================================
duke@435 408 // methodDataOop
duke@435 409 //
duke@435 410 // A methodDataOop holds information which has been collected about
duke@435 411 // a method.
duke@435 412
duke@435 413 int methodDataOopDesc::bytecode_cell_count(Bytecodes::Code code) {
duke@435 414 switch (code) {
duke@435 415 case Bytecodes::_checkcast:
duke@435 416 case Bytecodes::_instanceof:
duke@435 417 case Bytecodes::_aastore:
duke@435 418 if (TypeProfileCasts) {
duke@435 419 return ReceiverTypeData::static_cell_count();
duke@435 420 } else {
duke@435 421 return BitData::static_cell_count();
duke@435 422 }
duke@435 423 case Bytecodes::_invokespecial:
duke@435 424 case Bytecodes::_invokestatic:
duke@435 425 return CounterData::static_cell_count();
duke@435 426 case Bytecodes::_goto:
duke@435 427 case Bytecodes::_goto_w:
duke@435 428 case Bytecodes::_jsr:
duke@435 429 case Bytecodes::_jsr_w:
duke@435 430 return JumpData::static_cell_count();
duke@435 431 case Bytecodes::_invokevirtual:
duke@435 432 case Bytecodes::_invokeinterface:
duke@435 433 return VirtualCallData::static_cell_count();
duke@435 434 case Bytecodes::_ret:
duke@435 435 return RetData::static_cell_count();
duke@435 436 case Bytecodes::_ifeq:
duke@435 437 case Bytecodes::_ifne:
duke@435 438 case Bytecodes::_iflt:
duke@435 439 case Bytecodes::_ifge:
duke@435 440 case Bytecodes::_ifgt:
duke@435 441 case Bytecodes::_ifle:
duke@435 442 case Bytecodes::_if_icmpeq:
duke@435 443 case Bytecodes::_if_icmpne:
duke@435 444 case Bytecodes::_if_icmplt:
duke@435 445 case Bytecodes::_if_icmpge:
duke@435 446 case Bytecodes::_if_icmpgt:
duke@435 447 case Bytecodes::_if_icmple:
duke@435 448 case Bytecodes::_if_acmpeq:
duke@435 449 case Bytecodes::_if_acmpne:
duke@435 450 case Bytecodes::_ifnull:
duke@435 451 case Bytecodes::_ifnonnull:
duke@435 452 return BranchData::static_cell_count();
duke@435 453 case Bytecodes::_lookupswitch:
duke@435 454 case Bytecodes::_tableswitch:
duke@435 455 return variable_cell_count;
duke@435 456 }
duke@435 457 return no_profile_data;
duke@435 458 }
duke@435 459
duke@435 460 // Compute the size of the profiling information corresponding to
duke@435 461 // the current bytecode.
duke@435 462 int methodDataOopDesc::compute_data_size(BytecodeStream* stream) {
duke@435 463 int cell_count = bytecode_cell_count(stream->code());
duke@435 464 if (cell_count == no_profile_data) {
duke@435 465 return 0;
duke@435 466 }
duke@435 467 if (cell_count == variable_cell_count) {
duke@435 468 cell_count = MultiBranchData::compute_cell_count(stream);
duke@435 469 }
duke@435 470 // Note: cell_count might be zero, meaning that there is just
duke@435 471 // a DataLayout header, with no extra cells.
duke@435 472 assert(cell_count >= 0, "sanity");
duke@435 473 return DataLayout::compute_size_in_bytes(cell_count);
duke@435 474 }
duke@435 475
duke@435 476 int methodDataOopDesc::compute_extra_data_count(int data_size, int empty_bc_count) {
duke@435 477 if (ProfileTraps) {
duke@435 478 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
duke@435 479 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
duke@435 480 // If the method is large, let the extra BCIs grow numerous (to ~1%).
duke@435 481 int one_percent_of_data
duke@435 482 = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
duke@435 483 if (extra_data_count < one_percent_of_data)
duke@435 484 extra_data_count = one_percent_of_data;
duke@435 485 if (extra_data_count > empty_bc_count)
duke@435 486 extra_data_count = empty_bc_count; // no need for more
duke@435 487 return extra_data_count;
duke@435 488 } else {
duke@435 489 return 0;
duke@435 490 }
duke@435 491 }
duke@435 492
duke@435 493 // Compute the size of the methodDataOop necessary to store
duke@435 494 // profiling information about a given method. Size is in bytes.
duke@435 495 int methodDataOopDesc::compute_allocation_size_in_bytes(methodHandle method) {
duke@435 496 int data_size = 0;
duke@435 497 BytecodeStream stream(method);
duke@435 498 Bytecodes::Code c;
duke@435 499 int empty_bc_count = 0; // number of bytecodes lacking data
duke@435 500 while ((c = stream.next()) >= 0) {
duke@435 501 int size_in_bytes = compute_data_size(&stream);
duke@435 502 data_size += size_in_bytes;
duke@435 503 if (size_in_bytes == 0) empty_bc_count += 1;
duke@435 504 }
duke@435 505 int object_size = in_bytes(data_offset()) + data_size;
duke@435 506
duke@435 507 // Add some extra DataLayout cells (at least one) to track stray traps.
duke@435 508 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
duke@435 509 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
duke@435 510
duke@435 511 return object_size;
duke@435 512 }
duke@435 513
duke@435 514 // Compute the size of the methodDataOop necessary to store
duke@435 515 // profiling information about a given method. Size is in words
duke@435 516 int methodDataOopDesc::compute_allocation_size_in_words(methodHandle method) {
duke@435 517 int byte_size = compute_allocation_size_in_bytes(method);
duke@435 518 int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
duke@435 519 return align_object_size(word_size);
duke@435 520 }
duke@435 521
duke@435 522 // Initialize an individual data segment. Returns the size of
duke@435 523 // the segment in bytes.
duke@435 524 int methodDataOopDesc::initialize_data(BytecodeStream* stream,
duke@435 525 int data_index) {
duke@435 526 int cell_count = -1;
duke@435 527 int tag = DataLayout::no_tag;
duke@435 528 DataLayout* data_layout = data_layout_at(data_index);
duke@435 529 Bytecodes::Code c = stream->code();
duke@435 530 switch (c) {
duke@435 531 case Bytecodes::_checkcast:
duke@435 532 case Bytecodes::_instanceof:
duke@435 533 case Bytecodes::_aastore:
duke@435 534 if (TypeProfileCasts) {
duke@435 535 cell_count = ReceiverTypeData::static_cell_count();
duke@435 536 tag = DataLayout::receiver_type_data_tag;
duke@435 537 } else {
duke@435 538 cell_count = BitData::static_cell_count();
duke@435 539 tag = DataLayout::bit_data_tag;
duke@435 540 }
duke@435 541 break;
duke@435 542 case Bytecodes::_invokespecial:
duke@435 543 case Bytecodes::_invokestatic:
duke@435 544 cell_count = CounterData::static_cell_count();
duke@435 545 tag = DataLayout::counter_data_tag;
duke@435 546 break;
duke@435 547 case Bytecodes::_goto:
duke@435 548 case Bytecodes::_goto_w:
duke@435 549 case Bytecodes::_jsr:
duke@435 550 case Bytecodes::_jsr_w:
duke@435 551 cell_count = JumpData::static_cell_count();
duke@435 552 tag = DataLayout::jump_data_tag;
duke@435 553 break;
duke@435 554 case Bytecodes::_invokevirtual:
duke@435 555 case Bytecodes::_invokeinterface:
duke@435 556 cell_count = VirtualCallData::static_cell_count();
duke@435 557 tag = DataLayout::virtual_call_data_tag;
duke@435 558 break;
duke@435 559 case Bytecodes::_ret:
duke@435 560 cell_count = RetData::static_cell_count();
duke@435 561 tag = DataLayout::ret_data_tag;
duke@435 562 break;
duke@435 563 case Bytecodes::_ifeq:
duke@435 564 case Bytecodes::_ifne:
duke@435 565 case Bytecodes::_iflt:
duke@435 566 case Bytecodes::_ifge:
duke@435 567 case Bytecodes::_ifgt:
duke@435 568 case Bytecodes::_ifle:
duke@435 569 case Bytecodes::_if_icmpeq:
duke@435 570 case Bytecodes::_if_icmpne:
duke@435 571 case Bytecodes::_if_icmplt:
duke@435 572 case Bytecodes::_if_icmpge:
duke@435 573 case Bytecodes::_if_icmpgt:
duke@435 574 case Bytecodes::_if_icmple:
duke@435 575 case Bytecodes::_if_acmpeq:
duke@435 576 case Bytecodes::_if_acmpne:
duke@435 577 case Bytecodes::_ifnull:
duke@435 578 case Bytecodes::_ifnonnull:
duke@435 579 cell_count = BranchData::static_cell_count();
duke@435 580 tag = DataLayout::branch_data_tag;
duke@435 581 break;
duke@435 582 case Bytecodes::_lookupswitch:
duke@435 583 case Bytecodes::_tableswitch:
duke@435 584 cell_count = MultiBranchData::compute_cell_count(stream);
duke@435 585 tag = DataLayout::multi_branch_data_tag;
duke@435 586 break;
duke@435 587 }
duke@435 588 assert(tag == DataLayout::multi_branch_data_tag ||
duke@435 589 cell_count == bytecode_cell_count(c), "cell counts must agree");
duke@435 590 if (cell_count >= 0) {
duke@435 591 assert(tag != DataLayout::no_tag, "bad tag");
duke@435 592 assert(bytecode_has_profile(c), "agree w/ BHP");
duke@435 593 data_layout->initialize(tag, stream->bci(), cell_count);
duke@435 594 return DataLayout::compute_size_in_bytes(cell_count);
duke@435 595 } else {
duke@435 596 assert(!bytecode_has_profile(c), "agree w/ !BHP");
duke@435 597 return 0;
duke@435 598 }
duke@435 599 }
duke@435 600
duke@435 601 // Get the data at an arbitrary (sort of) data index.
duke@435 602 ProfileData* methodDataOopDesc::data_at(int data_index) {
duke@435 603 if (out_of_bounds(data_index)) {
duke@435 604 return NULL;
duke@435 605 }
duke@435 606 DataLayout* data_layout = data_layout_at(data_index);
duke@435 607
duke@435 608 switch (data_layout->tag()) {
duke@435 609 case DataLayout::no_tag:
duke@435 610 default:
duke@435 611 ShouldNotReachHere();
duke@435 612 return NULL;
duke@435 613 case DataLayout::bit_data_tag:
duke@435 614 return new BitData(data_layout);
duke@435 615 case DataLayout::counter_data_tag:
duke@435 616 return new CounterData(data_layout);
duke@435 617 case DataLayout::jump_data_tag:
duke@435 618 return new JumpData(data_layout);
duke@435 619 case DataLayout::receiver_type_data_tag:
duke@435 620 return new ReceiverTypeData(data_layout);
duke@435 621 case DataLayout::virtual_call_data_tag:
duke@435 622 return new VirtualCallData(data_layout);
duke@435 623 case DataLayout::ret_data_tag:
duke@435 624 return new RetData(data_layout);
duke@435 625 case DataLayout::branch_data_tag:
duke@435 626 return new BranchData(data_layout);
duke@435 627 case DataLayout::multi_branch_data_tag:
duke@435 628 return new MultiBranchData(data_layout);
duke@435 629 };
duke@435 630 }
duke@435 631
duke@435 632 // Iteration over data.
duke@435 633 ProfileData* methodDataOopDesc::next_data(ProfileData* current) {
duke@435 634 int current_index = dp_to_di(current->dp());
duke@435 635 int next_index = current_index + current->size_in_bytes();
duke@435 636 ProfileData* next = data_at(next_index);
duke@435 637 return next;
duke@435 638 }
duke@435 639
duke@435 640 // Give each of the data entries a chance to perform specific
duke@435 641 // data initialization.
duke@435 642 void methodDataOopDesc::post_initialize(BytecodeStream* stream) {
duke@435 643 ResourceMark rm;
duke@435 644 ProfileData* data;
duke@435 645 for (data = first_data(); is_valid(data); data = next_data(data)) {
duke@435 646 stream->set_start(data->bci());
duke@435 647 stream->next();
duke@435 648 data->post_initialize(stream, this);
duke@435 649 }
duke@435 650 }
duke@435 651
duke@435 652 // Initialize the methodDataOop corresponding to a given method.
duke@435 653 void methodDataOopDesc::initialize(methodHandle method) {
duke@435 654 ResourceMark rm;
duke@435 655
duke@435 656 // Set the method back-pointer.
duke@435 657 _method = method();
duke@435 658 set_creation_mileage(mileage_of(method()));
duke@435 659
duke@435 660 // Initialize flags and trap history.
duke@435 661 _nof_decompiles = 0;
duke@435 662 _nof_overflow_recompiles = 0;
duke@435 663 _nof_overflow_traps = 0;
duke@435 664 assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align");
duke@435 665 Copy::zero_to_words((HeapWord*) &_trap_hist,
duke@435 666 sizeof(_trap_hist) / sizeof(HeapWord));
duke@435 667
duke@435 668 // Go through the bytecodes and allocate and initialize the
duke@435 669 // corresponding data cells.
duke@435 670 int data_size = 0;
duke@435 671 int empty_bc_count = 0; // number of bytecodes lacking data
duke@435 672 BytecodeStream stream(method);
duke@435 673 Bytecodes::Code c;
duke@435 674 while ((c = stream.next()) >= 0) {
duke@435 675 int size_in_bytes = initialize_data(&stream, data_size);
duke@435 676 data_size += size_in_bytes;
duke@435 677 if (size_in_bytes == 0) empty_bc_count += 1;
duke@435 678 }
duke@435 679 _data_size = data_size;
duke@435 680 int object_size = in_bytes(data_offset()) + data_size;
duke@435 681
duke@435 682 // Add some extra DataLayout cells (at least one) to track stray traps.
duke@435 683 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
duke@435 684 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
duke@435 685
duke@435 686 // Set an initial hint. Don't use set_hint_di() because
duke@435 687 // first_di() may be out of bounds if data_size is 0.
duke@435 688 // In that situation, _hint_di is never used, but at
duke@435 689 // least well-defined.
duke@435 690 _hint_di = first_di();
duke@435 691
duke@435 692 post_initialize(&stream);
duke@435 693
duke@435 694 set_object_is_parsable(object_size);
duke@435 695 }
duke@435 696
duke@435 697 // Get a measure of how much mileage the method has on it.
duke@435 698 int methodDataOopDesc::mileage_of(methodOop method) {
duke@435 699 int mileage = 0;
duke@435 700 int iic = method->interpreter_invocation_count();
duke@435 701 if (mileage < iic) mileage = iic;
duke@435 702
duke@435 703 InvocationCounter* ic = method->invocation_counter();
duke@435 704 InvocationCounter* bc = method->backedge_counter();
duke@435 705
duke@435 706 int icval = ic->count();
duke@435 707 if (ic->carry()) icval += CompileThreshold;
duke@435 708 if (mileage < icval) mileage = icval;
duke@435 709 int bcval = bc->count();
duke@435 710 if (bc->carry()) bcval += CompileThreshold;
duke@435 711 if (mileage < bcval) mileage = bcval;
duke@435 712 return mileage;
duke@435 713 }
duke@435 714
duke@435 715 bool methodDataOopDesc::is_mature() const {
duke@435 716 uint current = mileage_of(_method);
duke@435 717 uint initial = creation_mileage();
duke@435 718 if (current < initial)
duke@435 719 return true; // some sort of overflow
duke@435 720 uint target;
duke@435 721 if (ProfileMaturityPercentage <= 0)
duke@435 722 target = (uint) -ProfileMaturityPercentage; // absolute value
duke@435 723 else
duke@435 724 target = (uint)( (ProfileMaturityPercentage * CompileThreshold) / 100 );
duke@435 725 return (current >= initial + target);
duke@435 726 }
duke@435 727
duke@435 728 // Translate a bci to its corresponding data index (di).
duke@435 729 address methodDataOopDesc::bci_to_dp(int bci) {
duke@435 730 ResourceMark rm;
duke@435 731 ProfileData* data = data_before(bci);
duke@435 732 ProfileData* prev = NULL;
duke@435 733 for ( ; is_valid(data); data = next_data(data)) {
duke@435 734 if (data->bci() >= bci) {
duke@435 735 if (data->bci() == bci) set_hint_di(dp_to_di(data->dp()));
duke@435 736 else if (prev != NULL) set_hint_di(dp_to_di(prev->dp()));
duke@435 737 return data->dp();
duke@435 738 }
duke@435 739 prev = data;
duke@435 740 }
duke@435 741 return (address)limit_data_position();
duke@435 742 }
duke@435 743
duke@435 744 // Translate a bci to its corresponding data, or NULL.
duke@435 745 ProfileData* methodDataOopDesc::bci_to_data(int bci) {
duke@435 746 ProfileData* data = data_before(bci);
duke@435 747 for ( ; is_valid(data); data = next_data(data)) {
duke@435 748 if (data->bci() == bci) {
duke@435 749 set_hint_di(dp_to_di(data->dp()));
duke@435 750 return data;
duke@435 751 } else if (data->bci() > bci) {
duke@435 752 break;
duke@435 753 }
duke@435 754 }
duke@435 755 return bci_to_extra_data(bci, false);
duke@435 756 }
duke@435 757
duke@435 758 // Translate a bci to its corresponding extra data, or NULL.
duke@435 759 ProfileData* methodDataOopDesc::bci_to_extra_data(int bci, bool create_if_missing) {
duke@435 760 DataLayout* dp = extra_data_base();
duke@435 761 DataLayout* end = extra_data_limit();
duke@435 762 DataLayout* avail = NULL;
duke@435 763 for (; dp < end; dp = next_extra(dp)) {
duke@435 764 // No need for "OrderAccess::load_acquire" ops,
duke@435 765 // since the data structure is monotonic.
duke@435 766 if (dp->tag() == DataLayout::no_tag) break;
duke@435 767 if (dp->bci() == bci) {
duke@435 768 assert(dp->tag() == DataLayout::bit_data_tag, "sane");
duke@435 769 return new BitData(dp);
duke@435 770 }
duke@435 771 }
duke@435 772 if (create_if_missing && dp < end) {
duke@435 773 // Allocate this one. There is no mutual exclusion,
duke@435 774 // so two threads could allocate different BCIs to the
duke@435 775 // same data layout. This means these extra data
duke@435 776 // records, like most other MDO contents, must not be
duke@435 777 // trusted too much.
duke@435 778 DataLayout temp;
duke@435 779 temp.initialize(DataLayout::bit_data_tag, bci, 0);
duke@435 780 dp->release_set_header(temp.header());
duke@435 781 assert(dp->tag() == DataLayout::bit_data_tag, "sane");
duke@435 782 //NO: assert(dp->bci() == bci, "no concurrent allocation");
duke@435 783 return new BitData(dp);
duke@435 784 }
duke@435 785 return NULL;
duke@435 786 }
duke@435 787
duke@435 788 #ifndef PRODUCT
duke@435 789 void methodDataOopDesc::print_data_on(outputStream* st) {
duke@435 790 ResourceMark rm;
duke@435 791 ProfileData* data = first_data();
duke@435 792 for ( ; is_valid(data); data = next_data(data)) {
duke@435 793 st->print("%d", dp_to_di(data->dp()));
duke@435 794 st->fill_to(6);
duke@435 795 data->print_data_on(st);
duke@435 796 }
duke@435 797 DataLayout* dp = extra_data_base();
duke@435 798 DataLayout* end = extra_data_limit();
duke@435 799 for (; dp < end; dp = next_extra(dp)) {
duke@435 800 // No need for "OrderAccess::load_acquire" ops,
duke@435 801 // since the data structure is monotonic.
duke@435 802 if (dp->tag() == DataLayout::no_tag) break;
duke@435 803 if (dp == extra_data_base())
duke@435 804 st->print_cr("--- Extra data:");
duke@435 805 data = new BitData(dp);
duke@435 806 st->print("%d", dp_to_di(data->dp()));
duke@435 807 st->fill_to(6);
duke@435 808 data->print_data_on(st);
duke@435 809 }
duke@435 810 }
duke@435 811 #endif
duke@435 812
duke@435 813 void methodDataOopDesc::verify_data_on(outputStream* st) {
duke@435 814 NEEDS_CLEANUP;
duke@435 815 // not yet implemented.
duke@435 816 }

mercurial