annotate src/share/vm/oops/methodData.hpp @ 5479:d13d7aba8c12

8023657: New type profiling points: arguments to call Summary: x86 interpreter and c1 type profiling for arguments at calls Reviewed-by: kvn, twisti
author roland
date Wed, 09 Oct 2013 16:32:21 +0200
parents 190899198332
children ce0cc25bc5e2
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,
roland@5479 120 arg_info_data_tag,
roland@5479 121 call_type_data_tag,
roland@5479 122 virtual_call_type_data_tag
duke@0 123 };
duke@0 124
duke@0 125 enum {
duke@0 126 // The _struct._flags word is formatted as [trap_state:4 | flags:4].
duke@0 127 // The trap state breaks down further as [recompile:1 | reason:3].
duke@0 128 // This further breakdown is defined in deoptimization.cpp.
duke@0 129 // See Deoptimization::trap_state_reason for an assert that
duke@0 130 // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
duke@0 131 //
duke@0 132 // The trap_state is collected only if ProfileTraps is true.
duke@0 133 trap_bits = 1+3, // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
duke@0 134 trap_shift = BitsPerByte - trap_bits,
duke@0 135 trap_mask = right_n_bits(trap_bits),
duke@0 136 trap_mask_in_place = (trap_mask << trap_shift),
duke@0 137 flag_limit = trap_shift,
duke@0 138 flag_mask = right_n_bits(flag_limit),
duke@0 139 first_flag = 0
duke@0 140 };
duke@0 141
duke@0 142 // Size computation
duke@0 143 static int header_size_in_bytes() {
duke@0 144 return cell_size;
duke@0 145 }
duke@0 146 static int header_size_in_cells() {
duke@0 147 return 1;
duke@0 148 }
duke@0 149
duke@0 150 static int compute_size_in_bytes(int cell_count) {
duke@0 151 return header_size_in_bytes() + cell_count * cell_size;
duke@0 152 }
duke@0 153
duke@0 154 // Initialization
duke@0 155 void initialize(u1 tag, u2 bci, int cell_count);
duke@0 156
duke@0 157 // Accessors
duke@0 158 u1 tag() {
duke@0 159 return _header._struct._tag;
duke@0 160 }
duke@0 161
duke@0 162 // Return a few bits of trap state. Range is [0..trap_mask].
duke@0 163 // The state tells if traps with zero, one, or many reasons have occurred.
duke@0 164 // It also tells whether zero or many recompilations have occurred.
duke@0 165 // The associated trap histogram in the MDO itself tells whether
duke@0 166 // traps are common or not. If a BCI shows that a trap X has
duke@0 167 // occurred, and the MDO shows N occurrences of X, we make the
duke@0 168 // simplifying assumption that all N occurrences can be blamed
duke@0 169 // on that BCI.
roland@5479 170 int trap_state() const {
duke@0 171 return ((_header._struct._flags >> trap_shift) & trap_mask);
duke@0 172 }
duke@0 173
duke@0 174 void set_trap_state(int new_state) {
duke@0 175 assert(ProfileTraps, "used only under +ProfileTraps");
duke@0 176 uint old_flags = (_header._struct._flags & flag_mask);
duke@0 177 _header._struct._flags = (new_state << trap_shift) | old_flags;
duke@0 178 }
duke@0 179
roland@5479 180 u1 flags() const {
duke@0 181 return _header._struct._flags;
duke@0 182 }
duke@0 183
roland@5479 184 u2 bci() const {
duke@0 185 return _header._struct._bci;
duke@0 186 }
duke@0 187
duke@0 188 void set_header(intptr_t value) {
duke@0 189 _header._bits = value;
duke@0 190 }
duke@0 191 void release_set_header(intptr_t value) {
duke@0 192 OrderAccess::release_store_ptr(&_header._bits, value);
duke@0 193 }
duke@0 194 intptr_t header() {
duke@0 195 return _header._bits;
duke@0 196 }
duke@0 197 void set_cell_at(int index, intptr_t value) {
duke@0 198 _cells[index] = value;
duke@0 199 }
duke@0 200 void release_set_cell_at(int index, intptr_t value) {
duke@0 201 OrderAccess::release_store_ptr(&_cells[index], value);
duke@0 202 }
roland@5479 203 intptr_t cell_at(int index) const {
duke@0 204 return _cells[index];
duke@0 205 }
duke@0 206
duke@0 207 void set_flag_at(int flag_number) {
duke@0 208 assert(flag_number < flag_limit, "oob");
duke@0 209 _header._struct._flags |= (0x1 << flag_number);
duke@0 210 }
roland@5479 211 bool flag_at(int flag_number) const {
duke@0 212 assert(flag_number < flag_limit, "oob");
duke@0 213 return (_header._struct._flags & (0x1 << flag_number)) != 0;
duke@0 214 }
duke@0 215
duke@0 216 // Low-level support for code generation.
duke@0 217 static ByteSize header_offset() {
duke@0 218 return byte_offset_of(DataLayout, _header);
duke@0 219 }
duke@0 220 static ByteSize tag_offset() {
duke@0 221 return byte_offset_of(DataLayout, _header._struct._tag);
duke@0 222 }
duke@0 223 static ByteSize flags_offset() {
duke@0 224 return byte_offset_of(DataLayout, _header._struct._flags);
duke@0 225 }
duke@0 226 static ByteSize bci_offset() {
duke@0 227 return byte_offset_of(DataLayout, _header._struct._bci);
duke@0 228 }
duke@0 229 static ByteSize cell_offset(int index) {
coleenp@2180 230 return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
duke@0 231 }
duke@0 232 // Return a value which, when or-ed as a byte into _flags, sets the flag.
duke@0 233 static int flag_number_to_byte_constant(int flag_number) {
duke@0 234 assert(0 <= flag_number && flag_number < flag_limit, "oob");
duke@0 235 DataLayout temp; temp.set_header(0);
duke@0 236 temp.set_flag_at(flag_number);
duke@0 237 return temp._header._struct._flags;
duke@0 238 }
duke@0 239 // Return a value which, when or-ed as a word into _header, sets the flag.
duke@0 240 static intptr_t flag_mask_to_header_mask(int byte_constant) {
duke@0 241 DataLayout temp; temp.set_header(0);
duke@0 242 temp._header._struct._flags = byte_constant;
duke@0 243 return temp._header._bits;
duke@0 244 }
ysr@941 245
coleenp@3602 246 ProfileData* data_in();
coleenp@3602 247
ysr@941 248 // GC support
coleenp@3602 249 void clean_weak_klass_links(BoolObjectClosure* cl);
duke@0 250 };
duke@0 251
duke@0 252
duke@0 253 // ProfileData class hierarchy
duke@0 254 class ProfileData;
duke@0 255 class BitData;
duke@0 256 class CounterData;
duke@0 257 class ReceiverTypeData;
duke@0 258 class VirtualCallData;
roland@5479 259 class VirtualCallTypeData;
duke@0 260 class RetData;
roland@5479 261 class CallTypeData;
duke@0 262 class JumpData;
duke@0 263 class BranchData;
duke@0 264 class ArrayData;
duke@0 265 class MultiBranchData;
kvn@45 266 class ArgInfoData;
duke@0 267
duke@0 268 // ProfileData
duke@0 269 //
duke@0 270 // A ProfileData object is created to refer to a section of profiling
duke@0 271 // data in a structured way.
duke@0 272 class ProfileData : public ResourceObj {
roland@5479 273 friend class TypeEntries;
roland@5479 274 friend class TypeStackSlotEntries;
duke@0 275 private:
duke@0 276 #ifndef PRODUCT
duke@0 277 enum {
duke@0 278 tab_width_one = 16,
duke@0 279 tab_width_two = 36
duke@0 280 };
duke@0 281 #endif // !PRODUCT
duke@0 282
duke@0 283 // This is a pointer to a section of profiling data.
duke@0 284 DataLayout* _data;
duke@0 285
duke@0 286 protected:
duke@0 287 DataLayout* data() { return _data; }
roland@5479 288 const DataLayout* data() const { return _data; }
duke@0 289
duke@0 290 enum {
duke@0 291 cell_size = DataLayout::cell_size
duke@0 292 };
duke@0 293
duke@0 294 public:
duke@0 295 // How many cells are in this?
roland@5479 296 virtual int cell_count() const {
duke@0 297 ShouldNotReachHere();
duke@0 298 return -1;
duke@0 299 }
duke@0 300
duke@0 301 // Return the size of this data.
duke@0 302 int size_in_bytes() {
duke@0 303 return DataLayout::compute_size_in_bytes(cell_count());
duke@0 304 }
duke@0 305
duke@0 306 protected:
duke@0 307 // Low-level accessors for underlying data
duke@0 308 void set_intptr_at(int index, intptr_t value) {
duke@0 309 assert(0 <= index && index < cell_count(), "oob");
duke@0 310 data()->set_cell_at(index, value);
duke@0 311 }
duke@0 312 void release_set_intptr_at(int index, intptr_t value) {
duke@0 313 assert(0 <= index && index < cell_count(), "oob");
duke@0 314 data()->release_set_cell_at(index, value);
duke@0 315 }
roland@5479 316 intptr_t intptr_at(int index) const {
duke@0 317 assert(0 <= index && index < cell_count(), "oob");
duke@0 318 return data()->cell_at(index);
duke@0 319 }
duke@0 320 void set_uint_at(int index, uint value) {
duke@0 321 set_intptr_at(index, (intptr_t) value);
duke@0 322 }
duke@0 323 void release_set_uint_at(int index, uint value) {
duke@0 324 release_set_intptr_at(index, (intptr_t) value);
duke@0 325 }
roland@5479 326 uint uint_at(int index) const {
duke@0 327 return (uint)intptr_at(index);
duke@0 328 }
duke@0 329 void set_int_at(int index, int value) {
duke@0 330 set_intptr_at(index, (intptr_t) value);
duke@0 331 }
duke@0 332 void release_set_int_at(int index, int value) {
duke@0 333 release_set_intptr_at(index, (intptr_t) value);
duke@0 334 }
roland@5479 335 int int_at(int index) const {
duke@0 336 return (int)intptr_at(index);
duke@0 337 }
roland@5479 338 int int_at_unchecked(int index) const {
duke@0 339 return (int)data()->cell_at(index);
duke@0 340 }
duke@0 341 void set_oop_at(int index, oop value) {
hseigel@5349 342 set_intptr_at(index, cast_from_oop<intptr_t>(value));
duke@0 343 }
roland@5479 344 oop oop_at(int index) const {
hseigel@5349 345 return cast_to_oop(intptr_at(index));
duke@0 346 }
duke@0 347
duke@0 348 void set_flag_at(int flag_number) {
duke@0 349 data()->set_flag_at(flag_number);
duke@0 350 }
roland@5479 351 bool flag_at(int flag_number) const {
duke@0 352 return data()->flag_at(flag_number);
duke@0 353 }
duke@0 354
duke@0 355 // two convenient imports for use by subclasses:
duke@0 356 static ByteSize cell_offset(int index) {
duke@0 357 return DataLayout::cell_offset(index);
duke@0 358 }
duke@0 359 static int flag_number_to_byte_constant(int flag_number) {
duke@0 360 return DataLayout::flag_number_to_byte_constant(flag_number);
duke@0 361 }
duke@0 362
duke@0 363 ProfileData(DataLayout* data) {
duke@0 364 _data = data;
duke@0 365 }
duke@0 366
duke@0 367 public:
duke@0 368 // Constructor for invalid ProfileData.
duke@0 369 ProfileData();
duke@0 370
roland@5479 371 u2 bci() const {
duke@0 372 return data()->bci();
duke@0 373 }
duke@0 374
duke@0 375 address dp() {
duke@0 376 return (address)_data;
duke@0 377 }
duke@0 378
roland@5479 379 int trap_state() const {
duke@0 380 return data()->trap_state();
duke@0 381 }
duke@0 382 void set_trap_state(int new_state) {
duke@0 383 data()->set_trap_state(new_state);
duke@0 384 }
duke@0 385
duke@0 386 // Type checking
roland@5479 387 virtual bool is_BitData() const { return false; }
roland@5479 388 virtual bool is_CounterData() const { return false; }
roland@5479 389 virtual bool is_JumpData() const { return false; }
roland@5479 390 virtual bool is_ReceiverTypeData()const { return false; }
roland@5479 391 virtual bool is_VirtualCallData() const { return false; }
roland@5479 392 virtual bool is_RetData() const { return false; }
roland@5479 393 virtual bool is_BranchData() const { return false; }
roland@5479 394 virtual bool is_ArrayData() const { return false; }
roland@5479 395 virtual bool is_MultiBranchData() const { return false; }
roland@5479 396 virtual bool is_ArgInfoData() const { return false; }
roland@5479 397 virtual bool is_CallTypeData() const { return false; }
roland@5479 398 virtual bool is_VirtualCallTypeData()const { return false; }
kvn@45 399
duke@0 400
roland@5479 401 BitData* as_BitData() const {
duke@0 402 assert(is_BitData(), "wrong type");
duke@0 403 return is_BitData() ? (BitData*) this : NULL;
duke@0 404 }
roland@5479 405 CounterData* as_CounterData() const {
duke@0 406 assert(is_CounterData(), "wrong type");
duke@0 407 return is_CounterData() ? (CounterData*) this : NULL;
duke@0 408 }
roland@5479 409 JumpData* as_JumpData() const {
duke@0 410 assert(is_JumpData(), "wrong type");
duke@0 411 return is_JumpData() ? (JumpData*) this : NULL;
duke@0 412 }
roland@5479 413 ReceiverTypeData* as_ReceiverTypeData() const {
duke@0 414 assert(is_ReceiverTypeData(), "wrong type");
duke@0 415 return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
duke@0 416 }
roland@5479 417 VirtualCallData* as_VirtualCallData() const {
duke@0 418 assert(is_VirtualCallData(), "wrong type");
duke@0 419 return is_VirtualCallData() ? (VirtualCallData*)this : NULL;
duke@0 420 }
roland@5479 421 RetData* as_RetData() const {
duke@0 422 assert(is_RetData(), "wrong type");
duke@0 423 return is_RetData() ? (RetData*) this : NULL;
duke@0 424 }
roland@5479 425 BranchData* as_BranchData() const {
duke@0 426 assert(is_BranchData(), "wrong type");
duke@0 427 return is_BranchData() ? (BranchData*) this : NULL;
duke@0 428 }
roland@5479 429 ArrayData* as_ArrayData() const {
duke@0 430 assert(is_ArrayData(), "wrong type");
duke@0 431 return is_ArrayData() ? (ArrayData*) this : NULL;
duke@0 432 }
roland@5479 433 MultiBranchData* as_MultiBranchData() const {
duke@0 434 assert(is_MultiBranchData(), "wrong type");
duke@0 435 return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
duke@0 436 }
roland@5479 437 ArgInfoData* as_ArgInfoData() const {
kvn@45 438 assert(is_ArgInfoData(), "wrong type");
kvn@45 439 return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
kvn@45 440 }
roland@5479 441 CallTypeData* as_CallTypeData() const {
roland@5479 442 assert(is_CallTypeData(), "wrong type");
roland@5479 443 return is_CallTypeData() ? (CallTypeData*)this : NULL;
roland@5479 444 }
roland@5479 445 VirtualCallTypeData* as_VirtualCallTypeData() const {
roland@5479 446 assert(is_VirtualCallTypeData(), "wrong type");
roland@5479 447 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
roland@5479 448 }
duke@0 449
duke@0 450
duke@0 451 // Subclass specific initialization
coleenp@3602 452 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
duke@0 453
duke@0 454 // GC support
coleenp@3602 455 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
duke@0 456
duke@0 457 // CI translation: ProfileData can represent both MethodDataOop data
duke@0 458 // as well as CIMethodData data. This function is provided for translating
duke@0 459 // an oop in a ProfileData to the ci equivalent. Generally speaking,
duke@0 460 // most ProfileData don't require any translation, so we provide the null
duke@0 461 // translation here, and the required translators are in the ci subclasses.
roland@5479 462 virtual void translate_from(const ProfileData* data) {}
duke@0 463
roland@5479 464 virtual void print_data_on(outputStream* st) const {
duke@0 465 ShouldNotReachHere();
duke@0 466 }
duke@0 467
duke@0 468 #ifndef PRODUCT
roland@5479 469 void print_shared(outputStream* st, const char* name) const;
roland@5479 470 void tab(outputStream* st, bool first = false) const;
duke@0 471 #endif
duke@0 472 };
duke@0 473
duke@0 474 // BitData
duke@0 475 //
duke@0 476 // A BitData holds a flag or two in its header.
duke@0 477 class BitData : public ProfileData {
duke@0 478 protected:
duke@0 479 enum {
duke@0 480 // null_seen:
duke@0 481 // saw a null operand (cast/aastore/instanceof)
duke@0 482 null_seen_flag = DataLayout::first_flag + 0
duke@0 483 };
duke@0 484 enum { bit_cell_count = 0 }; // no additional data fields needed.
duke@0 485 public:
duke@0 486 BitData(DataLayout* layout) : ProfileData(layout) {
duke@0 487 }
duke@0 488
roland@5479 489 virtual bool is_BitData() const { return true; }
duke@0 490
duke@0 491 static int static_cell_count() {
duke@0 492 return bit_cell_count;
duke@0 493 }
duke@0 494
roland@5479 495 virtual int cell_count() const {
duke@0 496 return static_cell_count();
duke@0 497 }
duke@0 498
duke@0 499 // Accessor
duke@0 500
duke@0 501 // The null_seen flag bit is specially known to the interpreter.
duke@0 502 // Consulting it allows the compiler to avoid setting up null_check traps.
duke@0 503 bool null_seen() { return flag_at(null_seen_flag); }
duke@0 504 void set_null_seen() { set_flag_at(null_seen_flag); }
duke@0 505
duke@0 506
duke@0 507 // Code generation support
duke@0 508 static int null_seen_byte_constant() {
duke@0 509 return flag_number_to_byte_constant(null_seen_flag);
duke@0 510 }
duke@0 511
duke@0 512 static ByteSize bit_data_size() {
duke@0 513 return cell_offset(bit_cell_count);
duke@0 514 }
duke@0 515
duke@0 516 #ifndef PRODUCT
roland@5479 517 void print_data_on(outputStream* st) const;
duke@0 518 #endif
duke@0 519 };
duke@0 520
duke@0 521 // CounterData
duke@0 522 //
duke@0 523 // A CounterData corresponds to a simple counter.
duke@0 524 class CounterData : public BitData {
duke@0 525 protected:
duke@0 526 enum {
duke@0 527 count_off,
duke@0 528 counter_cell_count
duke@0 529 };
duke@0 530 public:
duke@0 531 CounterData(DataLayout* layout) : BitData(layout) {}
duke@0 532
roland@5479 533 virtual bool is_CounterData() const { return true; }
duke@0 534
duke@0 535 static int static_cell_count() {
duke@0 536 return counter_cell_count;
duke@0 537 }
duke@0 538
roland@5479 539 virtual int cell_count() const {
duke@0 540 return static_cell_count();
duke@0 541 }
duke@0 542
duke@0 543 // Direct accessor
roland@5479 544 uint count() const {
duke@0 545 return uint_at(count_off);
duke@0 546 }
duke@0 547
duke@0 548 // Code generation support
duke@0 549 static ByteSize count_offset() {
duke@0 550 return cell_offset(count_off);
duke@0 551 }
duke@0 552 static ByteSize counter_data_size() {
duke@0 553 return cell_offset(counter_cell_count);
duke@0 554 }
duke@0 555
kvn@1251 556 void set_count(uint count) {
kvn@1251 557 set_uint_at(count_off, count);
kvn@1251 558 }
kvn@1251 559
duke@0 560 #ifndef PRODUCT
roland@5479 561 void print_data_on(outputStream* st) const;
duke@0 562 #endif
duke@0 563 };
duke@0 564
duke@0 565 // JumpData
duke@0 566 //
duke@0 567 // A JumpData is used to access profiling information for a direct
duke@0 568 // branch. It is a counter, used for counting the number of branches,
duke@0 569 // plus a data displacement, used for realigning the data pointer to
duke@0 570 // the corresponding target bci.
duke@0 571 class JumpData : public ProfileData {
duke@0 572 protected:
duke@0 573 enum {
duke@0 574 taken_off_set,
duke@0 575 displacement_off_set,
duke@0 576 jump_cell_count
duke@0 577 };
duke@0 578
duke@0 579 void set_displacement(int displacement) {
duke@0 580 set_int_at(displacement_off_set, displacement);
duke@0 581 }
duke@0 582
duke@0 583 public:
duke@0 584 JumpData(DataLayout* layout) : ProfileData(layout) {
duke@0 585 assert(layout->tag() == DataLayout::jump_data_tag ||
duke@0 586 layout->tag() == DataLayout::branch_data_tag, "wrong type");
duke@0 587 }
duke@0 588
roland@5479 589 virtual bool is_JumpData() const { return true; }
duke@0 590
duke@0 591 static int static_cell_count() {
duke@0 592 return jump_cell_count;
duke@0 593 }
duke@0 594
roland@5479 595 virtual int cell_count() const {
duke@0 596 return static_cell_count();
duke@0 597 }
duke@0 598
duke@0 599 // Direct accessor
roland@5479 600 uint taken() const {
duke@0 601 return uint_at(taken_off_set);
duke@0 602 }
never@2670 603
never@2670 604 void set_taken(uint cnt) {
never@2670 605 set_uint_at(taken_off_set, cnt);
never@2670 606 }
never@2670 607
duke@0 608 // Saturating counter
duke@0 609 uint inc_taken() {
duke@0 610 uint cnt = taken() + 1;
duke@0 611 // Did we wrap? Will compiler screw us??
duke@0 612 if (cnt == 0) cnt--;
duke@0 613 set_uint_at(taken_off_set, cnt);
duke@0 614 return cnt;
duke@0 615 }
duke@0 616
roland@5479 617 int displacement() const {
duke@0 618 return int_at(displacement_off_set);
duke@0 619 }
duke@0 620
duke@0 621 // Code generation support
duke@0 622 static ByteSize taken_offset() {
duke@0 623 return cell_offset(taken_off_set);
duke@0 624 }
duke@0 625
duke@0 626 static ByteSize displacement_offset() {
duke@0 627 return cell_offset(displacement_off_set);
duke@0 628 }
duke@0 629
duke@0 630 // Specific initialization.
coleenp@3602 631 void post_initialize(BytecodeStream* stream, MethodData* mdo);
duke@0 632
duke@0 633 #ifndef PRODUCT
roland@5479 634 void print_data_on(outputStream* st) const;
roland@5479 635 #endif
roland@5479 636 };
roland@5479 637
roland@5479 638 // Entries in a ProfileData object to record types: it can either be
roland@5479 639 // none (no profile), unknown (conflicting profile data) or a klass if
roland@5479 640 // a single one is seen. Whether a null reference was seen is also
roland@5479 641 // recorded. No counter is associated with the type and a single type
roland@5479 642 // is tracked (unlike VirtualCallData).
roland@5479 643 class TypeEntries {
roland@5479 644
roland@5479 645 public:
roland@5479 646
roland@5479 647 // A single cell is used to record information for a type:
roland@5479 648 // - the cell is initialized to 0
roland@5479 649 // - when a type is discovered it is stored in the cell
roland@5479 650 // - bit zero of the cell is used to record whether a null reference
roland@5479 651 // was encountered or not
roland@5479 652 // - bit 1 is set to record a conflict in the type information
roland@5479 653
roland@5479 654 enum {
roland@5479 655 null_seen = 1,
roland@5479 656 type_mask = ~null_seen,
roland@5479 657 type_unknown = 2,
roland@5479 658 status_bits = null_seen | type_unknown,
roland@5479 659 type_klass_mask = ~status_bits
roland@5479 660 };
roland@5479 661
roland@5479 662 // what to initialize a cell to
roland@5479 663 static intptr_t type_none() {
roland@5479 664 return 0;
roland@5479 665 }
roland@5479 666
roland@5479 667 // null seen = bit 0 set?
roland@5479 668 static bool was_null_seen(intptr_t v) {
roland@5479 669 return (v & null_seen) != 0;
roland@5479 670 }
roland@5479 671
roland@5479 672 // conflicting type information = bit 1 set?
roland@5479 673 static bool is_type_unknown(intptr_t v) {
roland@5479 674 return (v & type_unknown) != 0;
roland@5479 675 }
roland@5479 676
roland@5479 677 // not type information yet = all bits cleared, ignoring bit 0?
roland@5479 678 static bool is_type_none(intptr_t v) {
roland@5479 679 return (v & type_mask) == 0;
roland@5479 680 }
roland@5479 681
roland@5479 682 // recorded type: cell without bit 0 and 1
roland@5479 683 static intptr_t klass_part(intptr_t v) {
roland@5479 684 intptr_t r = v & type_klass_mask;
roland@5479 685 assert (r != 0, "invalid");
roland@5479 686 return r;
roland@5479 687 }
roland@5479 688
roland@5479 689 // type recorded
roland@5479 690 static Klass* valid_klass(intptr_t k) {
roland@5479 691 if (!is_type_none(k) &&
roland@5479 692 !is_type_unknown(k)) {
roland@5479 693 return (Klass*)klass_part(k);
roland@5479 694 } else {
roland@5479 695 return NULL;
roland@5479 696 }
roland@5479 697 }
roland@5479 698
roland@5479 699 static intptr_t with_status(intptr_t k, intptr_t in) {
roland@5479 700 return k | (in & status_bits);
roland@5479 701 }
roland@5479 702
roland@5479 703 static intptr_t with_status(Klass* k, intptr_t in) {
roland@5479 704 return with_status((intptr_t)k, in);
roland@5479 705 }
roland@5479 706
roland@5479 707 #ifndef PRODUCT
roland@5479 708 static void print_klass(outputStream* st, intptr_t k);
roland@5479 709 #endif
roland@5479 710
roland@5479 711 // GC support
roland@5479 712 static bool is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p);
roland@5479 713
roland@5479 714 protected:
roland@5479 715 // ProfileData object these entries are part of
roland@5479 716 ProfileData* _pd;
roland@5479 717 // offset within the ProfileData object where the entries start
roland@5479 718 const int _base_off;
roland@5479 719
roland@5479 720 TypeEntries(int base_off)
roland@5479 721 : _base_off(base_off), _pd(NULL) {}
roland@5479 722
roland@5479 723 void set_intptr_at(int index, intptr_t value) {
roland@5479 724 _pd->set_intptr_at(index, value);
roland@5479 725 }
roland@5479 726
roland@5479 727 intptr_t intptr_at(int index) const {
roland@5479 728 return _pd->intptr_at(index);
roland@5479 729 }
roland@5479 730
roland@5479 731 public:
roland@5479 732 void set_profile_data(ProfileData* pd) {
roland@5479 733 _pd = pd;
roland@5479 734 }
roland@5479 735 };
roland@5479 736
roland@5479 737 // Type entries used for arguments passed at a call and parameters on
roland@5479 738 // method entry. 2 cells per entry: one for the type encoded as in
roland@5479 739 // TypeEntries and one initialized with the stack slot where the
roland@5479 740 // profiled object is to be found so that the interpreter can locate
roland@5479 741 // it quickly.
roland@5479 742 class TypeStackSlotEntries : public TypeEntries {
roland@5479 743
roland@5479 744 private:
roland@5479 745 enum {
roland@5479 746 stack_slot_entry,
roland@5479 747 type_entry,
roland@5479 748 per_arg_cell_count
roland@5479 749 };
roland@5479 750
roland@5479 751 // Start with a header if needed. It stores the number of cells used
roland@5479 752 // for this call type information. Unless we collect only profiling
roland@5479 753 // for a single argument the number of cells is unknown statically.
roland@5479 754 static int header_cell_count() {
roland@5479 755 return (TypeProfileArgsLimit > 1) ? 1 : 0;
roland@5479 756 }
roland@5479 757
roland@5479 758 static int cell_count_local_offset() {
roland@5479 759 assert(arguments_profiling_enabled() && TypeProfileArgsLimit > 1, "no cell count");
roland@5479 760 return 0;
roland@5479 761 }
roland@5479 762
roland@5479 763 int cell_count_global_offset() const {
roland@5479 764 return _base_off + cell_count_local_offset();
roland@5479 765 }
roland@5479 766
roland@5479 767 // offset of cell for stack slot for entry i within ProfileData object
roland@5479 768 int stack_slot_global_offset(int i) const {
roland@5479 769 return _base_off + stack_slot_local_offset(i);
roland@5479 770 }
roland@5479 771
roland@5479 772 void check_number_of_arguments(int total) {
roland@5479 773 assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
roland@5479 774 }
roland@5479 775
roland@5479 776 // number of cells not counting the header
roland@5479 777 int cell_count_no_header() const {
roland@5479 778 return _pd->uint_at(cell_count_global_offset());
roland@5479 779 }
roland@5479 780
roland@5479 781 static bool arguments_profiling_enabled();
roland@5479 782 static void assert_arguments_profiling_enabled() {
roland@5479 783 assert(arguments_profiling_enabled(), "args profiling should be on");
roland@5479 784 }
roland@5479 785
roland@5479 786 protected:
roland@5479 787
roland@5479 788 // offset of cell for type for entry i within ProfileData object
roland@5479 789 int type_global_offset(int i) const {
roland@5479 790 return _base_off + type_local_offset(i);
roland@5479 791 }
roland@5479 792
roland@5479 793 public:
roland@5479 794
roland@5479 795 TypeStackSlotEntries(int base_off)
roland@5479 796 : TypeEntries(base_off) {}
roland@5479 797
roland@5479 798 static int compute_cell_count(BytecodeStream* stream);
roland@5479 799
roland@5479 800 static void initialize(DataLayout* dl, int base, int cell_count) {
roland@5479 801 if (TypeProfileArgsLimit > 1) {
roland@5479 802 int off = base + cell_count_local_offset();
roland@5479 803 dl->set_cell_at(off, cell_count - base - header_cell_count());
roland@5479 804 }
roland@5479 805 }
roland@5479 806
roland@5479 807 void post_initialize(BytecodeStream* stream);
roland@5479 808
roland@5479 809 int number_of_arguments() const {
roland@5479 810 assert_arguments_profiling_enabled();
roland@5479 811 if (TypeProfileArgsLimit > 1) {
roland@5479 812 int cell_count = cell_count_no_header();
roland@5479 813 int nb = cell_count / TypeStackSlotEntries::per_arg_count();
roland@5479 814 assert(nb > 0 && nb <= TypeProfileArgsLimit , "only when we profile args");
roland@5479 815 return nb;
roland@5479 816 } else {
roland@5479 817 assert(TypeProfileArgsLimit == 1, "at least one arg");
roland@5479 818 return 1;
roland@5479 819 }
roland@5479 820 }
roland@5479 821
roland@5479 822 int cell_count() const {
roland@5479 823 assert_arguments_profiling_enabled();
roland@5479 824 if (TypeProfileArgsLimit > 1) {
roland@5479 825 return _base_off + header_cell_count() + _pd->int_at_unchecked(cell_count_global_offset());
roland@5479 826 } else {
roland@5479 827 return _base_off + TypeStackSlotEntries::per_arg_count();
roland@5479 828 }
roland@5479 829 }
roland@5479 830
roland@5479 831 // offset of cell for stack slot for entry i within this block of cells for a TypeStackSlotEntries
roland@5479 832 static int stack_slot_local_offset(int i) {
roland@5479 833 assert_arguments_profiling_enabled();
roland@5479 834 return header_cell_count() + i * per_arg_cell_count + stack_slot_entry;
roland@5479 835 }
roland@5479 836
roland@5479 837 // offset of cell for type for entry i within this block of cells for a TypeStackSlotEntries
roland@5479 838 static int type_local_offset(int i) {
roland@5479 839 return header_cell_count() + i * per_arg_cell_count + type_entry;
roland@5479 840 }
roland@5479 841
roland@5479 842 // stack slot for entry i
roland@5479 843 uint stack_slot(int i) const {
roland@5479 844 assert(i >= 0 && i < number_of_arguments(), "oob");
roland@5479 845 return _pd->uint_at(stack_slot_global_offset(i));
roland@5479 846 }
roland@5479 847
roland@5479 848 // set stack slot for entry i
roland@5479 849 void set_stack_slot(int i, uint num) {
roland@5479 850 assert(i >= 0 && i < number_of_arguments(), "oob");
roland@5479 851 _pd->set_uint_at(stack_slot_global_offset(i), num);
roland@5479 852 }
roland@5479 853
roland@5479 854 // type for entry i
roland@5479 855 intptr_t type(int i) const {
roland@5479 856 assert(i >= 0 && i < number_of_arguments(), "oob");
roland@5479 857 return _pd->intptr_at(type_global_offset(i));
roland@5479 858 }
roland@5479 859
roland@5479 860 // set type for entry i
roland@5479 861 void set_type(int i, intptr_t k) {
roland@5479 862 assert(i >= 0 && i < number_of_arguments(), "oob");
roland@5479 863 _pd->set_intptr_at(type_global_offset(i), k);
roland@5479 864 }
roland@5479 865
roland@5479 866 static ByteSize per_arg_size() {
roland@5479 867 return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
roland@5479 868 }
roland@5479 869
roland@5479 870 static int per_arg_count() {
roland@5479 871 return per_arg_cell_count ;
roland@5479 872 }
roland@5479 873
roland@5479 874 // Code generation support
roland@5479 875 static ByteSize cell_count_offset() {
roland@5479 876 return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size);
roland@5479 877 }
roland@5479 878
roland@5479 879 static ByteSize args_data_offset() {
roland@5479 880 return in_ByteSize(header_cell_count() * DataLayout::cell_size);
roland@5479 881 }
roland@5479 882
roland@5479 883 static ByteSize stack_slot_offset(int i) {
roland@5479 884 return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size);
roland@5479 885 }
roland@5479 886
roland@5479 887 static ByteSize type_offset(int i) {
roland@5479 888 return in_ByteSize(type_local_offset(i) * DataLayout::cell_size);
roland@5479 889 }
roland@5479 890
roland@5479 891 // GC support
roland@5479 892 void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
roland@5479 893
roland@5479 894 #ifndef PRODUCT
roland@5479 895 void print_data_on(outputStream* st) const;
roland@5479 896 #endif
roland@5479 897 };
roland@5479 898
roland@5479 899 // CallTypeData
roland@5479 900 //
roland@5479 901 // A CallTypeData is used to access profiling information about a non
roland@5479 902 // virtual call for which we collect type information about arguments.
roland@5479 903 class CallTypeData : public CounterData {
roland@5479 904 private:
roland@5479 905 TypeStackSlotEntries _args;
roland@5479 906
roland@5479 907 public:
roland@5479 908 CallTypeData(DataLayout* layout) :
roland@5479 909 CounterData(layout), _args(CounterData::static_cell_count()) {
roland@5479 910 assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
roland@5479 911 // Some compilers (VC++) don't want this passed in member initialization list
roland@5479 912 _args.set_profile_data(this);
roland@5479 913 }
roland@5479 914
roland@5479 915 const TypeStackSlotEntries* args() const { return &_args; }
roland@5479 916
roland@5479 917 virtual bool is_CallTypeData() const { return true; }
roland@5479 918
roland@5479 919 static int static_cell_count() {
roland@5479 920 return -1;
roland@5479 921 }
roland@5479 922
roland@5479 923 static int compute_cell_count(BytecodeStream* stream) {
roland@5479 924 return CounterData::static_cell_count() + TypeStackSlotEntries::compute_cell_count(stream);
roland@5479 925 }
roland@5479 926
roland@5479 927 static void initialize(DataLayout* dl, int cell_count) {
roland@5479 928 TypeStackSlotEntries::initialize(dl, CounterData::static_cell_count(), cell_count);
roland@5479 929 }
roland@5479 930
roland@5479 931 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {
roland@5479 932 _args.post_initialize(stream);
roland@5479 933 }
roland@5479 934
roland@5479 935 virtual int cell_count() const {
roland@5479 936 return _args.cell_count();
roland@5479 937 }
roland@5479 938
roland@5479 939 uint number_of_arguments() const {
roland@5479 940 return args()->number_of_arguments();
roland@5479 941 }
roland@5479 942
roland@5479 943 void set_argument_type(int i, Klass* k) {
roland@5479 944 intptr_t current = _args.type(i);
roland@5479 945 _args.set_type(i, TypeEntries::with_status(k, current));
roland@5479 946 }
roland@5479 947
roland@5479 948 // Code generation support
roland@5479 949 static ByteSize args_data_offset() {
roland@5479 950 return cell_offset(CounterData::static_cell_count()) + TypeStackSlotEntries::args_data_offset();
roland@5479 951 }
roland@5479 952
roland@5479 953 // GC support
roland@5479 954 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
roland@5479 955 _args.clean_weak_klass_links(is_alive_closure);
roland@5479 956 }
roland@5479 957
roland@5479 958 #ifndef PRODUCT
roland@5479 959 virtual void print_data_on(outputStream* st) const;
duke@0 960 #endif
duke@0 961 };
duke@0 962
duke@0 963 // ReceiverTypeData
duke@0 964 //
duke@0 965 // A ReceiverTypeData is used to access profiling information about a
duke@0 966 // dynamic type check. It consists of a counter which counts the total times
coleenp@3602 967 // that the check is reached, and a series of (Klass*, count) pairs
duke@0 968 // which are used to store a type profile for the receiver of the check.
duke@0 969 class ReceiverTypeData : public CounterData {
duke@0 970 protected:
duke@0 971 enum {
duke@0 972 receiver0_offset = counter_cell_count,
duke@0 973 count0_offset,
duke@0 974 receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
duke@0 975 };
duke@0 976
duke@0 977 public:
duke@0 978 ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
duke@0 979 assert(layout->tag() == DataLayout::receiver_type_data_tag ||
roland@5479 980 layout->tag() == DataLayout::virtual_call_data_tag ||
roland@5479 981 layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
duke@0 982 }
duke@0 983
roland@5479 984 virtual bool is_ReceiverTypeData() const { return true; }
duke@0 985
duke@0 986 static int static_cell_count() {
duke@0 987 return counter_cell_count + (uint) TypeProfileWidth * receiver_type_row_cell_count;
duke@0 988 }
duke@0 989
roland@5479 990 virtual int cell_count() const {
duke@0 991 return static_cell_count();
duke@0 992 }
duke@0 993
duke@0 994 // Direct accessors
duke@0 995 static uint row_limit() {
duke@0 996 return TypeProfileWidth;
duke@0 997 }
duke@0 998 static int receiver_cell_index(uint row) {
duke@0 999 return receiver0_offset + row * receiver_type_row_cell_count;
duke@0 1000 }
duke@0 1001 static int receiver_count_cell_index(uint row) {
duke@0 1002 return count0_offset + row * receiver_type_row_cell_count;
duke@0 1003 }
duke@0 1004
roland@5479 1005 Klass* receiver(uint row) const {
duke@0 1006 assert(row < row_limit(), "oob");
duke@0 1007
coleenp@3602 1008 Klass* recv = (Klass*)intptr_at(receiver_cell_index(row));
coleenp@3602 1009 assert(recv == NULL || recv->is_klass(), "wrong type");
duke@0 1010 return recv;
duke@0 1011 }
duke@0 1012
coleenp@3602 1013 void set_receiver(uint row, Klass* k) {
ysr@941 1014 assert((uint)row < row_limit(), "oob");
coleenp@3602 1015 set_intptr_at(receiver_cell_index(row), (uintptr_t)k);
ysr@941 1016 }
ysr@941 1017
roland@5479 1018 uint receiver_count(uint row) const {
duke@0 1019 assert(row < row_limit(), "oob");
duke@0 1020 return uint_at(receiver_count_cell_index(row));
duke@0 1021 }
duke@0 1022
ysr@941 1023 void set_receiver_count(uint row, uint count) {
ysr@941 1024 assert(row < row_limit(), "oob");
ysr@941 1025 set_uint_at(receiver_count_cell_index(row), count);
ysr@941 1026 }
ysr@941 1027
ysr@941 1028 void clear_row(uint row) {
ysr@941 1029 assert(row < row_limit(), "oob");
kvn@1251 1030 // Clear total count - indicator of polymorphic call site.
kvn@1251 1031 // The site may look like as monomorphic after that but
kvn@1251 1032 // it allow to have more accurate profiling information because
kvn@1251 1033 // there was execution phase change since klasses were unloaded.
kvn@1251 1034 // If the site is still polymorphic then MDO will be updated
kvn@1251 1035 // to reflect it. But it could be the case that the site becomes
kvn@1251 1036 // only bimorphic. Then keeping total count not 0 will be wrong.
kvn@1251 1037 // Even if we use monomorphic (when it is not) for compilation
kvn@1251 1038 // we will only have trap, deoptimization and recompile again
kvn@1251 1039 // with updated MDO after executing method in Interpreter.
kvn@1251 1040 // An additional receiver will be recorded in the cleaned row
kvn@1251 1041 // during next call execution.
kvn@1251 1042 //
kvn@1251 1043 // Note: our profiling logic works with empty rows in any slot.
kvn@1251 1044 // We do sorting a profiling info (ciCallProfile) for compilation.
kvn@1251 1045 //
kvn@1251 1046 set_count(0);
ysr@941 1047 set_receiver(row, NULL);
ysr@941 1048 set_receiver_count(row, 0);
ysr@941 1049 }
ysr@941 1050
duke@0 1051 // Code generation support
duke@0 1052 static ByteSize receiver_offset(uint row) {
duke@0 1053 return cell_offset(receiver_cell_index(row));
duke@0 1054 }
duke@0 1055 static ByteSize receiver_count_offset(uint row) {
duke@0 1056 return cell_offset(receiver_count_cell_index(row));
duke@0 1057 }
duke@0 1058 static ByteSize receiver_type_data_size() {
duke@0 1059 return cell_offset(static_cell_count());
duke@0 1060 }
duke@0 1061
duke@0 1062 // GC support
coleenp@3602 1063 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
duke@0 1064
duke@0 1065 #ifndef PRODUCT
roland@5479 1066 void print_receiver_data_on(outputStream* st) const;
roland@5479 1067 void print_data_on(outputStream* st) const;
duke@0 1068 #endif
duke@0 1069 };
duke@0 1070
duke@0 1071 // VirtualCallData
duke@0 1072 //
duke@0 1073 // A VirtualCallData is used to access profiling information about a
duke@0 1074 // virtual call. For now, it has nothing more than a ReceiverTypeData.
duke@0 1075 class VirtualCallData : public ReceiverTypeData {
duke@0 1076 public:
duke@0 1077 VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
roland@5479 1078 assert(layout->tag() == DataLayout::virtual_call_data_tag ||
roland@5479 1079 layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
duke@0 1080 }
duke@0 1081
roland@5479 1082 virtual bool is_VirtualCallData() const { return true; }
duke@0 1083
duke@0 1084 static int static_cell_count() {
duke@0 1085 // At this point we could add more profile state, e.g., for arguments.
duke@0 1086 // But for now it's the same size as the base record type.
duke@0 1087 return ReceiverTypeData::static_cell_count();
duke@0 1088 }
duke@0 1089
roland@5479 1090 virtual int cell_count() const {
duke@0 1091 return static_cell_count();
duke@0 1092 }
duke@0 1093
duke@0 1094 // Direct accessors
duke@0 1095 static ByteSize virtual_call_data_size() {
duke@0 1096 return cell_offset(static_cell_count());
duke@0 1097 }
duke@0 1098
duke@0 1099 #ifndef PRODUCT
roland@5479 1100 void print_data_on(outputStream* st) const;
roland@5479 1101 #endif
roland@5479 1102 };
roland@5479 1103
roland@5479 1104 // VirtualCallTypeData
roland@5479 1105 //
roland@5479 1106 // A VirtualCallTypeData is used to access profiling information about
roland@5479 1107 // a virtual call for which we collect type information about
roland@5479 1108 // arguments.
roland@5479 1109 class VirtualCallTypeData : public VirtualCallData {
roland@5479 1110 private:
roland@5479 1111 TypeStackSlotEntries _args;
roland@5479 1112
roland@5479 1113 public:
roland@5479 1114 VirtualCallTypeData(DataLayout* layout) :
roland@5479 1115 VirtualCallData(layout), _args(VirtualCallData::static_cell_count()) {
roland@5479 1116 assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
roland@5479 1117 // Some compilers (VC++) don't want this passed in member initialization list
roland@5479 1118 _args.set_profile_data(this);
roland@5479 1119 }
roland@5479 1120
roland@5479 1121 const TypeStackSlotEntries* args() const { return &_args; }
roland@5479 1122
roland@5479 1123 virtual bool is_VirtualCallTypeData() const { return true; }
roland@5479 1124
roland@5479 1125 static int static_cell_count() {
roland@5479 1126 return -1;
roland@5479 1127 }
roland@5479 1128
roland@5479 1129 static int compute_cell_count(BytecodeStream* stream) {
roland@5479 1130 return VirtualCallData::static_cell_count() + TypeStackSlotEntries::compute_cell_count(stream);
roland@5479 1131 }
roland@5479 1132
roland@5479 1133 static void initialize(DataLayout* dl, int cell_count) {
roland@5479 1134 TypeStackSlotEntries::initialize(dl, VirtualCallData::static_cell_count(), cell_count);
roland@5479 1135 }
roland@5479 1136
roland@5479 1137 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {
roland@5479 1138 _args.post_initialize(stream);
roland@5479 1139 }
roland@5479 1140
roland@5479 1141 virtual int cell_count() const {
roland@5479 1142 return _args.cell_count();
roland@5479 1143 }
roland@5479 1144
roland@5479 1145 uint number_of_arguments() const {
roland@5479 1146 return args()->number_of_arguments();
roland@5479 1147 }
roland@5479 1148
roland@5479 1149 void set_argument_type(int i, Klass* k) {
roland@5479 1150 intptr_t current = _args.type(i);
roland@5479 1151 _args.set_type(i, TypeEntries::with_status(k, current));
roland@5479 1152 }
roland@5479 1153
roland@5479 1154 // Code generation support
roland@5479 1155 static ByteSize args_data_offset() {
roland@5479 1156 return cell_offset(VirtualCallData::static_cell_count()) + TypeStackSlotEntries::args_data_offset();
roland@5479 1157 }
roland@5479 1158
roland@5479 1159 // GC support
roland@5479 1160 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
roland@5479 1161 ReceiverTypeData::clean_weak_klass_links(is_alive_closure);
roland@5479 1162 _args.clean_weak_klass_links(is_alive_closure);
roland@5479 1163 }
roland@5479 1164
roland@5479 1165 #ifndef PRODUCT
roland@5479 1166 virtual void print_data_on(outputStream* st) const;
duke@0 1167 #endif
duke@0 1168 };
duke@0 1169
duke@0 1170 // RetData
duke@0 1171 //
duke@0 1172 // A RetData is used to access profiling information for a ret bytecode.
duke@0 1173 // It is composed of a count of the number of times that the ret has
duke@0 1174 // been executed, followed by a series of triples of the form
duke@0 1175 // (bci, count, di) which count the number of times that some bci was the
duke@0 1176 // target of the ret and cache a corresponding data displacement.
duke@0 1177 class RetData : public CounterData {
duke@0 1178 protected:
duke@0 1179 enum {
duke@0 1180 bci0_offset = counter_cell_count,
duke@0 1181 count0_offset,
duke@0 1182 displacement0_offset,
duke@0 1183 ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
duke@0 1184 };
duke@0 1185
duke@0 1186 void set_bci(uint row, int bci) {
duke@0 1187 assert((uint)row < row_limit(), "oob");
duke@0 1188 set_int_at(bci0_offset + row * ret_row_cell_count, bci);
duke@0 1189 }
duke@0 1190 void release_set_bci(uint row, int bci) {
duke@0 1191 assert((uint)row < row_limit(), "oob");
duke@0 1192 // 'release' when setting the bci acts as a valid flag for other
duke@0 1193 // threads wrt bci_count and bci_displacement.
duke@0 1194 release_set_int_at(bci0_offset + row * ret_row_cell_count, bci);
duke@0 1195 }
duke@0 1196 void set_bci_count(uint row, uint count) {
duke@0 1197 assert((uint)row < row_limit(), "oob");
duke@0 1198 set_uint_at(count0_offset + row * ret_row_cell_count, count);
duke@0 1199 }
duke@0 1200 void set_bci_displacement(uint row, int disp) {
duke@0 1201 set_int_at(displacement0_offset + row * ret_row_cell_count, disp);
duke@0 1202 }
duke@0 1203
duke@0 1204 public:
duke@0 1205 RetData(DataLayout* layout) : CounterData(layout) {
duke@0 1206 assert(layout->tag() == DataLayout::ret_data_tag, "wrong type");
duke@0 1207 }
duke@0 1208
roland@5479 1209 virtual bool is_RetData() const { return true; }
duke@0 1210
duke@0 1211 enum {
duke@0 1212 no_bci = -1 // value of bci when bci1/2 are not in use.
duke@0 1213 };
duke@0 1214
duke@0 1215 static int static_cell_count() {
duke@0 1216 return counter_cell_count + (uint) BciProfileWidth * ret_row_cell_count;
duke@0 1217 }
duke@0 1218
roland@5479 1219 virtual int cell_count() const {
duke@0 1220 return static_cell_count();
duke@0 1221 }
duke@0 1222
duke@0 1223 static uint row_limit() {
duke@0 1224 return BciProfileWidth;
duke@0 1225 }
duke@0 1226 static int bci_cell_index(uint row) {
duke@0 1227 return bci0_offset + row * ret_row_cell_count;
duke@0 1228 }
duke@0 1229 static int bci_count_cell_index(uint row) {
duke@0 1230 return count0_offset + row * ret_row_cell_count;
duke@0 1231 }
duke@0 1232 static int bci_displacement_cell_index(uint row) {
duke@0 1233 return displacement0_offset + row * ret_row_cell_count;
duke@0 1234 }
duke@0 1235
duke@0 1236 // Direct accessors
roland@5479 1237 int bci(uint row) const {
duke@0 1238 return int_at(bci_cell_index(row));
duke@0 1239 }
roland@5479 1240 uint bci_count(uint row) const {
duke@0 1241 return uint_at(bci_count_cell_index(row));
duke@0 1242 }
roland@5479 1243 int bci_displacement(uint row) const {
duke@0 1244 return int_at(bci_displacement_cell_index(row));
duke@0 1245 }
duke@0 1246
duke@0 1247 // Interpreter Runtime support
coleenp@3602 1248 address fixup_ret(int return_bci, MethodData* mdo);
duke@0 1249
duke@0 1250 // Code generation support
duke@0 1251 static ByteSize bci_offset(uint row) {
duke@0 1252 return cell_offset(bci_cell_index(row));
duke@0 1253 }
duke@0 1254 static ByteSize bci_count_offset(uint row) {
duke@0 1255 return cell_offset(bci_count_cell_index(row));
duke@0 1256 }
duke@0 1257 static ByteSize bci_displacement_offset(uint row) {
duke@0 1258 return cell_offset(bci_displacement_cell_index(row));
duke@0 1259 }
duke@0 1260
duke@0 1261 // Specific initialization.
coleenp@3602 1262 void post_initialize(BytecodeStream* stream, MethodData* mdo);
duke@0 1263
duke@0 1264 #ifndef PRODUCT
roland@5479 1265 void print_data_on(outputStream* st) const;
duke@0 1266 #endif
duke@0 1267 };
duke@0 1268
duke@0 1269 // BranchData
duke@0 1270 //
duke@0 1271 // A BranchData is used to access profiling data for a two-way branch.
duke@0 1272 // It consists of taken and not_taken counts as well as a data displacement
duke@0 1273 // for the taken case.
duke@0 1274 class BranchData : public JumpData {
duke@0 1275 protected:
duke@0 1276 enum {
duke@0 1277 not_taken_off_set = jump_cell_count,
duke@0 1278 branch_cell_count
duke@0 1279 };
duke@0 1280
duke@0 1281 void set_displacement(int displacement) {
duke@0 1282 set_int_at(displacement_off_set, displacement);
duke@0 1283 }
duke@0 1284
duke@0 1285 public:
duke@0 1286 BranchData(DataLayout* layout) : JumpData(layout) {
duke@0 1287 assert(layout->tag() == DataLayout::branch_data_tag, "wrong type");
duke@0 1288 }
duke@0 1289
roland@5479 1290 virtual bool is_BranchData() const { return true; }
duke@0 1291
duke@0 1292 static int static_cell_count() {
duke@0 1293 return branch_cell_count;
duke@0 1294 }
duke@0 1295
roland@5479 1296 virtual int cell_count() const {
duke@0 1297 return static_cell_count();
duke@0 1298 }
duke@0 1299
duke@0 1300 // Direct accessor
roland@5479 1301 uint not_taken() const {
duke@0 1302 return uint_at(not_taken_off_set);
duke@0 1303 }
duke@0 1304
never@2670 1305 void set_not_taken(uint cnt) {
never@2670 1306 set_uint_at(not_taken_off_set, cnt);
never@2670 1307 }
never@2670 1308
duke@0 1309 uint inc_not_taken() {
duke@0 1310 uint cnt = not_taken() + 1;
duke@0 1311 // Did we wrap? Will compiler screw us??
duke@0 1312 if (cnt == 0) cnt--;
duke@0 1313 set_uint_at(not_taken_off_set, cnt);
duke@0 1314 return cnt;
duke@0 1315 }
duke@0 1316
duke@0 1317 // Code generation support
duke@0 1318 static ByteSize not_taken_offset() {
duke@0 1319 return cell_offset(not_taken_off_set);
duke@0 1320 }
duke@0 1321 static ByteSize branch_data_size() {
duke@0 1322 return cell_offset(branch_cell_count);
duke@0 1323 }
duke@0 1324
duke@0 1325 // Specific initialization.
coleenp@3602 1326 void post_initialize(BytecodeStream* stream, MethodData* mdo);
duke@0 1327
duke@0 1328 #ifndef PRODUCT
roland@5479 1329 void print_data_on(outputStream* st) const;
duke@0 1330 #endif
duke@0 1331 };
duke@0 1332
duke@0 1333 // ArrayData
duke@0 1334 //
duke@0 1335 // A ArrayData is a base class for accessing profiling data which does
duke@0 1336 // not have a statically known size. It consists of an array length
duke@0 1337 // and an array start.
duke@0 1338 class ArrayData : public ProfileData {
duke@0 1339 protected:
duke@0 1340 friend class DataLayout;
duke@0 1341
duke@0 1342 enum {
duke@0 1343 array_len_off_set,
duke@0 1344 array_start_off_set
duke@0 1345 };
duke@0 1346
roland@5479 1347 uint array_uint_at(int index) const {
duke@0 1348 int aindex = index + array_start_off_set;
duke@0 1349 return uint_at(aindex);
duke@0 1350 }
roland@5479 1351 int array_int_at(int index) const {
duke@0 1352 int aindex = index + array_start_off_set;
duke@0 1353 return int_at(aindex);
duke@0 1354 }
roland@5479 1355 oop array_oop_at(int index) const {
duke@0 1356 int aindex = index + array_start_off_set;
duke@0 1357 return oop_at(aindex);
duke@0 1358 }
duke@0 1359 void array_set_int_at(int index, int value) {
duke@0 1360 int aindex = index + array_start_off_set;
duke@0 1361 set_int_at(aindex, value);
duke@0 1362 }
duke@0 1363
duke@0 1364 // Code generation support for subclasses.
duke@0 1365 static ByteSize array_element_offset(int index) {
duke@0 1366 return cell_offset(array_start_off_set + index);
duke@0 1367 }
duke@0 1368
duke@0 1369 public:
duke@0 1370 ArrayData(DataLayout* layout) : ProfileData(layout) {}
duke@0 1371
roland@5479 1372 virtual bool is_ArrayData() const { return true; }
duke@0 1373
duke@0 1374 static int static_cell_count() {
duke@0 1375 return -1;
duke@0 1376 }
duke@0 1377
roland@5479 1378 int array_len() const {
duke@0 1379 return int_at_unchecked(array_len_off_set);
duke@0 1380 }
duke@0 1381
roland@5479 1382 virtual int cell_count() const {
duke@0 1383 return array_len() + 1;
duke@0 1384 }
duke@0 1385
duke@0 1386 // Code generation support
duke@0 1387 static ByteSize array_len_offset() {
duke@0 1388 return cell_offset(array_len_off_set);
duke@0 1389 }
duke@0 1390 static ByteSize array_start_offset() {
duke@0 1391 return cell_offset(array_start_off_set);
duke@0 1392 }
duke@0 1393 };
duke@0 1394
duke@0 1395 // MultiBranchData
duke@0 1396 //
duke@0 1397 // A MultiBranchData is used to access profiling information for
duke@0 1398 // a multi-way branch (*switch bytecodes). It consists of a series
duke@0 1399 // of (count, displacement) pairs, which count the number of times each
duke@0 1400 // case was taken and specify the data displacment for each branch target.
duke@0 1401 class MultiBranchData : public ArrayData {
duke@0 1402 protected:
duke@0 1403 enum {
duke@0 1404 default_count_off_set,
duke@0 1405 default_disaplacement_off_set,
duke@0 1406 case_array_start
duke@0 1407 };
duke@0 1408 enum {
duke@0 1409 relative_count_off_set,
duke@0 1410 relative_displacement_off_set,
duke@0 1411 per_case_cell_count
duke@0 1412 };
duke@0 1413
duke@0 1414 void set_default_displacement(int displacement) {
duke@0 1415 array_set_int_at(default_disaplacement_off_set, displacement);
duke@0 1416 }
duke@0 1417 void set_displacement_at(int index, int displacement) {
duke@0 1418 array_set_int_at(case_array_start +
duke@0 1419 index * per_case_cell_count +
duke@0 1420 relative_displacement_off_set,
duke@0 1421 displacement);
duke@0 1422 }
duke@0 1423
duke@0 1424 public:
duke@0 1425 MultiBranchData(DataLayout* layout) : ArrayData(layout) {
duke@0 1426 assert(layout->tag() == DataLayout::multi_branch_data_tag, "wrong type");
duke@0 1427 }
duke@0 1428
roland@5479 1429 virtual bool is_MultiBranchData() const { return true; }
duke@0 1430
duke@0 1431 static int compute_cell_count(BytecodeStream* stream);
duke@0 1432
roland@5479 1433 int number_of_cases() const {
duke@0 1434 int alen = array_len() - 2; // get rid of default case here.
duke@0 1435 assert(alen % per_case_cell_count == 0, "must be even");
duke@0 1436 return (alen / per_case_cell_count);
duke@0 1437 }
duke@0 1438
roland@5479 1439 uint default_count() const {
duke@0 1440 return array_uint_at(default_count_off_set);
duke@0 1441 }
roland@5479 1442 int default_displacement() const {
duke@0 1443 return array_int_at(default_disaplacement_off_set);
duke@0 1444 }
duke@0 1445
roland@5479 1446 uint count_at(int index) const {
duke@0 1447 return array_uint_at(case_array_start +
duke@0 1448 index * per_case_cell_count +
duke@0 1449 relative_count_off_set);
duke@0 1450 }
roland@5479 1451 int displacement_at(int index) const {
duke@0 1452 return array_int_at(case_array_start +
duke@0 1453 index * per_case_cell_count +
duke@0 1454 relative_displacement_off_set);
duke@0 1455 }
duke@0 1456
duke@0 1457 // Code generation support
duke@0 1458 static ByteSize default_count_offset() {
duke@0 1459 return array_element_offset(default_count_off_set);
duke@0 1460 }
duke@0 1461 static ByteSize default_displacement_offset() {
duke@0 1462 return array_element_offset(default_disaplacement_off_set);
duke@0 1463 }
duke@0 1464 static ByteSize case_count_offset(int index) {
duke@0 1465 return case_array_offset() +
duke@0 1466 (per_case_size() * index) +
duke@0 1467 relative_count_offset();
duke@0 1468 }
duke@0 1469 static ByteSize case_array_offset() {
duke@0 1470 return array_element_offset(case_array_start);
duke@0 1471 }
duke@0 1472 static ByteSize per_case_size() {
duke@0 1473 return in_ByteSize(per_case_cell_count) * cell_size;
duke@0 1474 }
duke@0 1475 static ByteSize relative_count_offset() {
duke@0 1476 return in_ByteSize(relative_count_off_set) * cell_size;
duke@0 1477 }
duke@0 1478 static ByteSize relative_displacement_offset() {
duke@0 1479 return in_ByteSize(relative_displacement_off_set) * cell_size;
duke@0 1480 }
duke@0 1481
duke@0 1482 // Specific initialization.
coleenp@3602 1483 void post_initialize(BytecodeStream* stream, MethodData* mdo);
duke@0 1484
duke@0 1485 #ifndef PRODUCT
roland@5479 1486 void print_data_on(outputStream* st) const;
duke@0 1487 #endif
duke@0 1488 };
duke@0 1489
kvn@45 1490 class ArgInfoData : public ArrayData {
kvn@45 1491
kvn@45 1492 public:
kvn@45 1493 ArgInfoData(DataLayout* layout) : ArrayData(layout) {
kvn@45 1494 assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type");
kvn@45 1495 }
kvn@45 1496
roland@5479 1497 virtual bool is_ArgInfoData() const { return true; }
kvn@45 1498
kvn@45 1499
roland@5479 1500 int number_of_args() const {
kvn@45 1501 return array_len();
kvn@45 1502 }
kvn@45 1503
roland@5479 1504 uint arg_modified(int arg) const {
kvn@45 1505 return array_uint_at(arg);
kvn@45 1506 }
kvn@45 1507
kvn@45 1508 void set_arg_modified(int arg, uint val) {
kvn@45 1509 array_set_int_at(arg, val);
kvn@45 1510 }
kvn@45 1511
kvn@45 1512 #ifndef PRODUCT
roland@5479 1513 void print_data_on(outputStream* st) const;
kvn@45 1514 #endif
kvn@45 1515 };
kvn@45 1516
coleenp@3602 1517 // MethodData*
duke@0 1518 //
coleenp@3602 1519 // A MethodData* holds information which has been collected about
duke@0 1520 // a method. Its layout looks like this:
duke@0 1521 //
duke@0 1522 // -----------------------------
duke@0 1523 // | header |
duke@0 1524 // | klass |
duke@0 1525 // -----------------------------
duke@0 1526 // | method |
coleenp@3602 1527 // | size of the MethodData* |
duke@0 1528 // -----------------------------
duke@0 1529 // | Data entries... |
duke@0 1530 // | (variable size) |
duke@0 1531 // | |
duke@0 1532 // . .
duke@0 1533 // . .
duke@0 1534 // . .
duke@0 1535 // | |
duke@0 1536 // -----------------------------
duke@0 1537 //
duke@0 1538 // The data entry area is a heterogeneous array of DataLayouts. Each
duke@0 1539 // DataLayout in the array corresponds to a specific bytecode in the
duke@0 1540 // method. The entries in the array are sorted by the corresponding
duke@0 1541 // bytecode. Access to the data is via resource-allocated ProfileData,
duke@0 1542 // which point to the underlying blocks of DataLayout structures.
duke@0 1543 //
duke@0 1544 // During interpretation, if profiling in enabled, the interpreter
duke@0 1545 // maintains a method data pointer (mdp), which points at the entry
duke@0 1546 // in the array corresponding to the current bci. In the course of
duke@0 1547 // intepretation, when a bytecode is encountered that has profile data
duke@0 1548 // associated with it, the entry pointed to by mdp is updated, then the
duke@0 1549 // mdp is adjusted to point to the next appropriate DataLayout. If mdp
duke@0 1550 // is NULL to begin with, the interpreter assumes that the current method
duke@0 1551 // is not (yet) being profiled.
duke@0 1552 //
coleenp@3602 1553 // In MethodData* parlance, "dp" is a "data pointer", the actual address
duke@0 1554 // of a DataLayout element. A "di" is a "data index", the offset in bytes
duke@0 1555 // from the base of the data entry array. A "displacement" is the byte offset
duke@0 1556 // in certain ProfileData objects that indicate the amount the mdp must be
duke@0 1557 // adjusted in the event of a change in control flow.
duke@0 1558 //
duke@0 1559
coleenp@3602 1560 class MethodData : public Metadata {
duke@0 1561 friend class VMStructs;
duke@0 1562 private:
duke@0 1563 friend class ProfileData;
duke@0 1564
coleenp@3602 1565 // Back pointer to the Method*
coleenp@3602 1566 Method* _method;
duke@0 1567
duke@0 1568 // Size of this oop in bytes
duke@0 1569 int _size;
duke@0 1570
duke@0 1571 // Cached hint for bci_to_dp and bci_to_data
duke@0 1572 int _hint_di;
duke@0 1573
coleenp@3602 1574 MethodData(methodHandle method, int size, TRAPS);
coleenp@3602 1575 public:
coleenp@3602 1576 static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS);
coleenp@3602 1577 MethodData() {}; // For ciMethodData
coleenp@3602 1578
coleenp@3602 1579 bool is_methodData() const volatile { return true; }
coleenp@3602 1580
duke@0 1581 // Whole-method sticky bits and flags
duke@0 1582 enum {
kvn@2442 1583 _trap_hist_limit = 17, // decoupled from Deoptimization::Reason_LIMIT
duke@0 1584 _trap_hist_mask = max_jubyte,
duke@0 1585 _extra_data_count = 4 // extra DataLayout headers, for trap history
duke@0 1586 }; // Public flag values
duke@0 1587 private:
duke@0 1588 uint _nof_decompiles; // count of all nmethod removals
duke@0 1589 uint _nof_overflow_recompiles; // recompile count, excluding recomp. bits
duke@0 1590 uint _nof_overflow_traps; // trap count, excluding _trap_hist
duke@0 1591 union {
duke@0 1592 intptr_t _align;
duke@0 1593 u1 _array[_trap_hist_limit];
duke@0 1594 } _trap_hist;
duke@0 1595
duke@0 1596 // Support for interprocedural escape analysis, from Thomas Kotzmann.
duke@0 1597 intx _eflags; // flags on escape information
duke@0 1598 intx _arg_local; // bit set of non-escaping arguments
duke@0 1599 intx _arg_stack; // bit set of stack-allocatable arguments
duke@0 1600 intx _arg_returned; // bit set of returned arguments
duke@0 1601
iveresov@1703 1602 int _creation_mileage; // method mileage at MDO creation
iveresov@1703 1603
iveresov@1703 1604 // How many invocations has this MDO seen?
iveresov@1703 1605 // These counters are used to determine the exact age of MDO.
iveresov@1703 1606 // We need those because in tiered a method can be concurrently
iveresov@1703 1607 // executed at different levels.
iveresov@1703 1608 InvocationCounter _invocation_counter;
iveresov@1703 1609 // Same for backedges.
iveresov@1703 1610 InvocationCounter _backedge_counter;
iveresov@2124 1611 // Counter values at the time profiling started.
iveresov@2124 1612 int _invocation_counter_start;
iveresov@2124 1613 int _backedge_counter_start;
iveresov@1703 1614 // Number of loops and blocks is computed when compiling the first
iveresov@1703 1615 // time with C1. It is used to determine if method is trivial.
iveresov@1703 1616 short _num_loops;
iveresov@1703 1617 short _num_blocks;
iveresov@1703 1618 // Highest compile level this method has ever seen.
iveresov@1703 1619 u1 _highest_comp_level;
iveresov@1703 1620 // Same for OSR level
iveresov@1703 1621 u1 _highest_osr_comp_level;
iveresov@1703 1622 // Does this method contain anything worth profiling?
iveresov@1703 1623 bool _would_profile;
duke@0 1624
duke@0 1625 // Size of _data array in bytes. (Excludes header and extra_data fields.)
duke@0 1626 int _data_size;
duke@0 1627
duke@0 1628 // Beginning of the data entries
duke@0 1629 intptr_t _data[1];
duke@0 1630
duke@0 1631 // Helper for size computation
duke@0 1632 static int compute_data_size(BytecodeStream* stream);
duke@0 1633 static int bytecode_cell_count(Bytecodes::Code code);
duke@0 1634 enum { no_profile_data = -1, variable_cell_count = -2 };
duke@0 1635
duke@0 1636 // Helper for initialization
coleenp@3602 1637 DataLayout* data_layout_at(int data_index) const {
duke@0 1638 assert(data_index % sizeof(intptr_t) == 0, "unaligned");
duke@0 1639 return (DataLayout*) (((address)_data) + data_index);
duke@0 1640 }
duke@0 1641
duke@0 1642 // Initialize an individual data segment. Returns the size of
duke@0 1643 // the segment in bytes.
duke@0 1644 int initialize_data(BytecodeStream* stream, int data_index);
duke@0 1645
duke@0 1646 // Helper for data_at
coleenp@3602 1647 DataLayout* limit_data_position() const {
duke@0 1648 return (DataLayout*)((address)data_base() + _data_size);
duke@0 1649 }
coleenp@3602 1650 bool out_of_bounds(int data_index) const {
duke@0 1651 return data_index >= data_size();
duke@0 1652 }
duke@0 1653
duke@0 1654 // Give each of the data entries a chance to perform specific
duke@0 1655 // data initialization.
duke@0 1656 void post_initialize(BytecodeStream* stream);
duke@0 1657
duke@0 1658 // hint accessors
duke@0 1659 int hint_di() const { return _hint_di; }
duke@0 1660 void set_hint_di(int di) {
duke@0 1661 assert(!out_of_bounds(di), "hint_di out of bounds");
duke@0 1662 _hint_di = di;
duke@0 1663 }
duke@0 1664 ProfileData* data_before(int bci) {
duke@0 1665 // avoid SEGV on this edge case
duke@0 1666 if (data_size() == 0)
duke@0 1667 return NULL;
duke@0 1668 int hint = hint_di();
duke@0 1669 if (data_layout_at(hint)->bci() <= bci)
duke@0 1670 return data_at(hint);
duke@0 1671 return first_data();
duke@0 1672 }
duke@0 1673
duke@0 1674 // What is the index of the first data entry?
coleenp@3602 1675 int first_di() const { return 0; }
duke@0 1676
duke@0 1677 // Find or create an extra ProfileData:
duke@0 1678 ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
duke@0 1679
kvn@45 1680 // return the argument info cell
kvn@45 1681 ArgInfoData *arg_info();
kvn@45 1682
roland@5479 1683 enum {
roland@5479 1684 no_type_profile = 0,
roland@5479 1685 type_profile_jsr292 = 1,
roland@5479 1686 type_profile_all = 2
roland@5479 1687 };
roland@5479 1688
roland@5479 1689 static bool profile_jsr292(methodHandle m, int bci);
roland@5479 1690 static int profile_arguments_flag();
roland@5479 1691 static bool profile_arguments_jsr292_only();
roland@5479 1692 static bool profile_all_arguments();
roland@5479 1693 static bool profile_arguments_for_invoke(methodHandle m, int bci);
roland@5479 1694
duke@0 1695 public:
duke@0 1696 static int header_size() {
coleenp@3602 1697 return sizeof(MethodData)/wordSize;
duke@0 1698 }
duke@0 1699
coleenp@3602 1700 // Compute the size of a MethodData* before it is created.
duke@0 1701 static int compute_allocation_size_in_bytes(methodHandle method);
duke@0 1702 static int compute_allocation_size_in_words(methodHandle method);
duke@0 1703 static int compute_extra_data_count(int data_size, int empty_bc_count);
duke@0 1704
duke@0 1705 // Determine if a given bytecode can have profile information.
duke@0 1706 static bool bytecode_has_profile(Bytecodes::Code code) {
duke@0 1707 return bytecode_cell_count(code) != no_profile_data;
duke@0 1708 }
duke@0 1709
iignatyev@4473 1710 // reset into original state
iignatyev@4473 1711 void init();
duke@0 1712
duke@0 1713 // My size
coleenp@3602 1714 int size_in_bytes() const { return _size; }
coleenp@3602 1715 int size() const { return align_object_size(align_size_up(_size, BytesPerWord)/BytesPerWord); }
acorn@4062 1716 #if INCLUDE_SERVICES
acorn@4062 1717 void collect_statistics(KlassSizeStats *sz) const;
acorn@4062 1718 #endif
duke@0 1719
duke@0 1720 int creation_mileage() const { return _creation_mileage; }
duke@0 1721 void set_creation_mileage(int x) { _creation_mileage = x; }
iveresov@1703 1722
iveresov@1703 1723 int invocation_count() {
iveresov@1703 1724 if (invocation_counter()->carry()) {
iveresov@1703 1725 return InvocationCounter::count_limit;
iveresov@1703 1726 }
iveresov@1703 1727 return invocation_counter()->count();
iveresov@1703 1728 }
iveresov@1703 1729 int backedge_count() {
iveresov@1703 1730 if (backedge_counter()->carry()) {
iveresov@1703 1731 return InvocationCounter::count_limit;
iveresov@1703 1732 }
iveresov@1703 1733 return backedge_counter()->count();
iveresov@1703 1734 }
iveresov@1703 1735
iveresov@2124 1736 int invocation_count_start() {
iveresov@2124 1737 if (invocation_counter()->carry()) {
iveresov@2124 1738 return 0;
iveresov@2124 1739 }
iveresov@2124 1740 return _invocation_counter_start;
iveresov@2124 1741 }
iveresov@2124 1742
iveresov@2124 1743 int backedge_count_start() {
iveresov@2124 1744 if (backedge_counter()->carry()) {
iveresov@2124 1745 return 0;
iveresov@2124 1746 }
iveresov@2124 1747 return _backedge_counter_start;
iveresov@2124 1748 }
iveresov@2124 1749
iveresov@2124 1750 int invocation_count_delta() { return invocation_count() - invocation_count_start(); }
iveresov@2124 1751 int backedge_count_delta() { return backedge_count() - backedge_count_start(); }
iveresov@2124 1752
iveresov@2124 1753 void reset_start_counters() {
iveresov@2124 1754 _invocation_counter_start = invocation_count();
iveresov@2124 1755 _backedge_counter_start = backedge_count();
iveresov@2124 1756 }
iveresov@2124 1757
iveresov@1703 1758 InvocationCounter* invocation_counter() { return &_invocation_counter; }
iveresov@1703 1759 InvocationCounter* backedge_counter() { return &_backedge_counter; }
iveresov@1703 1760
iveresov@1703 1761 void set_would_profile(bool p) { _would_profile = p; }
iveresov@1703 1762 bool would_profile() const { return _would_profile; }
iveresov@1703 1763
minqi@4662 1764 int highest_comp_level() const { return _highest_comp_level; }
iveresov@1703 1765 void set_highest_comp_level(int level) { _highest_comp_level = level; }
minqi@4662 1766 int highest_osr_comp_level() const { return _highest_osr_comp_level; }
iveresov@1703 1767 void set_highest_osr_comp_level(int level) { _highest_osr_comp_level = level; }
iveresov@1703 1768
iveresov@1703 1769 int num_loops() const { return _num_loops; }
iveresov@1703 1770 void set_num_loops(int n) { _num_loops = n; }
iveresov@1703 1771 int num_blocks() const { return _num_blocks; }
iveresov@1703 1772 void set_num_blocks(int n) { _num_blocks = n; }
iveresov@1703 1773
duke@0 1774 bool is_mature() const; // consult mileage and ProfileMaturityPercentage
coleenp@3602 1775 static int mileage_of(Method* m);
duke@0 1776
duke@0 1777 // Support for interprocedural escape analysis, from Thomas Kotzmann.
duke@0 1778 enum EscapeFlag {
duke@0 1779 estimated = 1 << 0,
kvn@78 1780 return_local = 1 << 1,
kvn@78 1781 return_allocated = 1 << 2,
kvn@78 1782 allocated_escapes = 1 << 3,
kvn@78 1783 unknown_modified = 1 << 4
duke@0 1784 };
duke@0 1785
duke@0 1786 intx eflags() { return _eflags; }
duke@0 1787 intx arg_local() { return _arg_local; }
duke@0 1788 intx arg_stack() { return _arg_stack; }
duke@0 1789 intx arg_returned() { return _arg_returned; }
kvn@45 1790 uint arg_modified(int a) { ArgInfoData *aid = arg_info();
iignatyev@4473 1791 assert(aid != NULL, "arg_info must be not null");
kvn@45 1792 assert(a >= 0 && a < aid->number_of_args(), "valid argument number");
kvn@45 1793 return aid->arg_modified(a); }
duke@0 1794
duke@0 1795 void set_eflags(intx v) { _eflags = v; }
duke@0 1796 void set_arg_local(intx v) { _arg_local = v; }
duke@0 1797 void set_arg_stack(intx v) { _arg_stack = v; }
duke@0 1798 void set_arg_returned(intx v) { _arg_returned = v; }
kvn@45 1799 void set_arg_modified(int a, uint v) { ArgInfoData *aid = arg_info();
iignatyev@4473 1800 assert(aid != NULL, "arg_info must be not null");
kvn@45 1801 assert(a >= 0 && a < aid->number_of_args(), "valid argument number");
kvn@45 1802 aid->set_arg_modified(a, v); }
duke@0 1803
duke@0 1804 void clear_escape_info() { _eflags = _arg_local = _arg_stack = _arg_returned = 0; }
duke@0 1805
duke@0 1806 // Location and size of data area
duke@0 1807 address data_base() const {
duke@0 1808 return (address) _data;
duke@0 1809 }
coleenp@3602 1810 int data_size() const {
duke@0 1811 return _data_size;
duke@0 1812 }
duke@0 1813
duke@0 1814 // Accessors
coleenp@3602 1815 Method* method() const { return _method; }
duke@0 1816
duke@0 1817 // Get the data at an arbitrary (sort of) data index.
coleenp@3602 1818 ProfileData* data_at(int data_index) const;
duke@0 1819
duke@0 1820 // Walk through the data in order.
coleenp@3602 1821 ProfileData* first_data() const { return data_at(first_di()); }
coleenp@3602 1822 ProfileData* next_data(ProfileData* current) const;
coleenp@3602 1823 bool is_valid(ProfileData* current) const { return current != NULL; }
duke@0 1824
duke@0 1825 // Convert a dp (data pointer) to a di (data index).
coleenp@3602 1826 int dp_to_di(address dp) const {
duke@0 1827 return dp - ((address)_data);
duke@0 1828 }
duke@0 1829
duke@0 1830 address di_to_dp(int di) {
duke@0 1831 return (address)data_layout_at(di);
duke@0 1832 }
duke@0 1833
duke@0 1834 // bci to di/dp conversion.
duke@0 1835 address bci_to_dp(int bci);
duke@0 1836 int bci_to_di(int bci) {
duke@0 1837 return dp_to_di(bci_to_dp(bci));
duke@0 1838 }
duke@0 1839
duke@0 1840 // Get the data at an arbitrary bci, or NULL if there is none.
duke@0 1841 ProfileData* bci_to_data(int bci);
duke@0 1842
duke@0 1843 // Same, but try to create an extra_data record if one is needed:
duke@0 1844 ProfileData* allocate_bci_to_data(int bci) {
duke@0 1845 ProfileData* data = bci_to_data(bci);
duke@0 1846 return (data != NULL) ? data : bci_to_extra_data(bci, true);
duke@0 1847 }
duke@0 1848
duke@0 1849 // Add a handful of extra data records, for trap tracking.
coleenp@3602 1850 DataLayout* extra_data_base() const { return limit_data_position(); }
coleenp@3602 1851 DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); }
coleenp@3602 1852 int extra_data_size() const { return (address)extra_data_limit()
duke@0 1853 - (address)extra_data_base(); }
duke@0 1854 static DataLayout* next_extra(DataLayout* dp) { return (DataLayout*)((address)dp + in_bytes(DataLayout::cell_offset(0))); }
duke@0 1855
duke@0 1856 // Return (uint)-1 for overflow.
duke@0 1857 uint trap_count(int reason) const {
duke@0 1858 assert((uint)reason < _trap_hist_limit, "oob");
duke@0 1859 return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1;
duke@0 1860 }
duke@0 1861 // For loops:
duke@0 1862 static uint trap_reason_limit() { return _trap_hist_limit; }
duke@0 1863 static uint trap_count_limit() { return _trap_hist_mask; }
duke@0 1864 uint inc_trap_count(int reason) {
duke@0 1865 // Count another trap, anywhere in this method.
duke@0 1866 assert(reason >= 0, "must be single trap");
duke@0 1867 if ((uint)reason < _trap_hist_limit) {
duke@0 1868 uint cnt1 = 1 + _trap_hist._array[reason];
duke@0 1869 if ((cnt1 & _trap_hist_mask) != 0) { // if no counter overflow...
duke@0 1870 _trap_hist._array[reason] = cnt1;
duke@0 1871 return cnt1;
duke@0 1872 } else {
duke@0 1873 return _trap_hist_mask + (++_nof_overflow_traps);
duke@0 1874 }
duke@0 1875 } else {
duke@0 1876 // Could not represent the count in the histogram.
duke@0 1877 return (++_nof_overflow_traps);
duke@0 1878 }
duke@0 1879 }
duke@0 1880
duke@0 1881 uint overflow_trap_count() const {
duke@0 1882 return _nof_overflow_traps;
duke@0 1883 }
duke@0 1884 uint overflow_recompile_count() const {
duke@0 1885 return _nof_overflow_recompiles;
duke@0 1886 }
duke@0 1887 void inc_overflow_recompile_count() {
duke@0 1888 _nof_overflow_recompiles += 1;
duke@0 1889 }
duke@0 1890 uint decompile_count() const {
duke@0 1891 return _nof_decompiles;
duke@0 1892 }
duke@0 1893 void inc_decompile_count() {
duke@0 1894 _nof_decompiles += 1;
kvn@1206 1895 if (decompile_count() > (uint)PerMethodRecompilationCutoff) {
vlivanov@4104 1896 method()->set_not_compilable(CompLevel_full_optimization, true, "decompile_count > PerMethodRecompilationCutoff");
kvn@1206 1897 }
duke@0 1898 }
duke@0 1899
duke@0 1900 // Support for code generation
duke@0 1901 static ByteSize data_offset() {
coleenp@3602 1902 return byte_offset_of(MethodData, _data[0]);
duke@0 1903 }
duke@0 1904
iveresov@1703 1905 static ByteSize invocation_counter_offset() {
coleenp@3602 1906 return byte_offset_of(MethodData, _invocation_counter);
iveresov@1703 1907 }
iveresov@1703 1908 static ByteSize backedge_counter_offset() {
coleenp@3602 1909 return byte_offset_of(MethodData, _backedge_counter);
iveresov@1703 1910 }
iveresov@1703 1911
coleenp@3602 1912 // Deallocation support - no pointer fields to deallocate
coleenp@3602 1913 void deallocate_contents(ClassLoaderData* loader_data) {}
coleenp@3602 1914
duke@0 1915 // GC support
coleenp@3602 1916 void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
coleenp@3602 1917
coleenp@3602 1918 // Printing
coleenp@3602 1919 #ifndef PRODUCT
coleenp@3602 1920 void print_on (outputStream* st) const;
coleenp@3602 1921 #endif
coleenp@3602 1922 void print_value_on(outputStream* st) const;
duke@0 1923
duke@0 1924 #ifndef PRODUCT
duke@0 1925 // printing support for method data
coleenp@3602 1926 void print_data_on(outputStream* st) const;
duke@0 1927 #endif
duke@0 1928
coleenp@3602 1929 const char* internal_name() const { return "{method data}"; }
coleenp@3602 1930
duke@0 1931 // verification
coleenp@3602 1932 void verify_on(outputStream* st);
duke@0 1933 void verify_data_on(outputStream* st);
roland@5479 1934
roland@5479 1935 static bool profile_arguments();
duke@0 1936 };
stefank@1879 1937
stefank@1879 1938 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP