Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/nio/ch/FileDispatcherImpl.java
32288 views
1
/*
2
* Copyright (c) 2000, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.nio.ch;
27
28
import java.io.FileDescriptor;
29
import java.io.IOException;
30
import java.security.PrivilegedAction;
31
import sun.misc.SharedSecrets;
32
import sun.misc.JavaIOFileDescriptorAccess;
33
34
class FileDispatcherImpl extends FileDispatcher {
35
36
// set to true if fast file transmission (TransmitFile) is enabled
37
private static final boolean fastFileTransfer;
38
39
/**
40
* Indicates if the dispatcher should first advance the file position
41
* to the end of file when writing.
42
*/
43
private final boolean append;
44
45
FileDispatcherImpl(boolean append) {
46
this.append = append;
47
}
48
49
FileDispatcherImpl() {
50
this(false);
51
}
52
53
@Override
54
boolean needsPositionLock() {
55
return true;
56
}
57
58
int read(FileDescriptor fd, long address, int len)
59
throws IOException
60
{
61
return read0(fd, address, len);
62
}
63
64
int pread(FileDescriptor fd, long address, int len, long position)
65
throws IOException
66
{
67
return pread0(fd, address, len, position);
68
}
69
70
long readv(FileDescriptor fd, long address, int len) throws IOException {
71
return readv0(fd, address, len);
72
}
73
74
int write(FileDescriptor fd, long address, int len) throws IOException {
75
return write0(fd, address, len, append);
76
}
77
78
int pwrite(FileDescriptor fd, long address, int len, long position)
79
throws IOException
80
{
81
return pwrite0(fd, address, len, position);
82
}
83
84
long writev(FileDescriptor fd, long address, int len) throws IOException {
85
return writev0(fd, address, len, append);
86
}
87
88
long seek(FileDescriptor fd, long offset) throws IOException {
89
return seek0(fd, offset);
90
}
91
92
int force(FileDescriptor fd, boolean metaData) throws IOException {
93
return force0(fd, metaData);
94
}
95
96
int truncate(FileDescriptor fd, long size) throws IOException {
97
return truncate0(fd, size);
98
}
99
100
long size(FileDescriptor fd) throws IOException {
101
return size0(fd);
102
}
103
104
int lock(FileDescriptor fd, boolean blocking, long pos, long size,
105
boolean shared) throws IOException
106
{
107
return lock0(fd, blocking, pos, size, shared);
108
}
109
110
void release(FileDescriptor fd, long pos, long size) throws IOException {
111
release0(fd, pos, size);
112
}
113
114
void close(FileDescriptor fd) throws IOException {
115
close0(fd);
116
}
117
118
FileDescriptor duplicateForMapping(FileDescriptor fd) throws IOException {
119
// on Windows we need to keep a handle to the file
120
JavaIOFileDescriptorAccess fdAccess =
121
SharedSecrets.getJavaIOFileDescriptorAccess();
122
FileDescriptor result = new FileDescriptor();
123
long handle = duplicateHandle(fdAccess.getHandle(fd));
124
fdAccess.setHandle(result, handle);
125
return result;
126
}
127
128
boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) {
129
return fastFileTransfer && sc.isBlocking();
130
}
131
132
boolean transferToDirectlyNeedsPositionLock() {
133
return true;
134
}
135
136
static boolean isFastFileTransferRequested() {
137
String fileTransferProp = java.security.AccessController.doPrivileged(
138
new PrivilegedAction<String>() {
139
@Override
140
public String run() {
141
return System.getProperty("jdk.nio.enableFastFileTransfer");
142
}
143
});
144
boolean enable;
145
if ("".equals(fileTransferProp)) {
146
enable = true;
147
} else {
148
enable = Boolean.parseBoolean(fileTransferProp);
149
}
150
return enable;
151
}
152
153
static {
154
IOUtil.load();
155
fastFileTransfer = isFastFileTransferRequested();
156
}
157
158
//-- Native methods
159
160
static native int read0(FileDescriptor fd, long address, int len)
161
throws IOException;
162
163
static native int pread0(FileDescriptor fd, long address, int len,
164
long position) throws IOException;
165
166
static native long readv0(FileDescriptor fd, long address, int len)
167
throws IOException;
168
169
static native int write0(FileDescriptor fd, long address, int len, boolean append)
170
throws IOException;
171
172
static native int pwrite0(FileDescriptor fd, long address, int len,
173
long position) throws IOException;
174
175
static native long writev0(FileDescriptor fd, long address, int len, boolean append)
176
throws IOException;
177
178
static native long seek0(FileDescriptor fd, long offset) throws IOException;
179
180
static native int force0(FileDescriptor fd, boolean metaData)
181
throws IOException;
182
183
static native int truncate0(FileDescriptor fd, long size)
184
throws IOException;
185
186
static native long size0(FileDescriptor fd) throws IOException;
187
188
static native int lock0(FileDescriptor fd, boolean blocking, long pos,
189
long size, boolean shared) throws IOException;
190
191
static native void release0(FileDescriptor fd, long pos, long size)
192
throws IOException;
193
194
static native void close0(FileDescriptor fd) throws IOException;
195
196
static native void closeByHandle(long fd) throws IOException;
197
198
static native long duplicateHandle(long fd) throws IOException;
199
}
200
201