src/share/vm/oops/methodData.hpp

Tue, 25 Feb 2014 18:16:24 +0100

author
roland
date
Tue, 25 Feb 2014 18:16:24 +0100
changeset 6377
b8413a9cbb84
parent 6105
6e1826d5c23e
child 6382
1a43981d86ea
permissions
-rw-r--r--

8031752: Failed speculative optimizations should be reattempted when root of compilation is different
Summary: support for speculative traps that keep track of the root of the compilation in which a trap occurs.
Reviewed-by: kvn, twisti

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

mercurial