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
apetushkov@9858 | 1 | /* |
apetushkov@9858 | 2 | * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
apetushkov@9858 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
apetushkov@9858 | 4 | * |
apetushkov@9858 | 5 | * This code is free software; you can redistribute it and/or modify it |
apetushkov@9858 | 6 | * under the terms of the GNU General Public License version 2 only, as |
apetushkov@9858 | 7 | * published by the Free Software Foundation. |
apetushkov@9858 | 8 | * |
apetushkov@9858 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
apetushkov@9858 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
apetushkov@9858 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
apetushkov@9858 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
apetushkov@9858 | 13 | * accompanied this code). |
apetushkov@9858 | 14 | * |
apetushkov@9858 | 15 | * You should have received a copy of the GNU General Public License version |
apetushkov@9858 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
apetushkov@9858 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
apetushkov@9858 | 18 | * |
apetushkov@9858 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
apetushkov@9858 | 20 | * or visit www.oracle.com if you need additional information or have any |
apetushkov@9858 | 21 | * questions. |
apetushkov@9858 | 22 | * |
apetushkov@9858 | 23 | */ |
apetushkov@9858 | 24 | |
apetushkov@9858 | 25 | #include "precompiled.hpp" |
apetushkov@9858 | 26 | #include "classfile/classLoaderData.inline.hpp" |
apetushkov@9858 | 27 | #include "classfile/symbolTable.hpp" |
apetushkov@9858 | 28 | #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
apetushkov@9858 | 29 | #include "jfr/utilities/jfrTypes.hpp" |
apetushkov@9858 | 30 | #include "oops/arrayKlass.hpp" |
apetushkov@9858 | 31 | #include "oops/klass.inline.hpp" |
apetushkov@9858 | 32 | #include "oops/instanceKlass.hpp" |
apetushkov@9858 | 33 | #include "oops/method.hpp" |
apetushkov@9858 | 34 | #include "oops/oop.inline.hpp" |
apetushkov@9858 | 35 | #include "runtime/atomic.inline.hpp" |
apetushkov@9858 | 36 | #include "runtime/orderAccess.inline.hpp" |
apetushkov@9858 | 37 | #include "runtime/vm_version.hpp" |
apetushkov@9858 | 38 | #include "runtime/jniHandles.hpp" |
apetushkov@9858 | 39 | #include "runtime/thread.inline.hpp" |
apetushkov@9858 | 40 | #include "utilities/debug.hpp" |
apetushkov@9858 | 41 | |
apetushkov@9858 | 42 | // returns updated value |
apetushkov@9858 | 43 | static traceid atomic_inc(traceid volatile* const dest) { |
apetushkov@9858 | 44 | return (traceid) atomic_add_jlong(1, (jlong volatile*) dest); |
apetushkov@9858 | 45 | } |
apetushkov@9858 | 46 | |
apetushkov@9858 | 47 | static traceid next_class_id() { |
apetushkov@9858 | 48 | static volatile traceid class_id_counter = MaxJfrEventId + 100; |
apetushkov@9858 | 49 | return atomic_inc(&class_id_counter) << TRACE_ID_SHIFT; |
apetushkov@9858 | 50 | } |
apetushkov@9858 | 51 | |
apetushkov@9858 | 52 | static traceid next_thread_id() { |
apetushkov@9858 | 53 | #ifdef _LP64 |
apetushkov@9858 | 54 | static volatile traceid thread_id_counter = 0; |
apetushkov@9858 | 55 | return atomic_inc(&thread_id_counter); |
apetushkov@9858 | 56 | #else |
apetushkov@9858 | 57 | static volatile jint thread_id_counter = 0; |
apetushkov@9858 | 58 | assert(thread_id_counter >= 0 && thread_id_counter < INT_MAX, "thread counter has been overflown"); |
apetushkov@9858 | 59 | Atomic::inc(&thread_id_counter); |
apetushkov@9858 | 60 | return (traceid) thread_id_counter; |
apetushkov@9858 | 61 | #endif |
apetushkov@9858 | 62 | } |
apetushkov@9858 | 63 | |
apetushkov@9858 | 64 | // XXX |
apetushkov@9858 | 65 | // static traceid next_package_id() { |
apetushkov@9858 | 66 | // static volatile traceid package_id_counter = 1; |
apetushkov@9858 | 67 | // return atomic_inc(&package_id_counter) << TRACE_ID_SHIFT; |
apetushkov@9858 | 68 | // } |
apetushkov@9858 | 69 | |
apetushkov@9858 | 70 | static traceid next_class_loader_data_id() { |
apetushkov@9858 | 71 | static volatile traceid cld_id_counter = 1; |
apetushkov@9858 | 72 | return atomic_inc(&cld_id_counter) << TRACE_ID_SHIFT; |
apetushkov@9858 | 73 | } |
apetushkov@9858 | 74 | |
apetushkov@9858 | 75 | static bool found_jdk_jfr_event_klass = false; |
apetushkov@9858 | 76 | |
apetushkov@9858 | 77 | static void check_klass(const Klass* klass) { |
apetushkov@9858 | 78 | assert(klass != NULL, "invariant"); |
apetushkov@9858 | 79 | if (found_jdk_jfr_event_klass) { |
apetushkov@9858 | 80 | return; |
apetushkov@9858 | 81 | } |
apetushkov@9858 | 82 | static const Symbol* jdk_jfr_event_sym = NULL; |
apetushkov@9858 | 83 | if (jdk_jfr_event_sym == NULL) { |
apetushkov@9858 | 84 | // setup when loading the first TypeArrayKlass (Universe::genesis) hence single threaded invariant |
apetushkov@9858 | 85 | jdk_jfr_event_sym = SymbolTable::new_permanent_symbol("jdk/jfr/Event", Thread::current()); |
apetushkov@9858 | 86 | } |
apetushkov@9858 | 87 | assert(jdk_jfr_event_sym != NULL, "invariant"); |
apetushkov@9858 | 88 | if (jdk_jfr_event_sym == klass->name()/* XXX && klass->class_loader() == NULL*/) { |
apetushkov@9858 | 89 | found_jdk_jfr_event_klass = true; |
apetushkov@9858 | 90 | JfrTraceId::tag_as_jdk_jfr_event(klass); |
apetushkov@9858 | 91 | } |
apetushkov@9858 | 92 | } |
apetushkov@9858 | 93 | |
apetushkov@9858 | 94 | void JfrTraceId::assign(const Klass* klass) { |
apetushkov@9858 | 95 | assert(klass != NULL, "invariant"); |
apetushkov@9858 | 96 | klass->set_trace_id(next_class_id()); |
apetushkov@9858 | 97 | check_klass(klass); |
apetushkov@9858 | 98 | const Klass* const super = klass->super(); |
apetushkov@9858 | 99 | if (super == NULL) { |
apetushkov@9858 | 100 | return; |
apetushkov@9858 | 101 | } |
apetushkov@9858 | 102 | if (IS_EVENT_KLASS(super)) { |
apetushkov@9858 | 103 | tag_as_jdk_jfr_event_sub(klass); |
apetushkov@9858 | 104 | } |
apetushkov@9858 | 105 | } |
apetushkov@9858 | 106 | |
apetushkov@9858 | 107 | // XXX |
apetushkov@9858 | 108 | // void JfrTraceId::assign(const PackageEntry* package) { |
apetushkov@9858 | 109 | // assert(package != NULL, "invariant"); |
apetushkov@9858 | 110 | // package->set_trace_id(next_package_id()); |
apetushkov@9858 | 111 | // } |
apetushkov@9858 | 112 | |
apetushkov@9858 | 113 | void JfrTraceId::assign(const ClassLoaderData* cld) { |
apetushkov@9858 | 114 | assert(cld != NULL, "invariant"); |
apetushkov@9858 | 115 | if (cld->is_anonymous()) { |
apetushkov@9858 | 116 | cld->set_trace_id(0); |
apetushkov@9858 | 117 | return; |
apetushkov@9858 | 118 | } |
apetushkov@9858 | 119 | cld->set_trace_id(next_class_loader_data_id()); |
apetushkov@9858 | 120 | } |
apetushkov@9858 | 121 | |
apetushkov@9858 | 122 | traceid JfrTraceId::assign_thread_id() { |
apetushkov@9858 | 123 | return next_thread_id(); |
apetushkov@9858 | 124 | } |
apetushkov@9858 | 125 | |
apetushkov@9858 | 126 | // used by CDS / APPCDS as part of "remove_unshareable_info" |
apetushkov@9858 | 127 | void JfrTraceId::remove(const Klass* k) { |
apetushkov@9858 | 128 | assert(k != NULL, "invariant"); |
apetushkov@9858 | 129 | // Mask off and store the event flags. |
apetushkov@9858 | 130 | // This mechanism will retain the event specific flags |
apetushkov@9858 | 131 | // in the archive, allowing for event flag restoration |
apetushkov@9858 | 132 | // when renewing the traceid on klass revival. |
apetushkov@9858 | 133 | k->set_trace_id(EVENT_FLAGS_MASK(k)); |
apetushkov@9858 | 134 | } |
apetushkov@9858 | 135 | |
apetushkov@9858 | 136 | // used by CDS / APPCDS as part of "restore_unshareable_info" |
apetushkov@9858 | 137 | void JfrTraceId::restore(const Klass* k) { |
apetushkov@9858 | 138 | assert(k != NULL, "invariant"); |
apetushkov@9858 | 139 | if (IS_JDK_JFR_EVENT_KLASS(k)) { |
apetushkov@9858 | 140 | found_jdk_jfr_event_klass = true; |
apetushkov@9858 | 141 | } |
apetushkov@9858 | 142 | const traceid event_flags = k->trace_id(); |
apetushkov@9858 | 143 | // get a fresh traceid and restore the original event flags |
apetushkov@9858 | 144 | k->set_trace_id(next_class_id() | event_flags); |
apetushkov@9858 | 145 | } |
apetushkov@9858 | 146 | |
apetushkov@9858 | 147 | traceid JfrTraceId::get(jclass jc) { |
apetushkov@9858 | 148 | assert(jc != NULL, "invariant"); |
apetushkov@9858 | 149 | assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant"); |
apetushkov@9858 | 150 | const oop my_oop = JNIHandles::resolve(jc); |
apetushkov@9858 | 151 | assert(my_oop != NULL, "invariant"); |
apetushkov@9858 | 152 | return get(java_lang_Class::as_Klass(my_oop)); |
apetushkov@9858 | 153 | } |
apetushkov@9858 | 154 | |
apetushkov@9858 | 155 | traceid JfrTraceId::use(jclass jc, bool leakp /* false */) { |
apetushkov@9858 | 156 | assert(jc != NULL, "invariant"); |
apetushkov@9858 | 157 | assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant"); |
apetushkov@9858 | 158 | const oop my_oop = JNIHandles::resolve(jc); |
apetushkov@9858 | 159 | assert(my_oop != NULL, "invariant"); |
apetushkov@9858 | 160 | return use(java_lang_Class::as_Klass(my_oop), leakp); |
apetushkov@9858 | 161 | } |
apetushkov@9858 | 162 | |
apetushkov@9858 | 163 | bool JfrTraceId::in_visible_set(const jclass jc) { |
apetushkov@9858 | 164 | assert(jc != NULL, "invariant"); |
apetushkov@9858 | 165 | assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant"); |
apetushkov@9858 | 166 | const oop mirror = JNIHandles::resolve(jc); |
apetushkov@9858 | 167 | assert(mirror != NULL, "invariant"); |
apetushkov@9858 | 168 | return in_visible_set(java_lang_Class::as_Klass(mirror)); |
apetushkov@9858 | 169 | } |
apetushkov@9858 | 170 | |
apetushkov@9858 | 171 | bool JfrTraceId::in_jdk_jfr_event_hierarchy(const jclass jc) { |
apetushkov@9858 | 172 | assert(jc != NULL, "invariant"); |
apetushkov@9858 | 173 | const oop mirror = JNIHandles::resolve(jc); |
apetushkov@9858 | 174 | assert(mirror != NULL, "invariant"); |
apetushkov@9858 | 175 | return in_jdk_jfr_event_hierarchy(java_lang_Class::as_Klass(mirror)); |
apetushkov@9858 | 176 | } |
apetushkov@9858 | 177 | |
apetushkov@9858 | 178 | bool JfrTraceId::is_jdk_jfr_event_sub(const jclass jc) { |
apetushkov@9858 | 179 | assert(jc != NULL, "invariant"); |
apetushkov@9858 | 180 | const oop mirror = JNIHandles::resolve(jc); |
apetushkov@9858 | 181 | assert(mirror != NULL, "invariant"); |
apetushkov@9858 | 182 | return is_jdk_jfr_event_sub(java_lang_Class::as_Klass(mirror)); |
apetushkov@9858 | 183 | } |
apetushkov@9858 | 184 | |
apetushkov@9858 | 185 | bool JfrTraceId::is_jdk_jfr_event(const jclass jc) { |
apetushkov@9858 | 186 | assert(jc != NULL, "invariant"); |
apetushkov@9858 | 187 | const oop mirror = JNIHandles::resolve(jc); |
apetushkov@9858 | 188 | assert(mirror != NULL, "invariant"); |
apetushkov@9858 | 189 | return is_jdk_jfr_event(java_lang_Class::as_Klass(mirror)); |
apetushkov@9858 | 190 | } |
apetushkov@9858 | 191 | |
apetushkov@9858 | 192 | bool JfrTraceId::is_event_host(const jclass jc) { |
apetushkov@9858 | 193 | assert(jc != NULL, "invariant"); |
apetushkov@9858 | 194 | const oop mirror = JNIHandles::resolve(jc); |
apetushkov@9858 | 195 | assert(mirror != NULL, "invariant"); |
apetushkov@9858 | 196 | return is_event_host(java_lang_Class::as_Klass(mirror)); |
apetushkov@9858 | 197 | } |
apetushkov@9858 | 198 | |
apetushkov@9858 | 199 | void JfrTraceId::tag_as_jdk_jfr_event_sub(const jclass jc) { |
apetushkov@9858 | 200 | assert(jc != NULL, "invariant"); |
apetushkov@9858 | 201 | const oop mirror = JNIHandles::resolve(jc); |
apetushkov@9858 | 202 | assert(mirror != NULL, "invariant"); |
apetushkov@9858 | 203 | const Klass* const k = java_lang_Class::as_Klass(mirror); |
apetushkov@9858 | 204 | tag_as_jdk_jfr_event_sub(k); |
apetushkov@9858 | 205 | assert(IS_JDK_JFR_EVENT_SUBKLASS(k), "invariant"); |
apetushkov@9858 | 206 | } |
apetushkov@9858 | 207 | |
apetushkov@9858 | 208 | void JfrTraceId::tag_as_event_host(const jclass jc) { |
apetushkov@9858 | 209 | assert(jc != NULL, "invariant"); |
apetushkov@9858 | 210 | const oop mirror = JNIHandles::resolve(jc); |
apetushkov@9858 | 211 | assert(mirror != NULL, "invariant"); |
apetushkov@9858 | 212 | const Klass* const k = java_lang_Class::as_Klass(mirror); |
apetushkov@9858 | 213 | tag_as_event_host(k); |
apetushkov@9858 | 214 | assert(IS_EVENT_HOST_KLASS(k), "invariant"); |
apetushkov@9858 | 215 | } |