apetushkov@9858: /* apetushkov@9858: * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. apetushkov@9858: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. apetushkov@9858: * apetushkov@9858: * This code is free software; you can redistribute it and/or modify it apetushkov@9858: * under the terms of the GNU General Public License version 2 only, as apetushkov@9858: * published by the Free Software Foundation. apetushkov@9858: * apetushkov@9858: * This code is distributed in the hope that it will be useful, but WITHOUT apetushkov@9858: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or apetushkov@9858: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License apetushkov@9858: * version 2 for more details (a copy is included in the LICENSE file that apetushkov@9858: * accompanied this code). apetushkov@9858: * apetushkov@9858: * You should have received a copy of the GNU General Public License version apetushkov@9858: * 2 along with this work; if not, write to the Free Software Foundation, apetushkov@9858: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. apetushkov@9858: * apetushkov@9858: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA apetushkov@9858: * or visit www.oracle.com if you need additional information or have any apetushkov@9858: * questions. apetushkov@9858: * apetushkov@9858: */ apetushkov@9858: apetushkov@9858: #ifndef SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP apetushkov@9858: #define SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP apetushkov@9858: apetushkov@9858: #include "jfr/recorder/checkpoint/jfrCheckpointBlob.hpp" apetushkov@9858: #include "jfr/utilities/jfrTypes.hpp" apetushkov@9858: #include "utilities/sizes.hpp" apetushkov@9858: apetushkov@9858: class JavaThread; apetushkov@9858: class JfrBuffer; apetushkov@9858: class JfrStackFrame; apetushkov@9858: apetushkov@9858: class JfrThreadLocal { apetushkov@9858: private: apetushkov@9858: jobject _java_event_writer; apetushkov@9858: mutable JfrBuffer* _java_buffer; apetushkov@9858: mutable JfrBuffer* _native_buffer; apetushkov@9858: JfrBuffer* _shelved_buffer; apetushkov@9858: mutable JfrStackFrame* _stackframes; apetushkov@9858: mutable traceid _trace_id; apetushkov@9858: JfrCheckpointBlobHandle _thread_cp; apetushkov@9858: u8 _data_lost; apetushkov@9858: traceid _stack_trace_id; apetushkov@9858: jlong _user_time; apetushkov@9858: jlong _cpu_time; apetushkov@9858: jlong _wallclock_time; apetushkov@9858: unsigned int _stack_trace_hash; apetushkov@9858: mutable u4 _stackdepth; apetushkov@9858: volatile jint _entering_suspend_flag; apetushkov@9858: bool _dead; apetushkov@9858: apetushkov@9858: JfrBuffer* install_native_buffer() const; apetushkov@9858: JfrBuffer* install_java_buffer() const; apetushkov@9858: JfrStackFrame* install_stackframes() const; apetushkov@9858: apetushkov@9858: void set_dead(); apetushkov@9858: apetushkov@9858: public: apetushkov@9858: JfrThreadLocal(); apetushkov@9858: apetushkov@9858: JfrBuffer* native_buffer() const { apetushkov@9858: return _native_buffer != NULL ? _native_buffer : install_native_buffer(); apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool has_native_buffer() const { apetushkov@9858: return _native_buffer != NULL; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_native_buffer(JfrBuffer* buffer) { apetushkov@9858: _native_buffer = buffer; apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrBuffer* java_buffer() const { apetushkov@9858: return _java_buffer != NULL ? _java_buffer : install_java_buffer(); apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool has_java_buffer() const { apetushkov@9858: return _java_buffer != NULL; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_java_buffer(JfrBuffer* buffer) { apetushkov@9858: _java_buffer = buffer; apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrBuffer* shelved_buffer() const { apetushkov@9858: return _shelved_buffer; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void shelve_buffer(JfrBuffer* buffer) { apetushkov@9858: _shelved_buffer = buffer; apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool has_java_event_writer() const { apetushkov@9858: return _java_event_writer != NULL; apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject java_event_writer() { apetushkov@9858: return _java_event_writer; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_java_event_writer(jobject java_event_writer) { apetushkov@9858: _java_event_writer = java_event_writer; apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrStackFrame* stackframes() const { apetushkov@9858: return _stackframes != NULL ? _stackframes : install_stackframes(); apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_stackframes(JfrStackFrame* frames) { apetushkov@9858: _stackframes = frames; apetushkov@9858: } apetushkov@9858: apetushkov@9858: u4 stackdepth() const { apetushkov@9858: return _stackdepth; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_stackdepth(u4 depth) { apetushkov@9858: _stackdepth = depth; apetushkov@9858: } apetushkov@9858: apetushkov@9858: traceid thread_id() const { apetushkov@9858: return _trace_id; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_thread_id(traceid thread_id) { apetushkov@9858: _trace_id = thread_id; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_cached_stack_trace_id(traceid id, unsigned int hash = 0) { apetushkov@9858: _stack_trace_id = id; apetushkov@9858: _stack_trace_hash = hash; apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool has_cached_stack_trace() const { apetushkov@9858: return _stack_trace_id != max_julong; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void clear_cached_stack_trace() { apetushkov@9858: _stack_trace_id = max_julong; apetushkov@9858: _stack_trace_hash = 0; apetushkov@9858: } apetushkov@9858: apetushkov@9858: traceid cached_stack_trace_id() const { apetushkov@9858: return _stack_trace_id; apetushkov@9858: } apetushkov@9858: apetushkov@9858: unsigned int cached_stack_trace_hash() const { apetushkov@9858: return _stack_trace_hash; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_trace_block() { apetushkov@9858: _entering_suspend_flag = 1; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void clear_trace_block() { apetushkov@9858: _entering_suspend_flag = 0; apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool is_trace_block() const { apetushkov@9858: return _entering_suspend_flag != 0; apetushkov@9858: } apetushkov@9858: apetushkov@9858: u8 data_lost() const { apetushkov@9858: return _data_lost; apetushkov@9858: } apetushkov@9858: apetushkov@9858: u8 add_data_lost(u8 value); apetushkov@9858: apetushkov@9858: jlong get_user_time() const { apetushkov@9858: return _user_time; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_user_time(jlong user_time) { apetushkov@9858: _user_time = user_time; apetushkov@9858: } apetushkov@9858: apetushkov@9858: jlong get_cpu_time() const { apetushkov@9858: return _cpu_time; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_cpu_time(jlong cpu_time) { apetushkov@9858: _cpu_time = cpu_time; apetushkov@9858: } apetushkov@9858: apetushkov@9858: jlong get_wallclock_time() const { apetushkov@9858: return _wallclock_time; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_wallclock_time(jlong wallclock_time) { apetushkov@9858: _wallclock_time = wallclock_time; apetushkov@9858: } apetushkov@9858: apetushkov@9858: traceid trace_id() const { apetushkov@9858: return _trace_id; apetushkov@9858: } apetushkov@9858: apetushkov@9858: traceid* const trace_id_addr() const { apetushkov@9858: return &_trace_id; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void set_trace_id(traceid id) const { apetushkov@9858: _trace_id = id; apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool is_dead() const { apetushkov@9858: return _dead; apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool has_thread_checkpoint() const; apetushkov@9858: void set_thread_checkpoint(const JfrCheckpointBlobHandle& handle); apetushkov@9858: const JfrCheckpointBlobHandle& thread_checkpoint() const; apetushkov@9858: apetushkov@9858: static JfrBuffer* acquire(Thread* t, size_t size = 0); apetushkov@9858: static void release(JfrBuffer* buffer, Thread* t); apetushkov@9858: static void destroy_stackframes(Thread* t); apetushkov@9858: static void on_exit(JavaThread* t); apetushkov@9858: static void on_destruct(Thread* t); apetushkov@9858: apetushkov@9858: // Code generation apetushkov@9858: static ByteSize trace_id_offset() { apetushkov@9858: return in_ByteSize(offset_of(JfrThreadLocal, _trace_id)); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static ByteSize java_event_writer_offset() { apetushkov@9858: return in_ByteSize(offset_of(JfrThreadLocal, _java_event_writer)); apetushkov@9858: } apetushkov@9858: }; apetushkov@9858: apetushkov@9858: #endif // SHARE_VM_JFR_SUPPORT_JFRTHREADLOCAL_HPP