1 /*
2 * Copyright (c) 2011, 2025, 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 */
24
25 #ifndef SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACE_HPP
26 #define SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACE_HPP
27
28 #include "jfr/recorder/stacktrace/jfrStackFrame.hpp"
29 #include "jfr/utilities/jfrAllocation.hpp"
30 #include "jfr/utilities/jfrTypes.hpp"
31
32 class frame;
33 class InstanceKlass;
34 class JavaThread;
35 class JfrCheckpointWriter;
36 class JfrChunkWriter;
37 struct JfrSampleRequest;
38
39 class JfrStackTrace : public JfrCHeapObj {
40 friend class JfrNativeSamplerCallback;
41 friend class JfrStackTraceRepository;
42 friend class LeakProfilerStackTraceWriter;
43 friend class JfrThreadSampling;
44 friend class ObjectSampleCheckpoint;
45 friend class ObjectSampler;
46 friend class StackTraceResolver;
47 private:
48 const JfrStackTrace* _next;
49 JfrStackFrames* _frames;
50 traceid _id;
51 traceid _hash;
52 u4 _count;
53 u4 _max_frames;
54 bool _frames_ownership;
55 bool _reached_root;
56 mutable bool _lineno;
57 mutable bool _written;
58
59 const JfrStackTrace* next() const { return _next; }
60
61 void write(JfrChunkWriter& cw) const;
62 void write(JfrCheckpointWriter& cpw) const;
63 bool equals(const JfrStackTrace& rhs) const;
64
65 void set_id(traceid id) { _id = id; }
66 void set_hash(unsigned int hash) { _hash = hash; }
67 void set_reached_root(bool reached_root) { _reached_root = reached_root; }
68 void resolve_linenos() const;
69
70 int number_of_frames() const;
71 bool have_lineno() const { return _lineno; }
72 bool full_stacktrace() const { return _reached_root; }
73 bool record_inner(JavaThread* jt, const frame& frame, bool in_continuation, int skip, int64_t stack_filter_id = -1);
74 bool record(JavaThread* jt, const frame& frame, bool in_continuation, int skip, int64_t stack_filter_id = -1);
75 void record_interpreter_top_frame(const JfrSampleRequest& request);
76
77 JfrStackTrace(traceid id, const JfrStackTrace& trace, const JfrStackTrace* next);
78
79 public:
80 // ResourceArea allocation, remember ResourceMark.
81 JfrStackTrace();
82 ~JfrStackTrace();
83
84 traceid hash() const { return _hash; }
85 traceid id() const { return _id; }
86
87 bool record(JavaThread* current_thread, int skip, int64_t stack_filter_id);
88 bool record(JavaThread* jt, const frame& frame, bool in_continuation, const JfrSampleRequest& request);
89 bool should_write() const { return !_written; }
90 };
91
92 #endif // SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACE_HPP