src/share/vm/jfr/recorder/checkpoint/types/traceid/jfrTraceId.cpp

Tue, 02 Jun 2020 14:29:43 +0800

author
ddong
date
Tue, 02 Jun 2020 14:29:43 +0800
changeset 9941
45c8de52649c
parent 9858
b985cbb00e68
permissions
-rw-r--r--

8246310: Clean commented-out code about ModuleEntry andPackageEntry in JFR
Reviewed-by: adinn

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 static traceid next_class_loader_data_id() {
apetushkov@9858 65 static volatile traceid cld_id_counter = 1;
apetushkov@9858 66 return atomic_inc(&cld_id_counter) << TRACE_ID_SHIFT;
apetushkov@9858 67 }
apetushkov@9858 68
apetushkov@9858 69 static bool found_jdk_jfr_event_klass = false;
apetushkov@9858 70
apetushkov@9858 71 static void check_klass(const Klass* klass) {
apetushkov@9858 72 assert(klass != NULL, "invariant");
apetushkov@9858 73 if (found_jdk_jfr_event_klass) {
apetushkov@9858 74 return;
apetushkov@9858 75 }
apetushkov@9858 76 static const Symbol* jdk_jfr_event_sym = NULL;
apetushkov@9858 77 if (jdk_jfr_event_sym == NULL) {
apetushkov@9858 78 // setup when loading the first TypeArrayKlass (Universe::genesis) hence single threaded invariant
apetushkov@9858 79 jdk_jfr_event_sym = SymbolTable::new_permanent_symbol("jdk/jfr/Event", Thread::current());
apetushkov@9858 80 }
apetushkov@9858 81 assert(jdk_jfr_event_sym != NULL, "invariant");
apetushkov@9858 82 if (jdk_jfr_event_sym == klass->name()/* XXX && klass->class_loader() == NULL*/) {
apetushkov@9858 83 found_jdk_jfr_event_klass = true;
apetushkov@9858 84 JfrTraceId::tag_as_jdk_jfr_event(klass);
apetushkov@9858 85 }
apetushkov@9858 86 }
apetushkov@9858 87
apetushkov@9858 88 void JfrTraceId::assign(const Klass* klass) {
apetushkov@9858 89 assert(klass != NULL, "invariant");
apetushkov@9858 90 klass->set_trace_id(next_class_id());
apetushkov@9858 91 check_klass(klass);
apetushkov@9858 92 const Klass* const super = klass->super();
apetushkov@9858 93 if (super == NULL) {
apetushkov@9858 94 return;
apetushkov@9858 95 }
apetushkov@9858 96 if (IS_EVENT_KLASS(super)) {
apetushkov@9858 97 tag_as_jdk_jfr_event_sub(klass);
apetushkov@9858 98 }
apetushkov@9858 99 }
apetushkov@9858 100
apetushkov@9858 101 void JfrTraceId::assign(const ClassLoaderData* cld) {
apetushkov@9858 102 assert(cld != NULL, "invariant");
apetushkov@9858 103 if (cld->is_anonymous()) {
apetushkov@9858 104 cld->set_trace_id(0);
apetushkov@9858 105 return;
apetushkov@9858 106 }
apetushkov@9858 107 cld->set_trace_id(next_class_loader_data_id());
apetushkov@9858 108 }
apetushkov@9858 109
apetushkov@9858 110 traceid JfrTraceId::assign_thread_id() {
apetushkov@9858 111 return next_thread_id();
apetushkov@9858 112 }
apetushkov@9858 113
apetushkov@9858 114 // used by CDS / APPCDS as part of "remove_unshareable_info"
apetushkov@9858 115 void JfrTraceId::remove(const Klass* k) {
apetushkov@9858 116 assert(k != NULL, "invariant");
apetushkov@9858 117 // Mask off and store the event flags.
apetushkov@9858 118 // This mechanism will retain the event specific flags
apetushkov@9858 119 // in the archive, allowing for event flag restoration
apetushkov@9858 120 // when renewing the traceid on klass revival.
apetushkov@9858 121 k->set_trace_id(EVENT_FLAGS_MASK(k));
apetushkov@9858 122 }
apetushkov@9858 123
apetushkov@9858 124 // used by CDS / APPCDS as part of "restore_unshareable_info"
apetushkov@9858 125 void JfrTraceId::restore(const Klass* k) {
apetushkov@9858 126 assert(k != NULL, "invariant");
apetushkov@9858 127 if (IS_JDK_JFR_EVENT_KLASS(k)) {
apetushkov@9858 128 found_jdk_jfr_event_klass = true;
apetushkov@9858 129 }
apetushkov@9858 130 const traceid event_flags = k->trace_id();
apetushkov@9858 131 // get a fresh traceid and restore the original event flags
apetushkov@9858 132 k->set_trace_id(next_class_id() | event_flags);
apetushkov@9858 133 }
apetushkov@9858 134
apetushkov@9858 135 traceid JfrTraceId::get(jclass jc) {
apetushkov@9858 136 assert(jc != NULL, "invariant");
apetushkov@9858 137 assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant");
apetushkov@9858 138 const oop my_oop = JNIHandles::resolve(jc);
apetushkov@9858 139 assert(my_oop != NULL, "invariant");
apetushkov@9858 140 return get(java_lang_Class::as_Klass(my_oop));
apetushkov@9858 141 }
apetushkov@9858 142
apetushkov@9858 143 traceid JfrTraceId::use(jclass jc, bool leakp /* false */) {
apetushkov@9858 144 assert(jc != NULL, "invariant");
apetushkov@9858 145 assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant");
apetushkov@9858 146 const oop my_oop = JNIHandles::resolve(jc);
apetushkov@9858 147 assert(my_oop != NULL, "invariant");
apetushkov@9858 148 return use(java_lang_Class::as_Klass(my_oop), leakp);
apetushkov@9858 149 }
apetushkov@9858 150
apetushkov@9858 151 bool JfrTraceId::in_visible_set(const jclass jc) {
apetushkov@9858 152 assert(jc != NULL, "invariant");
apetushkov@9858 153 assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant");
apetushkov@9858 154 const oop mirror = JNIHandles::resolve(jc);
apetushkov@9858 155 assert(mirror != NULL, "invariant");
apetushkov@9858 156 return in_visible_set(java_lang_Class::as_Klass(mirror));
apetushkov@9858 157 }
apetushkov@9858 158
apetushkov@9858 159 bool JfrTraceId::in_jdk_jfr_event_hierarchy(const jclass jc) {
apetushkov@9858 160 assert(jc != NULL, "invariant");
apetushkov@9858 161 const oop mirror = JNIHandles::resolve(jc);
apetushkov@9858 162 assert(mirror != NULL, "invariant");
apetushkov@9858 163 return in_jdk_jfr_event_hierarchy(java_lang_Class::as_Klass(mirror));
apetushkov@9858 164 }
apetushkov@9858 165
apetushkov@9858 166 bool JfrTraceId::is_jdk_jfr_event_sub(const jclass jc) {
apetushkov@9858 167 assert(jc != NULL, "invariant");
apetushkov@9858 168 const oop mirror = JNIHandles::resolve(jc);
apetushkov@9858 169 assert(mirror != NULL, "invariant");
apetushkov@9858 170 return is_jdk_jfr_event_sub(java_lang_Class::as_Klass(mirror));
apetushkov@9858 171 }
apetushkov@9858 172
apetushkov@9858 173 bool JfrTraceId::is_jdk_jfr_event(const jclass jc) {
apetushkov@9858 174 assert(jc != NULL, "invariant");
apetushkov@9858 175 const oop mirror = JNIHandles::resolve(jc);
apetushkov@9858 176 assert(mirror != NULL, "invariant");
apetushkov@9858 177 return is_jdk_jfr_event(java_lang_Class::as_Klass(mirror));
apetushkov@9858 178 }
apetushkov@9858 179
apetushkov@9858 180 bool JfrTraceId::is_event_host(const jclass jc) {
apetushkov@9858 181 assert(jc != NULL, "invariant");
apetushkov@9858 182 const oop mirror = JNIHandles::resolve(jc);
apetushkov@9858 183 assert(mirror != NULL, "invariant");
apetushkov@9858 184 return is_event_host(java_lang_Class::as_Klass(mirror));
apetushkov@9858 185 }
apetushkov@9858 186
apetushkov@9858 187 void JfrTraceId::tag_as_jdk_jfr_event_sub(const jclass jc) {
apetushkov@9858 188 assert(jc != NULL, "invariant");
apetushkov@9858 189 const oop mirror = JNIHandles::resolve(jc);
apetushkov@9858 190 assert(mirror != NULL, "invariant");
apetushkov@9858 191 const Klass* const k = java_lang_Class::as_Klass(mirror);
apetushkov@9858 192 tag_as_jdk_jfr_event_sub(k);
apetushkov@9858 193 assert(IS_JDK_JFR_EVENT_SUBKLASS(k), "invariant");
apetushkov@9858 194 }
apetushkov@9858 195
apetushkov@9858 196 void JfrTraceId::tag_as_event_host(const jclass jc) {
apetushkov@9858 197 assert(jc != NULL, "invariant");
apetushkov@9858 198 const oop mirror = JNIHandles::resolve(jc);
apetushkov@9858 199 assert(mirror != NULL, "invariant");
apetushkov@9858 200 const Klass* const k = java_lang_Class::as_Klass(mirror);
apetushkov@9858 201 tag_as_event_host(k);
apetushkov@9858 202 assert(IS_EVENT_HOST_KLASS(k), "invariant");
apetushkov@9858 203 }

mercurial