src/share/vm/oops/methodData.hpp

Sun, 15 Sep 2013 15:28:58 +0200

author
goetz
date
Sun, 15 Sep 2013 15:28:58 +0200
changeset 6470
abe03600372a
parent 5097
92ef81e2f571
child 6472
2b8e28fdf503
permissions
-rw-r--r--

8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
Summary: Implement profiling for c2 jit compilation. Also enable new cppInterpreter features.
Reviewed-by: kvn

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 {
duke@435 75 private:
duke@435 76 // Every data layout begins with a header. This header
duke@435 77 // contains a tag, which is used to indicate the size/layout
duke@435 78 // of the data, 4 bits of flags, which can be used in any way,
duke@435 79 // 4 bits of trap history (none/one reason/many reasons),
duke@435 80 // and a bci, which is used to tie this piece of data to a
duke@435 81 // specific bci in the bytecodes.
duke@435 82 union {
duke@435 83 intptr_t _bits;
duke@435 84 struct {
duke@435 85 u1 _tag;
duke@435 86 u1 _flags;
duke@435 87 u2 _bci;
duke@435 88 } _struct;
duke@435 89 } _header;
duke@435 90
duke@435 91 // The data layout has an arbitrary number of cells, each sized
duke@435 92 // to accomodate a pointer or an integer.
duke@435 93 intptr_t _cells[1];
duke@435 94
duke@435 95 // Some types of data layouts need a length field.
duke@435 96 static bool needs_array_len(u1 tag);
duke@435 97
duke@435 98 public:
duke@435 99 enum {
duke@435 100 counter_increment = 1
duke@435 101 };
duke@435 102
duke@435 103 enum {
duke@435 104 cell_size = sizeof(intptr_t)
duke@435 105 };
duke@435 106
duke@435 107 // Tag values
duke@435 108 enum {
duke@435 109 no_tag,
duke@435 110 bit_data_tag,
duke@435 111 counter_data_tag,
duke@435 112 jump_data_tag,
duke@435 113 receiver_type_data_tag,
duke@435 114 virtual_call_data_tag,
duke@435 115 ret_data_tag,
duke@435 116 branch_data_tag,
kvn@480 117 multi_branch_data_tag,
kvn@480 118 arg_info_data_tag
duke@435 119 };
duke@435 120
duke@435 121 enum {
duke@435 122 // The _struct._flags word is formatted as [trap_state:4 | flags:4].
duke@435 123 // The trap state breaks down further as [recompile:1 | reason:3].
duke@435 124 // This further breakdown is defined in deoptimization.cpp.
duke@435 125 // See Deoptimization::trap_state_reason for an assert that
duke@435 126 // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
duke@435 127 //
duke@435 128 // The trap_state is collected only if ProfileTraps is true.
duke@435 129 trap_bits = 1+3, // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
duke@435 130 trap_shift = BitsPerByte - trap_bits,
duke@435 131 trap_mask = right_n_bits(trap_bits),
duke@435 132 trap_mask_in_place = (trap_mask << trap_shift),
duke@435 133 flag_limit = trap_shift,
duke@435 134 flag_mask = right_n_bits(flag_limit),
duke@435 135 first_flag = 0
duke@435 136 };
duke@435 137
duke@435 138 // Size computation
duke@435 139 static int header_size_in_bytes() {
duke@435 140 return cell_size;
duke@435 141 }
duke@435 142 static int header_size_in_cells() {
duke@435 143 return 1;
duke@435 144 }
duke@435 145
duke@435 146 static int compute_size_in_bytes(int cell_count) {
duke@435 147 return header_size_in_bytes() + cell_count * cell_size;
duke@435 148 }
duke@435 149
duke@435 150 // Initialization
duke@435 151 void initialize(u1 tag, u2 bci, int cell_count);
duke@435 152
duke@435 153 // Accessors
duke@435 154 u1 tag() {
duke@435 155 return _header._struct._tag;
duke@435 156 }
duke@435 157
duke@435 158 // Return a few bits of trap state. Range is [0..trap_mask].
duke@435 159 // The state tells if traps with zero, one, or many reasons have occurred.
duke@435 160 // It also tells whether zero or many recompilations have occurred.
duke@435 161 // The associated trap histogram in the MDO itself tells whether
duke@435 162 // traps are common or not. If a BCI shows that a trap X has
duke@435 163 // occurred, and the MDO shows N occurrences of X, we make the
duke@435 164 // simplifying assumption that all N occurrences can be blamed
duke@435 165 // on that BCI.
duke@435 166 int trap_state() {
duke@435 167 return ((_header._struct._flags >> trap_shift) & trap_mask);
duke@435 168 }
duke@435 169
duke@435 170 void set_trap_state(int new_state) {
duke@435 171 assert(ProfileTraps, "used only under +ProfileTraps");
duke@435 172 uint old_flags = (_header._struct._flags & flag_mask);
duke@435 173 _header._struct._flags = (new_state << trap_shift) | old_flags;
duke@435 174 }
duke@435 175
duke@435 176 u1 flags() {
duke@435 177 return _header._struct._flags;
duke@435 178 }
duke@435 179
duke@435 180 u2 bci() {
duke@435 181 return _header._struct._bci;
duke@435 182 }
duke@435 183
duke@435 184 void set_header(intptr_t value) {
duke@435 185 _header._bits = value;
duke@435 186 }
duke@435 187 void release_set_header(intptr_t value) {
duke@435 188 OrderAccess::release_store_ptr(&_header._bits, value);
duke@435 189 }
duke@435 190 intptr_t header() {
duke@435 191 return _header._bits;
duke@435 192 }
duke@435 193 void set_cell_at(int index, intptr_t value) {
duke@435 194 _cells[index] = value;
duke@435 195 }
duke@435 196 void release_set_cell_at(int index, intptr_t value) {
duke@435 197 OrderAccess::release_store_ptr(&_cells[index], value);
duke@435 198 }
duke@435 199 intptr_t cell_at(int index) {
duke@435 200 return _cells[index];
duke@435 201 }
duke@435 202
duke@435 203 void set_flag_at(int flag_number) {
duke@435 204 assert(flag_number < flag_limit, "oob");
duke@435 205 _header._struct._flags |= (0x1 << flag_number);
duke@435 206 }
duke@435 207 bool flag_at(int flag_number) {
duke@435 208 assert(flag_number < flag_limit, "oob");
duke@435 209 return (_header._struct._flags & (0x1 << flag_number)) != 0;
duke@435 210 }
duke@435 211
duke@435 212 // Low-level support for code generation.
duke@435 213 static ByteSize header_offset() {
duke@435 214 return byte_offset_of(DataLayout, _header);
duke@435 215 }
duke@435 216 static ByteSize tag_offset() {
duke@435 217 return byte_offset_of(DataLayout, _header._struct._tag);
duke@435 218 }
duke@435 219 static ByteSize flags_offset() {
duke@435 220 return byte_offset_of(DataLayout, _header._struct._flags);
duke@435 221 }
duke@435 222 static ByteSize bci_offset() {
duke@435 223 return byte_offset_of(DataLayout, _header._struct._bci);
duke@435 224 }
duke@435 225 static ByteSize cell_offset(int index) {
coleenp@2615 226 return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
duke@435 227 }
goetz@6470 228 #ifdef CC_INTERP
goetz@6470 229 static int cell_offset_in_bytes(int index) {
goetz@6470 230 return (int)offset_of(DataLayout, _cells[index]);
goetz@6470 231 }
goetz@6470 232 #endif // CC_INTERP
duke@435 233 // Return a value which, when or-ed as a byte into _flags, sets the flag.
duke@435 234 static int flag_number_to_byte_constant(int flag_number) {
duke@435 235 assert(0 <= flag_number && flag_number < flag_limit, "oob");
duke@435 236 DataLayout temp; temp.set_header(0);
duke@435 237 temp.set_flag_at(flag_number);
duke@435 238 return temp._header._struct._flags;
duke@435 239 }
duke@435 240 // Return a value which, when or-ed as a word into _header, sets the flag.
duke@435 241 static intptr_t flag_mask_to_header_mask(int byte_constant) {
duke@435 242 DataLayout temp; temp.set_header(0);
duke@435 243 temp._header._struct._flags = byte_constant;
duke@435 244 return temp._header._bits;
duke@435 245 }
ysr@1376 246
coleenp@4037 247 ProfileData* data_in();
coleenp@4037 248
ysr@1376 249 // GC support
coleenp@4037 250 void clean_weak_klass_links(BoolObjectClosure* cl);
duke@435 251 };
duke@435 252
duke@435 253
duke@435 254 // ProfileData class hierarchy
duke@435 255 class ProfileData;
duke@435 256 class BitData;
duke@435 257 class CounterData;
duke@435 258 class ReceiverTypeData;
duke@435 259 class VirtualCallData;
duke@435 260 class RetData;
duke@435 261 class JumpData;
duke@435 262 class BranchData;
duke@435 263 class ArrayData;
duke@435 264 class MultiBranchData;
kvn@480 265 class ArgInfoData;
duke@435 266
duke@435 267
duke@435 268 // ProfileData
duke@435 269 //
duke@435 270 // A ProfileData object is created to refer to a section of profiling
duke@435 271 // data in a structured way.
duke@435 272 class ProfileData : public ResourceObj {
duke@435 273 private:
duke@435 274 #ifndef PRODUCT
duke@435 275 enum {
duke@435 276 tab_width_one = 16,
duke@435 277 tab_width_two = 36
duke@435 278 };
duke@435 279 #endif // !PRODUCT
duke@435 280
duke@435 281 // This is a pointer to a section of profiling data.
duke@435 282 DataLayout* _data;
duke@435 283
duke@435 284 protected:
duke@435 285 DataLayout* data() { return _data; }
duke@435 286
duke@435 287 enum {
duke@435 288 cell_size = DataLayout::cell_size
duke@435 289 };
duke@435 290
duke@435 291 public:
duke@435 292 // How many cells are in this?
duke@435 293 virtual int cell_count() {
duke@435 294 ShouldNotReachHere();
duke@435 295 return -1;
duke@435 296 }
duke@435 297
duke@435 298 // Return the size of this data.
duke@435 299 int size_in_bytes() {
duke@435 300 return DataLayout::compute_size_in_bytes(cell_count());
duke@435 301 }
duke@435 302
duke@435 303 protected:
duke@435 304 // Low-level accessors for underlying data
duke@435 305 void set_intptr_at(int index, intptr_t value) {
duke@435 306 assert(0 <= index && index < cell_count(), "oob");
duke@435 307 data()->set_cell_at(index, value);
duke@435 308 }
duke@435 309 void release_set_intptr_at(int index, intptr_t value) {
duke@435 310 assert(0 <= index && index < cell_count(), "oob");
duke@435 311 data()->release_set_cell_at(index, value);
duke@435 312 }
duke@435 313 intptr_t intptr_at(int index) {
duke@435 314 assert(0 <= index && index < cell_count(), "oob");
duke@435 315 return data()->cell_at(index);
duke@435 316 }
duke@435 317 void set_uint_at(int index, uint value) {
duke@435 318 set_intptr_at(index, (intptr_t) value);
duke@435 319 }
duke@435 320 void release_set_uint_at(int index, uint value) {
duke@435 321 release_set_intptr_at(index, (intptr_t) value);
duke@435 322 }
duke@435 323 uint uint_at(int index) {
duke@435 324 return (uint)intptr_at(index);
duke@435 325 }
duke@435 326 void set_int_at(int index, int value) {
duke@435 327 set_intptr_at(index, (intptr_t) value);
duke@435 328 }
duke@435 329 void release_set_int_at(int index, int value) {
duke@435 330 release_set_intptr_at(index, (intptr_t) value);
duke@435 331 }
duke@435 332 int int_at(int index) {
duke@435 333 return (int)intptr_at(index);
duke@435 334 }
duke@435 335 int int_at_unchecked(int index) {
duke@435 336 return (int)data()->cell_at(index);
duke@435 337 }
duke@435 338 void set_oop_at(int index, oop value) {
duke@435 339 set_intptr_at(index, (intptr_t) value);
duke@435 340 }
duke@435 341 oop oop_at(int index) {
duke@435 342 return (oop)intptr_at(index);
duke@435 343 }
duke@435 344
duke@435 345 void set_flag_at(int flag_number) {
duke@435 346 data()->set_flag_at(flag_number);
duke@435 347 }
duke@435 348 bool flag_at(int flag_number) {
duke@435 349 return data()->flag_at(flag_number);
duke@435 350 }
duke@435 351
duke@435 352 // two convenient imports for use by subclasses:
duke@435 353 static ByteSize cell_offset(int index) {
duke@435 354 return DataLayout::cell_offset(index);
duke@435 355 }
duke@435 356 static int flag_number_to_byte_constant(int flag_number) {
duke@435 357 return DataLayout::flag_number_to_byte_constant(flag_number);
duke@435 358 }
duke@435 359
duke@435 360 ProfileData(DataLayout* data) {
duke@435 361 _data = data;
duke@435 362 }
duke@435 363
goetz@6470 364 #ifdef CC_INTERP
goetz@6470 365 // Static low level accessors for DataLayout with ProfileData's semantics.
goetz@6470 366
goetz@6470 367 static int cell_offset_in_bytes(int index) {
goetz@6470 368 return DataLayout::cell_offset_in_bytes(index);
goetz@6470 369 }
goetz@6470 370
goetz@6470 371 static void increment_uint_at_no_overflow(DataLayout* layout, int index,
goetz@6470 372 int inc = DataLayout::counter_increment) {
goetz@6470 373 uint count = ((uint)layout->cell_at(index)) + inc;
goetz@6470 374 if (count == 0) return;
goetz@6470 375 layout->set_cell_at(index, (intptr_t) count);
goetz@6470 376 }
goetz@6470 377
goetz@6470 378 static int int_at(DataLayout* layout, int index) {
goetz@6470 379 return (int)layout->cell_at(index);
goetz@6470 380 }
goetz@6470 381
goetz@6470 382 static int uint_at(DataLayout* layout, int index) {
goetz@6470 383 return (uint)layout->cell_at(index);
goetz@6470 384 }
goetz@6470 385
goetz@6470 386 static oop oop_at(DataLayout* layout, int index) {
goetz@6470 387 return (oop)layout->cell_at(index);
goetz@6470 388 }
goetz@6470 389
goetz@6470 390 static void set_intptr_at(DataLayout* layout, int index, intptr_t value) {
goetz@6470 391 layout->set_cell_at(index, (intptr_t) value);
goetz@6470 392 }
goetz@6470 393
goetz@6470 394 static void set_flag_at(DataLayout* layout, int flag_number) {
goetz@6470 395 layout->set_flag_at(flag_number);
goetz@6470 396 }
goetz@6470 397 #endif // CC_INTERP
goetz@6470 398
duke@435 399 public:
duke@435 400 // Constructor for invalid ProfileData.
duke@435 401 ProfileData();
duke@435 402
duke@435 403 u2 bci() {
duke@435 404 return data()->bci();
duke@435 405 }
duke@435 406
duke@435 407 address dp() {
duke@435 408 return (address)_data;
duke@435 409 }
duke@435 410
duke@435 411 int trap_state() {
duke@435 412 return data()->trap_state();
duke@435 413 }
duke@435 414 void set_trap_state(int new_state) {
duke@435 415 data()->set_trap_state(new_state);
duke@435 416 }
duke@435 417
duke@435 418 // Type checking
duke@435 419 virtual bool is_BitData() { return false; }
duke@435 420 virtual bool is_CounterData() { return false; }
duke@435 421 virtual bool is_JumpData() { return false; }
duke@435 422 virtual bool is_ReceiverTypeData(){ return false; }
duke@435 423 virtual bool is_VirtualCallData() { return false; }
duke@435 424 virtual bool is_RetData() { return false; }
duke@435 425 virtual bool is_BranchData() { return false; }
duke@435 426 virtual bool is_ArrayData() { return false; }
duke@435 427 virtual bool is_MultiBranchData() { return false; }
kvn@480 428 virtual bool is_ArgInfoData() { return false; }
kvn@480 429
duke@435 430
duke@435 431 BitData* as_BitData() {
duke@435 432 assert(is_BitData(), "wrong type");
duke@435 433 return is_BitData() ? (BitData*) this : NULL;
duke@435 434 }
duke@435 435 CounterData* as_CounterData() {
duke@435 436 assert(is_CounterData(), "wrong type");
duke@435 437 return is_CounterData() ? (CounterData*) this : NULL;
duke@435 438 }
duke@435 439 JumpData* as_JumpData() {
duke@435 440 assert(is_JumpData(), "wrong type");
duke@435 441 return is_JumpData() ? (JumpData*) this : NULL;
duke@435 442 }
duke@435 443 ReceiverTypeData* as_ReceiverTypeData() {
duke@435 444 assert(is_ReceiverTypeData(), "wrong type");
duke@435 445 return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
duke@435 446 }
duke@435 447 VirtualCallData* as_VirtualCallData() {
duke@435 448 assert(is_VirtualCallData(), "wrong type");
duke@435 449 return is_VirtualCallData() ? (VirtualCallData*)this : NULL;
duke@435 450 }
duke@435 451 RetData* as_RetData() {
duke@435 452 assert(is_RetData(), "wrong type");
duke@435 453 return is_RetData() ? (RetData*) this : NULL;
duke@435 454 }
duke@435 455 BranchData* as_BranchData() {
duke@435 456 assert(is_BranchData(), "wrong type");
duke@435 457 return is_BranchData() ? (BranchData*) this : NULL;
duke@435 458 }
duke@435 459 ArrayData* as_ArrayData() {
duke@435 460 assert(is_ArrayData(), "wrong type");
duke@435 461 return is_ArrayData() ? (ArrayData*) this : NULL;
duke@435 462 }
duke@435 463 MultiBranchData* as_MultiBranchData() {
duke@435 464 assert(is_MultiBranchData(), "wrong type");
duke@435 465 return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
duke@435 466 }
kvn@480 467 ArgInfoData* as_ArgInfoData() {
kvn@480 468 assert(is_ArgInfoData(), "wrong type");
kvn@480 469 return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
kvn@480 470 }
duke@435 471
duke@435 472
duke@435 473 // Subclass specific initialization
coleenp@4037 474 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
duke@435 475
duke@435 476 // GC support
coleenp@4037 477 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
duke@435 478
duke@435 479 // CI translation: ProfileData can represent both MethodDataOop data
duke@435 480 // as well as CIMethodData data. This function is provided for translating
duke@435 481 // an oop in a ProfileData to the ci equivalent. Generally speaking,
duke@435 482 // most ProfileData don't require any translation, so we provide the null
duke@435 483 // translation here, and the required translators are in the ci subclasses.
duke@435 484 virtual void translate_from(ProfileData* data) {}
duke@435 485
duke@435 486 virtual void print_data_on(outputStream* st) {
duke@435 487 ShouldNotReachHere();
duke@435 488 }
duke@435 489
duke@435 490 #ifndef PRODUCT
duke@435 491 void print_shared(outputStream* st, const char* name);
duke@435 492 void tab(outputStream* st);
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
duke@435 511 virtual bool is_BitData() { 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
duke@435 517 virtual int cell_count() {
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
goetz@6470 538 #ifdef CC_INTERP
goetz@6470 539 static int bit_data_size_in_bytes() {
goetz@6470 540 return cell_offset_in_bytes(bit_cell_count);
goetz@6470 541 }
goetz@6470 542
goetz@6470 543 static void set_null_seen(DataLayout* layout) {
goetz@6470 544 set_flag_at(layout, null_seen_flag);
goetz@6470 545 }
goetz@6470 546
goetz@6470 547 static DataLayout* advance(DataLayout* layout) {
goetz@6470 548 return (DataLayout*) (((address)layout) + (ssize_t)BitData::bit_data_size_in_bytes());
goetz@6470 549 }
goetz@6470 550 #endif // CC_INTERP
goetz@6470 551
duke@435 552 #ifndef PRODUCT
duke@435 553 void print_data_on(outputStream* st);
duke@435 554 #endif
duke@435 555 };
duke@435 556
duke@435 557 // CounterData
duke@435 558 //
duke@435 559 // A CounterData corresponds to a simple counter.
duke@435 560 class CounterData : public BitData {
duke@435 561 protected:
duke@435 562 enum {
duke@435 563 count_off,
duke@435 564 counter_cell_count
duke@435 565 };
duke@435 566 public:
duke@435 567 CounterData(DataLayout* layout) : BitData(layout) {}
duke@435 568
duke@435 569 virtual bool is_CounterData() { return true; }
duke@435 570
duke@435 571 static int static_cell_count() {
duke@435 572 return counter_cell_count;
duke@435 573 }
duke@435 574
duke@435 575 virtual int cell_count() {
duke@435 576 return static_cell_count();
duke@435 577 }
duke@435 578
duke@435 579 // Direct accessor
duke@435 580 uint count() {
duke@435 581 return uint_at(count_off);
duke@435 582 }
duke@435 583
duke@435 584 // Code generation support
duke@435 585 static ByteSize count_offset() {
duke@435 586 return cell_offset(count_off);
duke@435 587 }
duke@435 588 static ByteSize counter_data_size() {
duke@435 589 return cell_offset(counter_cell_count);
duke@435 590 }
duke@435 591
kvn@1686 592 void set_count(uint count) {
kvn@1686 593 set_uint_at(count_off, count);
kvn@1686 594 }
kvn@1686 595
goetz@6470 596 #ifdef CC_INTERP
goetz@6470 597 static int counter_data_size_in_bytes() {
goetz@6470 598 return cell_offset_in_bytes(counter_cell_count);
goetz@6470 599 }
goetz@6470 600
goetz@6470 601 static void increment_count_no_overflow(DataLayout* layout) {
goetz@6470 602 increment_uint_at_no_overflow(layout, count_off);
goetz@6470 603 }
goetz@6470 604
goetz@6470 605 // Support counter decrementation at checkcast / subtype check failed.
goetz@6470 606 static void decrement_count(DataLayout* layout) {
goetz@6470 607 increment_uint_at_no_overflow(layout, count_off, -1);
goetz@6470 608 }
goetz@6470 609
goetz@6470 610 static DataLayout* advance(DataLayout* layout) {
goetz@6470 611 return (DataLayout*) (((address)layout) + (ssize_t)CounterData::counter_data_size_in_bytes());
goetz@6470 612 }
goetz@6470 613 #endif // CC_INTERP
goetz@6470 614
duke@435 615 #ifndef PRODUCT
duke@435 616 void print_data_on(outputStream* st);
duke@435 617 #endif
duke@435 618 };
duke@435 619
duke@435 620 // JumpData
duke@435 621 //
duke@435 622 // A JumpData is used to access profiling information for a direct
duke@435 623 // branch. It is a counter, used for counting the number of branches,
duke@435 624 // plus a data displacement, used for realigning the data pointer to
duke@435 625 // the corresponding target bci.
duke@435 626 class JumpData : public ProfileData {
duke@435 627 protected:
duke@435 628 enum {
duke@435 629 taken_off_set,
duke@435 630 displacement_off_set,
duke@435 631 jump_cell_count
duke@435 632 };
duke@435 633
duke@435 634 void set_displacement(int displacement) {
duke@435 635 set_int_at(displacement_off_set, displacement);
duke@435 636 }
duke@435 637
duke@435 638 public:
duke@435 639 JumpData(DataLayout* layout) : ProfileData(layout) {
duke@435 640 assert(layout->tag() == DataLayout::jump_data_tag ||
duke@435 641 layout->tag() == DataLayout::branch_data_tag, "wrong type");
duke@435 642 }
duke@435 643
duke@435 644 virtual bool is_JumpData() { return true; }
duke@435 645
duke@435 646 static int static_cell_count() {
duke@435 647 return jump_cell_count;
duke@435 648 }
duke@435 649
duke@435 650 virtual int cell_count() {
duke@435 651 return static_cell_count();
duke@435 652 }
duke@435 653
duke@435 654 // Direct accessor
duke@435 655 uint taken() {
duke@435 656 return uint_at(taken_off_set);
duke@435 657 }
never@3105 658
never@3105 659 void set_taken(uint cnt) {
never@3105 660 set_uint_at(taken_off_set, cnt);
never@3105 661 }
never@3105 662
duke@435 663 // Saturating counter
duke@435 664 uint inc_taken() {
duke@435 665 uint cnt = taken() + 1;
duke@435 666 // Did we wrap? Will compiler screw us??
duke@435 667 if (cnt == 0) cnt--;
duke@435 668 set_uint_at(taken_off_set, cnt);
duke@435 669 return cnt;
duke@435 670 }
duke@435 671
duke@435 672 int displacement() {
duke@435 673 return int_at(displacement_off_set);
duke@435 674 }
duke@435 675
duke@435 676 // Code generation support
duke@435 677 static ByteSize taken_offset() {
duke@435 678 return cell_offset(taken_off_set);
duke@435 679 }
duke@435 680
duke@435 681 static ByteSize displacement_offset() {
duke@435 682 return cell_offset(displacement_off_set);
duke@435 683 }
duke@435 684
goetz@6470 685 #ifdef CC_INTERP
goetz@6470 686 static void increment_taken_count_no_overflow(DataLayout* layout) {
goetz@6470 687 increment_uint_at_no_overflow(layout, taken_off_set);
goetz@6470 688 }
goetz@6470 689
goetz@6470 690 static DataLayout* advance_taken(DataLayout* layout) {
goetz@6470 691 return (DataLayout*) (((address)layout) + (ssize_t)int_at(layout, displacement_off_set));
goetz@6470 692 }
goetz@6470 693
goetz@6470 694 static uint taken_count(DataLayout* layout) {
goetz@6470 695 return (uint) uint_at(layout, taken_off_set);
goetz@6470 696 }
goetz@6470 697 #endif // CC_INTERP
goetz@6470 698
duke@435 699 // Specific initialization.
coleenp@4037 700 void post_initialize(BytecodeStream* stream, MethodData* mdo);
duke@435 701
duke@435 702 #ifndef PRODUCT
duke@435 703 void print_data_on(outputStream* st);
duke@435 704 #endif
duke@435 705 };
duke@435 706
duke@435 707 // ReceiverTypeData
duke@435 708 //
duke@435 709 // A ReceiverTypeData is used to access profiling information about a
duke@435 710 // dynamic type check. It consists of a counter which counts the total times
coleenp@4037 711 // that the check is reached, and a series of (Klass*, count) pairs
duke@435 712 // which are used to store a type profile for the receiver of the check.
duke@435 713 class ReceiverTypeData : public CounterData {
duke@435 714 protected:
duke@435 715 enum {
duke@435 716 receiver0_offset = counter_cell_count,
duke@435 717 count0_offset,
duke@435 718 receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
duke@435 719 };
duke@435 720
duke@435 721 public:
duke@435 722 ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
duke@435 723 assert(layout->tag() == DataLayout::receiver_type_data_tag ||
duke@435 724 layout->tag() == DataLayout::virtual_call_data_tag, "wrong type");
duke@435 725 }
duke@435 726
duke@435 727 virtual bool is_ReceiverTypeData() { return true; }
duke@435 728
duke@435 729 static int static_cell_count() {
duke@435 730 return counter_cell_count + (uint) TypeProfileWidth * receiver_type_row_cell_count;
duke@435 731 }
duke@435 732
duke@435 733 virtual int cell_count() {
duke@435 734 return static_cell_count();
duke@435 735 }
duke@435 736
duke@435 737 // Direct accessors
duke@435 738 static uint row_limit() {
duke@435 739 return TypeProfileWidth;
duke@435 740 }
duke@435 741 static int receiver_cell_index(uint row) {
duke@435 742 return receiver0_offset + row * receiver_type_row_cell_count;
duke@435 743 }
duke@435 744 static int receiver_count_cell_index(uint row) {
duke@435 745 return count0_offset + row * receiver_type_row_cell_count;
duke@435 746 }
duke@435 747
coleenp@4037 748 Klass* receiver(uint row) {
duke@435 749 assert(row < row_limit(), "oob");
duke@435 750
coleenp@4037 751 Klass* recv = (Klass*)intptr_at(receiver_cell_index(row));
coleenp@4037 752 assert(recv == NULL || recv->is_klass(), "wrong type");
duke@435 753 return recv;
duke@435 754 }
duke@435 755
coleenp@4037 756 void set_receiver(uint row, Klass* k) {
ysr@1376 757 assert((uint)row < row_limit(), "oob");
coleenp@4037 758 set_intptr_at(receiver_cell_index(row), (uintptr_t)k);
ysr@1376 759 }
ysr@1376 760
duke@435 761 uint receiver_count(uint row) {
duke@435 762 assert(row < row_limit(), "oob");
duke@435 763 return uint_at(receiver_count_cell_index(row));
duke@435 764 }
duke@435 765
ysr@1376 766 void set_receiver_count(uint row, uint count) {
ysr@1376 767 assert(row < row_limit(), "oob");
ysr@1376 768 set_uint_at(receiver_count_cell_index(row), count);
ysr@1376 769 }
ysr@1376 770
ysr@1376 771 void clear_row(uint row) {
ysr@1376 772 assert(row < row_limit(), "oob");
kvn@1686 773 // Clear total count - indicator of polymorphic call site.
kvn@1686 774 // The site may look like as monomorphic after that but
kvn@1686 775 // it allow to have more accurate profiling information because
kvn@1686 776 // there was execution phase change since klasses were unloaded.
kvn@1686 777 // If the site is still polymorphic then MDO will be updated
kvn@1686 778 // to reflect it. But it could be the case that the site becomes
kvn@1686 779 // only bimorphic. Then keeping total count not 0 will be wrong.
kvn@1686 780 // Even if we use monomorphic (when it is not) for compilation
kvn@1686 781 // we will only have trap, deoptimization and recompile again
kvn@1686 782 // with updated MDO after executing method in Interpreter.
kvn@1686 783 // An additional receiver will be recorded in the cleaned row
kvn@1686 784 // during next call execution.
kvn@1686 785 //
kvn@1686 786 // Note: our profiling logic works with empty rows in any slot.
kvn@1686 787 // We do sorting a profiling info (ciCallProfile) for compilation.
kvn@1686 788 //
kvn@1686 789 set_count(0);
ysr@1376 790 set_receiver(row, NULL);
ysr@1376 791 set_receiver_count(row, 0);
ysr@1376 792 }
ysr@1376 793
duke@435 794 // Code generation support
duke@435 795 static ByteSize receiver_offset(uint row) {
duke@435 796 return cell_offset(receiver_cell_index(row));
duke@435 797 }
duke@435 798 static ByteSize receiver_count_offset(uint row) {
duke@435 799 return cell_offset(receiver_count_cell_index(row));
duke@435 800 }
duke@435 801 static ByteSize receiver_type_data_size() {
duke@435 802 return cell_offset(static_cell_count());
duke@435 803 }
duke@435 804
duke@435 805 // GC support
coleenp@4037 806 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
duke@435 807
goetz@6470 808 #ifdef CC_INTERP
goetz@6470 809 static int receiver_type_data_size_in_bytes() {
goetz@6470 810 return cell_offset_in_bytes(static_cell_count());
goetz@6470 811 }
goetz@6470 812
goetz@6470 813 static Klass *receiver_unchecked(DataLayout* layout, uint row) {
goetz@6470 814 oop recv = oop_at(layout, receiver_cell_index(row));
goetz@6470 815 return (Klass *)recv;
goetz@6470 816 }
goetz@6470 817
goetz@6470 818 static void increment_receiver_count_no_overflow(DataLayout* layout, Klass *rcvr) {
goetz@6470 819 const int num_rows = row_limit();
goetz@6470 820 // Receiver already exists?
goetz@6470 821 for (int row = 0; row < num_rows; row++) {
goetz@6470 822 if (receiver_unchecked(layout, row) == rcvr) {
goetz@6470 823 increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
goetz@6470 824 return;
goetz@6470 825 }
goetz@6470 826 }
goetz@6470 827 // New receiver, find a free slot.
goetz@6470 828 for (int row = 0; row < num_rows; row++) {
goetz@6470 829 if (receiver_unchecked(layout, row) == NULL) {
goetz@6470 830 set_intptr_at(layout, receiver_cell_index(row), (intptr_t)rcvr);
goetz@6470 831 increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
goetz@6470 832 return;
goetz@6470 833 }
goetz@6470 834 }
goetz@6470 835 // Receiver did not match any saved receiver and there is no empty row for it.
goetz@6470 836 // Increment total counter to indicate polymorphic case.
goetz@6470 837 increment_count_no_overflow(layout);
goetz@6470 838 }
goetz@6470 839
goetz@6470 840 static DataLayout* advance(DataLayout* layout) {
goetz@6470 841 return (DataLayout*) (((address)layout) + (ssize_t)ReceiverTypeData::receiver_type_data_size_in_bytes());
goetz@6470 842 }
goetz@6470 843 #endif // CC_INTERP
goetz@6470 844
duke@435 845 #ifndef PRODUCT
duke@435 846 void print_receiver_data_on(outputStream* st);
duke@435 847 void print_data_on(outputStream* st);
duke@435 848 #endif
duke@435 849 };
duke@435 850
duke@435 851 // VirtualCallData
duke@435 852 //
duke@435 853 // A VirtualCallData is used to access profiling information about a
duke@435 854 // virtual call. For now, it has nothing more than a ReceiverTypeData.
duke@435 855 class VirtualCallData : public ReceiverTypeData {
duke@435 856 public:
duke@435 857 VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
duke@435 858 assert(layout->tag() == DataLayout::virtual_call_data_tag, "wrong type");
duke@435 859 }
duke@435 860
duke@435 861 virtual bool is_VirtualCallData() { return true; }
duke@435 862
duke@435 863 static int static_cell_count() {
duke@435 864 // At this point we could add more profile state, e.g., for arguments.
duke@435 865 // But for now it's the same size as the base record type.
duke@435 866 return ReceiverTypeData::static_cell_count();
duke@435 867 }
duke@435 868
duke@435 869 virtual int cell_count() {
duke@435 870 return static_cell_count();
duke@435 871 }
duke@435 872
duke@435 873 // Direct accessors
duke@435 874 static ByteSize virtual_call_data_size() {
duke@435 875 return cell_offset(static_cell_count());
duke@435 876 }
duke@435 877
goetz@6470 878 #ifdef CC_INTERP
goetz@6470 879 static int virtual_call_data_size_in_bytes() {
goetz@6470 880 return cell_offset_in_bytes(static_cell_count());
goetz@6470 881 }
goetz@6470 882
goetz@6470 883 static DataLayout* advance(DataLayout* layout) {
goetz@6470 884 return (DataLayout*) (((address)layout) + (ssize_t)VirtualCallData::virtual_call_data_size_in_bytes());
goetz@6470 885 }
goetz@6470 886 #endif // CC_INTERP
goetz@6470 887
duke@435 888 #ifndef PRODUCT
duke@435 889 void print_data_on(outputStream* st);
duke@435 890 #endif
duke@435 891 };
duke@435 892
duke@435 893 // RetData
duke@435 894 //
duke@435 895 // A RetData is used to access profiling information for a ret bytecode.
duke@435 896 // It is composed of a count of the number of times that the ret has
duke@435 897 // been executed, followed by a series of triples of the form
duke@435 898 // (bci, count, di) which count the number of times that some bci was the
duke@435 899 // target of the ret and cache a corresponding data displacement.
duke@435 900 class RetData : public CounterData {
duke@435 901 protected:
duke@435 902 enum {
duke@435 903 bci0_offset = counter_cell_count,
duke@435 904 count0_offset,
duke@435 905 displacement0_offset,
duke@435 906 ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
duke@435 907 };
duke@435 908
duke@435 909 void set_bci(uint row, int bci) {
duke@435 910 assert((uint)row < row_limit(), "oob");
duke@435 911 set_int_at(bci0_offset + row * ret_row_cell_count, bci);
duke@435 912 }
duke@435 913 void release_set_bci(uint row, int bci) {
duke@435 914 assert((uint)row < row_limit(), "oob");
duke@435 915 // 'release' when setting the bci acts as a valid flag for other
duke@435 916 // threads wrt bci_count and bci_displacement.
duke@435 917 release_set_int_at(bci0_offset + row * ret_row_cell_count, bci);
duke@435 918 }
duke@435 919 void set_bci_count(uint row, uint count) {
duke@435 920 assert((uint)row < row_limit(), "oob");
duke@435 921 set_uint_at(count0_offset + row * ret_row_cell_count, count);
duke@435 922 }
duke@435 923 void set_bci_displacement(uint row, int disp) {
duke@435 924 set_int_at(displacement0_offset + row * ret_row_cell_count, disp);
duke@435 925 }
duke@435 926
duke@435 927 public:
duke@435 928 RetData(DataLayout* layout) : CounterData(layout) {
duke@435 929 assert(layout->tag() == DataLayout::ret_data_tag, "wrong type");
duke@435 930 }
duke@435 931
duke@435 932 virtual bool is_RetData() { return true; }
duke@435 933
duke@435 934 enum {
duke@435 935 no_bci = -1 // value of bci when bci1/2 are not in use.
duke@435 936 };
duke@435 937
duke@435 938 static int static_cell_count() {
duke@435 939 return counter_cell_count + (uint) BciProfileWidth * ret_row_cell_count;
duke@435 940 }
duke@435 941
duke@435 942 virtual int cell_count() {
duke@435 943 return static_cell_count();
duke@435 944 }
duke@435 945
duke@435 946 static uint row_limit() {
duke@435 947 return BciProfileWidth;
duke@435 948 }
duke@435 949 static int bci_cell_index(uint row) {
duke@435 950 return bci0_offset + row * ret_row_cell_count;
duke@435 951 }
duke@435 952 static int bci_count_cell_index(uint row) {
duke@435 953 return count0_offset + row * ret_row_cell_count;
duke@435 954 }
duke@435 955 static int bci_displacement_cell_index(uint row) {
duke@435 956 return displacement0_offset + row * ret_row_cell_count;
duke@435 957 }
duke@435 958
duke@435 959 // Direct accessors
duke@435 960 int bci(uint row) {
duke@435 961 return int_at(bci_cell_index(row));
duke@435 962 }
duke@435 963 uint bci_count(uint row) {
duke@435 964 return uint_at(bci_count_cell_index(row));
duke@435 965 }
duke@435 966 int bci_displacement(uint row) {
duke@435 967 return int_at(bci_displacement_cell_index(row));
duke@435 968 }
duke@435 969
duke@435 970 // Interpreter Runtime support
coleenp@4037 971 address fixup_ret(int return_bci, MethodData* mdo);
duke@435 972
duke@435 973 // Code generation support
duke@435 974 static ByteSize bci_offset(uint row) {
duke@435 975 return cell_offset(bci_cell_index(row));
duke@435 976 }
duke@435 977 static ByteSize bci_count_offset(uint row) {
duke@435 978 return cell_offset(bci_count_cell_index(row));
duke@435 979 }
duke@435 980 static ByteSize bci_displacement_offset(uint row) {
duke@435 981 return cell_offset(bci_displacement_cell_index(row));
duke@435 982 }
duke@435 983
goetz@6470 984 #ifdef CC_INTERP
goetz@6470 985 static DataLayout* advance(MethodData *md, int bci);
goetz@6470 986 #endif // CC_INTERP
goetz@6470 987
duke@435 988 // Specific initialization.
coleenp@4037 989 void post_initialize(BytecodeStream* stream, MethodData* mdo);
duke@435 990
duke@435 991 #ifndef PRODUCT
duke@435 992 void print_data_on(outputStream* st);
duke@435 993 #endif
duke@435 994 };
duke@435 995
duke@435 996 // BranchData
duke@435 997 //
duke@435 998 // A BranchData is used to access profiling data for a two-way branch.
duke@435 999 // It consists of taken and not_taken counts as well as a data displacement
duke@435 1000 // for the taken case.
duke@435 1001 class BranchData : public JumpData {
duke@435 1002 protected:
duke@435 1003 enum {
duke@435 1004 not_taken_off_set = jump_cell_count,
duke@435 1005 branch_cell_count
duke@435 1006 };
duke@435 1007
duke@435 1008 void set_displacement(int displacement) {
duke@435 1009 set_int_at(displacement_off_set, displacement);
duke@435 1010 }
duke@435 1011
duke@435 1012 public:
duke@435 1013 BranchData(DataLayout* layout) : JumpData(layout) {
duke@435 1014 assert(layout->tag() == DataLayout::branch_data_tag, "wrong type");
duke@435 1015 }
duke@435 1016
duke@435 1017 virtual bool is_BranchData() { return true; }
duke@435 1018
duke@435 1019 static int static_cell_count() {
duke@435 1020 return branch_cell_count;
duke@435 1021 }
duke@435 1022
duke@435 1023 virtual int cell_count() {
duke@435 1024 return static_cell_count();
duke@435 1025 }
duke@435 1026
duke@435 1027 // Direct accessor
duke@435 1028 uint not_taken() {
duke@435 1029 return uint_at(not_taken_off_set);
duke@435 1030 }
duke@435 1031
never@3105 1032 void set_not_taken(uint cnt) {
never@3105 1033 set_uint_at(not_taken_off_set, cnt);
never@3105 1034 }
never@3105 1035
duke@435 1036 uint inc_not_taken() {
duke@435 1037 uint cnt = not_taken() + 1;
duke@435 1038 // Did we wrap? Will compiler screw us??
duke@435 1039 if (cnt == 0) cnt--;
duke@435 1040 set_uint_at(not_taken_off_set, cnt);
duke@435 1041 return cnt;
duke@435 1042 }
duke@435 1043
duke@435 1044 // Code generation support
duke@435 1045 static ByteSize not_taken_offset() {
duke@435 1046 return cell_offset(not_taken_off_set);
duke@435 1047 }
duke@435 1048 static ByteSize branch_data_size() {
duke@435 1049 return cell_offset(branch_cell_count);
duke@435 1050 }
duke@435 1051
goetz@6470 1052 #ifdef CC_INTERP
goetz@6470 1053 static int branch_data_size_in_bytes() {
goetz@6470 1054 return cell_offset_in_bytes(branch_cell_count);
goetz@6470 1055 }
goetz@6470 1056
goetz@6470 1057 static void increment_not_taken_count_no_overflow(DataLayout* layout) {
goetz@6470 1058 increment_uint_at_no_overflow(layout, not_taken_off_set);
goetz@6470 1059 }
goetz@6470 1060
goetz@6470 1061 static DataLayout* advance_not_taken(DataLayout* layout) {
goetz@6470 1062 return (DataLayout*) (((address)layout) + (ssize_t)BranchData::branch_data_size_in_bytes());
goetz@6470 1063 }
goetz@6470 1064 #endif // CC_INTERP
goetz@6470 1065
duke@435 1066 // Specific initialization.
coleenp@4037 1067 void post_initialize(BytecodeStream* stream, MethodData* mdo);
duke@435 1068
duke@435 1069 #ifndef PRODUCT
duke@435 1070 void print_data_on(outputStream* st);
duke@435 1071 #endif
duke@435 1072 };
duke@435 1073
duke@435 1074 // ArrayData
duke@435 1075 //
duke@435 1076 // A ArrayData is a base class for accessing profiling data which does
duke@435 1077 // not have a statically known size. It consists of an array length
duke@435 1078 // and an array start.
duke@435 1079 class ArrayData : public ProfileData {
duke@435 1080 protected:
duke@435 1081 friend class DataLayout;
duke@435 1082
duke@435 1083 enum {
duke@435 1084 array_len_off_set,
duke@435 1085 array_start_off_set
duke@435 1086 };
duke@435 1087
duke@435 1088 uint array_uint_at(int index) {
duke@435 1089 int aindex = index + array_start_off_set;
duke@435 1090 return uint_at(aindex);
duke@435 1091 }
duke@435 1092 int array_int_at(int index) {
duke@435 1093 int aindex = index + array_start_off_set;
duke@435 1094 return int_at(aindex);
duke@435 1095 }
duke@435 1096 oop array_oop_at(int index) {
duke@435 1097 int aindex = index + array_start_off_set;
duke@435 1098 return oop_at(aindex);
duke@435 1099 }
duke@435 1100 void array_set_int_at(int index, int value) {
duke@435 1101 int aindex = index + array_start_off_set;
duke@435 1102 set_int_at(aindex, value);
duke@435 1103 }
duke@435 1104
goetz@6470 1105 #ifdef CC_INTERP
goetz@6470 1106 // Static low level accessors for DataLayout with ArrayData's semantics.
goetz@6470 1107
goetz@6470 1108 static void increment_array_uint_at_no_overflow(DataLayout* layout, int index) {
goetz@6470 1109 int aindex = index + array_start_off_set;
goetz@6470 1110 increment_uint_at_no_overflow(layout, aindex);
goetz@6470 1111 }
goetz@6470 1112
goetz@6470 1113 static int array_int_at(DataLayout* layout, int index) {
goetz@6470 1114 int aindex = index + array_start_off_set;
goetz@6470 1115 return int_at(layout, aindex);
goetz@6470 1116 }
goetz@6470 1117 #endif // CC_INTERP
goetz@6470 1118
duke@435 1119 // Code generation support for subclasses.
duke@435 1120 static ByteSize array_element_offset(int index) {
duke@435 1121 return cell_offset(array_start_off_set + index);
duke@435 1122 }
duke@435 1123
duke@435 1124 public:
duke@435 1125 ArrayData(DataLayout* layout) : ProfileData(layout) {}
duke@435 1126
duke@435 1127 virtual bool is_ArrayData() { return true; }
duke@435 1128
duke@435 1129 static int static_cell_count() {
duke@435 1130 return -1;
duke@435 1131 }
duke@435 1132
duke@435 1133 int array_len() {
duke@435 1134 return int_at_unchecked(array_len_off_set);
duke@435 1135 }
duke@435 1136
duke@435 1137 virtual int cell_count() {
duke@435 1138 return array_len() + 1;
duke@435 1139 }
duke@435 1140
duke@435 1141 // Code generation support
duke@435 1142 static ByteSize array_len_offset() {
duke@435 1143 return cell_offset(array_len_off_set);
duke@435 1144 }
duke@435 1145 static ByteSize array_start_offset() {
duke@435 1146 return cell_offset(array_start_off_set);
duke@435 1147 }
duke@435 1148 };
duke@435 1149
duke@435 1150 // MultiBranchData
duke@435 1151 //
duke@435 1152 // A MultiBranchData is used to access profiling information for
duke@435 1153 // a multi-way branch (*switch bytecodes). It consists of a series
duke@435 1154 // of (count, displacement) pairs, which count the number of times each
duke@435 1155 // case was taken and specify the data displacment for each branch target.
duke@435 1156 class MultiBranchData : public ArrayData {
duke@435 1157 protected:
duke@435 1158 enum {
duke@435 1159 default_count_off_set,
duke@435 1160 default_disaplacement_off_set,
duke@435 1161 case_array_start
duke@435 1162 };
duke@435 1163 enum {
duke@435 1164 relative_count_off_set,
duke@435 1165 relative_displacement_off_set,
duke@435 1166 per_case_cell_count
duke@435 1167 };
duke@435 1168
duke@435 1169 void set_default_displacement(int displacement) {
duke@435 1170 array_set_int_at(default_disaplacement_off_set, displacement);
duke@435 1171 }
duke@435 1172 void set_displacement_at(int index, int displacement) {
duke@435 1173 array_set_int_at(case_array_start +
duke@435 1174 index * per_case_cell_count +
duke@435 1175 relative_displacement_off_set,
duke@435 1176 displacement);
duke@435 1177 }
duke@435 1178
duke@435 1179 public:
duke@435 1180 MultiBranchData(DataLayout* layout) : ArrayData(layout) {
duke@435 1181 assert(layout->tag() == DataLayout::multi_branch_data_tag, "wrong type");
duke@435 1182 }
duke@435 1183
duke@435 1184 virtual bool is_MultiBranchData() { return true; }
duke@435 1185
duke@435 1186 static int compute_cell_count(BytecodeStream* stream);
duke@435 1187
duke@435 1188 int number_of_cases() {
duke@435 1189 int alen = array_len() - 2; // get rid of default case here.
duke@435 1190 assert(alen % per_case_cell_count == 0, "must be even");
duke@435 1191 return (alen / per_case_cell_count);
duke@435 1192 }
duke@435 1193
duke@435 1194 uint default_count() {
duke@435 1195 return array_uint_at(default_count_off_set);
duke@435 1196 }
duke@435 1197 int default_displacement() {
duke@435 1198 return array_int_at(default_disaplacement_off_set);
duke@435 1199 }
duke@435 1200
duke@435 1201 uint count_at(int index) {
duke@435 1202 return array_uint_at(case_array_start +
duke@435 1203 index * per_case_cell_count +
duke@435 1204 relative_count_off_set);
duke@435 1205 }
duke@435 1206 int displacement_at(int index) {
duke@435 1207 return array_int_at(case_array_start +
duke@435 1208 index * per_case_cell_count +
duke@435 1209 relative_displacement_off_set);
duke@435 1210 }
duke@435 1211
duke@435 1212 // Code generation support
duke@435 1213 static ByteSize default_count_offset() {
duke@435 1214 return array_element_offset(default_count_off_set);
duke@435 1215 }
duke@435 1216 static ByteSize default_displacement_offset() {
duke@435 1217 return array_element_offset(default_disaplacement_off_set);
duke@435 1218 }
duke@435 1219 static ByteSize case_count_offset(int index) {
duke@435 1220 return case_array_offset() +
duke@435 1221 (per_case_size() * index) +
duke@435 1222 relative_count_offset();
duke@435 1223 }
duke@435 1224 static ByteSize case_array_offset() {
duke@435 1225 return array_element_offset(case_array_start);
duke@435 1226 }
duke@435 1227 static ByteSize per_case_size() {
duke@435 1228 return in_ByteSize(per_case_cell_count) * cell_size;
duke@435 1229 }
duke@435 1230 static ByteSize relative_count_offset() {
duke@435 1231 return in_ByteSize(relative_count_off_set) * cell_size;
duke@435 1232 }
duke@435 1233 static ByteSize relative_displacement_offset() {
duke@435 1234 return in_ByteSize(relative_displacement_off_set) * cell_size;
duke@435 1235 }
duke@435 1236
goetz@6470 1237 #ifdef CC_INTERP
goetz@6470 1238 static void increment_count_no_overflow(DataLayout* layout, int index) {
goetz@6470 1239 if (index == -1) {
goetz@6470 1240 increment_array_uint_at_no_overflow(layout, default_count_off_set);
goetz@6470 1241 } else {
goetz@6470 1242 increment_array_uint_at_no_overflow(layout, case_array_start +
goetz@6470 1243 index * per_case_cell_count +
goetz@6470 1244 relative_count_off_set);
goetz@6470 1245 }
goetz@6470 1246 }
goetz@6470 1247
goetz@6470 1248 static DataLayout* advance(DataLayout* layout, int index) {
goetz@6470 1249 if (index == -1) {
goetz@6470 1250 return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, default_disaplacement_off_set));
goetz@6470 1251 } else {
goetz@6470 1252 return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, case_array_start +
goetz@6470 1253 index * per_case_cell_count +
goetz@6470 1254 relative_displacement_off_set));
goetz@6470 1255 }
goetz@6470 1256 }
goetz@6470 1257 #endif // CC_INTERP
goetz@6470 1258
duke@435 1259 // Specific initialization.
coleenp@4037 1260 void post_initialize(BytecodeStream* stream, MethodData* mdo);
duke@435 1261
duke@435 1262 #ifndef PRODUCT
duke@435 1263 void print_data_on(outputStream* st);
duke@435 1264 #endif
duke@435 1265 };
duke@435 1266
kvn@480 1267 class ArgInfoData : public ArrayData {
kvn@480 1268
kvn@480 1269 public:
kvn@480 1270 ArgInfoData(DataLayout* layout) : ArrayData(layout) {
kvn@480 1271 assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type");
kvn@480 1272 }
kvn@480 1273
kvn@480 1274 virtual bool is_ArgInfoData() { return true; }
kvn@480 1275
kvn@480 1276
kvn@480 1277 int number_of_args() {
kvn@480 1278 return array_len();
kvn@480 1279 }
kvn@480 1280
kvn@480 1281 uint arg_modified(int arg) {
kvn@480 1282 return array_uint_at(arg);
kvn@480 1283 }
kvn@480 1284
kvn@480 1285 void set_arg_modified(int arg, uint val) {
kvn@480 1286 array_set_int_at(arg, val);
kvn@480 1287 }
kvn@480 1288
kvn@480 1289 #ifndef PRODUCT
kvn@480 1290 void print_data_on(outputStream* st);
kvn@480 1291 #endif
kvn@480 1292 };
kvn@480 1293
coleenp@4037 1294 // MethodData*
duke@435 1295 //
coleenp@4037 1296 // A MethodData* holds information which has been collected about
duke@435 1297 // a method. Its layout looks like this:
duke@435 1298 //
duke@435 1299 // -----------------------------
duke@435 1300 // | header |
duke@435 1301 // | klass |
duke@435 1302 // -----------------------------
duke@435 1303 // | method |
coleenp@4037 1304 // | size of the MethodData* |
duke@435 1305 // -----------------------------
duke@435 1306 // | Data entries... |
duke@435 1307 // | (variable size) |
duke@435 1308 // | |
duke@435 1309 // . .
duke@435 1310 // . .
duke@435 1311 // . .
duke@435 1312 // | |
duke@435 1313 // -----------------------------
duke@435 1314 //
duke@435 1315 // The data entry area is a heterogeneous array of DataLayouts. Each
duke@435 1316 // DataLayout in the array corresponds to a specific bytecode in the
duke@435 1317 // method. The entries in the array are sorted by the corresponding
duke@435 1318 // bytecode. Access to the data is via resource-allocated ProfileData,
duke@435 1319 // which point to the underlying blocks of DataLayout structures.
duke@435 1320 //
duke@435 1321 // During interpretation, if profiling in enabled, the interpreter
duke@435 1322 // maintains a method data pointer (mdp), which points at the entry
duke@435 1323 // in the array corresponding to the current bci. In the course of
duke@435 1324 // intepretation, when a bytecode is encountered that has profile data
duke@435 1325 // associated with it, the entry pointed to by mdp is updated, then the
duke@435 1326 // mdp is adjusted to point to the next appropriate DataLayout. If mdp
duke@435 1327 // is NULL to begin with, the interpreter assumes that the current method
duke@435 1328 // is not (yet) being profiled.
duke@435 1329 //
coleenp@4037 1330 // In MethodData* parlance, "dp" is a "data pointer", the actual address
duke@435 1331 // of a DataLayout element. A "di" is a "data index", the offset in bytes
duke@435 1332 // from the base of the data entry array. A "displacement" is the byte offset
duke@435 1333 // in certain ProfileData objects that indicate the amount the mdp must be
duke@435 1334 // adjusted in the event of a change in control flow.
duke@435 1335 //
duke@435 1336
goetz@6470 1337 CC_INTERP_ONLY(class BytecodeInterpreter;)
goetz@6470 1338
coleenp@4037 1339 class MethodData : public Metadata {
duke@435 1340 friend class VMStructs;
goetz@6470 1341 CC_INTERP_ONLY(friend class BytecodeInterpreter;)
duke@435 1342 private:
duke@435 1343 friend class ProfileData;
duke@435 1344
coleenp@4037 1345 // Back pointer to the Method*
coleenp@4037 1346 Method* _method;
duke@435 1347
duke@435 1348 // Size of this oop in bytes
duke@435 1349 int _size;
duke@435 1350
duke@435 1351 // Cached hint for bci_to_dp and bci_to_data
duke@435 1352 int _hint_di;
duke@435 1353
coleenp@4037 1354 MethodData(methodHandle method, int size, TRAPS);
coleenp@4037 1355 public:
coleenp@4037 1356 static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS);
coleenp@4037 1357 MethodData() {}; // For ciMethodData
coleenp@4037 1358
coleenp@4037 1359 bool is_methodData() const volatile { return true; }
coleenp@4037 1360
duke@435 1361 // Whole-method sticky bits and flags
duke@435 1362 enum {
kvn@2877 1363 _trap_hist_limit = 17, // decoupled from Deoptimization::Reason_LIMIT
duke@435 1364 _trap_hist_mask = max_jubyte,
duke@435 1365 _extra_data_count = 4 // extra DataLayout headers, for trap history
duke@435 1366 }; // Public flag values
duke@435 1367 private:
duke@435 1368 uint _nof_decompiles; // count of all nmethod removals
duke@435 1369 uint _nof_overflow_recompiles; // recompile count, excluding recomp. bits
duke@435 1370 uint _nof_overflow_traps; // trap count, excluding _trap_hist
duke@435 1371 union {
duke@435 1372 intptr_t _align;
duke@435 1373 u1 _array[_trap_hist_limit];
duke@435 1374 } _trap_hist;
duke@435 1375
duke@435 1376 // Support for interprocedural escape analysis, from Thomas Kotzmann.
duke@435 1377 intx _eflags; // flags on escape information
duke@435 1378 intx _arg_local; // bit set of non-escaping arguments
duke@435 1379 intx _arg_stack; // bit set of stack-allocatable arguments
duke@435 1380 intx _arg_returned; // bit set of returned arguments
duke@435 1381
iveresov@2138 1382 int _creation_mileage; // method mileage at MDO creation
iveresov@2138 1383
iveresov@2138 1384 // How many invocations has this MDO seen?
iveresov@2138 1385 // These counters are used to determine the exact age of MDO.
iveresov@2138 1386 // We need those because in tiered a method can be concurrently
iveresov@2138 1387 // executed at different levels.
iveresov@2138 1388 InvocationCounter _invocation_counter;
iveresov@2138 1389 // Same for backedges.
iveresov@2138 1390 InvocationCounter _backedge_counter;
iveresov@2559 1391 // Counter values at the time profiling started.
iveresov@2559 1392 int _invocation_counter_start;
iveresov@2559 1393 int _backedge_counter_start;
iveresov@2138 1394 // Number of loops and blocks is computed when compiling the first
iveresov@2138 1395 // time with C1. It is used to determine if method is trivial.
iveresov@2138 1396 short _num_loops;
iveresov@2138 1397 short _num_blocks;
iveresov@2138 1398 // Highest compile level this method has ever seen.
iveresov@2138 1399 u1 _highest_comp_level;
iveresov@2138 1400 // Same for OSR level
iveresov@2138 1401 u1 _highest_osr_comp_level;
iveresov@2138 1402 // Does this method contain anything worth profiling?
iveresov@2138 1403 bool _would_profile;
duke@435 1404
duke@435 1405 // Size of _data array in bytes. (Excludes header and extra_data fields.)
duke@435 1406 int _data_size;
duke@435 1407
duke@435 1408 // Beginning of the data entries
duke@435 1409 intptr_t _data[1];
duke@435 1410
duke@435 1411 // Helper for size computation
duke@435 1412 static int compute_data_size(BytecodeStream* stream);
duke@435 1413 static int bytecode_cell_count(Bytecodes::Code code);
duke@435 1414 enum { no_profile_data = -1, variable_cell_count = -2 };
duke@435 1415
duke@435 1416 // Helper for initialization
coleenp@4037 1417 DataLayout* data_layout_at(int data_index) const {
duke@435 1418 assert(data_index % sizeof(intptr_t) == 0, "unaligned");
duke@435 1419 return (DataLayout*) (((address)_data) + data_index);
duke@435 1420 }
duke@435 1421
duke@435 1422 // Initialize an individual data segment. Returns the size of
duke@435 1423 // the segment in bytes.
duke@435 1424 int initialize_data(BytecodeStream* stream, int data_index);
duke@435 1425
duke@435 1426 // Helper for data_at
coleenp@4037 1427 DataLayout* limit_data_position() const {
duke@435 1428 return (DataLayout*)((address)data_base() + _data_size);
duke@435 1429 }
coleenp@4037 1430 bool out_of_bounds(int data_index) const {
duke@435 1431 return data_index >= data_size();
duke@435 1432 }
duke@435 1433
duke@435 1434 // Give each of the data entries a chance to perform specific
duke@435 1435 // data initialization.
duke@435 1436 void post_initialize(BytecodeStream* stream);
duke@435 1437
duke@435 1438 // hint accessors
duke@435 1439 int hint_di() const { return _hint_di; }
duke@435 1440 void set_hint_di(int di) {
duke@435 1441 assert(!out_of_bounds(di), "hint_di out of bounds");
duke@435 1442 _hint_di = di;
duke@435 1443 }
duke@435 1444 ProfileData* data_before(int bci) {
duke@435 1445 // avoid SEGV on this edge case
duke@435 1446 if (data_size() == 0)
duke@435 1447 return NULL;
duke@435 1448 int hint = hint_di();
duke@435 1449 if (data_layout_at(hint)->bci() <= bci)
duke@435 1450 return data_at(hint);
duke@435 1451 return first_data();
duke@435 1452 }
duke@435 1453
duke@435 1454 // What is the index of the first data entry?
coleenp@4037 1455 int first_di() const { return 0; }
duke@435 1456
duke@435 1457 // Find or create an extra ProfileData:
duke@435 1458 ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
duke@435 1459
kvn@480 1460 // return the argument info cell
kvn@480 1461 ArgInfoData *arg_info();
kvn@480 1462
duke@435 1463 public:
duke@435 1464 static int header_size() {
coleenp@4037 1465 return sizeof(MethodData)/wordSize;
duke@435 1466 }
duke@435 1467
coleenp@4037 1468 // Compute the size of a MethodData* before it is created.
duke@435 1469 static int compute_allocation_size_in_bytes(methodHandle method);
duke@435 1470 static int compute_allocation_size_in_words(methodHandle method);
duke@435 1471 static int compute_extra_data_count(int data_size, int empty_bc_count);
duke@435 1472
duke@435 1473 // Determine if a given bytecode can have profile information.
duke@435 1474 static bool bytecode_has_profile(Bytecodes::Code code) {
duke@435 1475 return bytecode_cell_count(code) != no_profile_data;
duke@435 1476 }
duke@435 1477
iignatyev@4908 1478 // reset into original state
iignatyev@4908 1479 void init();
duke@435 1480
duke@435 1481 // My size
coleenp@4037 1482 int size_in_bytes() const { return _size; }
coleenp@4037 1483 int size() const { return align_object_size(align_size_up(_size, BytesPerWord)/BytesPerWord); }
acorn@4497 1484 #if INCLUDE_SERVICES
acorn@4497 1485 void collect_statistics(KlassSizeStats *sz) const;
acorn@4497 1486 #endif
duke@435 1487
duke@435 1488 int creation_mileage() const { return _creation_mileage; }
duke@435 1489 void set_creation_mileage(int x) { _creation_mileage = x; }
iveresov@2138 1490
iveresov@2138 1491 int invocation_count() {
iveresov@2138 1492 if (invocation_counter()->carry()) {
iveresov@2138 1493 return InvocationCounter::count_limit;
iveresov@2138 1494 }
iveresov@2138 1495 return invocation_counter()->count();
iveresov@2138 1496 }
iveresov@2138 1497 int backedge_count() {
iveresov@2138 1498 if (backedge_counter()->carry()) {
iveresov@2138 1499 return InvocationCounter::count_limit;
iveresov@2138 1500 }
iveresov@2138 1501 return backedge_counter()->count();
iveresov@2138 1502 }
iveresov@2138 1503
iveresov@2559 1504 int invocation_count_start() {
iveresov@2559 1505 if (invocation_counter()->carry()) {
iveresov@2559 1506 return 0;
iveresov@2559 1507 }
iveresov@2559 1508 return _invocation_counter_start;
iveresov@2559 1509 }
iveresov@2559 1510
iveresov@2559 1511 int backedge_count_start() {
iveresov@2559 1512 if (backedge_counter()->carry()) {
iveresov@2559 1513 return 0;
iveresov@2559 1514 }
iveresov@2559 1515 return _backedge_counter_start;
iveresov@2559 1516 }
iveresov@2559 1517
iveresov@2559 1518 int invocation_count_delta() { return invocation_count() - invocation_count_start(); }
iveresov@2559 1519 int backedge_count_delta() { return backedge_count() - backedge_count_start(); }
iveresov@2559 1520
iveresov@2559 1521 void reset_start_counters() {
iveresov@2559 1522 _invocation_counter_start = invocation_count();
iveresov@2559 1523 _backedge_counter_start = backedge_count();
iveresov@2559 1524 }
iveresov@2559 1525
iveresov@2138 1526 InvocationCounter* invocation_counter() { return &_invocation_counter; }
iveresov@2138 1527 InvocationCounter* backedge_counter() { return &_backedge_counter; }
iveresov@2138 1528
iveresov@2138 1529 void set_would_profile(bool p) { _would_profile = p; }
iveresov@2138 1530 bool would_profile() const { return _would_profile; }
iveresov@2138 1531
minqi@5097 1532 int highest_comp_level() const { return _highest_comp_level; }
iveresov@2138 1533 void set_highest_comp_level(int level) { _highest_comp_level = level; }
minqi@5097 1534 int highest_osr_comp_level() const { return _highest_osr_comp_level; }
iveresov@2138 1535 void set_highest_osr_comp_level(int level) { _highest_osr_comp_level = level; }
iveresov@2138 1536
iveresov@2138 1537 int num_loops() const { return _num_loops; }
iveresov@2138 1538 void set_num_loops(int n) { _num_loops = n; }
iveresov@2138 1539 int num_blocks() const { return _num_blocks; }
iveresov@2138 1540 void set_num_blocks(int n) { _num_blocks = n; }
iveresov@2138 1541
duke@435 1542 bool is_mature() const; // consult mileage and ProfileMaturityPercentage
coleenp@4037 1543 static int mileage_of(Method* m);
duke@435 1544
duke@435 1545 // Support for interprocedural escape analysis, from Thomas Kotzmann.
duke@435 1546 enum EscapeFlag {
duke@435 1547 estimated = 1 << 0,
kvn@513 1548 return_local = 1 << 1,
kvn@513 1549 return_allocated = 1 << 2,
kvn@513 1550 allocated_escapes = 1 << 3,
kvn@513 1551 unknown_modified = 1 << 4
duke@435 1552 };
duke@435 1553
duke@435 1554 intx eflags() { return _eflags; }
duke@435 1555 intx arg_local() { return _arg_local; }
duke@435 1556 intx arg_stack() { return _arg_stack; }
duke@435 1557 intx arg_returned() { return _arg_returned; }
kvn@480 1558 uint arg_modified(int a) { ArgInfoData *aid = arg_info();
iignatyev@4908 1559 assert(aid != NULL, "arg_info must be not null");
kvn@480 1560 assert(a >= 0 && a < aid->number_of_args(), "valid argument number");
kvn@480 1561 return aid->arg_modified(a); }
duke@435 1562
duke@435 1563 void set_eflags(intx v) { _eflags = v; }
duke@435 1564 void set_arg_local(intx v) { _arg_local = v; }
duke@435 1565 void set_arg_stack(intx v) { _arg_stack = v; }
duke@435 1566 void set_arg_returned(intx v) { _arg_returned = v; }
kvn@480 1567 void set_arg_modified(int a, uint v) { ArgInfoData *aid = arg_info();
iignatyev@4908 1568 assert(aid != NULL, "arg_info must be not null");
kvn@480 1569 assert(a >= 0 && a < aid->number_of_args(), "valid argument number");
kvn@480 1570 aid->set_arg_modified(a, v); }
duke@435 1571
duke@435 1572 void clear_escape_info() { _eflags = _arg_local = _arg_stack = _arg_returned = 0; }
duke@435 1573
duke@435 1574 // Location and size of data area
duke@435 1575 address data_base() const {
duke@435 1576 return (address) _data;
duke@435 1577 }
coleenp@4037 1578 int data_size() const {
duke@435 1579 return _data_size;
duke@435 1580 }
duke@435 1581
duke@435 1582 // Accessors
coleenp@4037 1583 Method* method() const { return _method; }
duke@435 1584
duke@435 1585 // Get the data at an arbitrary (sort of) data index.
coleenp@4037 1586 ProfileData* data_at(int data_index) const;
duke@435 1587
duke@435 1588 // Walk through the data in order.
coleenp@4037 1589 ProfileData* first_data() const { return data_at(first_di()); }
coleenp@4037 1590 ProfileData* next_data(ProfileData* current) const;
coleenp@4037 1591 bool is_valid(ProfileData* current) const { return current != NULL; }
duke@435 1592
duke@435 1593 // Convert a dp (data pointer) to a di (data index).
coleenp@4037 1594 int dp_to_di(address dp) const {
duke@435 1595 return dp - ((address)_data);
duke@435 1596 }
duke@435 1597
duke@435 1598 address di_to_dp(int di) {
duke@435 1599 return (address)data_layout_at(di);
duke@435 1600 }
duke@435 1601
duke@435 1602 // bci to di/dp conversion.
duke@435 1603 address bci_to_dp(int bci);
duke@435 1604 int bci_to_di(int bci) {
duke@435 1605 return dp_to_di(bci_to_dp(bci));
duke@435 1606 }
duke@435 1607
duke@435 1608 // Get the data at an arbitrary bci, or NULL if there is none.
duke@435 1609 ProfileData* bci_to_data(int bci);
duke@435 1610
duke@435 1611 // Same, but try to create an extra_data record if one is needed:
duke@435 1612 ProfileData* allocate_bci_to_data(int bci) {
duke@435 1613 ProfileData* data = bci_to_data(bci);
duke@435 1614 return (data != NULL) ? data : bci_to_extra_data(bci, true);
duke@435 1615 }
duke@435 1616
duke@435 1617 // Add a handful of extra data records, for trap tracking.
coleenp@4037 1618 DataLayout* extra_data_base() const { return limit_data_position(); }
coleenp@4037 1619 DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); }
coleenp@4037 1620 int extra_data_size() const { return (address)extra_data_limit()
duke@435 1621 - (address)extra_data_base(); }
duke@435 1622 static DataLayout* next_extra(DataLayout* dp) { return (DataLayout*)((address)dp + in_bytes(DataLayout::cell_offset(0))); }
duke@435 1623
duke@435 1624 // Return (uint)-1 for overflow.
duke@435 1625 uint trap_count(int reason) const {
duke@435 1626 assert((uint)reason < _trap_hist_limit, "oob");
duke@435 1627 return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1;
duke@435 1628 }
duke@435 1629 // For loops:
duke@435 1630 static uint trap_reason_limit() { return _trap_hist_limit; }
duke@435 1631 static uint trap_count_limit() { return _trap_hist_mask; }
duke@435 1632 uint inc_trap_count(int reason) {
duke@435 1633 // Count another trap, anywhere in this method.
duke@435 1634 assert(reason >= 0, "must be single trap");
duke@435 1635 if ((uint)reason < _trap_hist_limit) {
duke@435 1636 uint cnt1 = 1 + _trap_hist._array[reason];
duke@435 1637 if ((cnt1 & _trap_hist_mask) != 0) { // if no counter overflow...
duke@435 1638 _trap_hist._array[reason] = cnt1;
duke@435 1639 return cnt1;
duke@435 1640 } else {
duke@435 1641 return _trap_hist_mask + (++_nof_overflow_traps);
duke@435 1642 }
duke@435 1643 } else {
duke@435 1644 // Could not represent the count in the histogram.
duke@435 1645 return (++_nof_overflow_traps);
duke@435 1646 }
duke@435 1647 }
duke@435 1648
duke@435 1649 uint overflow_trap_count() const {
duke@435 1650 return _nof_overflow_traps;
duke@435 1651 }
duke@435 1652 uint overflow_recompile_count() const {
duke@435 1653 return _nof_overflow_recompiles;
duke@435 1654 }
duke@435 1655 void inc_overflow_recompile_count() {
duke@435 1656 _nof_overflow_recompiles += 1;
duke@435 1657 }
duke@435 1658 uint decompile_count() const {
duke@435 1659 return _nof_decompiles;
duke@435 1660 }
duke@435 1661 void inc_decompile_count() {
duke@435 1662 _nof_decompiles += 1;
kvn@1641 1663 if (decompile_count() > (uint)PerMethodRecompilationCutoff) {
vlivanov@4539 1664 method()->set_not_compilable(CompLevel_full_optimization, true, "decompile_count > PerMethodRecompilationCutoff");
kvn@1641 1665 }
duke@435 1666 }
duke@435 1667
duke@435 1668 // Support for code generation
duke@435 1669 static ByteSize data_offset() {
coleenp@4037 1670 return byte_offset_of(MethodData, _data[0]);
duke@435 1671 }
duke@435 1672
iveresov@2138 1673 static ByteSize invocation_counter_offset() {
coleenp@4037 1674 return byte_offset_of(MethodData, _invocation_counter);
iveresov@2138 1675 }
iveresov@2138 1676 static ByteSize backedge_counter_offset() {
coleenp@4037 1677 return byte_offset_of(MethodData, _backedge_counter);
iveresov@2138 1678 }
iveresov@2138 1679
coleenp@4037 1680 // Deallocation support - no pointer fields to deallocate
coleenp@4037 1681 void deallocate_contents(ClassLoaderData* loader_data) {}
coleenp@4037 1682
duke@435 1683 // GC support
coleenp@4037 1684 void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
coleenp@4037 1685
coleenp@4037 1686 // Printing
coleenp@4037 1687 #ifndef PRODUCT
coleenp@4037 1688 void print_on (outputStream* st) const;
coleenp@4037 1689 #endif
coleenp@4037 1690 void print_value_on(outputStream* st) const;
duke@435 1691
duke@435 1692 #ifndef PRODUCT
duke@435 1693 // printing support for method data
coleenp@4037 1694 void print_data_on(outputStream* st) const;
duke@435 1695 #endif
duke@435 1696
coleenp@4037 1697 const char* internal_name() const { return "{method data}"; }
coleenp@4037 1698
duke@435 1699 // verification
coleenp@4037 1700 void verify_on(outputStream* st);
duke@435 1701 void verify_data_on(outputStream* st);
duke@435 1702 };
stefank@2314 1703
stefank@2314 1704 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP

mercurial