src/hotspot/share/jfr/support/jfrThreadLocal.hpp
changeset 50113 caf115bb98ad
child 51004 162867fa0f8d
equal deleted inserted replaced
50112:7a2a740815b7 50113:caf115bb98ad
       
     1 /*
       
     2  * Copyright (c) 2012, 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_SUPPORT_JFRTHREADLOCAL_HPP
       
    26 #define SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP
       
    27 
       
    28 #include "jfr/recorder/checkpoint/jfrCheckpointBlob.hpp"
       
    29 #include "jfr/utilities/jfrTypes.hpp"
       
    30 #include "utilities/sizes.hpp"
       
    31 
       
    32 class JavaThread;
       
    33 class JfrBuffer;
       
    34 class JfrStackFrame;
       
    35 
       
    36 class JfrThreadLocal {
       
    37  private:
       
    38   jobject _java_event_writer;
       
    39   mutable JfrBuffer* _java_buffer;
       
    40   mutable JfrBuffer* _native_buffer;
       
    41   JfrBuffer* _shelved_buffer;
       
    42   mutable JfrStackFrame* _stackframes;
       
    43   mutable traceid _trace_id;
       
    44   JfrCheckpointBlobHandle _thread_cp;
       
    45   u8 _data_lost;
       
    46   traceid _stack_trace_id;
       
    47   jlong _user_time;
       
    48   jlong _cpu_time;
       
    49   jlong _wallclock_time;
       
    50   unsigned int _stack_trace_hash;
       
    51   mutable u4 _stackdepth;
       
    52   volatile jint _entering_suspend_flag;
       
    53 
       
    54   JfrBuffer* install_native_buffer() const;
       
    55   JfrBuffer* install_java_buffer() const;
       
    56   JfrStackFrame* install_stackframes() const;
       
    57 
       
    58  public:
       
    59   JfrThreadLocal();
       
    60 
       
    61   JfrBuffer* native_buffer() const {
       
    62     return _native_buffer != NULL ? _native_buffer : install_native_buffer();
       
    63   }
       
    64 
       
    65   bool has_native_buffer() const {
       
    66     return _native_buffer != NULL;
       
    67   }
       
    68 
       
    69   void set_native_buffer(JfrBuffer* buffer) {
       
    70     _native_buffer = buffer;
       
    71   }
       
    72 
       
    73   JfrBuffer* java_buffer() const {
       
    74     return _java_buffer != NULL ? _java_buffer : install_java_buffer();
       
    75   }
       
    76 
       
    77   bool has_java_buffer() const {
       
    78     return _java_buffer != NULL;
       
    79   }
       
    80 
       
    81   void set_java_buffer(JfrBuffer* buffer) {
       
    82     _java_buffer = buffer;
       
    83   }
       
    84 
       
    85   JfrBuffer* shelved_buffer() const {
       
    86     return _shelved_buffer;
       
    87   }
       
    88 
       
    89   void shelve_buffer(JfrBuffer* buffer) {
       
    90     _shelved_buffer = buffer;
       
    91   }
       
    92 
       
    93   bool has_java_event_writer() const {
       
    94     return _java_event_writer != NULL;
       
    95   }
       
    96 
       
    97   jobject java_event_writer() {
       
    98     return _java_event_writer;
       
    99   }
       
   100 
       
   101   void set_java_event_writer(jobject java_event_writer) {
       
   102     _java_event_writer = java_event_writer;
       
   103   }
       
   104 
       
   105   JfrStackFrame* stackframes() const {
       
   106     return _stackframes != NULL ? _stackframes : install_stackframes();
       
   107   }
       
   108 
       
   109   void set_stackframes(JfrStackFrame* frames) {
       
   110     _stackframes = frames;
       
   111   }
       
   112 
       
   113   u4 stackdepth() const {
       
   114     return _stackdepth;
       
   115   }
       
   116 
       
   117   void set_stackdepth(u4 depth) {
       
   118     _stackdepth = depth;
       
   119   }
       
   120 
       
   121   traceid thread_id() const {
       
   122     return _trace_id;
       
   123   }
       
   124 
       
   125   void set_thread_id(traceid thread_id) {
       
   126     _trace_id = thread_id;
       
   127   }
       
   128 
       
   129   void set_cached_stack_trace_id(traceid id, unsigned int hash = 0) {
       
   130     _stack_trace_id = id;
       
   131     _stack_trace_hash = hash;
       
   132   }
       
   133 
       
   134   bool has_cached_stack_trace() const {
       
   135     return _stack_trace_id != max_julong;
       
   136   }
       
   137 
       
   138   void clear_cached_stack_trace() {
       
   139     _stack_trace_id = max_julong;
       
   140     _stack_trace_hash = 0;
       
   141   }
       
   142 
       
   143   traceid cached_stack_trace_id() const {
       
   144     return _stack_trace_id;
       
   145   }
       
   146 
       
   147   unsigned int cached_stack_trace_hash() const {
       
   148     return _stack_trace_hash;
       
   149   }
       
   150 
       
   151   void set_trace_block() {
       
   152     _entering_suspend_flag = 1;
       
   153   }
       
   154 
       
   155   void clear_trace_block() {
       
   156     _entering_suspend_flag = 0;
       
   157   }
       
   158 
       
   159   bool is_trace_block() const {
       
   160     return _entering_suspend_flag != 0;
       
   161   }
       
   162 
       
   163   u8 data_lost() const {
       
   164     return _data_lost;
       
   165   }
       
   166 
       
   167   u8 add_data_lost(u8 value);
       
   168 
       
   169   jlong get_user_time() const {
       
   170     return _user_time;
       
   171   }
       
   172 
       
   173   void set_user_time(jlong user_time) {
       
   174     _user_time = user_time;
       
   175   }
       
   176 
       
   177   jlong get_cpu_time() const {
       
   178     return _cpu_time;
       
   179   }
       
   180 
       
   181   void set_cpu_time(jlong cpu_time) {
       
   182     _cpu_time = cpu_time;
       
   183   }
       
   184 
       
   185   jlong get_wallclock_time() const {
       
   186     return _wallclock_time;
       
   187   }
       
   188 
       
   189   void set_wallclock_time(jlong wallclock_time) {
       
   190     _wallclock_time = wallclock_time;
       
   191   }
       
   192 
       
   193   traceid trace_id() const {
       
   194     return _trace_id;
       
   195   }
       
   196 
       
   197   traceid* const trace_id_addr() const {
       
   198     return &_trace_id;
       
   199   }
       
   200 
       
   201   void set_trace_id(traceid id) const {
       
   202     _trace_id = id;
       
   203   }
       
   204 
       
   205   bool has_thread_checkpoint() const;
       
   206   void set_thread_checkpoint(const JfrCheckpointBlobHandle& handle);
       
   207   const JfrCheckpointBlobHandle& thread_checkpoint() const;
       
   208 
       
   209   static JfrBuffer* acquire(Thread* t, size_t size = 0);
       
   210   static void release(JfrBuffer* buffer, Thread* t);
       
   211   static void destroy_stackframes(Thread* t);
       
   212   static void on_exit(JavaThread* t);
       
   213   static void on_destruct(Thread* t);
       
   214 
       
   215   // Code generation
       
   216   static ByteSize trace_id_offset() {
       
   217     return in_ByteSize(offset_of(JfrThreadLocal, _trace_id));
       
   218   }
       
   219 
       
   220   static ByteSize java_event_writer_offset() {
       
   221     return in_ByteSize(offset_of(JfrThreadLocal, _java_event_writer));
       
   222   }
       
   223 };
       
   224 
       
   225 #endif // SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP