src/share/vm/oops/methodData.hpp

Tue, 22 Oct 2013 09:51:47 +0200

author
roland
date
Tue, 22 Oct 2013 09:51:47 +0200
changeset 5987
5ccbab1c69f3
parent 5921
ce0cc25bc5e2
child 6105
6e1826d5c23e
child 6472
2b8e28fdf503
permissions
-rw-r--r--

8026251: New type profiling points: parameters to methods
Summary: x86 interpreter and c1 type profiling for parameters on method entries
Reviewed-by: kvn, twisti

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

mercurial