annotate src/share/vm/oops/methodData.hpp @ 5349:190899198332

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