1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/jfr/support/jfrThreadLocal.hpp Mon Aug 12 18:30:40 2019 +0300 1.3 @@ -0,0 +1,232 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP 1.29 +#define SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP 1.30 + 1.31 +#include "jfr/recorder/checkpoint/jfrCheckpointBlob.hpp" 1.32 +#include "jfr/utilities/jfrTypes.hpp" 1.33 +#include "utilities/sizes.hpp" 1.34 + 1.35 +class JavaThread; 1.36 +class JfrBuffer; 1.37 +class JfrStackFrame; 1.38 + 1.39 +class JfrThreadLocal { 1.40 + private: 1.41 + jobject _java_event_writer; 1.42 + mutable JfrBuffer* _java_buffer; 1.43 + mutable JfrBuffer* _native_buffer; 1.44 + JfrBuffer* _shelved_buffer; 1.45 + mutable JfrStackFrame* _stackframes; 1.46 + mutable traceid _trace_id; 1.47 + JfrCheckpointBlobHandle _thread_cp; 1.48 + u8 _data_lost; 1.49 + traceid _stack_trace_id; 1.50 + jlong _user_time; 1.51 + jlong _cpu_time; 1.52 + jlong _wallclock_time; 1.53 + unsigned int _stack_trace_hash; 1.54 + mutable u4 _stackdepth; 1.55 + volatile jint _entering_suspend_flag; 1.56 + bool _dead; 1.57 + 1.58 + JfrBuffer* install_native_buffer() const; 1.59 + JfrBuffer* install_java_buffer() const; 1.60 + JfrStackFrame* install_stackframes() const; 1.61 + 1.62 + void set_dead(); 1.63 + 1.64 + public: 1.65 + JfrThreadLocal(); 1.66 + 1.67 + JfrBuffer* native_buffer() const { 1.68 + return _native_buffer != NULL ? _native_buffer : install_native_buffer(); 1.69 + } 1.70 + 1.71 + bool has_native_buffer() const { 1.72 + return _native_buffer != NULL; 1.73 + } 1.74 + 1.75 + void set_native_buffer(JfrBuffer* buffer) { 1.76 + _native_buffer = buffer; 1.77 + } 1.78 + 1.79 + JfrBuffer* java_buffer() const { 1.80 + return _java_buffer != NULL ? _java_buffer : install_java_buffer(); 1.81 + } 1.82 + 1.83 + bool has_java_buffer() const { 1.84 + return _java_buffer != NULL; 1.85 + } 1.86 + 1.87 + void set_java_buffer(JfrBuffer* buffer) { 1.88 + _java_buffer = buffer; 1.89 + } 1.90 + 1.91 + JfrBuffer* shelved_buffer() const { 1.92 + return _shelved_buffer; 1.93 + } 1.94 + 1.95 + void shelve_buffer(JfrBuffer* buffer) { 1.96 + _shelved_buffer = buffer; 1.97 + } 1.98 + 1.99 + bool has_java_event_writer() const { 1.100 + return _java_event_writer != NULL; 1.101 + } 1.102 + 1.103 + jobject java_event_writer() { 1.104 + return _java_event_writer; 1.105 + } 1.106 + 1.107 + void set_java_event_writer(jobject java_event_writer) { 1.108 + _java_event_writer = java_event_writer; 1.109 + } 1.110 + 1.111 + JfrStackFrame* stackframes() const { 1.112 + return _stackframes != NULL ? _stackframes : install_stackframes(); 1.113 + } 1.114 + 1.115 + void set_stackframes(JfrStackFrame* frames) { 1.116 + _stackframes = frames; 1.117 + } 1.118 + 1.119 + u4 stackdepth() const { 1.120 + return _stackdepth; 1.121 + } 1.122 + 1.123 + void set_stackdepth(u4 depth) { 1.124 + _stackdepth = depth; 1.125 + } 1.126 + 1.127 + traceid thread_id() const { 1.128 + return _trace_id; 1.129 + } 1.130 + 1.131 + void set_thread_id(traceid thread_id) { 1.132 + _trace_id = thread_id; 1.133 + } 1.134 + 1.135 + void set_cached_stack_trace_id(traceid id, unsigned int hash = 0) { 1.136 + _stack_trace_id = id; 1.137 + _stack_trace_hash = hash; 1.138 + } 1.139 + 1.140 + bool has_cached_stack_trace() const { 1.141 + return _stack_trace_id != max_julong; 1.142 + } 1.143 + 1.144 + void clear_cached_stack_trace() { 1.145 + _stack_trace_id = max_julong; 1.146 + _stack_trace_hash = 0; 1.147 + } 1.148 + 1.149 + traceid cached_stack_trace_id() const { 1.150 + return _stack_trace_id; 1.151 + } 1.152 + 1.153 + unsigned int cached_stack_trace_hash() const { 1.154 + return _stack_trace_hash; 1.155 + } 1.156 + 1.157 + void set_trace_block() { 1.158 + _entering_suspend_flag = 1; 1.159 + } 1.160 + 1.161 + void clear_trace_block() { 1.162 + _entering_suspend_flag = 0; 1.163 + } 1.164 + 1.165 + bool is_trace_block() const { 1.166 + return _entering_suspend_flag != 0; 1.167 + } 1.168 + 1.169 + u8 data_lost() const { 1.170 + return _data_lost; 1.171 + } 1.172 + 1.173 + u8 add_data_lost(u8 value); 1.174 + 1.175 + jlong get_user_time() const { 1.176 + return _user_time; 1.177 + } 1.178 + 1.179 + void set_user_time(jlong user_time) { 1.180 + _user_time = user_time; 1.181 + } 1.182 + 1.183 + jlong get_cpu_time() const { 1.184 + return _cpu_time; 1.185 + } 1.186 + 1.187 + void set_cpu_time(jlong cpu_time) { 1.188 + _cpu_time = cpu_time; 1.189 + } 1.190 + 1.191 + jlong get_wallclock_time() const { 1.192 + return _wallclock_time; 1.193 + } 1.194 + 1.195 + void set_wallclock_time(jlong wallclock_time) { 1.196 + _wallclock_time = wallclock_time; 1.197 + } 1.198 + 1.199 + traceid trace_id() const { 1.200 + return _trace_id; 1.201 + } 1.202 + 1.203 + traceid* const trace_id_addr() const { 1.204 + return &_trace_id; 1.205 + } 1.206 + 1.207 + void set_trace_id(traceid id) const { 1.208 + _trace_id = id; 1.209 + } 1.210 + 1.211 + bool is_dead() const { 1.212 + return _dead; 1.213 + } 1.214 + 1.215 + bool has_thread_checkpoint() const; 1.216 + void set_thread_checkpoint(const JfrCheckpointBlobHandle& handle); 1.217 + const JfrCheckpointBlobHandle& thread_checkpoint() const; 1.218 + 1.219 + static JfrBuffer* acquire(Thread* t, size_t size = 0); 1.220 + static void release(JfrBuffer* buffer, Thread* t); 1.221 + static void destroy_stackframes(Thread* t); 1.222 + static void on_exit(JavaThread* t); 1.223 + static void on_destruct(Thread* t); 1.224 + 1.225 + // Code generation 1.226 + static ByteSize trace_id_offset() { 1.227 + return in_ByteSize(offset_of(JfrThreadLocal, _trace_id)); 1.228 + } 1.229 + 1.230 + static ByteSize java_event_writer_offset() { 1.231 + return in_ByteSize(offset_of(JfrThreadLocal, _java_event_writer)); 1.232 + } 1.233 +}; 1.234 + 1.235 +#endif // SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP