annotate src/share/vm/oops/methodDataOop.hpp @ 0:a61af66fc99e

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 48a3fa21394b
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 class BytecodeStream;
duke@0 26
duke@0 27 // The MethodData object collects counts and other profile information
duke@0 28 // during zeroth-tier (interpretive) and first-tier execution.
duke@0 29 // The profile is used later by compilation heuristics. Some heuristics
duke@0 30 // enable use of aggressive (or "heroic") optimizations. An aggressive
duke@0 31 // optimization often has a down-side, a corner case that it handles
duke@0 32 // poorly, but which is thought to be rare. The profile provides
duke@0 33 // evidence of this rarity for a given method or even BCI. It allows
duke@0 34 // the compiler to back out of the optimization at places where it
duke@0 35 // has historically been a poor choice. Other heuristics try to use
duke@0 36 // specific information gathered about types observed at a given site.
duke@0 37 //
duke@0 38 // All data in the profile is approximate. It is expected to be accurate
duke@0 39 // on the whole, but the system expects occasional inaccuraces, due to
duke@0 40 // counter overflow, multiprocessor races during data collection, space
duke@0 41 // limitations, missing MDO blocks, etc. Bad or missing data will degrade
duke@0 42 // optimization quality but will not affect correctness. Also, each MDO
duke@0 43 // is marked with its birth-date ("creation_mileage") which can be used
duke@0 44 // to assess the quality ("maturity") of its data.
duke@0 45 //
duke@0 46 // Short (<32-bit) counters are designed to overflow to a known "saturated"
duke@0 47 // state. Also, certain recorded per-BCI events are given one-bit counters
duke@0 48 // which overflow to a saturated state which applied to all counters at
duke@0 49 // that BCI. In other words, there is a small lattice which approximates
duke@0 50 // the ideal of an infinite-precision counter for each event at each BCI,
duke@0 51 // and the lattice quickly "bottoms out" in a state where all counters
duke@0 52 // are taken to be indefinitely large.
duke@0 53 //
duke@0 54 // The reader will find many data races in profile gathering code, starting
duke@0 55 // with invocation counter incrementation. None of these races harm correct
duke@0 56 // execution of the compiled code.
duke@0 57
duke@0 58 // DataLayout
duke@0 59 //
duke@0 60 // Overlay for generic profiling data.
duke@0 61 class DataLayout VALUE_OBJ_CLASS_SPEC {
duke@0 62 private:
duke@0 63 // Every data layout begins with a header. This header
duke@0 64 // contains a tag, which is used to indicate the size/layout
duke@0 65 // of the data, 4 bits of flags, which can be used in any way,
duke@0 66 // 4 bits of trap history (none/one reason/many reasons),
duke@0 67 // and a bci, which is used to tie this piece of data to a
duke@0 68 // specific bci in the bytecodes.
duke@0 69 union {
duke@0 70 intptr_t _bits;
duke@0 71 struct {
duke@0 72 u1 _tag;
duke@0 73 u1 _flags;
duke@0 74 u2 _bci;
duke@0 75 } _struct;
duke@0 76 } _header;
duke@0 77
duke@0 78 // The data layout has an arbitrary number of cells, each sized
duke@0 79 // to accomodate a pointer or an integer.
duke@0 80 intptr_t _cells[1];
duke@0 81
duke@0 82 // Some types of data layouts need a length field.
duke@0 83 static bool needs_array_len(u1 tag);
duke@0 84
duke@0 85 public:
duke@0 86 enum {
duke@0 87 counter_increment = 1
duke@0 88 };
duke@0 89
duke@0 90 enum {
duke@0 91 cell_size = sizeof(intptr_t)
duke@0 92 };
duke@0 93
duke@0 94 // Tag values
duke@0 95 enum {
duke@0 96 no_tag,
duke@0 97 bit_data_tag,
duke@0 98 counter_data_tag,
duke@0 99 jump_data_tag,
duke@0 100 receiver_type_data_tag,
duke@0 101 virtual_call_data_tag,
duke@0 102 ret_data_tag,
duke@0 103 branch_data_tag,
duke@0 104 multi_branch_data_tag
duke@0 105 };
duke@0 106
duke@0 107 enum {
duke@0 108 // The _struct._flags word is formatted as [trap_state:4 | flags:4].
duke@0 109 // The trap state breaks down further as [recompile:1 | reason:3].
duke@0 110 // This further breakdown is defined in deoptimization.cpp.
duke@0 111 // See Deoptimization::trap_state_reason for an assert that
duke@0 112 // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
duke@0 113 //
duke@0 114 // The trap_state is collected only if ProfileTraps is true.
duke@0 115 trap_bits = 1+3, // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
duke@0 116 trap_shift = BitsPerByte - trap_bits,
duke@0 117 trap_mask = right_n_bits(trap_bits),
duke@0 118 trap_mask_in_place = (trap_mask << trap_shift),
duke@0 119 flag_limit = trap_shift,
duke@0 120 flag_mask = right_n_bits(flag_limit),
duke@0 121 first_flag = 0
duke@0 122 };
duke@0 123
duke@0 124 // Size computation
duke@0 125 static int header_size_in_bytes() {
duke@0 126 return cell_size;
duke@0 127 }
duke@0 128 static int header_size_in_cells() {
duke@0 129 return 1;
duke@0 130 }
duke@0 131
duke@0 132 static int compute_size_in_bytes(int cell_count) {
duke@0 133 return header_size_in_bytes() + cell_count * cell_size;
duke@0 134 }
duke@0 135
duke@0 136 // Initialization
duke@0 137 void initialize(u1 tag, u2 bci, int cell_count);
duke@0 138
duke@0 139 // Accessors
duke@0 140 u1 tag() {
duke@0 141 return _header._struct._tag;
duke@0 142 }
duke@0 143
duke@0 144 // Return a few bits of trap state. Range is [0..trap_mask].
duke@0 145 // The state tells if traps with zero, one, or many reasons have occurred.
duke@0 146 // It also tells whether zero or many recompilations have occurred.
duke@0 147 // The associated trap histogram in the MDO itself tells whether
duke@0 148 // traps are common or not. If a BCI shows that a trap X has
duke@0 149 // occurred, and the MDO shows N occurrences of X, we make the
duke@0 150 // simplifying assumption that all N occurrences can be blamed
duke@0 151 // on that BCI.
duke@0 152 int trap_state() {
duke@0 153 return ((_header._struct._flags >> trap_shift) & trap_mask);
duke@0 154 }
duke@0 155
duke@0 156 void set_trap_state(int new_state) {
duke@0 157 assert(ProfileTraps, "used only under +ProfileTraps");
duke@0 158 uint old_flags = (_header._struct._flags & flag_mask);
duke@0 159 _header._struct._flags = (new_state << trap_shift) | old_flags;
duke@0 160 assert(trap_state() == new_state, "sanity");
duke@0 161 }
duke@0 162
duke@0 163 u1 flags() {
duke@0 164 return _header._struct._flags;
duke@0 165 }
duke@0 166
duke@0 167 u2 bci() {
duke@0 168 return _header._struct._bci;
duke@0 169 }
duke@0 170
duke@0 171 void set_header(intptr_t value) {
duke@0 172 _header._bits = value;
duke@0 173 }
duke@0 174 void release_set_header(intptr_t value) {
duke@0 175 OrderAccess::release_store_ptr(&_header._bits, value);
duke@0 176 }
duke@0 177 intptr_t header() {
duke@0 178 return _header._bits;
duke@0 179 }
duke@0 180 void set_cell_at(int index, intptr_t value) {
duke@0 181 _cells[index] = value;
duke@0 182 }
duke@0 183 void release_set_cell_at(int index, intptr_t value) {
duke@0 184 OrderAccess::release_store_ptr(&_cells[index], value);
duke@0 185 }
duke@0 186 intptr_t cell_at(int index) {
duke@0 187 return _cells[index];
duke@0 188 }
duke@0 189 intptr_t* adr_cell_at(int index) {
duke@0 190 return &_cells[index];
duke@0 191 }
duke@0 192 oop* adr_oop_at(int index) {
duke@0 193 return (oop*)&(_cells[index]);
duke@0 194 }
duke@0 195
duke@0 196 void set_flag_at(int flag_number) {
duke@0 197 assert(flag_number < flag_limit, "oob");
duke@0 198 _header._struct._flags |= (0x1 << flag_number);
duke@0 199 }
duke@0 200 bool flag_at(int flag_number) {
duke@0 201 assert(flag_number < flag_limit, "oob");
duke@0 202 return (_header._struct._flags & (0x1 << flag_number)) != 0;
duke@0 203 }
duke@0 204
duke@0 205 // Low-level support for code generation.
duke@0 206 static ByteSize header_offset() {
duke@0 207 return byte_offset_of(DataLayout, _header);
duke@0 208 }
duke@0 209 static ByteSize tag_offset() {
duke@0 210 return byte_offset_of(DataLayout, _header._struct._tag);
duke@0 211 }
duke@0 212 static ByteSize flags_offset() {
duke@0 213 return byte_offset_of(DataLayout, _header._struct._flags);
duke@0 214 }
duke@0 215 static ByteSize bci_offset() {
duke@0 216 return byte_offset_of(DataLayout, _header._struct._bci);
duke@0 217 }
duke@0 218 static ByteSize cell_offset(int index) {
duke@0 219 return byte_offset_of(DataLayout, _cells[index]);
duke@0 220 }
duke@0 221 // Return a value which, when or-ed as a byte into _flags, sets the flag.
duke@0 222 static int flag_number_to_byte_constant(int flag_number) {
duke@0 223 assert(0 <= flag_number && flag_number < flag_limit, "oob");
duke@0 224 DataLayout temp; temp.set_header(0);
duke@0 225 temp.set_flag_at(flag_number);
duke@0 226 return temp._header._struct._flags;
duke@0 227 }
duke@0 228 // Return a value which, when or-ed as a word into _header, sets the flag.
duke@0 229 static intptr_t flag_mask_to_header_mask(int byte_constant) {
duke@0 230 DataLayout temp; temp.set_header(0);
duke@0 231 temp._header._struct._flags = byte_constant;
duke@0 232 return temp._header._bits;
duke@0 233 }
duke@0 234 };
duke@0 235
duke@0 236
duke@0 237 // ProfileData class hierarchy
duke@0 238 class ProfileData;
duke@0 239 class BitData;
duke@0 240 class CounterData;
duke@0 241 class ReceiverTypeData;
duke@0 242 class VirtualCallData;
duke@0 243 class RetData;
duke@0 244 class JumpData;
duke@0 245 class BranchData;
duke@0 246 class ArrayData;
duke@0 247 class MultiBranchData;
duke@0 248
duke@0 249
duke@0 250 // ProfileData
duke@0 251 //
duke@0 252 // A ProfileData object is created to refer to a section of profiling
duke@0 253 // data in a structured way.
duke@0 254 class ProfileData : public ResourceObj {
duke@0 255 private:
duke@0 256 #ifndef PRODUCT
duke@0 257 enum {
duke@0 258 tab_width_one = 16,
duke@0 259 tab_width_two = 36
duke@0 260 };
duke@0 261 #endif // !PRODUCT
duke@0 262
duke@0 263 // This is a pointer to a section of profiling data.
duke@0 264 DataLayout* _data;
duke@0 265
duke@0 266 protected:
duke@0 267 DataLayout* data() { return _data; }
duke@0 268
duke@0 269 enum {
duke@0 270 cell_size = DataLayout::cell_size
duke@0 271 };
duke@0 272
duke@0 273 public:
duke@0 274 // How many cells are in this?
duke@0 275 virtual int cell_count() {
duke@0 276 ShouldNotReachHere();
duke@0 277 return -1;
duke@0 278 }
duke@0 279
duke@0 280 // Return the size of this data.
duke@0 281 int size_in_bytes() {
duke@0 282 return DataLayout::compute_size_in_bytes(cell_count());
duke@0 283 }
duke@0 284
duke@0 285 protected:
duke@0 286 // Low-level accessors for underlying data
duke@0 287 void set_intptr_at(int index, intptr_t value) {
duke@0 288 assert(0 <= index && index < cell_count(), "oob");
duke@0 289 data()->set_cell_at(index, value);
duke@0 290 }
duke@0 291 void release_set_intptr_at(int index, intptr_t value) {
duke@0 292 assert(0 <= index && index < cell_count(), "oob");
duke@0 293 data()->release_set_cell_at(index, value);
duke@0 294 }
duke@0 295 intptr_t intptr_at(int index) {
duke@0 296 assert(0 <= index && index < cell_count(), "oob");
duke@0 297 return data()->cell_at(index);
duke@0 298 }
duke@0 299 void set_uint_at(int index, uint value) {
duke@0 300 set_intptr_at(index, (intptr_t) value);
duke@0 301 }
duke@0 302 void release_set_uint_at(int index, uint value) {
duke@0 303 release_set_intptr_at(index, (intptr_t) value);
duke@0 304 }
duke@0 305 uint uint_at(int index) {
duke@0 306 return (uint)intptr_at(index);
duke@0 307 }
duke@0 308 void set_int_at(int index, int value) {
duke@0 309 set_intptr_at(index, (intptr_t) value);
duke@0 310 }
duke@0 311 void release_set_int_at(int index, int value) {
duke@0 312 release_set_intptr_at(index, (intptr_t) value);
duke@0 313 }
duke@0 314 int int_at(int index) {
duke@0 315 return (int)intptr_at(index);
duke@0 316 }
duke@0 317 int int_at_unchecked(int index) {
duke@0 318 return (int)data()->cell_at(index);
duke@0 319 }
duke@0 320 void set_oop_at(int index, oop value) {
duke@0 321 set_intptr_at(index, (intptr_t) value);
duke@0 322 }
duke@0 323 oop oop_at(int index) {
duke@0 324 return (oop)intptr_at(index);
duke@0 325 }
duke@0 326 oop* adr_oop_at(int index) {
duke@0 327 assert(0 <= index && index < cell_count(), "oob");
duke@0 328 return data()->adr_oop_at(index);
duke@0 329 }
duke@0 330
duke@0 331 void set_flag_at(int flag_number) {
duke@0 332 data()->set_flag_at(flag_number);
duke@0 333 }
duke@0 334 bool flag_at(int flag_number) {
duke@0 335 return data()->flag_at(flag_number);
duke@0 336 }
duke@0 337
duke@0 338 // two convenient imports for use by subclasses:
duke@0 339 static ByteSize cell_offset(int index) {
duke@0 340 return DataLayout::cell_offset(index);
duke@0 341 }
duke@0 342 static int flag_number_to_byte_constant(int flag_number) {
duke@0 343 return DataLayout::flag_number_to_byte_constant(flag_number);
duke@0 344 }
duke@0 345
duke@0 346 ProfileData(DataLayout* data) {
duke@0 347 _data = data;
duke@0 348 }
duke@0 349
duke@0 350 public:
duke@0 351 // Constructor for invalid ProfileData.
duke@0 352 ProfileData();
duke@0 353
duke@0 354 u2 bci() {
duke@0 355 return data()->bci();
duke@0 356 }
duke@0 357
duke@0 358 address dp() {
duke@0 359 return (address)_data;
duke@0 360 }
duke@0 361
duke@0 362 int trap_state() {
duke@0 363 return data()->trap_state();
duke@0 364 }
duke@0 365 void set_trap_state(int new_state) {
duke@0 366 data()->set_trap_state(new_state);
duke@0 367 }
duke@0 368
duke@0 369 // Type checking
duke@0 370 virtual bool is_BitData() { return false; }
duke@0 371 virtual bool is_CounterData() { return false; }
duke@0 372 virtual bool is_JumpData() { return false; }
duke@0 373 virtual bool is_ReceiverTypeData(){ return false; }
duke@0 374 virtual bool is_VirtualCallData() { return false; }
duke@0 375 virtual bool is_RetData() { return false; }
duke@0 376 virtual bool is_BranchData() { return false; }
duke@0 377 virtual bool is_ArrayData() { return false; }
duke@0 378 virtual bool is_MultiBranchData() { return false; }
duke@0 379
duke@0 380 BitData* as_BitData() {
duke@0 381 assert(is_BitData(), "wrong type");
duke@0 382 return is_BitData() ? (BitData*) this : NULL;
duke@0 383 }
duke@0 384 CounterData* as_CounterData() {
duke@0 385 assert(is_CounterData(), "wrong type");
duke@0 386 return is_CounterData() ? (CounterData*) this : NULL;
duke@0 387 }
duke@0 388 JumpData* as_JumpData() {
duke@0 389 assert(is_JumpData(), "wrong type");
duke@0 390 return is_JumpData() ? (JumpData*) this : NULL;
duke@0 391 }
duke@0 392 ReceiverTypeData* as_ReceiverTypeData() {
duke@0 393 assert(is_ReceiverTypeData(), "wrong type");
duke@0 394 return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
duke@0 395 }
duke@0 396 VirtualCallData* as_VirtualCallData() {
duke@0 397 assert(is_VirtualCallData(), "wrong type");
duke@0 398 return is_VirtualCallData() ? (VirtualCallData*)this : NULL;
duke@0 399 }
duke@0 400 RetData* as_RetData() {
duke@0 401 assert(is_RetData(), "wrong type");
duke@0 402 return is_RetData() ? (RetData*) this : NULL;
duke@0 403 }
duke@0 404 BranchData* as_BranchData() {
duke@0 405 assert(is_BranchData(), "wrong type");
duke@0 406 return is_BranchData() ? (BranchData*) this : NULL;
duke@0 407 }
duke@0 408 ArrayData* as_ArrayData() {
duke@0 409 assert(is_ArrayData(), "wrong type");
duke@0 410 return is_ArrayData() ? (ArrayData*) this : NULL;
duke@0 411 }
duke@0 412 MultiBranchData* as_MultiBranchData() {
duke@0 413 assert(is_MultiBranchData(), "wrong type");
duke@0 414 return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
duke@0 415 }
duke@0 416
duke@0 417
duke@0 418 // Subclass specific initialization
duke@0 419 virtual void post_initialize(BytecodeStream* stream, methodDataOop mdo) {}
duke@0 420
duke@0 421 // GC support
duke@0 422 virtual void follow_contents() {}
duke@0 423 virtual void oop_iterate(OopClosure* blk) {}
duke@0 424 virtual void oop_iterate_m(OopClosure* blk, MemRegion mr) {}
duke@0 425 virtual void adjust_pointers() {}
duke@0 426
duke@0 427 #ifndef SERIALGC
duke@0 428 // Parallel old support
duke@0 429 virtual void follow_contents(ParCompactionManager* cm) {}
duke@0 430 virtual void update_pointers() {}
duke@0 431 virtual void update_pointers(HeapWord* beg_addr, HeapWord* end_addr) {}
duke@0 432 #endif // SERIALGC
duke@0 433
duke@0 434 // CI translation: ProfileData can represent both MethodDataOop data
duke@0 435 // as well as CIMethodData data. This function is provided for translating
duke@0 436 // an oop in a ProfileData to the ci equivalent. Generally speaking,
duke@0 437 // most ProfileData don't require any translation, so we provide the null
duke@0 438 // translation here, and the required translators are in the ci subclasses.
duke@0 439 virtual void translate_from(ProfileData* data) {}
duke@0 440
duke@0 441 virtual void print_data_on(outputStream* st) {
duke@0 442 ShouldNotReachHere();
duke@0 443 }
duke@0 444
duke@0 445 #ifndef PRODUCT
duke@0 446 void print_shared(outputStream* st, const char* name);
duke@0 447 void tab(outputStream* st);
duke@0 448 #endif
duke@0 449 };
duke@0 450
duke@0 451 // BitData
duke@0 452 //
duke@0 453 // A BitData holds a flag or two in its header.
duke@0 454 class BitData : public ProfileData {
duke@0 455 protected:
duke@0 456 enum {
duke@0 457 // null_seen:
duke@0 458 // saw a null operand (cast/aastore/instanceof)
duke@0 459 null_seen_flag = DataLayout::first_flag + 0
duke@0 460 };
duke@0 461 enum { bit_cell_count = 0 }; // no additional data fields needed.
duke@0 462 public:
duke@0 463 BitData(DataLayout* layout) : ProfileData(layout) {
duke@0 464 }
duke@0 465
duke@0 466 virtual bool is_BitData() { return true; }
duke@0 467
duke@0 468 static int static_cell_count() {
duke@0 469 return bit_cell_count;
duke@0 470 }
duke@0 471
duke@0 472 virtual int cell_count() {
duke@0 473 return static_cell_count();
duke@0 474 }
duke@0 475
duke@0 476 // Accessor
duke@0 477
duke@0 478 // The null_seen flag bit is specially known to the interpreter.
duke@0 479 // Consulting it allows the compiler to avoid setting up null_check traps.
duke@0 480 bool null_seen() { return flag_at(null_seen_flag); }
duke@0 481 void set_null_seen() { set_flag_at(null_seen_flag); }
duke@0 482
duke@0 483
duke@0 484 // Code generation support
duke@0 485 static int null_seen_byte_constant() {
duke@0 486 return flag_number_to_byte_constant(null_seen_flag);
duke@0 487 }
duke@0 488
duke@0 489 static ByteSize bit_data_size() {
duke@0 490 return cell_offset(bit_cell_count);
duke@0 491 }
duke@0 492
duke@0 493 #ifndef PRODUCT
duke@0 494 void print_data_on(outputStream* st);
duke@0 495 #endif
duke@0 496 };
duke@0 497
duke@0 498 // CounterData
duke@0 499 //
duke@0 500 // A CounterData corresponds to a simple counter.
duke@0 501 class CounterData : public BitData {
duke@0 502 protected:
duke@0 503 enum {
duke@0 504 count_off,
duke@0 505 counter_cell_count
duke@0 506 };
duke@0 507 public:
duke@0 508 CounterData(DataLayout* layout) : BitData(layout) {}
duke@0 509
duke@0 510 virtual bool is_CounterData() { return true; }
duke@0 511
duke@0 512 static int static_cell_count() {
duke@0 513 return counter_cell_count;
duke@0 514 }
duke@0 515
duke@0 516 virtual int cell_count() {
duke@0 517 return static_cell_count();
duke@0 518 }
duke@0 519
duke@0 520 // Direct accessor
duke@0 521 uint count() {
duke@0 522 return uint_at(count_off);
duke@0 523 }
duke@0 524
duke@0 525 // Code generation support
duke@0 526 static ByteSize count_offset() {
duke@0 527 return cell_offset(count_off);
duke@0 528 }
duke@0 529 static ByteSize counter_data_size() {
duke@0 530 return cell_offset(counter_cell_count);
duke@0 531 }
duke@0 532
duke@0 533 #ifndef PRODUCT
duke@0 534 void print_data_on(outputStream* st);
duke@0 535 #endif
duke@0 536 };
duke@0 537
duke@0 538 // JumpData
duke@0 539 //
duke@0 540 // A JumpData is used to access profiling information for a direct
duke@0 541 // branch. It is a counter, used for counting the number of branches,
duke@0 542 // plus a data displacement, used for realigning the data pointer to
duke@0 543 // the corresponding target bci.
duke@0 544 class JumpData : public ProfileData {
duke@0 545 protected:
duke@0 546 enum {
duke@0 547 taken_off_set,
duke@0 548 displacement_off_set,
duke@0 549 jump_cell_count
duke@0 550 };
duke@0 551
duke@0 552 void set_displacement(int displacement) {
duke@0 553 set_int_at(displacement_off_set, displacement);
duke@0 554 }
duke@0 555
duke@0 556 public:
duke@0 557 JumpData(DataLayout* layout) : ProfileData(layout) {
duke@0 558 assert(layout->tag() == DataLayout::jump_data_tag ||
duke@0 559 layout->tag() == DataLayout::branch_data_tag, "wrong type");
duke@0 560 }
duke@0 561
duke@0 562 virtual bool is_JumpData() { return true; }
duke@0 563
duke@0 564 static int static_cell_count() {
duke@0 565 return jump_cell_count;
duke@0 566 }
duke@0 567
duke@0 568 virtual int cell_count() {
duke@0 569 return static_cell_count();
duke@0 570 }
duke@0 571
duke@0 572 // Direct accessor
duke@0 573 uint taken() {
duke@0 574 return uint_at(taken_off_set);
duke@0 575 }
duke@0 576 // Saturating counter
duke@0 577 uint inc_taken() {
duke@0 578 uint cnt = taken() + 1;
duke@0 579 // Did we wrap? Will compiler screw us??
duke@0 580 if (cnt == 0) cnt--;
duke@0 581 set_uint_at(taken_off_set, cnt);
duke@0 582 return cnt;
duke@0 583 }
duke@0 584
duke@0 585 int displacement() {
duke@0 586 return int_at(displacement_off_set);
duke@0 587 }
duke@0 588
duke@0 589 // Code generation support
duke@0 590 static ByteSize taken_offset() {
duke@0 591 return cell_offset(taken_off_set);
duke@0 592 }
duke@0 593
duke@0 594 static ByteSize displacement_offset() {
duke@0 595 return cell_offset(displacement_off_set);
duke@0 596 }
duke@0 597
duke@0 598 // Specific initialization.
duke@0 599 void post_initialize(BytecodeStream* stream, methodDataOop mdo);
duke@0 600
duke@0 601 #ifndef PRODUCT
duke@0 602 void print_data_on(outputStream* st);
duke@0 603 #endif
duke@0 604 };
duke@0 605
duke@0 606 // ReceiverTypeData
duke@0 607 //
duke@0 608 // A ReceiverTypeData is used to access profiling information about a
duke@0 609 // dynamic type check. It consists of a counter which counts the total times
duke@0 610 // that the check is reached, and a series of (klassOop, count) pairs
duke@0 611 // which are used to store a type profile for the receiver of the check.
duke@0 612 class ReceiverTypeData : public CounterData {
duke@0 613 protected:
duke@0 614 enum {
duke@0 615 receiver0_offset = counter_cell_count,
duke@0 616 count0_offset,
duke@0 617 receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
duke@0 618 };
duke@0 619
duke@0 620 public:
duke@0 621 ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
duke@0 622 assert(layout->tag() == DataLayout::receiver_type_data_tag ||
duke@0 623 layout->tag() == DataLayout::virtual_call_data_tag, "wrong type");
duke@0 624 }
duke@0 625
duke@0 626 virtual bool is_ReceiverTypeData() { return true; }
duke@0 627
duke@0 628 static int static_cell_count() {
duke@0 629 return counter_cell_count + (uint) TypeProfileWidth * receiver_type_row_cell_count;
duke@0 630 }
duke@0 631
duke@0 632 virtual int cell_count() {
duke@0 633 return static_cell_count();
duke@0 634 }
duke@0 635
duke@0 636 // Direct accessors
duke@0 637 static uint row_limit() {
duke@0 638 return TypeProfileWidth;
duke@0 639 }
duke@0 640 static int receiver_cell_index(uint row) {
duke@0 641 return receiver0_offset + row * receiver_type_row_cell_count;
duke@0 642 }
duke@0 643 static int receiver_count_cell_index(uint row) {
duke@0 644 return count0_offset + row * receiver_type_row_cell_count;
duke@0 645 }
duke@0 646
duke@0 647 // Get the receiver at row. The 'unchecked' version is needed by parallel old
duke@0 648 // gc; it does not assert the receiver is a klass. During compaction of the
duke@0 649 // perm gen, the klass may already have moved, so the is_klass() predicate
duke@0 650 // would fail. The 'normal' version should be used whenever possible.
duke@0 651 klassOop receiver_unchecked(uint row) {
duke@0 652 assert(row < row_limit(), "oob");
duke@0 653 oop recv = oop_at(receiver_cell_index(row));
duke@0 654 return (klassOop)recv;
duke@0 655 }
duke@0 656
duke@0 657 klassOop receiver(uint row) {
duke@0 658 klassOop recv = receiver_unchecked(row);
duke@0 659 assert(recv == NULL || ((oop)recv)->is_klass(), "wrong type");
duke@0 660 return recv;
duke@0 661 }
duke@0 662
duke@0 663 uint receiver_count(uint row) {
duke@0 664 assert(row < row_limit(), "oob");
duke@0 665 return uint_at(receiver_count_cell_index(row));
duke@0 666 }
duke@0 667
duke@0 668 // Code generation support
duke@0 669 static ByteSize receiver_offset(uint row) {
duke@0 670 return cell_offset(receiver_cell_index(row));
duke@0 671 }
duke@0 672 static ByteSize receiver_count_offset(uint row) {
duke@0 673 return cell_offset(receiver_count_cell_index(row));
duke@0 674 }
duke@0 675 static ByteSize receiver_type_data_size() {
duke@0 676 return cell_offset(static_cell_count());
duke@0 677 }
duke@0 678
duke@0 679 // GC support
duke@0 680 virtual void follow_contents();
duke@0 681 virtual void oop_iterate(OopClosure* blk);
duke@0 682 virtual void oop_iterate_m(OopClosure* blk, MemRegion mr);
duke@0 683 virtual void adjust_pointers();
duke@0 684
duke@0 685 #ifndef SERIALGC
duke@0 686 // Parallel old support
duke@0 687 virtual void follow_contents(ParCompactionManager* cm);
duke@0 688 virtual void update_pointers();
duke@0 689 virtual void update_pointers(HeapWord* beg_addr, HeapWord* end_addr);
duke@0 690 #endif // SERIALGC
duke@0 691
duke@0 692 oop* adr_receiver(uint row) {
duke@0 693 return adr_oop_at(receiver_cell_index(row));
duke@0 694 }
duke@0 695
duke@0 696 #ifndef PRODUCT
duke@0 697 void print_receiver_data_on(outputStream* st);
duke@0 698 void print_data_on(outputStream* st);
duke@0 699 #endif
duke@0 700 };
duke@0 701
duke@0 702 // VirtualCallData
duke@0 703 //
duke@0 704 // A VirtualCallData is used to access profiling information about a
duke@0 705 // virtual call. For now, it has nothing more than a ReceiverTypeData.
duke@0 706 class VirtualCallData : public ReceiverTypeData {
duke@0 707 public:
duke@0 708 VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
duke@0 709 assert(layout->tag() == DataLayout::virtual_call_data_tag, "wrong type");
duke@0 710 }
duke@0 711
duke@0 712 virtual bool is_VirtualCallData() { return true; }
duke@0 713
duke@0 714 static int static_cell_count() {
duke@0 715 // At this point we could add more profile state, e.g., for arguments.
duke@0 716 // But for now it's the same size as the base record type.
duke@0 717 return ReceiverTypeData::static_cell_count();
duke@0 718 }
duke@0 719
duke@0 720 virtual int cell_count() {
duke@0 721 return static_cell_count();
duke@0 722 }
duke@0 723
duke@0 724 // Direct accessors
duke@0 725 static ByteSize virtual_call_data_size() {
duke@0 726 return cell_offset(static_cell_count());
duke@0 727 }
duke@0 728
duke@0 729 #ifndef PRODUCT
duke@0 730 void print_data_on(outputStream* st);
duke@0 731 #endif
duke@0 732 };
duke@0 733
duke@0 734 // RetData
duke@0 735 //
duke@0 736 // A RetData is used to access profiling information for a ret bytecode.
duke@0 737 // It is composed of a count of the number of times that the ret has
duke@0 738 // been executed, followed by a series of triples of the form
duke@0 739 // (bci, count, di) which count the number of times that some bci was the
duke@0 740 // target of the ret and cache a corresponding data displacement.
duke@0 741 class RetData : public CounterData {
duke@0 742 protected:
duke@0 743 enum {
duke@0 744 bci0_offset = counter_cell_count,
duke@0 745 count0_offset,
duke@0 746 displacement0_offset,
duke@0 747 ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
duke@0 748 };
duke@0 749
duke@0 750 void set_bci(uint row, int bci) {
duke@0 751 assert((uint)row < row_limit(), "oob");
duke@0 752 set_int_at(bci0_offset + row * ret_row_cell_count, bci);
duke@0 753 }
duke@0 754 void release_set_bci(uint row, int bci) {
duke@0 755 assert((uint)row < row_limit(), "oob");
duke@0 756 // 'release' when setting the bci acts as a valid flag for other
duke@0 757 // threads wrt bci_count and bci_displacement.
duke@0 758 release_set_int_at(bci0_offset + row * ret_row_cell_count, bci);
duke@0 759 }
duke@0 760 void set_bci_count(uint row, uint count) {
duke@0 761 assert((uint)row < row_limit(), "oob");
duke@0 762 set_uint_at(count0_offset + row * ret_row_cell_count, count);
duke@0 763 }
duke@0 764 void set_bci_displacement(uint row, int disp) {
duke@0 765 set_int_at(displacement0_offset + row * ret_row_cell_count, disp);
duke@0 766 }
duke@0 767
duke@0 768 public:
duke@0 769 RetData(DataLayout* layout) : CounterData(layout) {
duke@0 770 assert(layout->tag() == DataLayout::ret_data_tag, "wrong type");
duke@0 771 }
duke@0 772
duke@0 773 virtual bool is_RetData() { return true; }
duke@0 774
duke@0 775 enum {
duke@0 776 no_bci = -1 // value of bci when bci1/2 are not in use.
duke@0 777 };
duke@0 778
duke@0 779 static int static_cell_count() {
duke@0 780 return counter_cell_count + (uint) BciProfileWidth * ret_row_cell_count;
duke@0 781 }
duke@0 782
duke@0 783 virtual int cell_count() {
duke@0 784 return static_cell_count();
duke@0 785 }
duke@0 786
duke@0 787 static uint row_limit() {
duke@0 788 return BciProfileWidth;
duke@0 789 }
duke@0 790 static int bci_cell_index(uint row) {
duke@0 791 return bci0_offset + row * ret_row_cell_count;
duke@0 792 }
duke@0 793 static int bci_count_cell_index(uint row) {
duke@0 794 return count0_offset + row * ret_row_cell_count;
duke@0 795 }
duke@0 796 static int bci_displacement_cell_index(uint row) {
duke@0 797 return displacement0_offset + row * ret_row_cell_count;
duke@0 798 }
duke@0 799
duke@0 800 // Direct accessors
duke@0 801 int bci(uint row) {
duke@0 802 return int_at(bci_cell_index(row));
duke@0 803 }
duke@0 804 uint bci_count(uint row) {
duke@0 805 return uint_at(bci_count_cell_index(row));
duke@0 806 }
duke@0 807 int bci_displacement(uint row) {
duke@0 808 return int_at(bci_displacement_cell_index(row));
duke@0 809 }
duke@0 810
duke@0 811 // Interpreter Runtime support
duke@0 812 address fixup_ret(int return_bci, methodDataHandle mdo);
duke@0 813
duke@0 814 // Code generation support
duke@0 815 static ByteSize bci_offset(uint row) {
duke@0 816 return cell_offset(bci_cell_index(row));
duke@0 817 }
duke@0 818 static ByteSize bci_count_offset(uint row) {
duke@0 819 return cell_offset(bci_count_cell_index(row));
duke@0 820 }
duke@0 821 static ByteSize bci_displacement_offset(uint row) {
duke@0 822 return cell_offset(bci_displacement_cell_index(row));
duke@0 823 }
duke@0 824
duke@0 825 // Specific initialization.
duke@0 826 void post_initialize(BytecodeStream* stream, methodDataOop mdo);
duke@0 827
duke@0 828 #ifndef PRODUCT
duke@0 829 void print_data_on(outputStream* st);
duke@0 830 #endif
duke@0 831 };
duke@0 832
duke@0 833 // BranchData
duke@0 834 //
duke@0 835 // A BranchData is used to access profiling data for a two-way branch.
duke@0 836 // It consists of taken and not_taken counts as well as a data displacement
duke@0 837 // for the taken case.
duke@0 838 class BranchData : public JumpData {
duke@0 839 protected:
duke@0 840 enum {
duke@0 841 not_taken_off_set = jump_cell_count,
duke@0 842 branch_cell_count
duke@0 843 };
duke@0 844
duke@0 845 void set_displacement(int displacement) {
duke@0 846 set_int_at(displacement_off_set, displacement);
duke@0 847 }
duke@0 848
duke@0 849 public:
duke@0 850 BranchData(DataLayout* layout) : JumpData(layout) {
duke@0 851 assert(layout->tag() == DataLayout::branch_data_tag, "wrong type");
duke@0 852 }
duke@0 853
duke@0 854 virtual bool is_BranchData() { return true; }
duke@0 855
duke@0 856 static int static_cell_count() {
duke@0 857 return branch_cell_count;
duke@0 858 }
duke@0 859
duke@0 860 virtual int cell_count() {
duke@0 861 return static_cell_count();
duke@0 862 }
duke@0 863
duke@0 864 // Direct accessor
duke@0 865 uint not_taken() {
duke@0 866 return uint_at(not_taken_off_set);
duke@0 867 }
duke@0 868
duke@0 869 uint inc_not_taken() {
duke@0 870 uint cnt = not_taken() + 1;
duke@0 871 // Did we wrap? Will compiler screw us??
duke@0 872 if (cnt == 0) cnt--;
duke@0 873 set_uint_at(not_taken_off_set, cnt);
duke@0 874 return cnt;
duke@0 875 }
duke@0 876
duke@0 877 // Code generation support
duke@0 878 static ByteSize not_taken_offset() {
duke@0 879 return cell_offset(not_taken_off_set);
duke@0 880 }
duke@0 881 static ByteSize branch_data_size() {
duke@0 882 return cell_offset(branch_cell_count);
duke@0 883 }
duke@0 884
duke@0 885 // Specific initialization.
duke@0 886 void post_initialize(BytecodeStream* stream, methodDataOop mdo);
duke@0 887
duke@0 888 #ifndef PRODUCT
duke@0 889 void print_data_on(outputStream* st);
duke@0 890 #endif
duke@0 891 };
duke@0 892
duke@0 893 // ArrayData
duke@0 894 //
duke@0 895 // A ArrayData is a base class for accessing profiling data which does
duke@0 896 // not have a statically known size. It consists of an array length
duke@0 897 // and an array start.
duke@0 898 class ArrayData : public ProfileData {
duke@0 899 protected:
duke@0 900 friend class DataLayout;
duke@0 901
duke@0 902 enum {
duke@0 903 array_len_off_set,
duke@0 904 array_start_off_set
duke@0 905 };
duke@0 906
duke@0 907 uint array_uint_at(int index) {
duke@0 908 int aindex = index + array_start_off_set;
duke@0 909 return uint_at(aindex);
duke@0 910 }
duke@0 911 int array_int_at(int index) {
duke@0 912 int aindex = index + array_start_off_set;
duke@0 913 return int_at(aindex);
duke@0 914 }
duke@0 915 oop array_oop_at(int index) {
duke@0 916 int aindex = index + array_start_off_set;
duke@0 917 return oop_at(aindex);
duke@0 918 }
duke@0 919 void array_set_int_at(int index, int value) {
duke@0 920 int aindex = index + array_start_off_set;
duke@0 921 set_int_at(aindex, value);
duke@0 922 }
duke@0 923
duke@0 924 // Code generation support for subclasses.
duke@0 925 static ByteSize array_element_offset(int index) {
duke@0 926 return cell_offset(array_start_off_set + index);
duke@0 927 }
duke@0 928
duke@0 929 public:
duke@0 930 ArrayData(DataLayout* layout) : ProfileData(layout) {}
duke@0 931
duke@0 932 virtual bool is_ArrayData() { return true; }
duke@0 933
duke@0 934 static int static_cell_count() {
duke@0 935 return -1;
duke@0 936 }
duke@0 937
duke@0 938 int array_len() {
duke@0 939 return int_at_unchecked(array_len_off_set);
duke@0 940 }
duke@0 941
duke@0 942 virtual int cell_count() {
duke@0 943 return array_len() + 1;
duke@0 944 }
duke@0 945
duke@0 946 // Code generation support
duke@0 947 static ByteSize array_len_offset() {
duke@0 948 return cell_offset(array_len_off_set);
duke@0 949 }
duke@0 950 static ByteSize array_start_offset() {
duke@0 951 return cell_offset(array_start_off_set);
duke@0 952 }
duke@0 953 };
duke@0 954
duke@0 955 // MultiBranchData
duke@0 956 //
duke@0 957 // A MultiBranchData is used to access profiling information for
duke@0 958 // a multi-way branch (*switch bytecodes). It consists of a series
duke@0 959 // of (count, displacement) pairs, which count the number of times each
duke@0 960 // case was taken and specify the data displacment for each branch target.
duke@0 961 class MultiBranchData : public ArrayData {
duke@0 962 protected:
duke@0 963 enum {
duke@0 964 default_count_off_set,
duke@0 965 default_disaplacement_off_set,
duke@0 966 case_array_start
duke@0 967 };
duke@0 968 enum {
duke@0 969 relative_count_off_set,
duke@0 970 relative_displacement_off_set,
duke@0 971 per_case_cell_count
duke@0 972 };
duke@0 973
duke@0 974 void set_default_displacement(int displacement) {
duke@0 975 array_set_int_at(default_disaplacement_off_set, displacement);
duke@0 976 }
duke@0 977 void set_displacement_at(int index, int displacement) {
duke@0 978 array_set_int_at(case_array_start +
duke@0 979 index * per_case_cell_count +
duke@0 980 relative_displacement_off_set,
duke@0 981 displacement);
duke@0 982 }
duke@0 983
duke@0 984 public:
duke@0 985 MultiBranchData(DataLayout* layout) : ArrayData(layout) {
duke@0 986 assert(layout->tag() == DataLayout::multi_branch_data_tag, "wrong type");
duke@0 987 }
duke@0 988
duke@0 989 virtual bool is_MultiBranchData() { return true; }
duke@0 990
duke@0 991 static int compute_cell_count(BytecodeStream* stream);
duke@0 992
duke@0 993 int number_of_cases() {
duke@0 994 int alen = array_len() - 2; // get rid of default case here.
duke@0 995 assert(alen % per_case_cell_count == 0, "must be even");
duke@0 996 return (alen / per_case_cell_count);
duke@0 997 }
duke@0 998
duke@0 999 uint default_count() {
duke@0 1000 return array_uint_at(default_count_off_set);
duke@0 1001 }
duke@0 1002 int default_displacement() {
duke@0 1003 return array_int_at(default_disaplacement_off_set);
duke@0 1004 }
duke@0 1005
duke@0 1006 uint count_at(int index) {
duke@0 1007 return array_uint_at(case_array_start +
duke@0 1008 index * per_case_cell_count +
duke@0 1009 relative_count_off_set);
duke@0 1010 }
duke@0 1011 int displacement_at(int index) {
duke@0 1012 return array_int_at(case_array_start +
duke@0 1013 index * per_case_cell_count +
duke@0 1014 relative_displacement_off_set);
duke@0 1015 }
duke@0 1016
duke@0 1017 // Code generation support
duke@0 1018 static ByteSize default_count_offset() {
duke@0 1019 return array_element_offset(default_count_off_set);
duke@0 1020 }
duke@0 1021 static ByteSize default_displacement_offset() {
duke@0 1022 return array_element_offset(default_disaplacement_off_set);
duke@0 1023 }
duke@0 1024 static ByteSize case_count_offset(int index) {
duke@0 1025 return case_array_offset() +
duke@0 1026 (per_case_size() * index) +
duke@0 1027 relative_count_offset();
duke@0 1028 }
duke@0 1029 static ByteSize case_array_offset() {
duke@0 1030 return array_element_offset(case_array_start);
duke@0 1031 }
duke@0 1032 static ByteSize per_case_size() {
duke@0 1033 return in_ByteSize(per_case_cell_count) * cell_size;
duke@0 1034 }
duke@0 1035 static ByteSize relative_count_offset() {
duke@0 1036 return in_ByteSize(relative_count_off_set) * cell_size;
duke@0 1037 }
duke@0 1038 static ByteSize relative_displacement_offset() {
duke@0 1039 return in_ByteSize(relative_displacement_off_set) * cell_size;
duke@0 1040 }
duke@0 1041
duke@0 1042 // Specific initialization.
duke@0 1043 void post_initialize(BytecodeStream* stream, methodDataOop mdo);
duke@0 1044
duke@0 1045 #ifndef PRODUCT
duke@0 1046 void print_data_on(outputStream* st);
duke@0 1047 #endif
duke@0 1048 };
duke@0 1049
duke@0 1050 // methodDataOop
duke@0 1051 //
duke@0 1052 // A methodDataOop holds information which has been collected about
duke@0 1053 // a method. Its layout looks like this:
duke@0 1054 //
duke@0 1055 // -----------------------------
duke@0 1056 // | header |
duke@0 1057 // | klass |
duke@0 1058 // -----------------------------
duke@0 1059 // | method |
duke@0 1060 // | size of the methodDataOop |
duke@0 1061 // -----------------------------
duke@0 1062 // | Data entries... |
duke@0 1063 // | (variable size) |
duke@0 1064 // | |
duke@0 1065 // . .
duke@0 1066 // . .
duke@0 1067 // . .
duke@0 1068 // | |
duke@0 1069 // -----------------------------
duke@0 1070 //
duke@0 1071 // The data entry area is a heterogeneous array of DataLayouts. Each
duke@0 1072 // DataLayout in the array corresponds to a specific bytecode in the
duke@0 1073 // method. The entries in the array are sorted by the corresponding
duke@0 1074 // bytecode. Access to the data is via resource-allocated ProfileData,
duke@0 1075 // which point to the underlying blocks of DataLayout structures.
duke@0 1076 //
duke@0 1077 // During interpretation, if profiling in enabled, the interpreter
duke@0 1078 // maintains a method data pointer (mdp), which points at the entry
duke@0 1079 // in the array corresponding to the current bci. In the course of
duke@0 1080 // intepretation, when a bytecode is encountered that has profile data
duke@0 1081 // associated with it, the entry pointed to by mdp is updated, then the
duke@0 1082 // mdp is adjusted to point to the next appropriate DataLayout. If mdp
duke@0 1083 // is NULL to begin with, the interpreter assumes that the current method
duke@0 1084 // is not (yet) being profiled.
duke@0 1085 //
duke@0 1086 // In methodDataOop parlance, "dp" is a "data pointer", the actual address
duke@0 1087 // of a DataLayout element. A "di" is a "data index", the offset in bytes
duke@0 1088 // from the base of the data entry array. A "displacement" is the byte offset
duke@0 1089 // in certain ProfileData objects that indicate the amount the mdp must be
duke@0 1090 // adjusted in the event of a change in control flow.
duke@0 1091 //
duke@0 1092
duke@0 1093 class methodDataOopDesc : public oopDesc {
duke@0 1094 friend class VMStructs;
duke@0 1095 private:
duke@0 1096 friend class ProfileData;
duke@0 1097
duke@0 1098 // Back pointer to the methodOop
duke@0 1099 methodOop _method;
duke@0 1100
duke@0 1101 // Size of this oop in bytes
duke@0 1102 int _size;
duke@0 1103
duke@0 1104 // Cached hint for bci_to_dp and bci_to_data
duke@0 1105 int _hint_di;
duke@0 1106
duke@0 1107 // Whole-method sticky bits and flags
duke@0 1108 public:
duke@0 1109 enum {
duke@0 1110 _trap_hist_limit = 16, // decoupled from Deoptimization::Reason_LIMIT
duke@0 1111 _trap_hist_mask = max_jubyte,
duke@0 1112 _extra_data_count = 4 // extra DataLayout headers, for trap history
duke@0 1113 }; // Public flag values
duke@0 1114 private:
duke@0 1115 uint _nof_decompiles; // count of all nmethod removals
duke@0 1116 uint _nof_overflow_recompiles; // recompile count, excluding recomp. bits
duke@0 1117 uint _nof_overflow_traps; // trap count, excluding _trap_hist
duke@0 1118 union {
duke@0 1119 intptr_t _align;
duke@0 1120 u1 _array[_trap_hist_limit];
duke@0 1121 } _trap_hist;
duke@0 1122
duke@0 1123 // Support for interprocedural escape analysis, from Thomas Kotzmann.
duke@0 1124 intx _eflags; // flags on escape information
duke@0 1125 intx _arg_local; // bit set of non-escaping arguments
duke@0 1126 intx _arg_stack; // bit set of stack-allocatable arguments
duke@0 1127 intx _arg_returned; // bit set of returned arguments
duke@0 1128
duke@0 1129 int _creation_mileage; // method mileage at MDO creation
duke@0 1130
duke@0 1131 // Size of _data array in bytes. (Excludes header and extra_data fields.)
duke@0 1132 int _data_size;
duke@0 1133
duke@0 1134 // Beginning of the data entries
duke@0 1135 intptr_t _data[1];
duke@0 1136
duke@0 1137 // Helper for size computation
duke@0 1138 static int compute_data_size(BytecodeStream* stream);
duke@0 1139 static int bytecode_cell_count(Bytecodes::Code code);
duke@0 1140 enum { no_profile_data = -1, variable_cell_count = -2 };
duke@0 1141
duke@0 1142 // Helper for initialization
duke@0 1143 DataLayout* data_layout_at(int data_index) {
duke@0 1144 assert(data_index % sizeof(intptr_t) == 0, "unaligned");
duke@0 1145 return (DataLayout*) (((address)_data) + data_index);
duke@0 1146 }
duke@0 1147
duke@0 1148 // Initialize an individual data segment. Returns the size of
duke@0 1149 // the segment in bytes.
duke@0 1150 int initialize_data(BytecodeStream* stream, int data_index);
duke@0 1151
duke@0 1152 // Helper for data_at
duke@0 1153 DataLayout* limit_data_position() {
duke@0 1154 return (DataLayout*)((address)data_base() + _data_size);
duke@0 1155 }
duke@0 1156 bool out_of_bounds(int data_index) {
duke@0 1157 return data_index >= data_size();
duke@0 1158 }
duke@0 1159
duke@0 1160 // Give each of the data entries a chance to perform specific
duke@0 1161 // data initialization.
duke@0 1162 void post_initialize(BytecodeStream* stream);
duke@0 1163
duke@0 1164 // hint accessors
duke@0 1165 int hint_di() const { return _hint_di; }
duke@0 1166 void set_hint_di(int di) {
duke@0 1167 assert(!out_of_bounds(di), "hint_di out of bounds");
duke@0 1168 _hint_di = di;
duke@0 1169 }
duke@0 1170 ProfileData* data_before(int bci) {
duke@0 1171 // avoid SEGV on this edge case
duke@0 1172 if (data_size() == 0)
duke@0 1173 return NULL;
duke@0 1174 int hint = hint_di();
duke@0 1175 if (data_layout_at(hint)->bci() <= bci)
duke@0 1176 return data_at(hint);
duke@0 1177 return first_data();
duke@0 1178 }
duke@0 1179
duke@0 1180 // What is the index of the first data entry?
duke@0 1181 int first_di() { return 0; }
duke@0 1182
duke@0 1183 // Find or create an extra ProfileData:
duke@0 1184 ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
duke@0 1185
duke@0 1186 public:
duke@0 1187 static int header_size() {
duke@0 1188 return sizeof(methodDataOopDesc)/wordSize;
duke@0 1189 }
duke@0 1190
duke@0 1191 // Compute the size of a methodDataOop before it is created.
duke@0 1192 static int compute_allocation_size_in_bytes(methodHandle method);
duke@0 1193 static int compute_allocation_size_in_words(methodHandle method);
duke@0 1194 static int compute_extra_data_count(int data_size, int empty_bc_count);
duke@0 1195
duke@0 1196 // Determine if a given bytecode can have profile information.
duke@0 1197 static bool bytecode_has_profile(Bytecodes::Code code) {
duke@0 1198 return bytecode_cell_count(code) != no_profile_data;
duke@0 1199 }
duke@0 1200
duke@0 1201 // Perform initialization of a new methodDataOop
duke@0 1202 void initialize(methodHandle method);
duke@0 1203
duke@0 1204 // My size
duke@0 1205 int object_size_in_bytes() { return _size; }
duke@0 1206 int object_size() {
duke@0 1207 return align_object_size(align_size_up(_size, BytesPerWord)/BytesPerWord);
duke@0 1208 }
duke@0 1209
duke@0 1210 int creation_mileage() const { return _creation_mileage; }
duke@0 1211 void set_creation_mileage(int x) { _creation_mileage = x; }
duke@0 1212 bool is_mature() const; // consult mileage and ProfileMaturityPercentage
duke@0 1213 static int mileage_of(methodOop m);
duke@0 1214
duke@0 1215 // Support for interprocedural escape analysis, from Thomas Kotzmann.
duke@0 1216 enum EscapeFlag {
duke@0 1217 estimated = 1 << 0,
duke@0 1218 return_local = 1 << 1
duke@0 1219 };
duke@0 1220
duke@0 1221 intx eflags() { return _eflags; }
duke@0 1222 intx arg_local() { return _arg_local; }
duke@0 1223 intx arg_stack() { return _arg_stack; }
duke@0 1224 intx arg_returned() { return _arg_returned; }
duke@0 1225
duke@0 1226 void set_eflags(intx v) { _eflags = v; }
duke@0 1227 void set_arg_local(intx v) { _arg_local = v; }
duke@0 1228 void set_arg_stack(intx v) { _arg_stack = v; }
duke@0 1229 void set_arg_returned(intx v) { _arg_returned = v; }
duke@0 1230
duke@0 1231 void clear_escape_info() { _eflags = _arg_local = _arg_stack = _arg_returned = 0; }
duke@0 1232
duke@0 1233 // Location and size of data area
duke@0 1234 address data_base() const {
duke@0 1235 return (address) _data;
duke@0 1236 }
duke@0 1237 int data_size() {
duke@0 1238 return _data_size;
duke@0 1239 }
duke@0 1240
duke@0 1241 // Accessors
duke@0 1242 methodOop method() { return _method; }
duke@0 1243
duke@0 1244 // Get the data at an arbitrary (sort of) data index.
duke@0 1245 ProfileData* data_at(int data_index);
duke@0 1246
duke@0 1247 // Walk through the data in order.
duke@0 1248 ProfileData* first_data() { return data_at(first_di()); }
duke@0 1249 ProfileData* next_data(ProfileData* current);
duke@0 1250 bool is_valid(ProfileData* current) { return current != NULL; }
duke@0 1251
duke@0 1252 // Convert a dp (data pointer) to a di (data index).
duke@0 1253 int dp_to_di(address dp) {
duke@0 1254 return dp - ((address)_data);
duke@0 1255 }
duke@0 1256
duke@0 1257 address di_to_dp(int di) {
duke@0 1258 return (address)data_layout_at(di);
duke@0 1259 }
duke@0 1260
duke@0 1261 // bci to di/dp conversion.
duke@0 1262 address bci_to_dp(int bci);
duke@0 1263 int bci_to_di(int bci) {
duke@0 1264 return dp_to_di(bci_to_dp(bci));
duke@0 1265 }
duke@0 1266
duke@0 1267 // Get the data at an arbitrary bci, or NULL if there is none.
duke@0 1268 ProfileData* bci_to_data(int bci);
duke@0 1269
duke@0 1270 // Same, but try to create an extra_data record if one is needed:
duke@0 1271 ProfileData* allocate_bci_to_data(int bci) {
duke@0 1272 ProfileData* data = bci_to_data(bci);
duke@0 1273 return (data != NULL) ? data : bci_to_extra_data(bci, true);
duke@0 1274 }
duke@0 1275
duke@0 1276 // Add a handful of extra data records, for trap tracking.
duke@0 1277 DataLayout* extra_data_base() { return limit_data_position(); }
duke@0 1278 DataLayout* extra_data_limit() { return (DataLayout*)((address)this + object_size_in_bytes()); }
duke@0 1279 int extra_data_size() { return (address)extra_data_limit()
duke@0 1280 - (address)extra_data_base(); }
duke@0 1281 static DataLayout* next_extra(DataLayout* dp) { return (DataLayout*)((address)dp + in_bytes(DataLayout::cell_offset(0))); }
duke@0 1282
duke@0 1283 // Return (uint)-1 for overflow.
duke@0 1284 uint trap_count(int reason) const {
duke@0 1285 assert((uint)reason < _trap_hist_limit, "oob");
duke@0 1286 return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1;
duke@0 1287 }
duke@0 1288 // For loops:
duke@0 1289 static uint trap_reason_limit() { return _trap_hist_limit; }
duke@0 1290 static uint trap_count_limit() { return _trap_hist_mask; }
duke@0 1291 uint inc_trap_count(int reason) {
duke@0 1292 // Count another trap, anywhere in this method.
duke@0 1293 assert(reason >= 0, "must be single trap");
duke@0 1294 if ((uint)reason < _trap_hist_limit) {
duke@0 1295 uint cnt1 = 1 + _trap_hist._array[reason];
duke@0 1296 if ((cnt1 & _trap_hist_mask) != 0) { // if no counter overflow...
duke@0 1297 _trap_hist._array[reason] = cnt1;
duke@0 1298 return cnt1;
duke@0 1299 } else {
duke@0 1300 return _trap_hist_mask + (++_nof_overflow_traps);
duke@0 1301 }
duke@0 1302 } else {
duke@0 1303 // Could not represent the count in the histogram.
duke@0 1304 return (++_nof_overflow_traps);
duke@0 1305 }
duke@0 1306 }
duke@0 1307
duke@0 1308 uint overflow_trap_count() const {
duke@0 1309 return _nof_overflow_traps;
duke@0 1310 }
duke@0 1311 uint overflow_recompile_count() const {
duke@0 1312 return _nof_overflow_recompiles;
duke@0 1313 }
duke@0 1314 void inc_overflow_recompile_count() {
duke@0 1315 _nof_overflow_recompiles += 1;
duke@0 1316 }
duke@0 1317 uint decompile_count() const {
duke@0 1318 return _nof_decompiles;
duke@0 1319 }
duke@0 1320 void inc_decompile_count() {
duke@0 1321 _nof_decompiles += 1;
duke@0 1322 }
duke@0 1323
duke@0 1324 // Support for code generation
duke@0 1325 static ByteSize data_offset() {
duke@0 1326 return byte_offset_of(methodDataOopDesc, _data[0]);
duke@0 1327 }
duke@0 1328
duke@0 1329 // GC support
duke@0 1330 oop* adr_method() const { return (oop*)&_method; }
duke@0 1331 bool object_is_parsable() const { return _size != 0; }
duke@0 1332 void set_object_is_parsable(int object_size_in_bytes) { _size = object_size_in_bytes; }
duke@0 1333
duke@0 1334 #ifndef PRODUCT
duke@0 1335 // printing support for method data
duke@0 1336 void print_data_on(outputStream* st);
duke@0 1337 #endif
duke@0 1338
duke@0 1339 // verification
duke@0 1340 void verify_data_on(outputStream* st);
duke@0 1341 };