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