Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/writers/jfrWriterHost.inline.hpp
38920 views
1
/*
2
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
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
#ifndef SHARE_VM_JFR_WRITERS_JFRWRITERHOST_INLINE_HPP
26
#define SHARE_VM_JFR_WRITERS_JFRWRITERHOST_INLINE_HPP
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
37
inline bool compressed_integers() {
38
static const bool comp_integers = JfrOptionSet::compressed_integers();
39
return comp_integers;
40
}
41
42
template <typename BE, typename IE, typename WriterPolicyImpl >
43
template <typename T>
44
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_padded(T value) {
45
write_padded(&value, 1);
46
}
47
48
template <typename BE, typename IE, typename WriterPolicyImpl >
49
template <typename T>
50
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_padded(const T* value, size_t len) {
51
assert(value != NULL, "invariant");
52
assert(len > 0, "invariant");
53
u1* const pos = ensure_size(sizeof(T) * len);
54
if (pos) {
55
this->set_current_pos(write_padded(value, len, pos));
56
}
57
}
58
59
template <typename BE, typename IE, typename WriterPolicyImpl >
60
template <typename T>
61
inline u1* WriterHost<BE, IE, WriterPolicyImpl>::write_padded(const T* value, size_t len, u1* pos) {
62
assert(value != NULL, "invariant");
63
assert(len > 0, "invariant");
64
assert(pos != NULL, "invariant");
65
return _compressed_integers ? IE::write_padded(value, len, pos) : BE::write_padded(value, len, pos);
66
}
67
68
template <typename BE, typename IE, typename WriterPolicyImpl >
69
template <typename T>
70
inline void WriterHost<BE, IE, WriterPolicyImpl>::write(const T* value, size_t len) {
71
assert(value != NULL, "invariant");
72
assert(len > 0, "invariant");
73
// Might need T + 1 size
74
u1* const pos = ensure_size(sizeof(T) * len + 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) {
117
u1* const pos = ensure_size(sizeof(T));
118
if (pos) {
119
this->set_current_pos(BE::be_write(&value, 1, pos));
120
}
121
}
122
123
template <typename BE, typename IE, typename WriterPolicyImpl >
124
template <typename T>
125
inline void WriterHost<BE, IE, WriterPolicyImpl>::be_write(const T* value, size_t len) {
126
assert(value != NULL, "invariant");
127
assert(len > 0, "invariant");
128
// Might need T + 1 size
129
u1* const pos = ensure_size(sizeof(T) * len + len);
130
if (pos) {
131
this->set_current_pos(BE::be_write(value, len, pos));
132
}
133
}
134
135
template <typename BE, typename IE, typename WriterPolicyImpl >
136
template <typename StorageType>
137
inline WriterHost<BE, IE, WriterPolicyImpl>::WriterHost(StorageType* storage, Thread* thread) :
138
WriterPolicyImpl(storage, thread),
139
_compressed_integers(compressed_integers()) {
140
}
141
142
// Extra size added as a safety cushion when dimensioning memory.
143
// With varint encoding, the worst case is
144
// associated with writing negative values.
145
// For example, writing a negative s1 (-1)
146
// will encode as 0xff 0x0f (2 bytes).
147
static const size_t size_safety_cushion = 1;
148
149
template <typename BE, typename IE, typename WriterPolicyImpl >
150
template <typename StorageType>
151
inline WriterHost<BE, IE, WriterPolicyImpl>::WriterHost(StorageType* storage, size_t size) :
152
WriterPolicyImpl(storage, size + size_safety_cushion),
153
_compressed_integers(compressed_integers()) {
154
}
155
156
template <typename BE, typename IE, typename WriterPolicyImpl >
157
inline WriterHost<BE, IE, WriterPolicyImpl>::WriterHost(Thread* thread) :
158
WriterPolicyImpl(thread),
159
_compressed_integers(compressed_integers()) {
160
}
161
162
template <typename BE, typename IE, typename WriterPolicyImpl>
163
inline u1* WriterHost<BE, IE, WriterPolicyImpl>::ensure_size(size_t requested_size) {
164
if (!this->is_valid()) {
165
// cancelled
166
return NULL;
167
}
168
if (this->available_size() < requested_size) {
169
if (!this->accommodate(this->used_size(), requested_size)) {
170
this->cancel();
171
return NULL;
172
}
173
}
174
assert(requested_size <= 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) {
196
be_write(*(u8*)&(value));
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 = false;
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 Symbol* symbol) {
261
ResourceMark rm;
262
write_utf8(symbol != NULL ? symbol->as_C_string() : NULL);
263
}
264
265
template <typename BE, typename IE, typename WriterPolicyImpl>
266
void WriterHost<BE, IE, WriterPolicyImpl>::write(const Ticks& time) {
267
write((u8)JfrTime::is_ft_enabled() ? time.ft_value() : time.value());
268
}
269
270
template <typename BE, typename IE, typename WriterPolicyImpl>
271
void WriterHost<BE, IE, WriterPolicyImpl>::write(const Tickspan& time) {
272
write((u8)JfrTime::is_ft_enabled() ? time.ft_value() : time.value());
273
}
274
275
template <typename BE, typename IE, typename WriterPolicyImpl>
276
void WriterHost<BE, IE, WriterPolicyImpl>::write(const JfrTicks& time) {
277
write((u8)time.value());
278
}
279
280
template <typename BE, typename IE, typename WriterPolicyImpl>
281
void WriterHost<BE, IE, WriterPolicyImpl>::write(const JfrTickspan& time) {
282
write((u8)time.value());
283
}
284
285
template <typename BE, typename IE, typename WriterPolicyImpl>
286
void WriterHost<BE, IE, WriterPolicyImpl>::bytes(const void* buf, size_t len) {
287
u1* const pos = this->ensure_size(len);
288
if (pos != NULL) {
289
WriterPolicyImpl::bytes(pos, buf, len); // WriterPolicyImpl responsible for position update
290
}
291
}
292
293
// UTF-8 for use with classfile/bytecodes
294
template <typename BE, typename IE, typename WriterPolicyImpl>
295
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_utf8_u2_len(const char* value) {
296
u2 len = 0;
297
if (value != NULL) {
298
len = MIN2<u2>(max_jushort, (u2)strlen(value));
299
}
300
write(len);
301
if (len > 0) {
302
be_write(value, len);
303
}
304
}
305
306
template <typename BE, typename IE, typename WriterPolicyImpl>
307
inline int64_t WriterHost<BE, IE, WriterPolicyImpl>::reserve(size_t size) {
308
if (ensure_size(size) != NULL) {
309
const int64_t reserved_offset = this->current_offset();
310
this->set_current_pos(size);
311
return reserved_offset;
312
}
313
this->cancel();
314
return 0;
315
}
316
317
template <typename BE, typename IE, typename WriterPolicyImpl>
318
template <typename T>
319
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_padded_at_offset(T value, int64_t offset) {
320
if (this->is_valid()) {
321
const int64_t current = this->current_offset();
322
this->seek(offset);
323
write_padded(value);
324
this->seek(current); // restore
325
}
326
}
327
328
template <typename BE, typename IE, typename WriterPolicyImpl>
329
template <typename T>
330
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_at_offset(T value, int64_t offset) {
331
if (this->is_valid()) {
332
const int64_t current = this->current_offset();
333
this->seek(offset);
334
write(value);
335
this->seek(current); // restore
336
}
337
}
338
339
template <typename BE, typename IE, typename WriterPolicyImpl>
340
template <typename T>
341
inline void WriterHost<BE, IE, WriterPolicyImpl>::write_be_at_offset(T value, int64_t offset) {
342
if (this->is_valid()) {
343
const int64_t current = this->current_offset();
344
this->seek(offset);
345
be_write(value);
346
this->seek(current); // restore
347
}
348
}
349
350
#endif // SHARE_VM_JFR_WRITERS_JFRWRITERHOST_INLINE_HPP
351
352
353