Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/writers/jfrStreamWriterHost.inline.hpp
41149 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/writers/jfrStreamWriterHost.hpp"
29
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
guarantee(num_written > 0, "Nothing got written, or os::write() failed");
81
_stream_pos += num_written;
82
len -= num_written;
83
buf += num_written;
84
}
85
}
86
87
template <typename Adapter, typename AP>
88
inline void StreamWriterHost<Adapter, AP>::flush(size_t size) {
89
assert(size > 0, "invariant");
90
assert(this->is_valid(), "invariant");
91
this->write_bytes(this->start_pos(), (intptr_t)size);
92
StorageHost<Adapter, AP>::reset();
93
assert(0 == this->used_offset(), "invariant");
94
}
95
96
template <typename Adapter, typename AP>
97
inline bool StreamWriterHost<Adapter, AP>::has_valid_fd() const {
98
return invalid_fd != _fd;
99
}
100
101
template <typename Adapter, typename AP>
102
inline int64_t StreamWriterHost<Adapter, AP>::current_offset() const {
103
return current_stream_position();
104
}
105
106
template <typename Adapter, typename AP>
107
void StreamWriterHost<Adapter, AP>::seek(int64_t offset) {
108
this->flush();
109
assert(0 == this->used_offset(), "can only seek from beginning");
110
_stream_pos = os::seek_to_file_offset(_fd, offset);
111
}
112
113
template <typename Adapter, typename AP>
114
void StreamWriterHost<Adapter, AP>::flush() {
115
if (this->is_valid()) {
116
const size_t used = this->used_size();
117
if (used > 0) {
118
this->flush(used);
119
}
120
}
121
}
122
123
template <typename Adapter, typename AP>
124
void StreamWriterHost<Adapter, AP>::write_unbuffered(const void* buf, intptr_t len) {
125
this->flush();
126
assert(0 == this->used_offset(), "can only seek from beginning");
127
this->write_bytes((const u1*)buf, len);
128
}
129
130
template <typename Adapter, typename AP>
131
inline bool StreamWriterHost<Adapter, AP>::is_valid() const {
132
return has_valid_fd();
133
}
134
135
template <typename Adapter, typename AP>
136
inline void StreamWriterHost<Adapter, AP>::close_fd() {
137
assert(this->has_valid_fd(), "closing invalid fd!");
138
os::close(_fd);
139
_fd = invalid_fd;
140
}
141
142
template <typename Adapter, typename AP>
143
inline void StreamWriterHost<Adapter, AP>::reset(fio_fd fd) {
144
assert(!this->has_valid_fd(), "invariant");
145
_fd = fd;
146
_stream_pos = 0;
147
this->hard_reset();
148
}
149
150
#endif // SHARE_JFR_WRITERS_JFRSTREAMWRITERHOST_INLINE_HPP
151
152