Mon, 12 Aug 2019 18:30:40 +0300
8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens
apetushkov@9858 | 1 | /* |
apetushkov@9858 | 2 | * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
apetushkov@9858 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
apetushkov@9858 | 4 | * |
apetushkov@9858 | 5 | * This code is free software; you can redistribute it and/or modify it |
apetushkov@9858 | 6 | * under the terms of the GNU General Public License version 2 only, as |
apetushkov@9858 | 7 | * published by the Free Software Foundation. |
apetushkov@9858 | 8 | * |
apetushkov@9858 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
apetushkov@9858 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
apetushkov@9858 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
apetushkov@9858 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
apetushkov@9858 | 13 | * accompanied this code). |
apetushkov@9858 | 14 | * |
apetushkov@9858 | 15 | * You should have received a copy of the GNU General Public License version |
apetushkov@9858 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
apetushkov@9858 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
apetushkov@9858 | 18 | * |
apetushkov@9858 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
apetushkov@9858 | 20 | * or visit www.oracle.com if you need additional information or have any |
apetushkov@9858 | 21 | * questions. |
apetushkov@9858 | 22 | * |
apetushkov@9858 | 23 | */ |
apetushkov@9858 | 24 | |
apetushkov@9858 | 25 | #ifndef SHARE_VM_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP |
apetushkov@9858 | 26 | #define SHARE_VM_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP |
apetushkov@9858 | 27 | |
apetushkov@9858 | 28 | #include "jfr/utilities/jfrAllocation.hpp" |
apetushkov@9858 | 29 | #include "jfr/utilities/jfrTypes.hpp" |
apetushkov@9858 | 30 | |
apetushkov@9858 | 31 | class frame; |
apetushkov@9858 | 32 | class JavaThread; |
apetushkov@9858 | 33 | class JfrCheckpointSystem; |
apetushkov@9858 | 34 | class JfrCheckpointWriter; |
apetushkov@9858 | 35 | class JfrChunkWriter; |
apetushkov@9858 | 36 | class Method; |
apetushkov@9858 | 37 | |
apetushkov@9858 | 38 | class JfrStackFrame { |
apetushkov@9858 | 39 | private: |
apetushkov@9858 | 40 | const Method* _method; |
apetushkov@9858 | 41 | traceid _methodid; |
apetushkov@9858 | 42 | int _line; |
apetushkov@9858 | 43 | int _bci; |
apetushkov@9858 | 44 | u1 _type; |
apetushkov@9858 | 45 | |
apetushkov@9858 | 46 | public: |
apetushkov@9858 | 47 | enum { |
apetushkov@9858 | 48 | FRAME_INTERPRETER = 0, |
apetushkov@9858 | 49 | FRAME_JIT, |
apetushkov@9858 | 50 | FRAME_INLINE, |
apetushkov@9858 | 51 | FRAME_NATIVE, |
apetushkov@9858 | 52 | NUM_FRAME_TYPES |
apetushkov@9858 | 53 | }; |
apetushkov@9858 | 54 | |
apetushkov@9858 | 55 | JfrStackFrame(const traceid& id, int bci, int type, const Method* method) : |
apetushkov@9858 | 56 | _method(method), _methodid(id), _line(0), _bci(bci), _type(type) {} |
apetushkov@9858 | 57 | JfrStackFrame(const traceid& id, int bci, int type, int lineno) : |
apetushkov@9858 | 58 | _method(NULL), _methodid(id), _line(0), _bci(bci), _type(type) {} |
apetushkov@9858 | 59 | bool equals(const JfrStackFrame& rhs) const; |
apetushkov@9858 | 60 | void write(JfrChunkWriter& cw) const; |
apetushkov@9858 | 61 | void write(JfrCheckpointWriter& cpw) const; |
apetushkov@9858 | 62 | void resolve_lineno(); |
apetushkov@9858 | 63 | }; |
apetushkov@9858 | 64 | |
apetushkov@9858 | 65 | class JfrStackTrace : public StackObj { |
apetushkov@9858 | 66 | friend class JfrStackTraceRepository; |
apetushkov@9858 | 67 | private: |
apetushkov@9858 | 68 | JfrStackFrame* _frames; |
apetushkov@9858 | 69 | traceid _id; |
apetushkov@9858 | 70 | u4 _nr_of_frames; |
apetushkov@9858 | 71 | unsigned int _hash; |
apetushkov@9858 | 72 | const u4 _max_frames; |
apetushkov@9858 | 73 | bool _reached_root; |
apetushkov@9858 | 74 | bool _lineno; |
apetushkov@9858 | 75 | |
apetushkov@9858 | 76 | public: |
apetushkov@9858 | 77 | JfrStackTrace(JfrStackFrame* frames, u4 max_frames) : _frames(frames), |
apetushkov@9858 | 78 | _id(0), |
apetushkov@9858 | 79 | _nr_of_frames(0), |
apetushkov@9858 | 80 | _hash(0), |
apetushkov@9858 | 81 | _reached_root(false), |
apetushkov@9858 | 82 | _max_frames(max_frames), |
apetushkov@9858 | 83 | _lineno(false) {} |
apetushkov@9858 | 84 | bool record_thread(JavaThread& thread, frame& frame); |
apetushkov@9858 | 85 | bool record_safe(JavaThread* thread, int skip, bool leakp = false); |
apetushkov@9858 | 86 | void resolve_linenos(); |
apetushkov@9858 | 87 | void set_nr_of_frames(u4 nr_of_frames) { _nr_of_frames = nr_of_frames; } |
apetushkov@9858 | 88 | void set_hash(unsigned int hash) { _hash = hash; } |
apetushkov@9858 | 89 | void set_frame(u4 frame_pos, JfrStackFrame& frame); |
apetushkov@9858 | 90 | void set_reached_root(bool reached_root) { _reached_root = reached_root; } |
apetushkov@9858 | 91 | bool full_stacktrace() const { return _reached_root; } |
apetushkov@9858 | 92 | bool have_lineno() const { return _lineno; } |
apetushkov@9858 | 93 | }; |
apetushkov@9858 | 94 | |
apetushkov@9858 | 95 | class JfrStackTraceRepository : public JfrCHeapObj { |
apetushkov@9858 | 96 | friend class JfrRecorder; |
apetushkov@9858 | 97 | friend class JfrRecorderService; |
apetushkov@9858 | 98 | friend class ObjectSampler; |
apetushkov@9858 | 99 | friend class WriteObjectSampleStacktrace; |
apetushkov@9858 | 100 | |
apetushkov@9858 | 101 | class StackTrace : public JfrCHeapObj { |
apetushkov@9858 | 102 | friend class JfrStackTrace; |
apetushkov@9858 | 103 | friend class JfrStackTraceRepository; |
apetushkov@9858 | 104 | private: |
apetushkov@9858 | 105 | StackTrace* _next; |
apetushkov@9858 | 106 | JfrStackFrame* _frames; |
apetushkov@9858 | 107 | const traceid _id; |
apetushkov@9858 | 108 | u4 _nr_of_frames; |
apetushkov@9858 | 109 | unsigned int _hash; |
apetushkov@9858 | 110 | bool _reached_root; |
apetushkov@9858 | 111 | mutable bool _written; |
apetushkov@9858 | 112 | |
apetushkov@9858 | 113 | unsigned int hash() const { return _hash; } |
apetushkov@9858 | 114 | bool should_write() const { return !_written; } |
apetushkov@9858 | 115 | |
apetushkov@9858 | 116 | public: |
apetushkov@9858 | 117 | StackTrace(traceid id, const JfrStackTrace& trace, StackTrace* next); |
apetushkov@9858 | 118 | ~StackTrace(); |
apetushkov@9858 | 119 | traceid id() const { return _id; } |
apetushkov@9858 | 120 | StackTrace* next() const { return _next; } |
apetushkov@9858 | 121 | void write(JfrChunkWriter& cw) const; |
apetushkov@9858 | 122 | void write(JfrCheckpointWriter& cpw) const; |
apetushkov@9858 | 123 | bool equals(const JfrStackTrace& rhs) const; |
apetushkov@9858 | 124 | }; |
apetushkov@9858 | 125 | |
apetushkov@9858 | 126 | private: |
apetushkov@9858 | 127 | static const u4 TABLE_SIZE = 2053; |
apetushkov@9858 | 128 | StackTrace* _table[TABLE_SIZE]; |
apetushkov@9858 | 129 | traceid _next_id; |
apetushkov@9858 | 130 | u4 _entries; |
apetushkov@9858 | 131 | |
apetushkov@9858 | 132 | size_t write_impl(JfrChunkWriter& cw, bool clear); |
apetushkov@9858 | 133 | traceid record_for(JavaThread* thread, int skip, JfrStackFrame* frames, u4 max_frames); |
apetushkov@9858 | 134 | traceid record_for(JavaThread* thread, int skip, JfrStackFrame* frames, u4 max_frames, unsigned int* hash); |
apetushkov@9858 | 135 | traceid add_trace(const JfrStackTrace& stacktrace); |
apetushkov@9858 | 136 | const StackTrace* resolve_entry(unsigned int hash, traceid id) const; |
apetushkov@9858 | 137 | |
apetushkov@9858 | 138 | static void write_metadata(JfrCheckpointWriter& cpw); |
apetushkov@9858 | 139 | |
apetushkov@9858 | 140 | JfrStackTraceRepository(); |
apetushkov@9858 | 141 | static JfrStackTraceRepository& instance(); |
apetushkov@9858 | 142 | public: |
apetushkov@9858 | 143 | static JfrStackTraceRepository* create(); |
apetushkov@9858 | 144 | bool initialize(); |
apetushkov@9858 | 145 | static void destroy(); |
apetushkov@9858 | 146 | static traceid add(const JfrStackTrace& stacktrace); |
apetushkov@9858 | 147 | static traceid record(Thread* thread, int skip = 0); |
apetushkov@9858 | 148 | static traceid record(Thread* thread, int skip, unsigned int* hash); |
apetushkov@9858 | 149 | traceid write(JfrCheckpointWriter& cpw, traceid id, unsigned int hash); |
apetushkov@9858 | 150 | size_t write(JfrChunkWriter& cw, bool clear); |
apetushkov@9858 | 151 | size_t clear(); |
apetushkov@9858 | 152 | }; |
apetushkov@9858 | 153 | |
apetushkov@9858 | 154 | #endif // SHARE_VM_JFR_RECORDER_STACKTRACE_JFRSTACKTRACEREPOSITORY_HPP |