diff -r 13588c901957 -r 9cf78a70fa4f src/hotspot/share/jfr/recorder/stacktrace/jfrStackTraceRepository.hpp --- a/src/hotspot/share/jfr/recorder/stacktrace/jfrStackTraceRepository.hpp Thu Oct 17 20:27:44 2019 +0100 +++ b/src/hotspot/share/jfr/recorder/stacktrace/jfrStackTraceRepository.hpp Thu Oct 17 20:53:35 2019 +0100 @@ -25,129 +25,49 @@ #ifndef SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP #define SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP +#include "jfr/recorder/stacktrace/jfrStackTrace.hpp" #include "jfr/utilities/jfrAllocation.hpp" #include "jfr/utilities/jfrTypes.hpp" -class frame; class JavaThread; class JfrCheckpointWriter; class JfrChunkWriter; -class Method; - -class JfrStackFrame { - private: - const Method* _method; - traceid _methodid; - int _line; - int _bci; - u1 _type; - - public: - enum { - FRAME_INTERPRETER = 0, - FRAME_JIT, - FRAME_INLINE, - FRAME_NATIVE, - NUM_FRAME_TYPES - }; - - JfrStackFrame(const traceid& id, int bci, int type, const Method* method) : - _method(method), _methodid(id), _line(0), _bci(bci), _type(type) {} - JfrStackFrame(const traceid& id, int bci, int type, int lineno) : - _method(NULL), _methodid(id), _line(lineno), _bci(bci), _type(type) {} - bool equals(const JfrStackFrame& rhs) const; - void write(JfrChunkWriter& cw) const; - void write(JfrCheckpointWriter& cpw) const; - void resolve_lineno(); -}; - -class JfrStackTrace : public StackObj { - friend class JfrStackTraceRepository; - private: - JfrStackFrame* _frames; - traceid _id; - u4 _nr_of_frames; - unsigned int _hash; - const u4 _max_frames; - bool _reached_root; - bool _lineno; - - public: - JfrStackTrace(JfrStackFrame* frames, u4 max_frames) : _frames(frames), - _id(0), - _nr_of_frames(0), - _hash(0), - _max_frames(max_frames), - _reached_root(false), - _lineno(false) {} - bool record_thread(JavaThread& thread, frame& frame); - bool record_safe(JavaThread* thread, int skip, bool leakp = false); - void resolve_linenos(); - void set_nr_of_frames(u4 nr_of_frames) { _nr_of_frames = nr_of_frames; } - void set_hash(unsigned int hash) { _hash = hash; } - void set_frame(u4 frame_pos, JfrStackFrame& frame); - void set_reached_root(bool reached_root) { _reached_root = reached_root; } - bool full_stacktrace() const { return _reached_root; } - bool have_lineno() const { return _lineno; } -}; class JfrStackTraceRepository : public JfrCHeapObj { friend class JfrRecorder; friend class JfrRecorderService; + friend class JfrThreadSampleClosure; + friend class ObjectSampleCheckpoint; friend class ObjectSampler; - friend class WriteObjectSampleStacktrace; - - class StackTrace : public JfrCHeapObj { - friend class JfrStackTrace; - friend class JfrStackTraceRepository; - private: - StackTrace* _next; - JfrStackFrame* _frames; - const traceid _id; - u4 _nr_of_frames; - unsigned int _hash; - bool _reached_root; - mutable bool _written; - - unsigned int hash() const { return _hash; } - bool should_write() const { return !_written; } - - public: - StackTrace(traceid id, const JfrStackTrace& trace, StackTrace* next); - ~StackTrace(); - traceid id() const { return _id; } - StackTrace* next() const { return _next; } - void write(JfrChunkWriter& cw) const; - void write(JfrCheckpointWriter& cpw) const; - bool equals(const JfrStackTrace& rhs) const; - }; + friend class StackTraceBlobInstaller; + friend class WriteStackTraceRepository; private: static const u4 TABLE_SIZE = 2053; - StackTrace* _table[TABLE_SIZE]; + JfrStackTrace* _table[TABLE_SIZE]; traceid _next_id; u4 _entries; - size_t write_impl(JfrChunkWriter& cw, bool clear); - traceid record_for(JavaThread* thread, int skip, JfrStackFrame* frames, u4 max_frames); - traceid record_for(JavaThread* thread, int skip, JfrStackFrame* frames, u4 max_frames, unsigned int* hash); - traceid add_trace(const JfrStackTrace& stacktrace); - const StackTrace* resolve_entry(unsigned int hash, traceid id) const; - - static void write_metadata(JfrCheckpointWriter& cpw); - JfrStackTraceRepository(); static JfrStackTraceRepository& instance(); - public: static JfrStackTraceRepository* create(); bool initialize(); static void destroy(); - static traceid add(const JfrStackTrace& stacktrace); - static traceid record(Thread* thread, int skip = 0); - static traceid record(Thread* thread, int skip, unsigned int* hash); + + size_t write_impl(JfrChunkWriter& cw, bool clear); + static void write_metadata(JfrCheckpointWriter& cpw); traceid write(JfrCheckpointWriter& cpw, traceid id, unsigned int hash); size_t write(JfrChunkWriter& cw, bool clear); size_t clear(); + + traceid add_trace(const JfrStackTrace& stacktrace); + static traceid add(const JfrStackTrace& stacktrace); + traceid record_for(JavaThread* thread, int skip, JfrStackFrame* frames, u4 max_frames); + const JfrStackTrace* lookup(unsigned int hash, traceid id) const; + + public: + static traceid record(Thread* thread, int skip = 0); + static void record_and_cache(JavaThread* thread, int skip = 0); }; #endif // SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP