author | mgronlun |
Sun, 15 Sep 2019 15:31:04 +0200 | |
branch | JEP-349-branch |
changeset 58158 | 369ebc2a11c2 |
parent 58157 | 9dca61a7df19 |
child 58159 | 892527a70da9 |
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" |
|
58101 | 26 |
#include "jfr/recorder/repository/jfrChunk.hpp" |
27 |
#include "jfr/recorder/service/jfrOptionSet.hpp" |
|
50113 | 28 |
#include "jfr/utilities/jfrTimeConverter.hpp" |
58101 | 29 |
#include "jfr/utilities/jfrTypes.hpp" |
50113 | 30 |
#include "runtime/os.inline.hpp" |
58101 | 31 |
|
58158 | 32 |
static const char* const MAGIC = "FLR"; |
33 |
static const u2 JFR_VERSION_MAJOR = 2; |
|
34 |
static const u2 JFR_VERSION_MINOR = 0; |
|
35 |
||
58101 | 36 |
static jlong nanos_now() { |
37 |
return os::javaTimeMillis() * JfrTimeConverter::NANOS_PER_MILLISEC; |
|
38 |
} |
|
50113 | 39 |
|
58101 | 40 |
static jlong ticks_now() { |
41 |
return JfrTicks::now(); |
|
42 |
} |
|
43 |
||
44 |
JfrChunk::JfrChunk() : |
|
50113 | 45 |
_path(NULL), |
46 |
_start_ticks(0), |
|
58101 | 47 |
_previous_start_ticks(invalid_time), |
50113 | 48 |
_start_nanos(0), |
58101 | 49 |
_previous_start_nanos(invalid_time), |
50 |
_last_update_nanos(0), |
|
58158 | 51 |
_last_checkpoint_offset(0), |
58101 | 52 |
_last_metadata_offset(0), |
53 |
_generation(1) {} |
|
50113 | 54 |
|
58101 | 55 |
JfrChunk::~JfrChunk() { |
50113 | 56 |
reset(); |
57 |
} |
|
58 |
||
58101 | 59 |
void JfrChunk::reset() { |
50113 | 60 |
if (_path != NULL) { |
61 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
62 |
_path = NULL; |
|
63 |
} |
|
58101 | 64 |
_last_checkpoint_offset = _last_metadata_offset = 0; |
65 |
_generation = 1; |
|
66 |
} |
|
67 |
||
68 |
const char* JfrChunk::magic() const { |
|
69 |
return MAGIC; |
|
70 |
} |
|
71 |
||
72 |
u2 JfrChunk::major_version() const { |
|
73 |
return JFR_VERSION_MAJOR; |
|
50113 | 74 |
} |
75 |
||
58101 | 76 |
u2 JfrChunk::minor_version() const { |
77 |
return JFR_VERSION_MINOR; |
|
78 |
} |
|
79 |
||
80 |
u2 JfrChunk::capabilities() const { |
|
81 |
// chunk capabilities, CompressedIntegers etc |
|
82 |
static bool compressed_integers = JfrOptionSet::compressed_integers(); |
|
83 |
return compressed_integers; |
|
84 |
} |
|
85 |
||
86 |
int64_t JfrChunk::cpu_frequency() const { |
|
87 |
static const jlong frequency = JfrTime::frequency(); |
|
88 |
return frequency; |
|
89 |
} |
|
90 |
||
91 |
void JfrChunk::set_last_checkpoint_offset(int64_t offset) { |
|
57983
a57907813a83
old object sample blob:ification and serialization support
mgronlun
parents:
53897
diff
changeset
|
92 |
_last_checkpoint_offset = offset; |
50113 | 93 |
} |
94 |
||
58101 | 95 |
int64_t JfrChunk::last_checkpoint_offset() const { |
57983
a57907813a83
old object sample blob:ification and serialization support
mgronlun
parents:
53897
diff
changeset
|
96 |
return _last_checkpoint_offset; |
50113 | 97 |
} |
98 |
||
58101 | 99 |
int64_t JfrChunk::start_ticks() const { |
100 |
assert(_start_ticks != 0, "invariant"); |
|
101 |
return _start_ticks; |
|
102 |
} |
|
103 |
||
104 |
int64_t JfrChunk::start_nanos() const { |
|
105 |
assert(_start_nanos != 0, "invariant"); |
|
106 |
return _start_nanos; |
|
107 |
} |
|
108 |
||
109 |
int64_t JfrChunk::previous_start_ticks() const { |
|
110 |
assert(_previous_start_ticks != invalid_time, "invariant"); |
|
50113 | 111 |
return _previous_start_ticks; |
112 |
} |
|
113 |
||
58101 | 114 |
int64_t JfrChunk::previous_start_nanos() const { |
115 |
assert(_previous_start_nanos != invalid_time, "invariant"); |
|
50113 | 116 |
return _previous_start_nanos; |
117 |
} |
|
118 |
||
58101 | 119 |
void JfrChunk::update_start_ticks() { |
120 |
_start_ticks = ticks_now(); |
|
50113 | 121 |
} |
122 |
||
58101 | 123 |
void JfrChunk::update_start_nanos() { |
124 |
_start_nanos = _last_update_nanos = nanos_now(); |
|
50113 | 125 |
} |
126 |
||
58101 | 127 |
void JfrChunk::update_current_nanos() { |
128 |
_last_update_nanos = nanos_now(); |
|
129 |
} |
|
130 |
||
131 |
void JfrChunk::save_current_and_update_start_ticks() { |
|
50113 | 132 |
_previous_start_ticks = _start_ticks; |
133 |
update_start_ticks(); |
|
134 |
} |
|
135 |
||
58101 | 136 |
void JfrChunk::save_current_and_update_start_nanos() { |
50113 | 137 |
_previous_start_nanos = _start_nanos; |
138 |
update_start_nanos(); |
|
139 |
} |
|
140 |
||
58101 | 141 |
void JfrChunk::set_time_stamp() { |
50113 | 142 |
save_current_and_update_start_nanos(); |
143 |
save_current_and_update_start_ticks(); |
|
144 |
} |
|
145 |
||
58101 | 146 |
int64_t JfrChunk::last_chunk_duration() const { |
147 |
assert(_previous_start_nanos != invalid_time, "invariant"); |
|
50113 | 148 |
return _start_nanos - _previous_start_nanos; |
149 |
} |
|
150 |
||
151 |
static char* copy_path(const char* path) { |
|
152 |
assert(path != NULL, "invariant"); |
|
153 |
const size_t path_len = strlen(path); |
|
154 |
char* new_path = JfrCHeapObj::new_array<char>(path_len + 1); |
|
53762 | 155 |
strncpy(new_path, path, path_len + 1); |
50113 | 156 |
return new_path; |
157 |
} |
|
158 |
||
58101 | 159 |
void JfrChunk::set_path(const char* path) { |
50113 | 160 |
if (_path != NULL) { |
161 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
162 |
_path = NULL; |
|
163 |
} |
|
164 |
if (path != NULL) { |
|
165 |
_path = copy_path(path); |
|
166 |
} |
|
167 |
} |
|
168 |
||
58101 | 169 |
const char* JfrChunk::path() const { |
50113 | 170 |
return _path; |
171 |
} |
|
58101 | 172 |
|
173 |
bool JfrChunk::is_started() const { |
|
174 |
return _start_nanos != 0; |
|
175 |
} |
|
176 |
||
177 |
bool JfrChunk::is_finished() const { |
|
178 |
return 0 == _generation; |
|
179 |
} |
|
180 |
||
181 |
int64_t JfrChunk::duration() const { |
|
182 |
assert(_last_update_nanos >= _start_nanos, "invariant"); |
|
183 |
return _last_update_nanos - _start_nanos; |
|
184 |
} |
|
185 |
||
186 |
int64_t JfrChunk::last_metadata_offset() const { |
|
187 |
return _last_metadata_offset; |
|
188 |
} |
|
189 |
||
190 |
void JfrChunk::set_last_metadata_offset(int64_t offset) { |
|
191 |
if (0 == offset) { |
|
192 |
return; |
|
193 |
} |
|
194 |
assert(offset > _last_metadata_offset, "invariant"); |
|
195 |
_last_metadata_offset = offset; |
|
196 |
} |
|
197 |
||
198 |
bool JfrChunk::has_metadata() const { |
|
199 |
return 0 != _last_metadata_offset; |
|
200 |
} |
|
201 |
||
202 |
u1 JfrChunk::generation() const { |
|
203 |
assert(_generation > 0, "invariant"); |
|
204 |
const u1 this_generation = _generation++; |
|
205 |
if (GUARD == _generation) { |
|
206 |
_generation = 1; |
|
207 |
} |
|
208 |
return this_generation; |
|
209 |
} |
|
210 |
||
211 |
u1 JfrChunk::next_generation() const { |
|
212 |
assert(_generation > 0, "invariant"); |
|
213 |
const u1 next_gen = _generation; |
|
214 |
return GUARD == next_gen ? 1 : next_gen; |
|
215 |
} |