src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp
changeset 50113 caf115bb98ad
child 50122 d2bcbcf0d3d9
equal deleted inserted replaced
50112:7a2a740815b7 50113:caf115bb98ad
       
     1 /*
       
     2  * Copyright (c) 2016, 2018, 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_TYPES_TRACEID_JFRTYPEIDS_INLINE_HPP
       
    26 #define SHARE_VM_JFR_CHECKPOINT_TYPES_TRACEID_JFRTYPEIDS_INLINE_HPP
       
    27 
       
    28 #include "classfile/classLoaderData.hpp"
       
    29 #include "classfile/moduleEntry.hpp"
       
    30 #include "classfile/packageEntry.hpp"
       
    31 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceIdMacros.hpp"
       
    32 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.hpp"
       
    33 #include "oops/arrayKlass.hpp"
       
    34 #include "oops/klass.hpp"
       
    35 #include "oops/instanceKlass.hpp"
       
    36 #include "oops/method.hpp"
       
    37 #include "runtime/thread.hpp"
       
    38 #include "utilities/debug.hpp"
       
    39 
       
    40 template <typename T>
       
    41 inline traceid set_used_and_get(const T* type, bool leakp) {
       
    42   assert(type != NULL, "invariant");
       
    43   if (leakp) {
       
    44     SET_LEAKP_USED_THIS_EPOCH(type);
       
    45     assert(LEAKP_USED_THIS_EPOCH(type), "invariant");
       
    46   }
       
    47   SET_USED_THIS_EPOCH(type);
       
    48   assert(USED_THIS_EPOCH(type), "invariant");
       
    49   return TRACE_ID_MASKED_PTR(type);
       
    50 }
       
    51 
       
    52 template <typename T>
       
    53 inline traceid set_used_and_get_shifted(const T* type, bool leakp) {
       
    54   assert(type != NULL, "invariant");
       
    55   return set_used_and_get(type, leakp) >> TRACE_ID_SHIFT;
       
    56 }
       
    57 
       
    58 inline traceid JfrTraceId::get(const Klass* klass) {
       
    59   assert(klass != NULL, "invariant");
       
    60   return TRACE_ID(klass);
       
    61 }
       
    62 
       
    63 inline traceid JfrTraceId::get(const Thread* t) {
       
    64   assert(t != NULL, "invariant");
       
    65   return TRACE_ID_RAW(t->jfr_thread_local());
       
    66 }
       
    67 
       
    68 inline traceid JfrTraceId::use(const Klass* klass, bool leakp /* false */) {
       
    69   assert(klass != NULL, "invariant");
       
    70   return set_used_and_get_shifted(klass, leakp);
       
    71 }
       
    72 
       
    73 inline traceid JfrTraceId::use(const Method* method, bool leakp /* false */) {
       
    74   assert(method != NULL, "invariant");
       
    75   SET_METHOD_FLAG_USED_THIS_EPOCH(method);
       
    76   const Klass* const klass = method->method_holder();
       
    77   assert(klass != NULL, "invariant");
       
    78   if (leakp) {
       
    79     SET_LEAKP_USED_THIS_EPOCH(klass);
       
    80     assert(LEAKP_USED_THIS_EPOCH(klass), "invariant");
       
    81   }
       
    82   SET_METHOD_AND_CLASS_USED_THIS_EPOCH(klass);
       
    83   assert(METHOD_AND_CLASS_USED_THIS_EPOCH(klass), "invariant");
       
    84   return (METHOD_ID(klass, method));
       
    85 }
       
    86 
       
    87 inline traceid JfrTraceId::use(const ModuleEntry* module, bool leakp /* false */) {
       
    88   assert(module != NULL, "invariant");
       
    89   return set_used_and_get_shifted(module, leakp);
       
    90 }
       
    91 
       
    92 inline traceid JfrTraceId::use(const PackageEntry* package, bool leakp /* false */) {
       
    93   assert(package != NULL, "invariant");
       
    94   return set_used_and_get_shifted(package, leakp);
       
    95 }
       
    96 
       
    97 inline traceid JfrTraceId::use(const ClassLoaderData* cld, bool leakp /* false */) {
       
    98   assert(cld != NULL, "invariant");
       
    99   return cld->is_anonymous() ? 0 : set_used_and_get_shifted(cld, leakp);
       
   100 }
       
   101 
       
   102 inline bool JfrTraceId::in_visible_set(const Klass* klass) {
       
   103   assert(klass != NULL, "invariant");
       
   104   assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_vm, "invariant");
       
   105   return (IS_JDK_JFR_EVENT_SUBKLASS(klass) && !klass->is_abstract()) || IS_EVENT_HOST_KLASS(klass);
       
   106 }
       
   107 
       
   108 inline bool JfrTraceId::is_jdk_jfr_event(const Klass* k) {
       
   109   assert(k != NULL, "invariant");
       
   110   return IS_JDK_JFR_EVENT_KLASS(k);
       
   111 }
       
   112 
       
   113 inline void JfrTraceId::tag_as_jdk_jfr_event(const Klass* klass) {
       
   114   assert(klass != NULL, "invariant");
       
   115   assert(IS_NOT_AN_EVENT_KLASS(klass), "invariant");
       
   116   SET_TAG(klass, JDK_JFR_EVENT_KLASS);
       
   117   assert(IS_JDK_JFR_EVENT_KLASS(klass), "invariant");
       
   118   assert(IS_NOT_AN_EVENT_SUB_KLASS(klass), "invariant");
       
   119 }
       
   120 
       
   121 inline bool JfrTraceId::is_jdk_jfr_event_sub(const Klass* k) {
       
   122   assert(k != NULL, "invariant");
       
   123   return IS_JDK_JFR_EVENT_SUBKLASS(k);
       
   124 }
       
   125 
       
   126 inline void JfrTraceId::tag_as_jdk_jfr_event_sub(const Klass* k) {
       
   127   assert(k != NULL, "invariant");
       
   128   if (IS_NOT_AN_EVENT_KLASS(k)) {
       
   129     SET_TAG(k, JDK_JFR_EVENT_SUBKLASS);
       
   130   }
       
   131   assert(IS_JDK_JFR_EVENT_SUBKLASS(k), "invariant");
       
   132 }
       
   133 
       
   134 inline bool JfrTraceId::in_jdk_jfr_event_hierarchy(const Klass* klass) {
       
   135   assert(klass != NULL, "invariant");
       
   136   if (is_jdk_jfr_event(klass)) {
       
   137     return true;
       
   138   }
       
   139   const Klass* const super = klass->super();
       
   140   return super != NULL ? IS_EVENT_KLASS(super) : false;
       
   141 }
       
   142 
       
   143 inline bool JfrTraceId::is_event_host(const Klass* k) {
       
   144   assert(k != NULL, "invariant");
       
   145   return IS_EVENT_HOST_KLASS(k);
       
   146 }
       
   147 
       
   148 inline void JfrTraceId::tag_as_event_host(const Klass* k) {
       
   149   assert(k != NULL, "invariant");
       
   150   SET_TAG(k, EVENT_HOST_KLASS);
       
   151   assert(IS_EVENT_HOST_KLASS(k), "invariant");
       
   152 }
       
   153 
       
   154 #endif // SHARE_VM_JFR_CHECKPOINT_TYPES_TRACEID_JFRTYPEIDS_INLINE_HPP