author | mgronlun |
Wed, 30 Oct 2019 19:43:52 +0100 | |
changeset 58863 | c16ac7a2eba4 |
parent 58132 | caa25ab47aca |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
2 |
* Copyright (c) 2016, 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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
25 |
#ifndef SHARE_JFR_WRITERS_JFRWRITERHOST_INLINE_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
26 |
#define SHARE_JFR_WRITERS_JFRWRITERHOST_INLINE_HPP |
50113 | 27 |
|
28 |
#include "classfile/javaClasses.hpp" |
|
29 |
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
|
30 |
#include "jfr/recorder/service/jfrOptionSet.hpp" |
|
31 |
#include "jfr/writers/jfrEncoding.hpp" |
|
32 |
#include "jfr/writers/jfrWriterHost.hpp" |
|
33 |
#include "memory/resourceArea.hpp" |
|
34 |
#include "oops/oop.hpp" |
|
35 |
#include "oops/symbol.hpp" |
|
36 |
#include "oops/typeArrayOop.inline.hpp" |
|
37 |
||
38 |
inline bool compressed_integers() { |
|
39 |
static const bool comp_integers = JfrOptionSet::compressed_integers(); |
|
40 |
return comp_integers; |
|
41 |
} |
|
42 |
||
43 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
44 |
template <typename T> |
|
45 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_padded(T value) { |
|
46 |
write_padded(&value, 1); |
|
47 |
} |
|
48 |
||
49 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
50 |
template <typename T> |
|
51 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_padded(const T* value, size_t len) { |
|
52 |
assert(value != NULL, "invariant"); |
|
53 |
assert(len > 0, "invariant"); |
|
54 |
u1* const pos = ensure_size(sizeof(T) * len); |
|
55 |
if (pos) { |
|
56 |
this->set_current_pos(write_padded(value, len, pos)); |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
61 |
template <typename T> |
|
62 |
inline u1* WriterHost<BE, IE, WriterPolicyImpl>::write_padded(const T* value, size_t len, u1* pos) { |
|
63 |
assert(value != NULL, "invariant"); |
|
64 |
assert(len > 0, "invariant"); |
|
65 |
assert(pos != NULL, "invariant"); |
|
66 |
return _compressed_integers ? IE::write_padded(value, len, pos) : BE::write_padded(value, len, pos); |
|
67 |
} |
|
68 |
||
69 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
70 |
template <typename T> |
|
71 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write(const T* value, size_t len) { |
|
72 |
assert(value != NULL, "invariant"); |
|
73 |
assert(len > 0, "invariant"); |
|
74 |
u1* const pos = ensure_size(sizeof(T) * len); |
|
75 |
if (pos) { |
|
76 |
this->set_current_pos(write(value, len, pos)); |
|
77 |
} |
|
78 |
} |
|
79 |
||
80 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
81 |
template <typename T> |
|
82 |
inline u1* WriterHost<BE, IE, WriterPolicyImpl>::write(const T* value, size_t len, u1* pos) { |
|
83 |
assert(value != NULL, "invariant"); |
|
84 |
assert(len > 0, "invariant"); |
|
85 |
assert(pos != NULL, "invariant"); |
|
86 |
return _compressed_integers ? IE::write(value, len, pos) : BE::write(value, len, pos); |
|
87 |
} |
|
88 |
||
89 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
90 |
void WriterHost<BE, IE, WriterPolicyImpl>::write_utf8(const char* value) { |
|
91 |
if (NULL == value) { |
|
92 |
// only write encoding byte indicating NULL string |
|
93 |
write<u1>(NULL_STRING); |
|
94 |
return; |
|
95 |
} |
|
96 |
write<u1>(UTF8); // designate encoding |
|
97 |
const jint len = MIN2<jint>(max_jint, (jint)strlen(value)); |
|
98 |
write(len); |
|
99 |
if (len > 0) { |
|
100 |
be_write(value, len); |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
105 |
void WriterHost<BE, IE, WriterPolicyImpl>::write_utf16(const jchar* value, jint len) { |
|
106 |
assert(value != NULL, "invariant"); |
|
107 |
write((u1)UTF16); // designate encoding |
|
108 |
write(len); |
|
109 |
if (len > 0) { |
|
110 |
write(value, len); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
115 |
template <typename T> |
|
116 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::be_write(T value) { |
|
58863 | 117 |
be_write(&value, 1); |
50113 | 118 |
} |
119 |
||
120 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
121 |
template <typename T> |
|
122 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::be_write(const T* value, size_t len) { |
|
123 |
assert(value != NULL, "invariant"); |
|
124 |
assert(len > 0, "invariant"); |
|
125 |
u1* const pos = ensure_size(sizeof(T) * len); |
|
126 |
if (pos) { |
|
127 |
this->set_current_pos(BE::be_write(value, len, pos)); |
|
128 |
} |
|
129 |
} |
|
130 |
||
131 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
132 |
template <typename StorageType> |
|
133 |
inline WriterHost<BE, IE, WriterPolicyImpl>::WriterHost(StorageType* storage, Thread* thread) : |
|
134 |
WriterPolicyImpl(storage, thread), |
|
135 |
_compressed_integers(compressed_integers()) { |
|
136 |
} |
|
137 |
||
138 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
139 |
template <typename StorageType> |
|
140 |
inline WriterHost<BE, IE, WriterPolicyImpl>::WriterHost(StorageType* storage, size_t size) : |
|
141 |
WriterPolicyImpl(storage, size), |
|
142 |
_compressed_integers(compressed_integers()) { |
|
143 |
} |
|
144 |
||
145 |
template <typename BE, typename IE, typename WriterPolicyImpl > |
|
146 |
inline WriterHost<BE, IE, WriterPolicyImpl>::WriterHost(Thread* thread) : |
|
147 |
WriterPolicyImpl(thread), |
|
148 |
_compressed_integers(compressed_integers()) { |
|
149 |
} |
|
150 |
||
151 |
// Extra size added as a safety cushion when dimensioning memory. |
|
152 |
// With varint encoding, the worst case is |
|
153 |
// associated with writing negative values. |
|
154 |
// For example, writing a negative s1 (-1) |
|
155 |
// will encode as 0xff 0x0f (2 bytes). |
|
156 |
// In this example, the sizeof(T) == 1 and length == 1, |
|
157 |
// but the implementation will need to dimension |
|
158 |
// 2 bytes for the encoding. |
|
159 |
// Hopefully, negative values should be relatively rare. |
|
160 |
static const size_t size_safety_cushion = 1; |
|
161 |
||
162 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
163 |
inline u1* WriterHost<BE, IE, WriterPolicyImpl>::ensure_size(size_t requested) { |
|
164 |
if (!this->is_valid()) { |
|
165 |
// cancelled |
|
166 |
return NULL; |
|
167 |
} |
|
168 |
if (this->available_size() < requested + size_safety_cushion) { |
|
169 |
if (!this->accommodate(this->used_size(), requested + size_safety_cushion)) { |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
170 |
assert(!this->is_valid(), "invariant"); |
50113 | 171 |
return NULL; |
172 |
} |
|
173 |
} |
|
174 |
assert(requested + size_safety_cushion <= this->available_size(), "invariant"); |
|
175 |
return this->current_pos(); |
|
176 |
} |
|
177 |
||
178 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
179 |
template <typename T> |
|
180 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write(T value) { |
|
181 |
write(&value, 1); |
|
182 |
} |
|
183 |
||
184 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
185 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write(bool value) { |
|
186 |
be_write((u1)value); |
|
187 |
} |
|
188 |
||
189 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
190 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write(float value) { |
|
191 |
be_write(*(u4*)&(value)); |
|
192 |
} |
|
193 |
||
194 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
195 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write(double value) { |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53244
diff
changeset
|
196 |
be_write(*(u8*)&(value)); |
50113 | 197 |
} |
198 |
||
199 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
200 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write(const char* value) { |
|
201 |
// UTF-8, max_jint len |
|
202 |
write_utf8(value); |
|
203 |
} |
|
204 |
||
205 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
206 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write(char* value) { |
|
207 |
write(const_cast<const char*>(value)); |
|
208 |
} |
|
209 |
||
210 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
211 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write(jstring string) { |
|
212 |
if (string == NULL) { |
|
213 |
write<u1>(NULL_STRING); |
|
214 |
return; |
|
215 |
} |
|
216 |
const oop string_oop = JNIHandles::resolve_external_guard(string); |
|
217 |
assert(string_oop != NULL, "invariant"); |
|
218 |
const size_t length = (size_t)java_lang_String::length(string_oop); |
|
219 |
if (0 == length) { |
|
220 |
write<u1>(EMPTY_STRING); |
|
221 |
return; |
|
222 |
} |
|
223 |
const bool is_latin1_encoded = java_lang_String::is_latin1(string_oop); |
|
224 |
const typeArrayOop value = java_lang_String::value(string_oop); |
|
225 |
assert(value != NULL, "invariant"); |
|
226 |
if (is_latin1_encoded) { |
|
227 |
write<u1>(LATIN1); |
|
228 |
write<u4>((u4)length); |
|
229 |
be_write(value->byte_at_addr(0), length); |
|
230 |
} else { |
|
231 |
write<u1>(UTF16); |
|
232 |
write<u4>((u4)length); |
|
233 |
write(value->char_at_addr(0), length); |
|
234 |
} |
|
235 |
} |
|
236 |
||
237 |
template <typename Writer, typename T> |
|
238 |
inline void tag_write(Writer* w, const T* t) { |
|
239 |
assert(w != NULL, "invariant"); |
|
240 |
const traceid id = t == NULL ? 0 : JfrTraceId::use(t); |
|
241 |
w->write(id); |
|
242 |
} |
|
243 |
||
244 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
245 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const ClassLoaderData* cld) { |
|
246 |
tag_write(this, cld); |
|
247 |
} |
|
248 |
||
249 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
250 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const Klass* klass) { |
|
251 |
tag_write(this, klass); |
|
252 |
} |
|
253 |
||
254 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
255 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const Method* method) { |
|
256 |
tag_write(this, method); |
|
257 |
} |
|
258 |
||
259 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
260 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const ModuleEntry* module) { |
|
261 |
tag_write(this, module); |
|
262 |
} |
|
263 |
||
264 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
265 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const PackageEntry* package) { |
|
266 |
tag_write(this, package); |
|
267 |
} |
|
268 |
||
269 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
270 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const Symbol* symbol) { |
|
271 |
ResourceMark rm; |
|
272 |
write_utf8(symbol != NULL ? symbol->as_C_string() : NULL); |
|
273 |
} |
|
274 |
||
275 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
276 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const Ticks& time) { |
|
277 |
write((uintptr_t)JfrTime::is_ft_enabled() ? time.ft_value() : time.value()); |
|
278 |
} |
|
279 |
||
280 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
281 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const Tickspan& time) { |
|
282 |
write((uintptr_t)JfrTime::is_ft_enabled() ? time.ft_value() : time.value()); |
|
283 |
} |
|
284 |
||
285 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
286 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const JfrTicks& time) { |
|
287 |
write((uintptr_t)time.value()); |
|
288 |
} |
|
289 |
||
290 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
291 |
void WriterHost<BE, IE, WriterPolicyImpl>::write(const JfrTickspan& time) { |
|
292 |
write((uintptr_t)time.value()); |
|
293 |
} |
|
294 |
||
295 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
296 |
void WriterHost<BE, IE, WriterPolicyImpl>::bytes(const void* buf, size_t len) { |
|
297 |
u1* const pos = this->ensure_size(len); |
|
298 |
if (pos != NULL) { |
|
299 |
WriterPolicyImpl::bytes(pos, buf, len); // WriterPolicyImpl responsible for position update |
|
300 |
} |
|
301 |
} |
|
302 |
||
303 |
// UTF-8 for use with classfile/bytecodes |
|
304 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
305 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_utf8_u2_len(const char* value) { |
|
306 |
u2 len = 0; |
|
307 |
if (value != NULL) { |
|
308 |
len = MIN2<u2>(max_jushort, (u2)strlen(value)); |
|
309 |
} |
|
310 |
write(len); |
|
311 |
if (len > 0) { |
|
312 |
be_write(value, len); |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53244
diff
changeset
|
317 |
inline int64_t WriterHost<BE, IE, WriterPolicyImpl>::reserve(size_t size) { |
50113 | 318 |
if (ensure_size(size) != NULL) { |
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53244
diff
changeset
|
319 |
const int64_t reserved_offset = this->current_offset(); |
50113 | 320 |
this->set_current_pos(size); |
321 |
return reserved_offset; |
|
322 |
} |
|
323 |
this->cancel(); |
|
324 |
return 0; |
|
325 |
} |
|
326 |
||
327 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
328 |
template <typename T> |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53244
diff
changeset
|
329 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_padded_at_offset(T value, int64_t offset) { |
50113 | 330 |
if (this->is_valid()) { |
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53244
diff
changeset
|
331 |
const int64_t current = this->current_offset(); |
50113 | 332 |
this->seek(offset); |
333 |
write_padded(value); |
|
334 |
this->seek(current); // restore |
|
335 |
} |
|
336 |
} |
|
337 |
||
338 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
339 |
template <typename T> |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53244
diff
changeset
|
340 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_at_offset(T value, int64_t offset) { |
50113 | 341 |
if (this->is_valid()) { |
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53244
diff
changeset
|
342 |
const int64_t current = this->current_offset(); |
50113 | 343 |
this->seek(offset); |
344 |
write(value); |
|
345 |
this->seek(current); // restore |
|
346 |
} |
|
347 |
} |
|
348 |
||
349 |
template <typename BE, typename IE, typename WriterPolicyImpl> |
|
350 |
template <typename T> |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53244
diff
changeset
|
351 |
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_be_at_offset(T value, int64_t offset) { |
50113 | 352 |
if (this->is_valid()) { |
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
53244
diff
changeset
|
353 |
const int64_t current = this->current_offset(); |
50113 | 354 |
this->seek(offset); |
355 |
be_write(value); |
|
356 |
this->seek(current); // restore |
|
357 |
} |
|
358 |
} |
|
359 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
360 |
#endif // SHARE_JFR_WRITERS_JFRWRITERHOST_INLINE_HPP |