author | egahlin |
Fri, 22 Nov 2019 17:20:43 +0100 | |
changeset 59226 | a0f39cc47387 |
parent 58863 | c16ac7a2eba4 |
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" |
|
58863 | 26 |
#include "jfr/recorder/repository/jfrChunk.hpp" |
27 |
#include "jfr/recorder/service/jfrOptionSet.hpp" |
|
50113 | 28 |
#include "jfr/utilities/jfrTime.hpp" |
29 |
#include "jfr/utilities/jfrTimeConverter.hpp" |
|
58863 | 30 |
#include "jfr/utilities/jfrTypes.hpp" |
50113 | 31 |
#include "runtime/os.inline.hpp" |
58863 | 32 |
|
33 |
static const char* const MAGIC = "FLR"; |
|
34 |
static const u2 JFR_VERSION_MAJOR = 2; |
|
35 |
static const u2 JFR_VERSION_MINOR = 1; |
|
50113 | 36 |
|
58863 | 37 |
// strictly monotone |
38 |
static jlong nanos_now() { |
|
39 |
static jlong last = 0; |
|
40 |
const jlong now = os::javaTimeMillis() * JfrTimeConverter::NANOS_PER_MILLISEC; |
|
41 |
if (now > last) { |
|
42 |
last = now; |
|
43 |
} else { |
|
44 |
++last; |
|
45 |
} |
|
46 |
return last; |
|
47 |
} |
|
48 |
||
49 |
static jlong ticks_now() { |
|
50 |
return JfrTicks::now(); |
|
51 |
} |
|
52 |
||
53 |
JfrChunk::JfrChunk() : |
|
50113 | 54 |
_path(NULL), |
55 |
_start_ticks(0), |
|
58863 | 56 |
_previous_start_ticks(invalid_time), |
50113 | 57 |
_start_nanos(0), |
58863 | 58 |
_previous_start_nanos(invalid_time), |
59 |
_last_update_nanos(0), |
|
60 |
_last_checkpoint_offset(0), |
|
61 |
_last_metadata_offset(0), |
|
59226 | 62 |
_generation(1), |
63 |
_final(false) {} |
|
50113 | 64 |
|
58863 | 65 |
JfrChunk::~JfrChunk() { |
50113 | 66 |
reset(); |
67 |
} |
|
68 |
||
58863 | 69 |
void JfrChunk::reset() { |
50113 | 70 |
if (_path != NULL) { |
71 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
72 |
_path = NULL; |
|
73 |
} |
|
58863 | 74 |
_last_checkpoint_offset = _last_metadata_offset = 0; |
75 |
_generation = 1; |
|
76 |
} |
|
77 |
||
78 |
const char* JfrChunk::magic() const { |
|
79 |
return MAGIC; |
|
80 |
} |
|
81 |
||
82 |
u2 JfrChunk::major_version() const { |
|
83 |
return JFR_VERSION_MAJOR; |
|
50113 | 84 |
} |
85 |
||
58863 | 86 |
u2 JfrChunk::minor_version() const { |
87 |
return JFR_VERSION_MINOR; |
|
88 |
} |
|
89 |
||
59226 | 90 |
void JfrChunk::mark_final() { |
91 |
_final = true; |
|
92 |
} |
|
93 |
||
94 |
u2 JfrChunk::flags() const { |
|
58863 | 95 |
// chunk capabilities, CompressedIntegers etc |
59226 | 96 |
u2 flags = 0; |
97 |
if (JfrOptionSet::compressed_integers()) { |
|
98 |
flags |= 1 << 0; |
|
99 |
} |
|
100 |
if (_final) { |
|
101 |
flags |= 1 << 1; |
|
102 |
} |
|
103 |
return flags; |
|
58863 | 104 |
} |
105 |
||
106 |
int64_t JfrChunk::cpu_frequency() const { |
|
107 |
static const jlong frequency = JfrTime::frequency(); |
|
108 |
return frequency; |
|
109 |
} |
|
110 |
||
111 |
void JfrChunk::set_last_checkpoint_offset(int64_t offset) { |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
112 |
_last_checkpoint_offset = offset; |
50113 | 113 |
} |
114 |
||
58863 | 115 |
int64_t JfrChunk::last_checkpoint_offset() const { |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
116 |
return _last_checkpoint_offset; |
50113 | 117 |
} |
118 |
||
58863 | 119 |
int64_t JfrChunk::start_ticks() const { |
120 |
assert(_start_ticks != 0, "invariant"); |
|
121 |
return _start_ticks; |
|
122 |
} |
|
123 |
||
124 |
int64_t JfrChunk::start_nanos() const { |
|
125 |
assert(_start_nanos != 0, "invariant"); |
|
126 |
return _start_nanos; |
|
127 |
} |
|
128 |
||
129 |
int64_t JfrChunk::previous_start_ticks() const { |
|
130 |
assert(_previous_start_ticks != invalid_time, "invariant"); |
|
50113 | 131 |
return _previous_start_ticks; |
132 |
} |
|
133 |
||
58863 | 134 |
int64_t JfrChunk::previous_start_nanos() const { |
135 |
assert(_previous_start_nanos != invalid_time, "invariant"); |
|
50113 | 136 |
return _previous_start_nanos; |
137 |
} |
|
138 |
||
58863 | 139 |
void JfrChunk::update_start_ticks() { |
140 |
_start_ticks = ticks_now(); |
|
50113 | 141 |
} |
142 |
||
58863 | 143 |
void JfrChunk::update_start_nanos() { |
144 |
const jlong now = nanos_now(); |
|
145 |
assert(now > _start_nanos, "invariant"); |
|
146 |
assert(now > _last_update_nanos, "invariant"); |
|
147 |
_start_nanos = _last_update_nanos = now; |
|
50113 | 148 |
} |
149 |
||
58863 | 150 |
void JfrChunk::update_current_nanos() { |
151 |
const jlong now = nanos_now(); |
|
152 |
assert(now > _last_update_nanos, "invariant"); |
|
153 |
_last_update_nanos = now; |
|
154 |
} |
|
155 |
||
156 |
void JfrChunk::save_current_and_update_start_ticks() { |
|
50113 | 157 |
_previous_start_ticks = _start_ticks; |
158 |
update_start_ticks(); |
|
159 |
} |
|
160 |
||
58863 | 161 |
void JfrChunk::save_current_and_update_start_nanos() { |
50113 | 162 |
_previous_start_nanos = _start_nanos; |
163 |
update_start_nanos(); |
|
164 |
} |
|
165 |
||
58863 | 166 |
void JfrChunk::set_time_stamp() { |
50113 | 167 |
save_current_and_update_start_nanos(); |
168 |
save_current_and_update_start_ticks(); |
|
169 |
} |
|
170 |
||
58863 | 171 |
int64_t JfrChunk::last_chunk_duration() const { |
172 |
assert(_previous_start_nanos != invalid_time, "invariant"); |
|
50113 | 173 |
return _start_nanos - _previous_start_nanos; |
174 |
} |
|
175 |
||
176 |
static char* copy_path(const char* path) { |
|
177 |
assert(path != NULL, "invariant"); |
|
178 |
const size_t path_len = strlen(path); |
|
179 |
char* new_path = JfrCHeapObj::new_array<char>(path_len + 1); |
|
53762 | 180 |
strncpy(new_path, path, path_len + 1); |
50113 | 181 |
return new_path; |
182 |
} |
|
183 |
||
58863 | 184 |
void JfrChunk::set_path(const char* path) { |
50113 | 185 |
if (_path != NULL) { |
186 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
187 |
_path = NULL; |
|
188 |
} |
|
189 |
if (path != NULL) { |
|
190 |
_path = copy_path(path); |
|
191 |
} |
|
192 |
} |
|
193 |
||
58863 | 194 |
const char* JfrChunk::path() const { |
50113 | 195 |
return _path; |
196 |
} |
|
58863 | 197 |
|
198 |
bool JfrChunk::is_started() const { |
|
199 |
return _start_nanos != 0; |
|
200 |
} |
|
201 |
||
202 |
bool JfrChunk::is_finished() const { |
|
203 |
return 0 == _generation; |
|
204 |
} |
|
205 |
||
206 |
int64_t JfrChunk::duration() const { |
|
207 |
assert(_last_update_nanos >= _start_nanos, "invariant"); |
|
208 |
return _last_update_nanos - _start_nanos; |
|
209 |
} |
|
210 |
||
211 |
int64_t JfrChunk::last_metadata_offset() const { |
|
212 |
return _last_metadata_offset; |
|
213 |
} |
|
214 |
||
215 |
void JfrChunk::set_last_metadata_offset(int64_t offset) { |
|
216 |
assert(offset > _last_metadata_offset, "invariant"); |
|
217 |
_last_metadata_offset = offset; |
|
218 |
} |
|
219 |
||
220 |
bool JfrChunk::has_metadata() const { |
|
221 |
return 0 != _last_metadata_offset; |
|
222 |
} |
|
223 |
||
224 |
u1 JfrChunk::generation() const { |
|
225 |
assert(_generation > 0, "invariant"); |
|
226 |
const u1 this_generation = _generation++; |
|
227 |
if (GUARD == _generation) { |
|
228 |
_generation = 1; |
|
229 |
} |
|
230 |
return this_generation; |
|
231 |
} |
|
232 |
||
233 |
u1 JfrChunk::next_generation() const { |
|
234 |
assert(_generation > 0, "invariant"); |
|
235 |
const u1 next_gen = _generation; |
|
236 |
return GUARD == next_gen ? 1 : next_gen; |
|
237 |
} |