1 /* 2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_JFR_CHECKPOINT_CONSTANT_TRACEID_JFRTYPEIDS_INLINE_HPP 26 #define SHARE_VM_JFR_CHECKPOINT_CONSTANT_TRACEID_JFRTYPEIDS_INLINE_HPP 27 28 #include "jfr/recorder/checkpoint/constant/traceid/jfrTraceIdMacros.hpp" 29 #include "jfr/recorder/checkpoint/constant/traceid/jfrTraceId.hpp" 30 #include "runtime/thread.hpp" 31 #include "utilities/debug.hpp" 32 33 template <typename T> 34 inline traceid set_used_and_get(const T* type, bool leakp) { 35 assert(type != NULL, "invariant"); 36 if (leakp) { 37 SET_LEAKP_USED_THIS_EPOCH(type); 38 assert(LEAKP_USED_THIS_EPOCH(type), "invariant"); 39 } 40 SET_USED_THIS_EPOCH(type); 41 assert(USED_THIS_EPOCH(type), "invariant"); 42 return TRACE_ID_MASKED_PTR(type); 43 } 44 45 template <typename T> 46 inline traceid set_used_and_get_shifted(const T* type, bool leakp) { 47 assert(type != NULL, "invariant"); 48 return set_used_and_get(type, leakp) >> TRACE_ID_SHIFT; 49 } 50 51 inline traceid JfrTraceId::get(const Klass* klass) { 52 assert(klass != NULL, "invariant"); 53 return TRACE_ID(klass); 54 } 55 56 inline traceid JfrTraceId::get(const Thread* t) { 57 assert(t != NULL, "invariant"); 58 return TRACE_ID_RAW(t->trace_data()); 59 } 60 61 inline traceid JfrTraceId::use(const Klass* klass, bool leakp /* false */) { 62 assert(klass != NULL, "invariant"); 63 return set_used_and_get_shifted(klass, leakp); 64 } 65 66 inline traceid JfrTraceId::use(const Method* method, bool leakp /* false */) { 67 assert(method != NULL, "invariant"); 68 SET_METHOD_FLAG_USED_THIS_EPOCH(method); 69 const Klass* const klass = method->method_holder(); 70 assert(klass != NULL, "invariant"); 71 if (leakp) { 72 SET_LEAKP_USED_THIS_EPOCH(klass); 73 assert(LEAKP_USED_THIS_EPOCH(klass), "invariant"); 74 } 75 SET_METHOD_AND_CLASS_USED_THIS_EPOCH(klass); 76 assert(METHOD_AND_CLASS_USED_THIS_EPOCH(klass), "invariant"); 77 return (METHOD_ID(klass, method)); 78 } 79 80 inline traceid JfrTraceId::use(const ClassLoaderData* cld, bool leakp /* false */) { 81 assert(cld != NULL, "invariant"); 82 return cld->is_anonymous() ? 0 : set_used_and_get_shifted(cld, leakp); 83 } 84 85 inline bool JfrTraceId::in_visible_set(const Klass* klass) { 86 assert(klass != NULL, "invariant"); 87 assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant"); 88 return (IS_JDK_JFR_EVENT_SUBKLASS(klass) && !klass->is_abstract()) || IS_EVENT_HOST_KLASS(klass); 89 } 90 91 inline bool JfrTraceId::is_jdk_jfr_event(const Klass* k) { 92 assert(k != NULL, "invariant"); 93 return IS_JDK_JFR_EVENT_KLASS(k); 94 } 95 96 inline void JfrTraceId::tag_as_jdk_jfr_event(const Klass* klass) { 97 assert(klass != NULL, "invariant"); 98 assert(IS_NOT_AN_EVENT_KLASS(klass), "invariant"); 99 SET_TAG(klass, JDK_JFR_EVENT_KLASS); 100 assert(IS_JDK_JFR_EVENT_KLASS(klass), "invariant"); 101 assert(IS_NOT_AN_EVENT_SUB_KLASS(klass), "invariant"); 102 } 103 104 inline bool JfrTraceId::is_jdk_jfr_event_sub(const Klass* k) { 105 assert(k != NULL, "invariant"); 106 return IS_JDK_JFR_EVENT_SUBKLASS(k); 107 } 108 109 inline void JfrTraceId::tag_as_jdk_jfr_event_sub(const Klass* k) { 110 assert(k != NULL, "invariant"); 111 if (IS_NOT_AN_EVENT_KLASS(k)) { 112 SET_TAG(k, JDK_JFR_EVENT_SUBKLASS); 113 } 114 assert(IS_JDK_JFR_EVENT_SUBKLASS(k), "invariant"); 115 } 116 117 inline bool JfrTraceId::in_jdk_jfr_event_hierarchy(const Klass* klass) { 118 assert(klass != NULL, "invariant"); 119 if (is_jdk_jfr_event(klass)) { 120 return true; 121 } 122 const Klass* const super = klass->super(); 123 return super != NULL ? IS_EVENT_KLASS(super) : false; 124 } 125 126 inline bool JfrTraceId::is_event_host(const Klass* k) { 127 assert(k != NULL, "invariant"); 128 return IS_EVENT_HOST_KLASS(k); 129 } 130 131 inline void JfrTraceId::tag_as_event_host(const Klass* k) { 132 assert(k != NULL, "invariant"); 133 SET_TAG(k, EVENT_HOST_KLASS); 134 assert(IS_EVENT_HOST_KLASS(k), "invariant"); 135 } 136 137 #endif // SHARE_VM_JFR_CHECKPOINT_CONSTANT_TRACEID_JFRTYPEIDS_INLINE_HPP