src/share/vm/oops/methodData.hpp

Tue, 11 Nov 2014 11:05:41 +0100

author
thartmann
date
Tue, 11 Nov 2014 11:05:41 +0100
changeset 7365
600c44255e5f
parent 7171
631667807de7
child 7535
7ae4e26cb1e0
child 9183
f95c67788f18
permissions
-rw-r--r--

8056071: compiler/whitebox/IsMethodCompilableTest.java fails with 'method() is not compilable after 3 iterations'
Summary: Always use MDO if valid and always compile trivial methods with C1 if available.
Reviewed-by: kvn, iveresov

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

mercurial