src/hotspot/share/jfr/recorder/stacktrace/jfrStackTraceRepository.hpp
changeset 58132 caa25ab47aca
parent 55571 49102ba8cf14
child 58157 9dca61a7df19
child 58679 9c3209ff7550
child 58863 c16ac7a2eba4
equal deleted inserted replaced
58131:3054503bad7d 58132:caa25ab47aca
    23  */
    23  */
    24 
    24 
    25 #ifndef SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP
    25 #ifndef SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP
    26 #define SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP
    26 #define SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP
    27 
    27 
       
    28 #include "jfr/recorder/stacktrace/jfrStackTrace.hpp"
    28 #include "jfr/utilities/jfrAllocation.hpp"
    29 #include "jfr/utilities/jfrAllocation.hpp"
    29 #include "jfr/utilities/jfrTypes.hpp"
    30 #include "jfr/utilities/jfrTypes.hpp"
    30 
    31 
    31 class frame;
       
    32 class JavaThread;
    32 class JavaThread;
    33 class JfrCheckpointWriter;
    33 class JfrCheckpointWriter;
    34 class JfrChunkWriter;
    34 class JfrChunkWriter;
    35 class Method;
       
    36 
       
    37 class JfrStackFrame {
       
    38  private:
       
    39   mutable const Method* _method;
       
    40   traceid _methodid;
       
    41   mutable int _line;
       
    42   int _bci;
       
    43   u1 _type;
       
    44 
       
    45  public:
       
    46   enum {
       
    47     FRAME_INTERPRETER = 0,
       
    48     FRAME_JIT,
       
    49     FRAME_INLINE,
       
    50     FRAME_NATIVE,
       
    51     NUM_FRAME_TYPES
       
    52   };
       
    53 
       
    54   JfrStackFrame(const traceid& id, int bci, int type, const Method* method) :
       
    55     _method(method), _methodid(id), _line(0), _bci(bci), _type(type) {}
       
    56   JfrStackFrame(const traceid& id, int bci, int type, int lineno) :
       
    57     _method(NULL), _methodid(id), _line(lineno), _bci(bci), _type(type) {}
       
    58   bool equals(const JfrStackFrame& rhs) const;
       
    59   void write(JfrChunkWriter& cw) const;
       
    60   void write(JfrCheckpointWriter& cpw) const;
       
    61   void resolve_lineno() const;
       
    62 };
       
    63 
       
    64 class JfrStackTrace : public StackObj {
       
    65   friend class JfrStackTraceRepository;
       
    66  private:
       
    67   JfrStackFrame* _frames;
       
    68   traceid _id;
       
    69   u4 _nr_of_frames;
       
    70   unsigned int _hash;
       
    71   const u4 _max_frames;
       
    72   bool _reached_root;
       
    73   mutable bool _lineno;
       
    74 
       
    75  public:
       
    76   JfrStackTrace(JfrStackFrame* frames, u4 max_frames) : _frames(frames),
       
    77                                                         _id(0),
       
    78                                                         _nr_of_frames(0),
       
    79                                                         _hash(0),
       
    80                                                         _max_frames(max_frames),
       
    81                                                         _reached_root(false),
       
    82                                                         _lineno(false) {}
       
    83   bool record_thread(JavaThread& thread, frame& frame);
       
    84   bool record_safe(JavaThread* thread, int skip, bool leakp = false);
       
    85   void resolve_linenos() const;
       
    86   void set_nr_of_frames(u4 nr_of_frames) { _nr_of_frames = nr_of_frames; }
       
    87   void set_hash(unsigned int hash) { _hash = hash; }
       
    88   unsigned int hash() const { return _hash; }
       
    89   void set_frame(u4 frame_pos, JfrStackFrame& frame);
       
    90   void set_reached_root(bool reached_root) { _reached_root = reached_root; }
       
    91   bool full_stacktrace() const { return _reached_root; }
       
    92   bool have_lineno() const { return _lineno; }
       
    93 };
       
    94 
    35 
    95 class JfrStackTraceRepository : public JfrCHeapObj {
    36 class JfrStackTraceRepository : public JfrCHeapObj {
    96   friend class JfrRecorder;
    37   friend class JfrRecorder;
    97   friend class JfrRecorderService;
    38   friend class JfrRecorderService;
       
    39   friend class JfrThreadSampleClosure;
       
    40   friend class ObjectSampleCheckpoint;
    98   friend class ObjectSampler;
    41   friend class ObjectSampler;
    99   friend class WriteObjectSampleStacktrace;
    42   friend class StackTraceBlobInstaller;
   100 
    43   friend class WriteStackTraceRepository;
   101   class StackTrace : public JfrCHeapObj {
       
   102     friend class JfrStackTrace;
       
   103     friend class JfrStackTraceRepository;
       
   104    private:
       
   105     StackTrace* _next;
       
   106     JfrStackFrame* _frames;
       
   107     const traceid _id;
       
   108     u4 _nr_of_frames;
       
   109     unsigned int _hash;
       
   110     bool _reached_root;
       
   111     mutable bool _written;
       
   112 
       
   113     unsigned int hash() const { return _hash; }
       
   114     bool should_write() const { return !_written; }
       
   115 
       
   116    public:
       
   117     StackTrace(traceid id, const JfrStackTrace& trace, StackTrace* next);
       
   118     ~StackTrace();
       
   119     traceid id() const { return _id; }
       
   120     StackTrace* next() const { return _next; }
       
   121     void write(JfrChunkWriter& cw) const;
       
   122     void write(JfrCheckpointWriter& cpw) const;
       
   123     bool equals(const JfrStackTrace& rhs) const;
       
   124   };
       
   125 
    44 
   126  private:
    45  private:
   127   static const u4 TABLE_SIZE = 2053;
    46   static const u4 TABLE_SIZE = 2053;
   128   StackTrace* _table[TABLE_SIZE];
    47   JfrStackTrace* _table[TABLE_SIZE];
   129   traceid _next_id;
    48   traceid _next_id;
   130   u4 _entries;
    49   u4 _entries;
   131 
    50 
   132   traceid add_trace(const JfrStackTrace& stacktrace);
       
   133   static traceid add(const JfrStackTrace* stacktrace, JavaThread* thread);
       
   134   traceid record_for(JavaThread* thread, int skip, JfrStackFrame* frames, u4 max_frames);
       
   135 
       
   136   size_t write_impl(JfrChunkWriter& cw, bool clear);
       
   137   const StackTrace* resolve_entry(unsigned int hash, traceid id) const;
       
   138   static void write_metadata(JfrCheckpointWriter& cpw);
       
   139 
       
   140   static bool fill_stacktrace_for(JavaThread* thread, JfrStackTrace* stacktrace, int skip);
       
   141 
       
   142   JfrStackTraceRepository();
    51   JfrStackTraceRepository();
       
    52   static JfrStackTraceRepository& instance();
   143   static JfrStackTraceRepository* create();
    53   static JfrStackTraceRepository* create();
   144   bool initialize();
    54   bool initialize();
   145   static void destroy();
    55   static void destroy();
   146 
    56 
   147   static JfrStackTraceRepository& instance();
    57   size_t write_impl(JfrChunkWriter& cw, bool clear);
   148 
    58   static void write_metadata(JfrCheckpointWriter& cpw);
   149  public:
       
   150   static traceid add(const JfrStackTrace& stacktrace);
       
   151   static traceid record(Thread* thread, int skip = 0);
       
   152   traceid write(JfrCheckpointWriter& cpw, traceid id, unsigned int hash);
    59   traceid write(JfrCheckpointWriter& cpw, traceid id, unsigned int hash);
   153   size_t write(JfrChunkWriter& cw, bool clear);
    60   size_t write(JfrChunkWriter& cw, bool clear);
   154   size_t clear();
    61   size_t clear();
       
    62 
       
    63   traceid add_trace(const JfrStackTrace& stacktrace);
       
    64   static traceid add(const JfrStackTrace& stacktrace);
       
    65   traceid record_for(JavaThread* thread, int skip, JfrStackFrame* frames, u4 max_frames);
       
    66   const JfrStackTrace* lookup(unsigned int hash, traceid id) const;
       
    67 
       
    68  public:
       
    69   static traceid record(Thread* thread, int skip = 0);
       
    70   static void record_and_cache(JavaThread* thread, int skip = 0);
   155 };
    71 };
   156 
    72 
   157 #endif // SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP
    73 #endif // SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP