src/share/vm/oops/methodDataOop.hpp

Wed, 17 Mar 2010 11:01:05 +0100

author
fparain
date
Wed, 17 Mar 2010 11:01:05 +0100
changeset 1759
e392695de029
parent 1686
576e77447e3c
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6935224: Adding new DTrace probes to work with Palantir
Summary: Adding probes related to thread scheduling and class initialization
Reviewed-by: kamg, never

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

mercurial