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