Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/jfr/writers/jfrStreamWriterHost.inline.hpp
64442 views
1
/*
2
* Copyright (c) 2016, 2020, 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_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP
26
#define SHARE_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP
27
28
#include "jfr/jni/jfrJavaSupport.hpp"
29
#include "jfr/writers/jfrStreamWriterHost.hpp"
30
#include "runtime/os.hpp"
31
32
template <typename Adapter, typename AP>
33
StreamWriterHost<Adapter, AP>::StreamWriterHost(typename Adapter::StorageType* storage, Thread* thread) :
34
MemoryWriterHost<Adapter, AP>(storage, thread), _stream_pos(0), _fd(invalid_fd) {
35
}
36
37
template <typename Adapter, typename AP>
38
StreamWriterHost<Adapter, AP>::StreamWriterHost(typename Adapter::StorageType* storage, size_t size) :
39
MemoryWriterHost<Adapter, AP>(storage, size), _stream_pos(0), _fd(invalid_fd) {
40
}
41
42
template <typename Adapter, typename AP>
43
StreamWriterHost<Adapter, AP>::StreamWriterHost(Thread* thread) :
44
MemoryWriterHost<Adapter, AP>(thread), _stream_pos(0), _fd(invalid_fd) {
45
}
46
47
template <typename Adapter, typename AP>
48
inline int64_t StreamWriterHost<Adapter, AP>::current_stream_position() const {
49
return this->used_offset() + _stream_pos;
50
}
51
52
template <typename Adapter, typename AP>
53
inline bool StreamWriterHost<Adapter, AP>::accommodate(size_t used, size_t requested) {
54
if (used > 0) {
55
this->flush(used);
56
}
57
assert(this->used_size() == 0, "invariant");
58
if (this->available_size() >= requested) {
59
return true;
60
}
61
return StorageHost<Adapter, AP>::accommodate(0, requested);
62
}
63
64
template <typename Adapter, typename AP>
65
inline void StreamWriterHost<Adapter, AP>::write_bytes(void* dest, const void* buf, intptr_t len) {
66
assert(len >= 0, "invariant");
67
if (len > (intptr_t)this->available_size()) {
68
this->write_unbuffered(buf, len);
69
return;
70
}
71
MemoryWriterHost<Adapter, AP>::write_bytes(dest, buf, len);
72
}
73
74
template <typename Adapter, typename AP>
75
inline void StreamWriterHost<Adapter, AP>::write_bytes(const u1* buf, intptr_t len) {
76
assert(len >= 0, "invariant");
77
while (len > 0) {
78
const unsigned int nBytes = len > INT_MAX ? INT_MAX : (unsigned int)len;
79
const ssize_t num_written = (ssize_t)os::write(_fd, buf, nBytes);
80
if (errno == ENOSPC) {
81
JfrJavaSupport::abort("Failed to write to jfr stream because no space left on device", false);
82
}
83
guarantee(num_written > 0, "Nothing got written, or os::write() failed");
84
_stream_pos += num_written;
85
len -= num_written;
86
buf += num_written;
87
}
88
}
89
90
template <typename Adapter, typename AP>
91
inline void StreamWriterHost<Adapter, AP>::flush(size_t size) {
92
assert(size > 0, "invariant");
93
assert(this->is_valid(), "invariant");
94
this->write_bytes(this->start_pos(), (intptr_t)size);
95
StorageHost<Adapter, AP>::reset();
96
assert(0 == this->used_offset(), "invariant");
97
}
98
99
template <typename Adapter, typename AP>
100
inline bool StreamWriterHost<Adapter, AP>::has_valid_fd() const {
101
return invalid_fd != _fd;
102
}
103
104
template <typename Adapter, typename AP>
105
inline int64_t StreamWriterHost<Adapter, AP>::current_offset() const {
106
return current_stream_position();
107
}
108
109
template <typename Adapter, typename AP>
110
void StreamWriterHost<Adapter, AP>::seek(int64_t offset) {
111
this->flush();
112
assert(0 == this->used_offset(), "can only seek from beginning");
113
_stream_pos = os::seek_to_file_offset(_fd, offset);
114
}
115
116
template <typename Adapter, typename AP>
117
void StreamWriterHost<Adapter, AP>::flush() {
118
if (this->is_valid()) {
119
const size_t used = this->used_size();
120
if (used > 0) {
121
this->flush(used);
122
}
123
}
124
}
125
126
template <typename Adapter, typename AP>
127
void StreamWriterHost<Adapter, AP>::write_unbuffered(const void* buf, intptr_t len) {
128
this->flush();
129
assert(0 == this->used_offset(), "can only seek from beginning");
130
this->write_bytes((const u1*)buf, len);
131
}
132
133
template <typename Adapter, typename AP>
134
inline bool StreamWriterHost<Adapter, AP>::is_valid() const {
135
return has_valid_fd();
136
}
137
138
template <typename Adapter, typename AP>
139
inline void StreamWriterHost<Adapter, AP>::close_fd() {
140
assert(this->has_valid_fd(), "closing invalid fd!");
141
os::close(_fd);
142
_fd = invalid_fd;
143
}
144
145
template <typename Adapter, typename AP>
146
inline void StreamWriterHost<Adapter, AP>::reset(fio_fd fd) {
147
assert(!this->has_valid_fd(), "invariant");
148
_fd = fd;
149
_stream_pos = 0;
150
this->hard_reset();
151
}
152
153
#endif // SHARE_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP
154
155