annotate src/share/vm/oops/methodData.hpp @ 6464:75e1ec763270

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