src/hotspot/share/jfr/recorder/stacktrace/jfrStackTrace.cpp
branchJEP-349-branch
changeset 57983 a57907813a83
parent 57870 00860d9caf4d
child 58100 0e549560be5e
equal deleted inserted replaced
57971:aa7b1ea52413 57983:a57907813a83
    37     *lhs_frames = NEW_C_HEAP_ARRAY(JfrStackFrame, length, mtTracing);
    37     *lhs_frames = NEW_C_HEAP_ARRAY(JfrStackFrame, length, mtTracing);
    38     memcpy(*lhs_frames, rhs_frames, length * sizeof(JfrStackFrame));
    38     memcpy(*lhs_frames, rhs_frames, length * sizeof(JfrStackFrame));
    39   }
    39   }
    40 }
    40 }
    41 
    41 
    42 JfrStackFrame::JfrStackFrame(const traceid& id, int bci, int type, InstanceKlass* k) :
    42 JfrStackFrame::JfrStackFrame(const traceid& id, int bci, int type, const Method* method) :
    43   _klass(k), _methodid(id), _line(0), _bci(bci), _type(type) {}
    43   _method(method), _methodid(id), _line(0), _bci(bci), _type(type) {}
    44 
    44 
    45 JfrStackFrame::JfrStackFrame(const traceid& id, int bci, int type, int lineno) :
    45 JfrStackFrame::JfrStackFrame(const traceid& id, int bci, int type, int lineno) :
    46   _klass(NULL), _methodid(id), _line(lineno), _bci(bci), _type(type) {}
    46   _method(NULL), _methodid(id), _line(lineno), _bci(bci), _type(type) {}
    47 
    47 
    48 JfrStackTrace::JfrStackTrace(JfrStackFrame* frames, u4 max_frames) :
    48 JfrStackTrace::JfrStackTrace(JfrStackFrame* frames, u4 max_frames) :
    49   _next(NULL),
    49   _next(NULL),
    50   _frames(frames),
    50   _frames(frames),
    51   _id(0),
    51   _id(0),
    73 
    73 
    74 JfrStackTrace::~JfrStackTrace() {
    74 JfrStackTrace::~JfrStackTrace() {
    75   if (_frames_ownership && _frames != NULL) {
    75   if (_frames_ownership && _frames != NULL) {
    76     FREE_C_HEAP_ARRAY(JfrStackFrame, _frames);
    76     FREE_C_HEAP_ARRAY(JfrStackFrame, _frames);
    77   }
    77   }
    78 }
       
    79 
       
    80 void JfrStackTrace::operator=(const JfrStackTrace& trace) {
       
    81   assert(_next == NULL, "invariant");
       
    82   assert(_frames_ownership, "invariant");
       
    83 
       
    84   if (_id == trace._id) {
       
    85     assert(_hash == trace._hash, "invariant");
       
    86     assert(_nr_of_frames == trace._nr_of_frames, "invariant");
       
    87     return;
       
    88   }
       
    89   _next = NULL;
       
    90   _id = trace._id;
       
    91   _hash = trace._hash;
       
    92   _nr_of_frames = trace._nr_of_frames;
       
    93   _max_frames = trace._max_frames;
       
    94   _reached_root = trace._reached_root;
       
    95   _lineno = trace._lineno;
       
    96   _written = false;
       
    97   copy_frames(&_frames, trace._nr_of_frames, trace._frames);
       
    98 }
    78 }
    99 
    79 
   100 template <typename Writer>
    80 template <typename Writer>
   101 static void write_stacktrace(Writer& w, traceid id, bool reached_root, u4 nr_of_frames, const JfrStackFrame* frames) {
    81 static void write_stacktrace(Writer& w, traceid id, bool reached_root, u4 nr_of_frames, const JfrStackFrame* frames) {
   102   w.write((u8)id);
    82   w.write((u8)id);
   218       bci = st.bci();
   198       bci = st.bci();
   219     }
   199     }
   220     const int lineno = method->line_number_from_bci(bci);
   200     const int lineno = method->line_number_from_bci(bci);
   221     // Can we determine if it's inlined?
   201     // Can we determine if it's inlined?
   222     _hash = (_hash << 2) + (unsigned int)(((size_t)mid >> 2) + (bci << 4) + type);
   202     _hash = (_hash << 2) + (unsigned int)(((size_t)mid >> 2) + (bci << 4) + type);
   223     _frames[count] = JfrStackFrame(mid, bci, type, method->constants()->pool_holder());
   203     _frames[count] = JfrStackFrame(mid, bci, type, method);
   224     st.samples_next();
   204     st.samples_next();
   225     count++;
   205     count++;
   226   }
   206   }
   227 
   207 
   228   _lineno = true;
   208   _lineno = true;
   229   _nr_of_frames = count;
   209   _nr_of_frames = count;
   230   return true;
   210   return true;
   231 }
   211 }
   232 
   212 
   233 void JfrStackFrame::resolve_lineno() const {
   213 void JfrStackFrame::resolve_lineno() const {
   234   assert(_klass, "no klass pointer");
   214   assert(_method, "no method pointer");
   235   assert(_line == 0, "already have linenumber");
   215   assert(_line == 0, "already have linenumber");
   236   const int id_num = _methodid & METHOD_ID_NUM_MASK;
   216   _line = _method->line_number_from_bci(_bci);
   237   const Method* const method = _klass->method_with_orig_idnum(id_num);
       
   238   assert(method != NULL, "invariant");
       
   239   _line = method->line_number_from_bci(_bci);
       
   240 }
   217 }
   241 
   218 
   242 void JfrStackTrace::resolve_linenos() const {
   219 void JfrStackTrace::resolve_linenos() const {
   243   for (unsigned int i = 0; i < _nr_of_frames; i++) {
   220   for (unsigned int i = 0; i < _nr_of_frames; i++) {
   244     _frames[i].resolve_lineno();
   221     _frames[i].resolve_lineno();
   273     else {
   250     else {
   274       bci = vfs.bci();
   251       bci = vfs.bci();
   275     }
   252     }
   276     // Can we determine if it's inlined?
   253     // Can we determine if it's inlined?
   277     _hash = (_hash << 2) + (unsigned int)(((size_t)mid >> 2) + (bci << 4) + type);
   254     _hash = (_hash << 2) + (unsigned int)(((size_t)mid >> 2) + (bci << 4) + type);
   278     _frames[count] = JfrStackFrame(mid, bci, type, method->constants()->pool_holder());
   255     _frames[count] = JfrStackFrame(mid, bci, type, method);
   279     vfs.next();
   256     vfs.next();
   280     count++;
   257     count++;
   281   }
   258   }
   282 
   259 
   283   _nr_of_frames = count;
   260   _nr_of_frames = count;