author | mgronlun |
Wed, 30 Oct 2019 19:43:52 +0100 | |
changeset 58863 | c16ac7a2eba4 |
parent 58132 | src/hotspot/share/jfr/recorder/repository/jfrChunkState.cpp@caa25ab47aca |
child 59226 | a0f39cc47387 |
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), |
|
62 |
_generation(1) {} |
|
50113 | 63 |
|
58863 | 64 |
JfrChunk::~JfrChunk() { |
50113 | 65 |
reset(); |
66 |
} |
|
67 |
||
58863 | 68 |
void JfrChunk::reset() { |
50113 | 69 |
if (_path != NULL) { |
70 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
71 |
_path = NULL; |
|
72 |
} |
|
58863 | 73 |
_last_checkpoint_offset = _last_metadata_offset = 0; |
74 |
_generation = 1; |
|
75 |
} |
|
76 |
||
77 |
const char* JfrChunk::magic() const { |
|
78 |
return MAGIC; |
|
79 |
} |
|
80 |
||
81 |
u2 JfrChunk::major_version() const { |
|
82 |
return JFR_VERSION_MAJOR; |
|
50113 | 83 |
} |
84 |
||
58863 | 85 |
u2 JfrChunk::minor_version() const { |
86 |
return JFR_VERSION_MINOR; |
|
87 |
} |
|
88 |
||
89 |
u2 JfrChunk::capabilities() const { |
|
90 |
// chunk capabilities, CompressedIntegers etc |
|
91 |
static bool compressed_integers = JfrOptionSet::compressed_integers(); |
|
92 |
return compressed_integers; |
|
93 |
} |
|
94 |
||
95 |
int64_t JfrChunk::cpu_frequency() const { |
|
96 |
static const jlong frequency = JfrTime::frequency(); |
|
97 |
return frequency; |
|
98 |
} |
|
99 |
||
100 |
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
|
101 |
_last_checkpoint_offset = offset; |
50113 | 102 |
} |
103 |
||
58863 | 104 |
int64_t JfrChunk::last_checkpoint_offset() const { |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
105 |
return _last_checkpoint_offset; |
50113 | 106 |
} |
107 |
||
58863 | 108 |
int64_t JfrChunk::start_ticks() const { |
109 |
assert(_start_ticks != 0, "invariant"); |
|
110 |
return _start_ticks; |
|
111 |
} |
|
112 |
||
113 |
int64_t JfrChunk::start_nanos() const { |
|
114 |
assert(_start_nanos != 0, "invariant"); |
|
115 |
return _start_nanos; |
|
116 |
} |
|
117 |
||
118 |
int64_t JfrChunk::previous_start_ticks() const { |
|
119 |
assert(_previous_start_ticks != invalid_time, "invariant"); |
|
50113 | 120 |
return _previous_start_ticks; |
121 |
} |
|
122 |
||
58863 | 123 |
int64_t JfrChunk::previous_start_nanos() const { |
124 |
assert(_previous_start_nanos != invalid_time, "invariant"); |
|
50113 | 125 |
return _previous_start_nanos; |
126 |
} |
|
127 |
||
58863 | 128 |
void JfrChunk::update_start_ticks() { |
129 |
_start_ticks = ticks_now(); |
|
50113 | 130 |
} |
131 |
||
58863 | 132 |
void JfrChunk::update_start_nanos() { |
133 |
const jlong now = nanos_now(); |
|
134 |
assert(now > _start_nanos, "invariant"); |
|
135 |
assert(now > _last_update_nanos, "invariant"); |
|
136 |
_start_nanos = _last_update_nanos = now; |
|
50113 | 137 |
} |
138 |
||
58863 | 139 |
void JfrChunk::update_current_nanos() { |
140 |
const jlong now = nanos_now(); |
|
141 |
assert(now > _last_update_nanos, "invariant"); |
|
142 |
_last_update_nanos = now; |
|
143 |
} |
|
144 |
||
145 |
void JfrChunk::save_current_and_update_start_ticks() { |
|
50113 | 146 |
_previous_start_ticks = _start_ticks; |
147 |
update_start_ticks(); |
|
148 |
} |
|
149 |
||
58863 | 150 |
void JfrChunk::save_current_and_update_start_nanos() { |
50113 | 151 |
_previous_start_nanos = _start_nanos; |
152 |
update_start_nanos(); |
|
153 |
} |
|
154 |
||
58863 | 155 |
void JfrChunk::set_time_stamp() { |
50113 | 156 |
save_current_and_update_start_nanos(); |
157 |
save_current_and_update_start_ticks(); |
|
158 |
} |
|
159 |
||
58863 | 160 |
int64_t JfrChunk::last_chunk_duration() const { |
161 |
assert(_previous_start_nanos != invalid_time, "invariant"); |
|
50113 | 162 |
return _start_nanos - _previous_start_nanos; |
163 |
} |
|
164 |
||
165 |
static char* copy_path(const char* path) { |
|
166 |
assert(path != NULL, "invariant"); |
|
167 |
const size_t path_len = strlen(path); |
|
168 |
char* new_path = JfrCHeapObj::new_array<char>(path_len + 1); |
|
53762 | 169 |
strncpy(new_path, path, path_len + 1); |
50113 | 170 |
return new_path; |
171 |
} |
|
172 |
||
58863 | 173 |
void JfrChunk::set_path(const char* path) { |
50113 | 174 |
if (_path != NULL) { |
175 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
176 |
_path = NULL; |
|
177 |
} |
|
178 |
if (path != NULL) { |
|
179 |
_path = copy_path(path); |
|
180 |
} |
|
181 |
} |
|
182 |
||
58863 | 183 |
const char* JfrChunk::path() const { |
50113 | 184 |
return _path; |
185 |
} |
|
58863 | 186 |
|
187 |
bool JfrChunk::is_started() const { |
|
188 |
return _start_nanos != 0; |
|
189 |
} |
|
190 |
||
191 |
bool JfrChunk::is_finished() const { |
|
192 |
return 0 == _generation; |
|
193 |
} |
|
194 |
||
195 |
int64_t JfrChunk::duration() const { |
|
196 |
assert(_last_update_nanos >= _start_nanos, "invariant"); |
|
197 |
return _last_update_nanos - _start_nanos; |
|
198 |
} |
|
199 |
||
200 |
int64_t JfrChunk::last_metadata_offset() const { |
|
201 |
return _last_metadata_offset; |
|
202 |
} |
|
203 |
||
204 |
void JfrChunk::set_last_metadata_offset(int64_t offset) { |
|
205 |
assert(offset > _last_metadata_offset, "invariant"); |
|
206 |
_last_metadata_offset = offset; |
|
207 |
} |
|
208 |
||
209 |
bool JfrChunk::has_metadata() const { |
|
210 |
return 0 != _last_metadata_offset; |
|
211 |
} |
|
212 |
||
213 |
u1 JfrChunk::generation() const { |
|
214 |
assert(_generation > 0, "invariant"); |
|
215 |
const u1 this_generation = _generation++; |
|
216 |
if (GUARD == _generation) { |
|
217 |
_generation = 1; |
|
218 |
} |
|
219 |
return this_generation; |
|
220 |
} |
|
221 |
||
222 |
u1 JfrChunk::next_generation() const { |
|
223 |
assert(_generation > 0, "invariant"); |
|
224 |
const u1 next_gen = _generation; |
|
225 |
return GUARD == next_gen ? 1 : next_gen; |
|
226 |
} |