annotate src/share/vm/oops/methodData.hpp @ 12823:b756e7a2ec33

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