author | alanb |
Wed, 20 Nov 2019 08:35:53 +0000 | |
changeset 59146 | 455612b3161a |
parent 52427 | 3c6aa484536c |
child 59208 | ff7655b93101 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
59146
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
52427
diff
changeset
|
2 |
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.nio.ch; |
|
27 |
||
27937
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
28 |
import java.io.FileDescriptor; |
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
29 |
import java.io.IOException; |
2 | 30 |
|
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
49897
diff
changeset
|
31 |
import jdk.internal.access.JavaIOFileDescriptorAccess; |
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
49897
diff
changeset
|
32 |
import jdk.internal.access.SharedSecrets; |
47235
9ef10c6e67b8
8187631: Refactor FileDescriptor close implementation
rriggs
parents:
47216
diff
changeset
|
33 |
|
27937
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
34 |
class FileDispatcherImpl extends FileDispatcher { |
2 | 35 |
|
36 |
static { |
|
19607
bee007586d06
8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents:
16921
diff
changeset
|
37 |
IOUtil.load(); |
2 | 38 |
init(); |
39 |
} |
|
40 |
||
47235
9ef10c6e67b8
8187631: Refactor FileDescriptor close implementation
rriggs
parents:
47216
diff
changeset
|
41 |
private static final JavaIOFileDescriptorAccess fdAccess = |
9ef10c6e67b8
8187631: Refactor FileDescriptor close implementation
rriggs
parents:
47216
diff
changeset
|
42 |
SharedSecrets.getJavaIOFileDescriptorAccess(); |
9ef10c6e67b8
8187631: Refactor FileDescriptor close implementation
rriggs
parents:
47216
diff
changeset
|
43 |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
44 |
FileDispatcherImpl() { |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
45 |
} |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
46 |
|
2 | 47 |
int read(FileDescriptor fd, long address, int len) throws IOException { |
48 |
return read0(fd, address, len); |
|
49 |
} |
|
50 |
||
16921
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
7668
diff
changeset
|
51 |
int pread(FileDescriptor fd, long address, int len, long position) |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
7668
diff
changeset
|
52 |
throws IOException |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
7668
diff
changeset
|
53 |
{ |
2 | 54 |
return pread0(fd, address, len, position); |
55 |
} |
|
56 |
||
57 |
long readv(FileDescriptor fd, long address, int len) throws IOException { |
|
58 |
return readv0(fd, address, len); |
|
59 |
} |
|
60 |
||
61 |
int write(FileDescriptor fd, long address, int len) throws IOException { |
|
62 |
return write0(fd, address, len); |
|
63 |
} |
|
64 |
||
16921
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
7668
diff
changeset
|
65 |
int pwrite(FileDescriptor fd, long address, int len, long position) |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
7668
diff
changeset
|
66 |
throws IOException |
2 | 67 |
{ |
68 |
return pwrite0(fd, address, len, position); |
|
69 |
} |
|
70 |
||
71 |
long writev(FileDescriptor fd, long address, int len) |
|
72 |
throws IOException |
|
73 |
{ |
|
74 |
return writev0(fd, address, len); |
|
75 |
} |
|
76 |
||
49897
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
77 |
long seek(FileDescriptor fd, long offset) throws IOException { |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
78 |
return seek0(fd, offset); |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
79 |
} |
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
80 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
81 |
int force(FileDescriptor fd, boolean metaData) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
82 |
return force0(fd, metaData); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
83 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
84 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
85 |
int truncate(FileDescriptor fd, long size) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
86 |
return truncate0(fd, size); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
87 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
88 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
89 |
long size(FileDescriptor fd) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
90 |
return size0(fd); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
91 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
92 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
93 |
int lock(FileDescriptor fd, boolean blocking, long pos, long size, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
94 |
boolean shared) throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
95 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
96 |
return lock0(fd, blocking, pos, size, shared); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
97 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
98 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
99 |
void release(FileDescriptor fd, long pos, long size) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
100 |
release0(fd, pos, size); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
101 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
102 |
|
2 | 103 |
void close(FileDescriptor fd) throws IOException { |
47235
9ef10c6e67b8
8187631: Refactor FileDescriptor close implementation
rriggs
parents:
47216
diff
changeset
|
104 |
fdAccess.close(fd); |
2 | 105 |
} |
106 |
||
107 |
void preClose(FileDescriptor fd) throws IOException { |
|
108 |
preClose0(fd); |
|
109 |
} |
|
110 |
||
59146
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
52427
diff
changeset
|
111 |
void dup(FileDescriptor fd1, FileDescriptor fd2) throws IOException { |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
52427
diff
changeset
|
112 |
dup0(fd1, fd2); |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
52427
diff
changeset
|
113 |
} |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
52427
diff
changeset
|
114 |
|
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
115 |
FileDescriptor duplicateForMapping(FileDescriptor fd) { |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
116 |
// file descriptor not required for mapping operations; okay |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
117 |
// to return invalid file descriptor. |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
118 |
return new FileDescriptor(); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
119 |
} |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
120 |
|
27937
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
121 |
boolean canTransferToDirectly(java.nio.channels.SelectableChannel sc) { |
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
122 |
return true; |
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
123 |
} |
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
124 |
|
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
125 |
boolean transferToDirectlyNeedsPositionLock() { |
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
126 |
return false; |
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
127 |
} |
0c9f63e42e91
8064407: (fc) FileChannel transferTo should use TransmitFile on Windows
alanb
parents:
27263
diff
changeset
|
128 |
|
47428 | 129 |
int setDirectIO(FileDescriptor fd, String path) { |
130 |
int result = -1; |
|
131 |
try { |
|
132 |
result = setDirect0(fd); |
|
133 |
} catch (IOException e) { |
|
134 |
throw new UnsupportedOperationException |
|
135 |
("Error setting up DirectIO", e); |
|
136 |
} |
|
137 |
return result; |
|
138 |
} |
|
139 |
||
2 | 140 |
// -- Native methods -- |
141 |
||
142 |
static native int read0(FileDescriptor fd, long address, int len) |
|
143 |
throws IOException; |
|
144 |
||
145 |
static native int pread0(FileDescriptor fd, long address, int len, |
|
146 |
long position) throws IOException; |
|
147 |
||
148 |
static native long readv0(FileDescriptor fd, long address, int len) |
|
149 |
throws IOException; |
|
150 |
||
151 |
static native int write0(FileDescriptor fd, long address, int len) |
|
152 |
throws IOException; |
|
153 |
||
154 |
static native int pwrite0(FileDescriptor fd, long address, int len, |
|
155 |
long position) throws IOException; |
|
156 |
||
157 |
static native long writev0(FileDescriptor fd, long address, int len) |
|
158 |
throws IOException; |
|
159 |
||
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
160 |
static native int force0(FileDescriptor fd, boolean metaData) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
161 |
throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
162 |
|
49897
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
163 |
static native long seek0(FileDescriptor fd, long offset) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
164 |
throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
165 |
|
49897
117501815bed
8202261: (fc) FileChannel.map and RandomAccessFile.setLength should not preallocate space
alanb
parents:
47428
diff
changeset
|
166 |
static native int truncate0(FileDescriptor fd, long size) |
42447
36db92901ae9
8168628: (fc) SIGBUS when extending file size to map it
bpb
parents:
27937
diff
changeset
|
167 |
throws IOException; |
36db92901ae9
8168628: (fc) SIGBUS when extending file size to map it
bpb
parents:
27937
diff
changeset
|
168 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
169 |
static native long size0(FileDescriptor fd) throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
170 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
171 |
static native int lock0(FileDescriptor fd, boolean blocking, long pos, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
172 |
long size, boolean shared) throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
173 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
174 |
static native void release0(FileDescriptor fd, long pos, long size) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
175 |
throws IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
176 |
|
47235
9ef10c6e67b8
8187631: Refactor FileDescriptor close implementation
rriggs
parents:
47216
diff
changeset
|
177 |
// Shared with SocketDispatcher and DatagramDispatcher but |
9ef10c6e67b8
8187631: Refactor FileDescriptor close implementation
rriggs
parents:
47216
diff
changeset
|
178 |
// NOT used by FileDispatcherImpl |
2 | 179 |
static native void close0(FileDescriptor fd) throws IOException; |
180 |
||
181 |
static native void preClose0(FileDescriptor fd) throws IOException; |
|
182 |
||
59146
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
52427
diff
changeset
|
183 |
static native void dup0(FileDescriptor fd1, FileDescriptor fd2) throws IOException; |
455612b3161a
8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
alanb
parents:
52427
diff
changeset
|
184 |
|
2 | 185 |
static native void closeIntFD(int fd) throws IOException; |
186 |
||
47428 | 187 |
static native int setDirect0(FileDescriptor fd) throws IOException; |
188 |
||
2 | 189 |
static native void init(); |
190 |
||
191 |
} |