src/share/vm/oops/methodData.hpp

Thu, 21 Nov 2013 12:30:35 -0800

author
kvn
date
Thu, 21 Nov 2013 12:30:35 -0800
changeset 6485
da862781b584
parent 6483
018b357638aa
parent 6105
6e1826d5c23e
child 6518
62c54fcc0a35
permissions
-rw-r--r--

Merge

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

mercurial