src/share/vm/jfr/support/jfrThreadLocal.hpp

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 9858
b985cbb00e68
child 9868
69fb91513217
permissions
-rw-r--r--

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

     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  */
    25 #ifndef SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP
    26 #define SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP
    28 #include "jfr/recorder/checkpoint/jfrCheckpointBlob.hpp"
    29 #include "jfr/utilities/jfrTypes.hpp"
    30 #include "utilities/sizes.hpp"
    32 class JavaThread;
    33 class JfrBuffer;
    34 class JfrStackFrame;
    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   bool _dead;
    55   JfrBuffer* install_native_buffer() const;
    56   JfrBuffer* install_java_buffer() const;
    57   JfrStackFrame* install_stackframes() const;
    59   void set_dead();
    61  public:
    62   JfrThreadLocal();
    64   JfrBuffer* native_buffer() const {
    65     return _native_buffer != NULL ? _native_buffer : install_native_buffer();
    66   }
    68   bool has_native_buffer() const {
    69     return _native_buffer != NULL;
    70   }
    72   void set_native_buffer(JfrBuffer* buffer) {
    73     _native_buffer = buffer;
    74   }
    76   JfrBuffer* java_buffer() const {
    77     return _java_buffer != NULL ? _java_buffer : install_java_buffer();
    78   }
    80   bool has_java_buffer() const {
    81     return _java_buffer != NULL;
    82   }
    84   void set_java_buffer(JfrBuffer* buffer) {
    85     _java_buffer = buffer;
    86   }
    88   JfrBuffer* shelved_buffer() const {
    89     return _shelved_buffer;
    90   }
    92   void shelve_buffer(JfrBuffer* buffer) {
    93     _shelved_buffer = buffer;
    94   }
    96   bool has_java_event_writer() const {
    97     return _java_event_writer != NULL;
    98   }
   100   jobject java_event_writer() {
   101     return _java_event_writer;
   102   }
   104   void set_java_event_writer(jobject java_event_writer) {
   105     _java_event_writer = java_event_writer;
   106   }
   108   JfrStackFrame* stackframes() const {
   109     return _stackframes != NULL ? _stackframes : install_stackframes();
   110   }
   112   void set_stackframes(JfrStackFrame* frames) {
   113     _stackframes = frames;
   114   }
   116   u4 stackdepth() const {
   117     return _stackdepth;
   118   }
   120   void set_stackdepth(u4 depth) {
   121     _stackdepth = depth;
   122   }
   124   traceid thread_id() const {
   125     return _trace_id;
   126   }
   128   void set_thread_id(traceid thread_id) {
   129     _trace_id = thread_id;
   130   }
   132   void set_cached_stack_trace_id(traceid id, unsigned int hash = 0) {
   133     _stack_trace_id = id;
   134     _stack_trace_hash = hash;
   135   }
   137   bool has_cached_stack_trace() const {
   138     return _stack_trace_id != max_julong;
   139   }
   141   void clear_cached_stack_trace() {
   142     _stack_trace_id = max_julong;
   143     _stack_trace_hash = 0;
   144   }
   146   traceid cached_stack_trace_id() const {
   147     return _stack_trace_id;
   148   }
   150   unsigned int cached_stack_trace_hash() const {
   151     return _stack_trace_hash;
   152   }
   154   void set_trace_block() {
   155     _entering_suspend_flag = 1;
   156   }
   158   void clear_trace_block() {
   159     _entering_suspend_flag = 0;
   160   }
   162   bool is_trace_block() const {
   163     return _entering_suspend_flag != 0;
   164   }
   166   u8 data_lost() const {
   167     return _data_lost;
   168   }
   170   u8 add_data_lost(u8 value);
   172   jlong get_user_time() const {
   173     return _user_time;
   174   }
   176   void set_user_time(jlong user_time) {
   177     _user_time = user_time;
   178   }
   180   jlong get_cpu_time() const {
   181     return _cpu_time;
   182   }
   184   void set_cpu_time(jlong cpu_time) {
   185     _cpu_time = cpu_time;
   186   }
   188   jlong get_wallclock_time() const {
   189     return _wallclock_time;
   190   }
   192   void set_wallclock_time(jlong wallclock_time) {
   193     _wallclock_time = wallclock_time;
   194   }
   196   traceid trace_id() const {
   197     return _trace_id;
   198   }
   200   traceid* const trace_id_addr() const {
   201     return &_trace_id;
   202   }
   204   void set_trace_id(traceid id) const {
   205     _trace_id = id;
   206   }
   208   bool is_dead() const {
   209     return _dead;
   210   }
   212   bool has_thread_checkpoint() const;
   213   void set_thread_checkpoint(const JfrCheckpointBlobHandle& handle);
   214   const JfrCheckpointBlobHandle& thread_checkpoint() const;
   216   static JfrBuffer* acquire(Thread* t, size_t size = 0);
   217   static void release(JfrBuffer* buffer, Thread* t);
   218   static void destroy_stackframes(Thread* t);
   219   static void on_exit(JavaThread* t);
   220   static void on_destruct(Thread* t);
   222   // Code generation
   223   static ByteSize trace_id_offset() {
   224     return in_ByteSize(offset_of(JfrThreadLocal, _trace_id));
   225   }
   227   static ByteSize java_event_writer_offset() {
   228     return in_ByteSize(offset_of(JfrThreadLocal, _java_event_writer));
   229   }
   230 };
   232 #endif // SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP

mercurial