1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/jfr/recorder/stacktrace/jfrStackTraceRepository.hpp Mon Aug 12 18:30:40 2019 +0300 1.3 @@ -0,0 +1,154 @@ 1.4 +/* 1.5 + * Copyright (c) 2011, 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_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP 1.29 +#define SHARE_VM_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP 1.30 + 1.31 +#include "jfr/utilities/jfrAllocation.hpp" 1.32 +#include "jfr/utilities/jfrTypes.hpp" 1.33 + 1.34 +class frame; 1.35 +class JavaThread; 1.36 +class JfrCheckpointSystem; 1.37 +class JfrCheckpointWriter; 1.38 +class JfrChunkWriter; 1.39 +class Method; 1.40 + 1.41 +class JfrStackFrame { 1.42 + private: 1.43 + const Method* _method; 1.44 + traceid _methodid; 1.45 + int _line; 1.46 + int _bci; 1.47 + u1 _type; 1.48 + 1.49 + public: 1.50 + enum { 1.51 + FRAME_INTERPRETER = 0, 1.52 + FRAME_JIT, 1.53 + FRAME_INLINE, 1.54 + FRAME_NATIVE, 1.55 + NUM_FRAME_TYPES 1.56 + }; 1.57 + 1.58 + JfrStackFrame(const traceid& id, int bci, int type, const Method* method) : 1.59 + _method(method), _methodid(id), _line(0), _bci(bci), _type(type) {} 1.60 + JfrStackFrame(const traceid& id, int bci, int type, int lineno) : 1.61 + _method(NULL), _methodid(id), _line(0), _bci(bci), _type(type) {} 1.62 + bool equals(const JfrStackFrame& rhs) const; 1.63 + void write(JfrChunkWriter& cw) const; 1.64 + void write(JfrCheckpointWriter& cpw) const; 1.65 + void resolve_lineno(); 1.66 +}; 1.67 + 1.68 +class JfrStackTrace : public StackObj { 1.69 + friend class JfrStackTraceRepository; 1.70 + private: 1.71 + JfrStackFrame* _frames; 1.72 + traceid _id; 1.73 + u4 _nr_of_frames; 1.74 + unsigned int _hash; 1.75 + const u4 _max_frames; 1.76 + bool _reached_root; 1.77 + bool _lineno; 1.78 + 1.79 + public: 1.80 + JfrStackTrace(JfrStackFrame* frames, u4 max_frames) : _frames(frames), 1.81 + _id(0), 1.82 + _nr_of_frames(0), 1.83 + _hash(0), 1.84 + _reached_root(false), 1.85 + _max_frames(max_frames), 1.86 + _lineno(false) {} 1.87 + bool record_thread(JavaThread& thread, frame& frame); 1.88 + bool record_safe(JavaThread* thread, int skip, bool leakp = false); 1.89 + void resolve_linenos(); 1.90 + void set_nr_of_frames(u4 nr_of_frames) { _nr_of_frames = nr_of_frames; } 1.91 + void set_hash(unsigned int hash) { _hash = hash; } 1.92 + void set_frame(u4 frame_pos, JfrStackFrame& frame); 1.93 + void set_reached_root(bool reached_root) { _reached_root = reached_root; } 1.94 + bool full_stacktrace() const { return _reached_root; } 1.95 + bool have_lineno() const { return _lineno; } 1.96 +}; 1.97 + 1.98 +class JfrStackTraceRepository : public JfrCHeapObj { 1.99 + friend class JfrRecorder; 1.100 + friend class JfrRecorderService; 1.101 + friend class ObjectSampler; 1.102 + friend class WriteObjectSampleStacktrace; 1.103 + 1.104 + class StackTrace : public JfrCHeapObj { 1.105 + friend class JfrStackTrace; 1.106 + friend class JfrStackTraceRepository; 1.107 + private: 1.108 + StackTrace* _next; 1.109 + JfrStackFrame* _frames; 1.110 + const traceid _id; 1.111 + u4 _nr_of_frames; 1.112 + unsigned int _hash; 1.113 + bool _reached_root; 1.114 + mutable bool _written; 1.115 + 1.116 + unsigned int hash() const { return _hash; } 1.117 + bool should_write() const { return !_written; } 1.118 + 1.119 + public: 1.120 + StackTrace(traceid id, const JfrStackTrace& trace, StackTrace* next); 1.121 + ~StackTrace(); 1.122 + traceid id() const { return _id; } 1.123 + StackTrace* next() const { return _next; } 1.124 + void write(JfrChunkWriter& cw) const; 1.125 + void write(JfrCheckpointWriter& cpw) const; 1.126 + bool equals(const JfrStackTrace& rhs) const; 1.127 + }; 1.128 + 1.129 + private: 1.130 + static const u4 TABLE_SIZE = 2053; 1.131 + StackTrace* _table[TABLE_SIZE]; 1.132 + traceid _next_id; 1.133 + u4 _entries; 1.134 + 1.135 + size_t write_impl(JfrChunkWriter& cw, bool clear); 1.136 + traceid record_for(JavaThread* thread, int skip, JfrStackFrame* frames, u4 max_frames); 1.137 + traceid record_for(JavaThread* thread, int skip, JfrStackFrame* frames, u4 max_frames, unsigned int* hash); 1.138 + traceid add_trace(const JfrStackTrace& stacktrace); 1.139 + const StackTrace* resolve_entry(unsigned int hash, traceid id) const; 1.140 + 1.141 + static void write_metadata(JfrCheckpointWriter& cpw); 1.142 + 1.143 + JfrStackTraceRepository(); 1.144 + static JfrStackTraceRepository& instance(); 1.145 + public: 1.146 + static JfrStackTraceRepository* create(); 1.147 + bool initialize(); 1.148 + static void destroy(); 1.149 + static traceid add(const JfrStackTrace& stacktrace); 1.150 + static traceid record(Thread* thread, int skip = 0); 1.151 + static traceid record(Thread* thread, int skip, unsigned int* hash); 1.152 + traceid write(JfrCheckpointWriter& cpw, traceid id, unsigned int hash); 1.153 + size_t write(JfrChunkWriter& cw, bool clear); 1.154 + size_t clear(); 1.155 +}; 1.156 + 1.157 +#endif // SHARE_VM_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP