src/hotspot/share/jfr/recorder/stacktrace/jfrStackTrace.hpp
branchJEP-349-branch
changeset 57870 00860d9caf4d
child 57934 9c150f2b1fea
equal deleted inserted replaced
57862:84ef29ccac56 57870:00860d9caf4d
       
     1 /*
       
     2  * Copyright (c) 2011, 2019, 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/utilities/jfrAllocation.hpp"
       
    29 #include "jfr/utilities/jfrTypes.hpp"
       
    30 
       
    31 class frame;
       
    32 class InstanceKlass;
       
    33 class JavaThread;
       
    34 class JfrCheckpointWriter;
       
    35 class JfrChunkWriter;
       
    36 class Method;
       
    37 
       
    38 class JfrStackFrame {
       
    39   friend class ObjectSampleCheckpoint;
       
    40  private:
       
    41   mutable InstanceKlass* _klass;
       
    42   traceid _methodid;
       
    43   mutable int _line;
       
    44   int _bci;
       
    45   u1 _type;
       
    46 
       
    47  public:
       
    48   JfrStackFrame(const traceid& id, int bci, int type, InstanceKlass* klass);
       
    49   JfrStackFrame(const traceid& id, int bci, int type, int lineno);
       
    50 
       
    51   bool equals(const JfrStackFrame& rhs) const;
       
    52   void write(JfrChunkWriter& cw) const;
       
    53   void write(JfrCheckpointWriter& cpw) const;
       
    54   void resolve_lineno() const;
       
    55 
       
    56   enum {
       
    57     FRAME_INTERPRETER = 0,
       
    58     FRAME_JIT,
       
    59     FRAME_INLINE,
       
    60     FRAME_NATIVE,
       
    61     NUM_FRAME_TYPES
       
    62   };
       
    63 };
       
    64 
       
    65 class JfrStackTrace : public JfrCHeapObj {
       
    66   friend class JfrNativeSamplerCallback;
       
    67   friend class JfrStackTraceRepository;
       
    68   friend class ObjectSampleCheckpoint;
       
    69   friend class ObjectSampler;
       
    70   friend class OSThreadSampler;
       
    71   friend class ProcessStackTrace;
       
    72   friend class StackTraceInstall;
       
    73   friend class StackTraceWrite;
       
    74 
       
    75  private:
       
    76   const JfrStackTrace* _next;
       
    77   JfrStackFrame* _frames;
       
    78   traceid _id;
       
    79   unsigned int _hash;
       
    80   u4 _nr_of_frames;
       
    81   u4 _max_frames;
       
    82   bool _frames_ownership;
       
    83   bool _reached_root;
       
    84   mutable bool _lineno;
       
    85   mutable bool _written;
       
    86 
       
    87   const JfrStackTrace* next() const { return _next; }
       
    88 
       
    89   bool should_write() const { return !_written; }
       
    90   void write(JfrChunkWriter& cw) const;
       
    91   void write(JfrCheckpointWriter& cpw) const;
       
    92   bool equals(const JfrStackTrace& rhs) const;
       
    93 
       
    94   void set_id(traceid id) { _id = id; }
       
    95   void set_nr_of_frames(u4 nr_of_frames) { _nr_of_frames = nr_of_frames; }
       
    96   void set_hash(unsigned int hash) { _hash = hash; }
       
    97   void set_reached_root(bool reached_root) { _reached_root = reached_root; }
       
    98   void resolve_linenos() const;
       
    99 
       
   100   bool record_thread(JavaThread& thread, frame& frame);
       
   101   bool record_safe(JavaThread* thread, int skip);
       
   102 
       
   103   bool have_lineno() const { return _lineno; }
       
   104   bool full_stacktrace() const { return _reached_root; }
       
   105 
       
   106   JfrStackTrace(traceid id, const JfrStackTrace& trace, const JfrStackTrace* next);
       
   107   void operator=(const JfrStackTrace& trace);
       
   108 
       
   109  public:
       
   110   JfrStackTrace(JfrStackFrame* frames, u4 max_frames);
       
   111   ~JfrStackTrace();
       
   112   unsigned int hash() const { return _hash; }
       
   113   traceid id() const { return _id; }
       
   114   u4 number_of_frames() const { return _nr_of_frames; }
       
   115 };
       
   116 
       
   117 #endif // SHARE_JFR_RECORDER_STACKTRACE_JFRSTACKTRACE_HPP