author | mgronlun |
Sat, 24 Aug 2019 14:30:27 +0200 | |
branch | JEP-349-branch |
changeset 57870 | 00860d9caf4d |
parent 57361 | 53dccc90a5be |
child 57887 | a9cc3698a55c |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
53762 | 2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 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 |
#include "precompiled.hpp" |
|
26 |
#include "jfr/dcmd/jfrDcmds.hpp" |
|
27 |
#include "jfr/recorder/jfrRecorder.hpp" |
|
57361 | 28 |
#include "jfr/recorder/repository/jfrChunk.hpp" |
50113 | 29 |
#include "jfr/recorder/repository/jfrChunkWriter.hpp" |
30 |
#include "jfr/utilities/jfrTimeConverter.hpp" |
|
31 |
#include "logging/log.hpp" |
|
32 |
#include "runtime/os.inline.hpp" |
|
33 |
#include "runtime/thread.inline.hpp" |
|
34 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
35 |
static const char* const MAGIC = "FLR"; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
36 |
static const u2 JFR_VERSION_MAJOR = 2; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
37 |
static const u2 JFR_VERSION_MINOR = 0; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
38 |
|
57361 | 39 |
static const u1 GUARD = 0xff; |
40 |
||
41 |
static jlong nanos_now() { |
|
42 |
return os::javaTimeMillis() * JfrTimeConverter::NANOS_PER_MILLISEC; |
|
43 |
} |
|
44 |
||
45 |
static jlong ticks_now() { |
|
46 |
return JfrTicks::now(); |
|
47 |
} |
|
48 |
||
49 |
JfrChunk::JfrChunk() : |
|
50113 | 50 |
_path(NULL), |
51 |
_start_ticks(0), |
|
57361 | 52 |
_previous_start_ticks(invalid_time), |
50113 | 53 |
_start_nanos(0), |
57361 | 54 |
_previous_start_nanos(invalid_time), |
55 |
_last_update_nanos(0), |
|
56 |
_last_checkpoint_offset(0), |
|
57 |
_last_metadata_offset(0), |
|
58 |
_generation(1) {} |
|
50113 | 59 |
|
57361 | 60 |
JfrChunk::~JfrChunk() { |
50113 | 61 |
reset(); |
62 |
} |
|
63 |
||
57361 | 64 |
void JfrChunk::reset() { |
50113 | 65 |
if (_path != NULL) { |
66 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
67 |
_path = NULL; |
|
68 |
} |
|
57361 | 69 |
_last_checkpoint_offset = _last_metadata_offset = 0; |
70 |
_generation = 1; |
|
71 |
} |
|
72 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
73 |
const char* JfrChunk::magic() const { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
74 |
return MAGIC; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
75 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
76 |
|
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
77 |
u2 JfrChunk::major_version() const { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
78 |
return JFR_VERSION_MAJOR; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
79 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
80 |
|
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
81 |
u2 JfrChunk::minor_version() const { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
82 |
return JFR_VERSION_MINOR; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
83 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
84 |
|
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
85 |
u2 JfrChunk::capabilities() const { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
86 |
// chunk capabilities, CompressedIntegers etc |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
87 |
static bool compressed_integers = JfrOptionSet::compressed_integers(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
88 |
return compressed_integers; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
89 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
90 |
|
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
91 |
int64_t JfrChunk::cpu_frequency() const { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
92 |
static const jlong frequency = JfrTime::frequency(); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
93 |
return frequency; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
94 |
} |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
95 |
|
57361 | 96 |
void JfrChunk::set_last_checkpoint_offset(int64_t offset) { |
97 |
_last_checkpoint_offset = offset; |
|
98 |
} |
|
99 |
||
100 |
int64_t JfrChunk::last_checkpoint_offset() const { |
|
101 |
return _last_checkpoint_offset; |
|
50113 | 102 |
} |
103 |
||
57361 | 104 |
int64_t JfrChunk::start_ticks() const { |
105 |
assert(_start_ticks != 0, "invariant"); |
|
106 |
return _start_ticks; |
|
50113 | 107 |
} |
108 |
||
57361 | 109 |
int64_t JfrChunk::start_nanos() const { |
110 |
assert(_start_nanos != 0, "invariant"); |
|
111 |
return _start_nanos; |
|
50113 | 112 |
} |
113 |
||
57361 | 114 |
int64_t JfrChunk::previous_start_ticks() const { |
115 |
assert(_previous_start_ticks != invalid_time, "invariant"); |
|
50113 | 116 |
return _previous_start_ticks; |
117 |
} |
|
118 |
||
57361 | 119 |
int64_t JfrChunk::previous_start_nanos() const { |
120 |
assert(_previous_start_nanos != invalid_time, "invariant"); |
|
50113 | 121 |
return _previous_start_nanos; |
122 |
} |
|
123 |
||
57361 | 124 |
void JfrChunk::update_start_ticks() { |
125 |
_start_ticks = ticks_now(); |
|
50113 | 126 |
} |
127 |
||
57361 | 128 |
void JfrChunk::update_start_nanos() { |
129 |
_start_nanos = _last_update_nanos = nanos_now(); |
|
50113 | 130 |
} |
131 |
||
57361 | 132 |
void JfrChunk::update() { |
133 |
_last_update_nanos = nanos_now(); |
|
134 |
} |
|
135 |
||
136 |
void JfrChunk::save_current_and_update_start_ticks() { |
|
50113 | 137 |
_previous_start_ticks = _start_ticks; |
138 |
update_start_ticks(); |
|
139 |
} |
|
140 |
||
57361 | 141 |
void JfrChunk::save_current_and_update_start_nanos() { |
50113 | 142 |
_previous_start_nanos = _start_nanos; |
143 |
update_start_nanos(); |
|
144 |
} |
|
145 |
||
57361 | 146 |
void JfrChunk::update_time_to_now() { |
50113 | 147 |
save_current_and_update_start_nanos(); |
148 |
save_current_and_update_start_ticks(); |
|
149 |
} |
|
150 |
||
57361 | 151 |
int64_t JfrChunk::last_chunk_duration() const { |
152 |
assert(_previous_start_nanos != invalid_time, "invariant"); |
|
50113 | 153 |
return _start_nanos - _previous_start_nanos; |
154 |
} |
|
155 |
||
156 |
static char* copy_path(const char* path) { |
|
157 |
assert(path != NULL, "invariant"); |
|
158 |
const size_t path_len = strlen(path); |
|
159 |
char* new_path = JfrCHeapObj::new_array<char>(path_len + 1); |
|
53762 | 160 |
strncpy(new_path, path, path_len + 1); |
50113 | 161 |
return new_path; |
162 |
} |
|
163 |
||
57361 | 164 |
void JfrChunk::set_path(const char* path) { |
50113 | 165 |
if (_path != NULL) { |
166 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
167 |
_path = NULL; |
|
168 |
} |
|
169 |
if (path != NULL) { |
|
170 |
_path = copy_path(path); |
|
171 |
} |
|
172 |
} |
|
173 |
||
57361 | 174 |
const char* JfrChunk::path() const { |
50113 | 175 |
return _path; |
176 |
} |
|
57361 | 177 |
|
178 |
bool JfrChunk::is_started() const { |
|
179 |
return _start_nanos != 0; |
|
180 |
} |
|
181 |
||
182 |
bool JfrChunk::is_finished() const { |
|
183 |
return 0 == _generation; |
|
184 |
} |
|
185 |
||
186 |
bool JfrChunk::is_initial_flush() const { |
|
187 |
return 0 == _last_metadata_offset; |
|
188 |
} |
|
189 |
||
190 |
int64_t JfrChunk::duration() const { |
|
191 |
assert(_last_update_nanos >= _start_nanos, "invariant"); |
|
192 |
return _last_update_nanos - _start_nanos; |
|
193 |
} |
|
194 |
||
195 |
int64_t JfrChunk::last_metadata_offset() const { |
|
196 |
return _last_metadata_offset; |
|
197 |
} |
|
198 |
||
199 |
void JfrChunk::set_last_metadata_offset(int64_t offset) { |
|
200 |
if (0 == offset) { |
|
201 |
return; |
|
202 |
} |
|
203 |
assert(offset > _last_metadata_offset, "invariant"); |
|
204 |
_last_metadata_offset = offset; |
|
205 |
} |
|
206 |
||
207 |
bool JfrChunk::has_metadata() const { |
|
208 |
return 0 != _last_metadata_offset; |
|
209 |
} |
|
210 |
||
211 |
u1 JfrChunk::generation() const { |
|
212 |
assert(_generation > 0, "invariant"); |
|
213 |
const u1 this_generation = _generation++; |
|
214 |
if (GUARD == _generation) { |
|
215 |
_generation = 1; |
|
216 |
} |
|
217 |
return this_generation; |
|
218 |
} |
|
219 |
||
57870
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
220 |
u1 JfrChunk::next_generation() const { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
221 |
assert(_generation > 0, "invariant"); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
222 |
const u1 next_gen = _generation; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
223 |
return GUARD == next_gen ? 1 : next_gen; |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57361
diff
changeset
|
224 |
} |