Path: blob/master/src/hotspot/share/jfr/support/jfrThreadLocal.hpp
41149 views
/*1* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_JFR_SUPPORT_JFRTHREADLOCAL_HPP25#define SHARE_JFR_SUPPORT_JFRTHREADLOCAL_HPP2627#include "jfr/utilities/jfrBlob.hpp"28#include "jfr/utilities/jfrTypes.hpp"2930class JavaThread;31class JfrBuffer;32class JfrStackFrame;33class Thread;3435class JfrThreadLocal {36private:37jobject _java_event_writer;38mutable JfrBuffer* _java_buffer;39mutable JfrBuffer* _native_buffer;40JfrBuffer* _shelved_buffer;41JfrBuffer* _load_barrier_buffer_epoch_0;42JfrBuffer* _load_barrier_buffer_epoch_1;43mutable JfrStackFrame* _stackframes;44mutable traceid _trace_id;45JfrBlobHandle _thread;46u8 _data_lost;47traceid _stack_trace_id;48jlong _user_time;49jlong _cpu_time;50jlong _wallclock_time;51unsigned int _stack_trace_hash;52mutable u4 _stackdepth;53volatile jint _entering_suspend_flag;54bool _excluded;55bool _dead;56traceid _parent_trace_id;5758JfrBuffer* install_native_buffer() const;59JfrBuffer* install_java_buffer() const;60JfrStackFrame* install_stackframes() const;61void release(Thread* t);62static void release(JfrThreadLocal* tl, Thread* t);6364public:65JfrThreadLocal();6667JfrBuffer* native_buffer() const {68return _native_buffer != NULL ? _native_buffer : install_native_buffer();69}7071bool has_native_buffer() const {72return _native_buffer != NULL;73}7475void set_native_buffer(JfrBuffer* buffer) {76_native_buffer = buffer;77}7879JfrBuffer* java_buffer() const {80return _java_buffer != NULL ? _java_buffer : install_java_buffer();81}8283bool has_java_buffer() const {84return _java_buffer != NULL;85}8687void set_java_buffer(JfrBuffer* buffer) {88_java_buffer = buffer;89}9091JfrBuffer* shelved_buffer() const {92return _shelved_buffer;93}9495void shelve_buffer(JfrBuffer* buffer) {96_shelved_buffer = buffer;97}9899bool has_java_event_writer() const {100return _java_event_writer != NULL;101}102103jobject java_event_writer() {104return _java_event_writer;105}106107void set_java_event_writer(jobject java_event_writer) {108_java_event_writer = java_event_writer;109}110111JfrStackFrame* stackframes() const {112return _stackframes != NULL ? _stackframes : install_stackframes();113}114115void set_stackframes(JfrStackFrame* frames) {116_stackframes = frames;117}118119u4 stackdepth() const;120121void set_stackdepth(u4 depth) {122_stackdepth = depth;123}124125traceid thread_id() const {126return _trace_id;127}128129void set_thread_id(traceid thread_id) {130_trace_id = thread_id;131}132133traceid parent_thread_id() const {134return _parent_trace_id;135}136137void set_cached_stack_trace_id(traceid id, unsigned int hash = 0) {138_stack_trace_id = id;139_stack_trace_hash = hash;140}141142bool has_cached_stack_trace() const {143return _stack_trace_id != max_julong;144}145146void clear_cached_stack_trace() {147_stack_trace_id = max_julong;148_stack_trace_hash = 0;149}150151traceid cached_stack_trace_id() const {152return _stack_trace_id;153}154155unsigned int cached_stack_trace_hash() const {156return _stack_trace_hash;157}158159void set_trace_block() {160_entering_suspend_flag = 1;161}162163void clear_trace_block() {164_entering_suspend_flag = 0;165}166167bool is_trace_block() const {168return _entering_suspend_flag != 0;169}170171u8 data_lost() const {172return _data_lost;173}174175u8 add_data_lost(u8 value);176177jlong get_user_time() const {178return _user_time;179}180181void set_user_time(jlong user_time) {182_user_time = user_time;183}184185jlong get_cpu_time() const {186return _cpu_time;187}188189void set_cpu_time(jlong cpu_time) {190_cpu_time = cpu_time;191}192193jlong get_wallclock_time() const {194return _wallclock_time;195}196197void set_wallclock_time(jlong wallclock_time) {198_wallclock_time = wallclock_time;199}200201traceid trace_id() const {202return _trace_id;203}204205traceid* const trace_id_addr() const {206return &_trace_id;207}208209void set_trace_id(traceid id) const {210_trace_id = id;211}212213bool is_excluded() const {214return _excluded;215}216217bool is_dead() const {218return _dead;219}220221bool has_thread_blob() const;222void set_thread_blob(const JfrBlobHandle& handle);223const JfrBlobHandle& thread_blob() const;224225static void exclude(Thread* t);226static void include(Thread* t);227228static void on_start(Thread* t);229static void on_exit(Thread* t);230231// Code generation232static ByteSize trace_id_offset();233static ByteSize java_event_writer_offset();234235template <typename>236friend class JfrEpochQueueKlassPolicy;237};238239#endif // SHARE_JFR_SUPPORT_JFRTHREADLOCAL_HPP240241242