author | mgronlun |
Tue, 27 Aug 2019 12:36:05 +0200 | |
branch | JEP-349-branch |
changeset 57887 | a9cc3698a55c |
parent 57870 | 00860d9caf4d |
child 58068 | 22dab580786c |
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" |
|
57361 | 26 |
#include "jfr/recorder/repository/jfrChunk.hpp" |
57887 | 27 |
#include "jfr/recorder/service/jfrOptionSet.hpp" |
50113 | 28 |
#include "jfr/utilities/jfrTimeConverter.hpp" |
57887 | 29 |
#include "jfr/utilities/jfrTypes.hpp" |
50113 | 30 |
#include "runtime/os.inline.hpp" |
57361 | 31 |
|
32 |
static jlong nanos_now() { |
|
33 |
return os::javaTimeMillis() * JfrTimeConverter::NANOS_PER_MILLISEC; |
|
34 |
} |
|
35 |
||
36 |
static jlong ticks_now() { |
|
37 |
return JfrTicks::now(); |
|
38 |
} |
|
39 |
||
40 |
JfrChunk::JfrChunk() : |
|
50113 | 41 |
_path(NULL), |
42 |
_start_ticks(0), |
|
57361 | 43 |
_previous_start_ticks(invalid_time), |
50113 | 44 |
_start_nanos(0), |
57361 | 45 |
_previous_start_nanos(invalid_time), |
46 |
_last_update_nanos(0), |
|
47 |
_last_checkpoint_offset(0), |
|
48 |
_last_metadata_offset(0), |
|
49 |
_generation(1) {} |
|
50113 | 50 |
|
57361 | 51 |
JfrChunk::~JfrChunk() { |
50113 | 52 |
reset(); |
53 |
} |
|
54 |
||
57361 | 55 |
void JfrChunk::reset() { |
50113 | 56 |
if (_path != NULL) { |
57 |
JfrCHeapObj::free(_path, strlen(_path) + 1); |
|
58 |
_path = NULL; |
|
59 |
} |
|
57361 | 60 |
_last_checkpoint_offset = _last_metadata_offset = 0; |
61 |
_generation = 1; |
|
62 |
} |
|
63 |
||
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
|
64 |
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
|
65 |
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
|
66 |
} |
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
|
67 |
|
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
|
68 |
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
|
69 |
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
|
70 |
} |
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
|
71 |
|
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
|
72 |
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
|
73 |
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
|
74 |
} |
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 |
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
|
77 |
// 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
|
78 |
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
|
79 |
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
|
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 |
|
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 |
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
|
83 |
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
|
84 |
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
|
85 |
} |
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 |
|
57361 | 87 |
void JfrChunk::set_last_checkpoint_offset(int64_t offset) { |
88 |
_last_checkpoint_offset = offset; |
|
89 |
} |
|
90 |
||
91 |
int64_t JfrChunk::last_checkpoint_offset() const { |
|
92 |
return _last_checkpoint_offset; |
|
50113 | 93 |
} |
94 |
||
57361 | 95 |
int64_t JfrChunk::start_ticks() const { |
96 |
assert(_start_ticks != 0, "invariant"); |
|
97 |
return _start_ticks; |
|
50113 | 98 |
} |
99 |
||
57361 | 100 |
int64_t JfrChunk::start_nanos() const { |
101 |
assert(_start_nanos != 0, "invariant"); |
|
102 |
return _start_nanos; |
|
50113 | 103 |
} |
104 |
||
57361 | 105 |
int64_t JfrChunk::previous_start_ticks() const { |
106 |
assert(_previous_start_ticks != invalid_time, "invariant"); |
|
50113 | 107 |
return _previous_start_ticks; |
108 |
} |
|
109 |
||
57361 | 110 |
int64_t JfrChunk::previous_start_nanos() const { |
111 |
assert(_previous_start_nanos != invalid_time, "invariant"); |
|
50113 | 112 |
return _previous_start_nanos; |
113 |
} |
|
114 |
||
57361 | 115 |
void JfrChunk::update_start_ticks() { |
116 |
_start_ticks = ticks_now(); |
|
50113 | 117 |
} |
118 |
||
57361 | 119 |
void JfrChunk::update_start_nanos() { |
120 |
_start_nanos = _last_update_nanos = nanos_now(); |
|
50113 | 121 |
} |
122 |
||
57361 | 123 |
void JfrChunk::update() { |
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 |
||
57361 | 132 |
void JfrChunk::save_current_and_update_start_nanos() { |
50113 | 133 |
_previous_start_nanos = _start_nanos; |
134 |
update_start_nanos(); |
|
135 |
} |
|
136 |
||
57887 | 137 |
void JfrChunk::set_time_stamp() { |
50113 | 138 |
save_current_and_update_start_nanos(); |
139 |
save_current_and_update_start_ticks(); |
|
140 |
} |
|
141 |
||
57361 | 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 |
||
57361 | 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 |
||
57361 | 165 |
const char* JfrChunk::path() const { |
50113 | 166 |
return _path; |
167 |
} |
|
57361 | 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 |
bool JfrChunk::is_initial_flush() const { |
|
178 |
return 0 == _last_metadata_offset; |
|
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 |
||
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
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
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
|
215 |
} |