Mon, 19 Aug 2019 10:11:31 +0200
8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com
duke@435 | 1 | /* |
dbuck@8997 | 2 | * Copyright (c) 1997, 2017, 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_CODE_COMPILEDIC_HPP |
stefank@2314 | 26 | #define SHARE_VM_CODE_COMPILEDIC_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "interpreter/linkResolver.hpp" |
coleenp@4037 | 29 | #include "oops/compiledICHolder.hpp" |
stefank@2314 | 30 | #ifdef TARGET_ARCH_x86 |
stefank@2314 | 31 | # include "nativeInst_x86.hpp" |
stefank@2314 | 32 | #endif |
stefank@2314 | 33 | #ifdef TARGET_ARCH_sparc |
stefank@2314 | 34 | # include "nativeInst_sparc.hpp" |
stefank@2314 | 35 | #endif |
stefank@2314 | 36 | #ifdef TARGET_ARCH_zero |
stefank@2314 | 37 | # include "nativeInst_zero.hpp" |
stefank@2314 | 38 | #endif |
bobv@2508 | 39 | #ifdef TARGET_ARCH_arm |
bobv@2508 | 40 | # include "nativeInst_arm.hpp" |
bobv@2508 | 41 | #endif |
bobv@2508 | 42 | #ifdef TARGET_ARCH_ppc |
bobv@2508 | 43 | # include "nativeInst_ppc.hpp" |
bobv@2508 | 44 | #endif |
stefank@2314 | 45 | |
duke@435 | 46 | //----------------------------------------------------------------------------- |
duke@435 | 47 | // The CompiledIC represents a compiled inline cache. |
duke@435 | 48 | // |
duke@435 | 49 | // In order to make patching of the inline cache MT-safe, we only allow the following |
duke@435 | 50 | // transitions (when not at a safepoint): |
duke@435 | 51 | // |
duke@435 | 52 | // |
duke@435 | 53 | // [1] --<-- Clean -->--- [1] |
duke@435 | 54 | // / (null) \ |
duke@435 | 55 | // / \ /-<-\ |
duke@435 | 56 | // / [2] \ / \ |
duke@435 | 57 | // Interpreted ---------> Monomorphic | [3] |
coleenp@4037 | 58 | // (CompiledICHolder*) (Klass*) | |
duke@435 | 59 | // \ / \ / |
duke@435 | 60 | // [4] \ / [4] \->-/ |
duke@435 | 61 | // \->- Megamorphic -<-/ |
dbuck@8997 | 62 | // (CompiledICHolder*) |
duke@435 | 63 | // |
dbuck@8997 | 64 | // The text in parentheses () refers to the value of the inline cache receiver (mov instruction) |
duke@435 | 65 | // |
dbuck@8997 | 66 | // The numbers in square brackets refer to the kind of transition: |
duke@435 | 67 | // [1]: Initial fixup. Receiver it found from debug information |
duke@435 | 68 | // [2]: Compilation of a method |
coleenp@4037 | 69 | // [3]: Recompilation of a method (note: only entry is changed. The Klass* must stay the same) |
duke@435 | 70 | // [4]: Inline cache miss. We go directly to megamorphic call. |
duke@435 | 71 | // |
duke@435 | 72 | // The class automatically inserts transition stubs (using the InlineCacheBuffer) when an MT-unsafe |
duke@435 | 73 | // transition is made to a stub. |
duke@435 | 74 | // |
duke@435 | 75 | class CompiledIC; |
coleenp@4037 | 76 | class ICStub; |
duke@435 | 77 | |
coleenp@4037 | 78 | class CompiledICInfo : public StackObj { |
duke@435 | 79 | private: |
duke@435 | 80 | address _entry; // entry point for call |
coleenp@4037 | 81 | void* _cached_value; // Value of cached_value (either in stub or inline cache) |
coleenp@4037 | 82 | bool _is_icholder; // Is the cached value a CompiledICHolder* |
duke@435 | 83 | bool _is_optimized; // it is an optimized virtual call (i.e., can be statically bound) |
duke@435 | 84 | bool _to_interpreter; // Call it to interpreter |
coleenp@4037 | 85 | bool _release_icholder; |
duke@435 | 86 | public: |
duke@435 | 87 | address entry() const { return _entry; } |
coleenp@4037 | 88 | Metadata* cached_metadata() const { assert(!_is_icholder, ""); return (Metadata*)_cached_value; } |
coleenp@4037 | 89 | CompiledICHolder* claim_cached_icholder() { |
coleenp@4037 | 90 | assert(_is_icholder, ""); |
coleenp@4037 | 91 | assert(_cached_value != NULL, "must be non-NULL"); |
coleenp@4037 | 92 | _release_icholder = false; |
coleenp@4037 | 93 | CompiledICHolder* icholder = (CompiledICHolder*)_cached_value; |
coleenp@4037 | 94 | icholder->claim(); |
coleenp@4037 | 95 | return icholder; |
coleenp@4037 | 96 | } |
duke@435 | 97 | bool is_optimized() const { return _is_optimized; } |
coleenp@4037 | 98 | bool to_interpreter() const { return _to_interpreter; } |
coleenp@4037 | 99 | |
coleenp@4037 | 100 | void set_compiled_entry(address entry, Klass* klass, bool is_optimized) { |
coleenp@4037 | 101 | _entry = entry; |
coleenp@4037 | 102 | _cached_value = (void*)klass; |
coleenp@4037 | 103 | _to_interpreter = false; |
coleenp@4037 | 104 | _is_icholder = false; |
coleenp@4037 | 105 | _is_optimized = is_optimized; |
coleenp@4037 | 106 | _release_icholder = false; |
coleenp@4037 | 107 | } |
coleenp@4037 | 108 | |
coleenp@4037 | 109 | void set_interpreter_entry(address entry, Method* method) { |
coleenp@4037 | 110 | _entry = entry; |
coleenp@4037 | 111 | _cached_value = (void*)method; |
coleenp@4037 | 112 | _to_interpreter = true; |
coleenp@4037 | 113 | _is_icholder = false; |
coleenp@4037 | 114 | _is_optimized = true; |
coleenp@4037 | 115 | _release_icholder = false; |
coleenp@4037 | 116 | } |
coleenp@4037 | 117 | |
coleenp@4037 | 118 | void set_icholder_entry(address entry, CompiledICHolder* icholder) { |
coleenp@4037 | 119 | _entry = entry; |
coleenp@4037 | 120 | _cached_value = (void*)icholder; |
coleenp@4037 | 121 | _to_interpreter = true; |
coleenp@4037 | 122 | _is_icholder = true; |
coleenp@4037 | 123 | _is_optimized = false; |
coleenp@4037 | 124 | _release_icholder = true; |
coleenp@4037 | 125 | } |
coleenp@4037 | 126 | |
coleenp@4037 | 127 | CompiledICInfo(): _entry(NULL), _cached_value(NULL), _is_icholder(false), |
coleenp@4037 | 128 | _to_interpreter(false), _is_optimized(false), _release_icholder(false) { |
coleenp@4037 | 129 | } |
coleenp@4037 | 130 | ~CompiledICInfo() { |
coleenp@4037 | 131 | // In rare cases the info is computed but not used, so release any |
coleenp@4037 | 132 | // CompiledICHolder* that was created |
coleenp@4037 | 133 | if (_release_icholder) { |
coleenp@4037 | 134 | assert(_is_icholder, "must be"); |
coleenp@4037 | 135 | CompiledICHolder* icholder = (CompiledICHolder*)_cached_value; |
coleenp@4037 | 136 | icholder->claim(); |
coleenp@4037 | 137 | delete icholder; |
coleenp@4037 | 138 | } |
coleenp@4037 | 139 | } |
duke@435 | 140 | }; |
duke@435 | 141 | |
duke@435 | 142 | class CompiledIC: public ResourceObj { |
duke@435 | 143 | friend class InlineCacheBuffer; |
duke@435 | 144 | friend class ICStub; |
duke@435 | 145 | |
duke@435 | 146 | |
duke@435 | 147 | private: |
duke@435 | 148 | NativeCall* _ic_call; // the call instruction |
coleenp@4037 | 149 | NativeMovConstReg* _value; // patchable value cell for this IC |
duke@435 | 150 | bool _is_optimized; // an optimized virtual call (i.e., no compiled IC) |
duke@435 | 151 | |
coleenp@4037 | 152 | CompiledIC(nmethod* nm, NativeCall* ic_call); |
stefank@6991 | 153 | CompiledIC(RelocIterator* iter); |
stefank@6991 | 154 | |
stefank@6991 | 155 | void initialize_from_iter(RelocIterator* iter); |
coleenp@4037 | 156 | |
coleenp@4037 | 157 | static bool is_icholder_entry(address entry); |
duke@435 | 158 | |
duke@435 | 159 | // low-level inline-cache manipulation. Cannot be accessed directly, since it might not be MT-safe |
duke@435 | 160 | // to change an inline-cache. These changes the underlying inline-cache directly. They *newer* make |
duke@435 | 161 | // changes to a transition stub. |
coleenp@4037 | 162 | void internal_set_ic_destination(address entry_point, bool is_icstub, void* cache, bool is_icholder); |
coleenp@4037 | 163 | void set_ic_destination(ICStub* stub); |
coleenp@4037 | 164 | void set_ic_destination(address entry_point) { |
coleenp@4037 | 165 | assert(_is_optimized, "use set_ic_destination_and_value instead"); |
coleenp@4037 | 166 | internal_set_ic_destination(entry_point, false, NULL, false); |
coleenp@4037 | 167 | } |
coleenp@4037 | 168 | // This only for use by ICStubs where the type of the value isn't known |
coleenp@4037 | 169 | void set_ic_destination_and_value(address entry_point, void* value) { |
coleenp@4037 | 170 | internal_set_ic_destination(entry_point, false, value, is_icholder_entry(entry_point)); |
coleenp@4037 | 171 | } |
coleenp@4037 | 172 | void set_ic_destination_and_value(address entry_point, Metadata* value) { |
coleenp@4037 | 173 | internal_set_ic_destination(entry_point, false, value, false); |
coleenp@4037 | 174 | } |
coleenp@4037 | 175 | void set_ic_destination_and_value(address entry_point, CompiledICHolder* value) { |
coleenp@4037 | 176 | internal_set_ic_destination(entry_point, false, value, true); |
coleenp@4037 | 177 | } |
duke@435 | 178 | |
duke@435 | 179 | // Reads the location of the transition stub. This will fail with an assertion, if no transition stub is |
duke@435 | 180 | // associated with the inline cache. |
duke@435 | 181 | address stub_address() const; |
duke@435 | 182 | bool is_in_transition_state() const; // Use InlineCacheBuffer |
duke@435 | 183 | |
duke@435 | 184 | public: |
duke@435 | 185 | // conversion (machine PC to CompiledIC*) |
coleenp@4037 | 186 | friend CompiledIC* CompiledIC_before(nmethod* nm, address return_addr); |
coleenp@4037 | 187 | friend CompiledIC* CompiledIC_at(nmethod* nm, address call_site); |
duke@435 | 188 | friend CompiledIC* CompiledIC_at(Relocation* call_site); |
stefank@6991 | 189 | friend CompiledIC* CompiledIC_at(RelocIterator* reloc_iter); |
duke@435 | 190 | |
coleenp@4037 | 191 | // This is used to release CompiledICHolder*s from nmethods that |
coleenp@4037 | 192 | // are about to be freed. The callsite might contain other stale |
coleenp@4037 | 193 | // values of other kinds so it must be careful. |
coleenp@4037 | 194 | static void cleanup_call_site(virtual_call_Relocation* call_site); |
coleenp@4037 | 195 | static bool is_icholder_call_site(virtual_call_Relocation* call_site); |
coleenp@4037 | 196 | |
coleenp@4037 | 197 | // Return the cached_metadata/destination associated with this inline cache. If the cache currently points |
duke@435 | 198 | // to a transition stub, it will read the values from the transition stub. |
coleenp@4037 | 199 | void* cached_value() const; |
coleenp@4037 | 200 | CompiledICHolder* cached_icholder() const { |
coleenp@4037 | 201 | assert(is_icholder_call(), "must be"); |
coleenp@4037 | 202 | return (CompiledICHolder*) cached_value(); |
coleenp@4037 | 203 | } |
coleenp@4037 | 204 | Metadata* cached_metadata() const { |
coleenp@4037 | 205 | assert(!is_icholder_call(), "must be"); |
coleenp@4037 | 206 | return (Metadata*) cached_value(); |
coleenp@4037 | 207 | } |
coleenp@4037 | 208 | |
duke@435 | 209 | address ic_destination() const; |
duke@435 | 210 | |
duke@435 | 211 | bool is_optimized() const { return _is_optimized; } |
duke@435 | 212 | |
duke@435 | 213 | // State |
duke@435 | 214 | bool is_clean() const; |
duke@435 | 215 | bool is_megamorphic() const; |
duke@435 | 216 | bool is_call_to_compiled() const; |
duke@435 | 217 | bool is_call_to_interpreted() const; |
duke@435 | 218 | |
coleenp@4037 | 219 | bool is_icholder_call() const; |
coleenp@4037 | 220 | |
duke@435 | 221 | address end_of_call() { return _ic_call->return_address(); } |
duke@435 | 222 | |
duke@435 | 223 | // MT-safe patching of inline caches. Note: Only safe to call is_xxx when holding the CompiledIC_ock |
duke@435 | 224 | // so you are guaranteed that no patching takes place. The same goes for verify. |
duke@435 | 225 | // |
duke@435 | 226 | // Note: We do not provide any direct access to the stub code, to prevent parts of the code |
duke@435 | 227 | // to manipulate the inline cache in MT-unsafe ways. |
duke@435 | 228 | // |
duke@435 | 229 | // They all takes a TRAP argument, since they can cause a GC if the inline-cache buffer is full. |
duke@435 | 230 | // |
thartmann@8075 | 231 | void set_to_clean(bool in_use = true); |
coleenp@4037 | 232 | void set_to_monomorphic(CompiledICInfo& info); |
thartmann@8073 | 233 | void clear_ic_stub(); |
anoll@5762 | 234 | |
anoll@5762 | 235 | // Returns true if successful and false otherwise. The call can fail if memory |
anoll@5762 | 236 | // allocation in the code cache fails. |
anoll@5762 | 237 | bool set_to_megamorphic(CallInfo* call_info, Bytecodes::Code bytecode, TRAPS); |
duke@435 | 238 | |
duke@435 | 239 | static void compute_monomorphic_entry(methodHandle method, KlassHandle receiver_klass, |
duke@435 | 240 | bool is_optimized, bool static_bound, CompiledICInfo& info, TRAPS); |
duke@435 | 241 | |
duke@435 | 242 | // Location |
duke@435 | 243 | address instruction_address() const { return _ic_call->instruction_address(); } |
duke@435 | 244 | |
duke@435 | 245 | // Misc |
duke@435 | 246 | void print() PRODUCT_RETURN; |
duke@435 | 247 | void print_compiled_ic() PRODUCT_RETURN; |
duke@435 | 248 | void verify() PRODUCT_RETURN; |
duke@435 | 249 | }; |
duke@435 | 250 | |
coleenp@4037 | 251 | inline CompiledIC* CompiledIC_before(nmethod* nm, address return_addr) { |
coleenp@4037 | 252 | CompiledIC* c_ic = new CompiledIC(nm, nativeCall_before(return_addr)); |
duke@435 | 253 | c_ic->verify(); |
duke@435 | 254 | return c_ic; |
duke@435 | 255 | } |
duke@435 | 256 | |
coleenp@4037 | 257 | inline CompiledIC* CompiledIC_at(nmethod* nm, address call_site) { |
coleenp@4037 | 258 | CompiledIC* c_ic = new CompiledIC(nm, nativeCall_at(call_site)); |
duke@435 | 259 | c_ic->verify(); |
duke@435 | 260 | return c_ic; |
duke@435 | 261 | } |
duke@435 | 262 | |
duke@435 | 263 | inline CompiledIC* CompiledIC_at(Relocation* call_site) { |
coleenp@4037 | 264 | assert(call_site->type() == relocInfo::virtual_call_type || |
coleenp@4037 | 265 | call_site->type() == relocInfo::opt_virtual_call_type, "wrong reloc. info"); |
coleenp@4037 | 266 | CompiledIC* c_ic = new CompiledIC(call_site->code(), nativeCall_at(call_site->addr())); |
duke@435 | 267 | c_ic->verify(); |
duke@435 | 268 | return c_ic; |
duke@435 | 269 | } |
duke@435 | 270 | |
stefank@6991 | 271 | inline CompiledIC* CompiledIC_at(RelocIterator* reloc_iter) { |
stefank@6991 | 272 | assert(reloc_iter->type() == relocInfo::virtual_call_type || |
stefank@6991 | 273 | reloc_iter->type() == relocInfo::opt_virtual_call_type, "wrong reloc. info"); |
stefank@6991 | 274 | CompiledIC* c_ic = new CompiledIC(reloc_iter); |
stefank@6991 | 275 | c_ic->verify(); |
stefank@6991 | 276 | return c_ic; |
stefank@6991 | 277 | } |
duke@435 | 278 | |
duke@435 | 279 | //----------------------------------------------------------------------------- |
duke@435 | 280 | // The CompiledStaticCall represents a call to a static method in the compiled |
duke@435 | 281 | // |
duke@435 | 282 | // Transition diagram of a static call site is somewhat simpler than for an inlined cache: |
duke@435 | 283 | // |
duke@435 | 284 | // |
duke@435 | 285 | // -----<----- Clean ----->----- |
duke@435 | 286 | // / \ |
duke@435 | 287 | // / \ |
duke@435 | 288 | // compilled code <------------> interpreted code |
duke@435 | 289 | // |
duke@435 | 290 | // Clean: Calls directly to runtime method for fixup |
duke@435 | 291 | // Compiled code: Calls directly to compiled code |
coleenp@4037 | 292 | // Interpreted code: Calls to stub that set Method* reference |
duke@435 | 293 | // |
duke@435 | 294 | // |
duke@435 | 295 | class CompiledStaticCall; |
duke@435 | 296 | |
duke@435 | 297 | class StaticCallInfo { |
duke@435 | 298 | private: |
duke@435 | 299 | address _entry; // Entrypoint |
duke@435 | 300 | methodHandle _callee; // Callee (used when calling interpreter) |
duke@435 | 301 | bool _to_interpreter; // call to interpreted method (otherwise compiled) |
duke@435 | 302 | |
duke@435 | 303 | friend class CompiledStaticCall; |
duke@435 | 304 | public: |
duke@435 | 305 | address entry() const { return _entry; } |
duke@435 | 306 | methodHandle callee() const { return _callee; } |
duke@435 | 307 | }; |
duke@435 | 308 | |
duke@435 | 309 | |
duke@435 | 310 | class CompiledStaticCall: public NativeCall { |
duke@435 | 311 | friend class CompiledIC; |
duke@435 | 312 | |
duke@435 | 313 | // Also used by CompiledIC |
duke@435 | 314 | void set_to_interpreted(methodHandle callee, address entry); |
duke@435 | 315 | bool is_optimized_virtual(); |
duke@435 | 316 | |
duke@435 | 317 | public: |
duke@435 | 318 | friend CompiledStaticCall* compiledStaticCall_before(address return_addr); |
duke@435 | 319 | friend CompiledStaticCall* compiledStaticCall_at(address native_call); |
duke@435 | 320 | friend CompiledStaticCall* compiledStaticCall_at(Relocation* call_site); |
duke@435 | 321 | |
dlong@5000 | 322 | // Code |
vkempik@8427 | 323 | static address emit_to_interp_stub(CodeBuffer &cbuf); |
dlong@5000 | 324 | static int to_interp_stub_size(); |
dlong@5000 | 325 | static int reloc_to_interp_stub(); |
dlong@5000 | 326 | |
duke@435 | 327 | // State |
duke@435 | 328 | bool is_clean() const; |
duke@435 | 329 | bool is_call_to_compiled() const; |
duke@435 | 330 | bool is_call_to_interpreted() const; |
duke@435 | 331 | |
duke@435 | 332 | // Clean static call (will force resolving on next use) |
duke@435 | 333 | void set_to_clean(); |
duke@435 | 334 | |
duke@435 | 335 | // Set state. The entry must be the same, as computed by compute_entry. |
duke@435 | 336 | // Computation and setting is split up, since the actions are separate during |
duke@435 | 337 | // a OptoRuntime::resolve_xxx. |
duke@435 | 338 | void set(const StaticCallInfo& info); |
duke@435 | 339 | |
duke@435 | 340 | // Compute entry point given a method |
duke@435 | 341 | static void compute_entry(methodHandle m, StaticCallInfo& info); |
duke@435 | 342 | |
duke@435 | 343 | // Stub support |
duke@435 | 344 | address find_stub(); |
duke@435 | 345 | static void set_stub_to_clean(static_stub_Relocation* static_stub); |
duke@435 | 346 | |
duke@435 | 347 | // Misc. |
duke@435 | 348 | void print() PRODUCT_RETURN; |
duke@435 | 349 | void verify() PRODUCT_RETURN; |
duke@435 | 350 | }; |
duke@435 | 351 | |
duke@435 | 352 | |
duke@435 | 353 | inline CompiledStaticCall* compiledStaticCall_before(address return_addr) { |
duke@435 | 354 | CompiledStaticCall* st = (CompiledStaticCall*)nativeCall_before(return_addr); |
duke@435 | 355 | st->verify(); |
duke@435 | 356 | return st; |
duke@435 | 357 | } |
duke@435 | 358 | |
duke@435 | 359 | inline CompiledStaticCall* compiledStaticCall_at(address native_call) { |
duke@435 | 360 | CompiledStaticCall* st = (CompiledStaticCall*)native_call; |
duke@435 | 361 | st->verify(); |
duke@435 | 362 | return st; |
duke@435 | 363 | } |
duke@435 | 364 | |
duke@435 | 365 | inline CompiledStaticCall* compiledStaticCall_at(Relocation* call_site) { |
duke@435 | 366 | return compiledStaticCall_at(call_site->addr()); |
duke@435 | 367 | } |
stefank@2314 | 368 | |
stefank@2314 | 369 | #endif // SHARE_VM_CODE_COMPILEDIC_HPP |