author | alanb |
Wed, 28 Aug 2013 15:50:03 +0100 | |
changeset 19607 | bee007586d06 |
parent 16921 | e70261f11307 |
child 21318 | 2dffe829fb18 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8539
diff
changeset
|
2 |
* Copyright (c) 2000, 2011, 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 |
||
28 |
import java.io.FileDescriptor; |
|
29 |
import java.io.IOException; |
|
30 |
import java.nio.ByteBuffer; |
|
31 |
import java.nio.MappedByteBuffer; |
|
32 |
import java.nio.channels.*; |
|
33 |
import java.util.ArrayList; |
|
34 |
import java.util.List; |
|
35 |
import java.security.AccessController; |
|
36 |
import sun.misc.Cleaner; |
|
37 |
import sun.security.action.GetPropertyAction; |
|
38 |
||
39 |
public class FileChannelImpl |
|
40 |
extends FileChannel |
|
41 |
{ |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
42 |
// Memory allocation size for mapping buffers |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
43 |
private static final long allocationGranularity; |
2 | 44 |
|
45 |
// Used to make native read and write calls |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
46 |
private final FileDispatcher nd; |
2 | 47 |
|
48 |
// File descriptor |
|
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
2
diff
changeset
|
49 |
private final FileDescriptor fd; |
2 | 50 |
|
51 |
// File access mode (immutable) |
|
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
2
diff
changeset
|
52 |
private final boolean writable; |
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
2
diff
changeset
|
53 |
private final boolean readable; |
8402
41789c995fe2
6526860: (fc) FileChannel.position returns 0 when FileOutputStream opened in append mode
alanb
parents:
7668
diff
changeset
|
54 |
private final boolean append; |
2 | 55 |
|
56 |
// Required to prevent finalization of creating stream (immutable) |
|
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
2
diff
changeset
|
57 |
private final Object parent; |
2 | 58 |
|
59 |
// Thread-safe set of IDs of native threads, for signalling |
|
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
2
diff
changeset
|
60 |
private final NativeThreadSet threads = new NativeThreadSet(2); |
2 | 61 |
|
62 |
// Lock for operations involving position and size |
|
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
2
diff
changeset
|
63 |
private final Object positionLock = new Object(); |
2 | 64 |
|
65 |
private FileChannelImpl(FileDescriptor fd, boolean readable, |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
66 |
boolean writable, boolean append, Object parent) |
2 | 67 |
{ |
68 |
this.fd = fd; |
|
69 |
this.readable = readable; |
|
70 |
this.writable = writable; |
|
8402
41789c995fe2
6526860: (fc) FileChannel.position returns 0 when FileOutputStream opened in append mode
alanb
parents:
7668
diff
changeset
|
71 |
this.append = append; |
2 | 72 |
this.parent = parent; |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
73 |
this.nd = new FileDispatcherImpl(append); |
2 | 74 |
} |
75 |
||
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
76 |
// Used by FileInputStream.getChannel() and RandomAccessFile.getChannel() |
2 | 77 |
public static FileChannel open(FileDescriptor fd, |
78 |
boolean readable, boolean writable, |
|
79 |
Object parent) |
|
80 |
{ |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
81 |
return new FileChannelImpl(fd, readable, writable, false, parent); |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
82 |
} |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
83 |
|
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
84 |
// Used by FileOutputStream.getChannel |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
85 |
public static FileChannel open(FileDescriptor fd, |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
86 |
boolean readable, boolean writable, |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
87 |
boolean append, Object parent) |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
88 |
{ |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
89 |
return new FileChannelImpl(fd, readable, writable, append, parent); |
2 | 90 |
} |
91 |
||
92 |
private void ensureOpen() throws IOException { |
|
93 |
if (!isOpen()) |
|
94 |
throw new ClosedChannelException(); |
|
95 |
} |
|
96 |
||
97 |
||
98 |
// -- Standard channel operations -- |
|
99 |
||
100 |
protected void implCloseChannel() throws IOException { |
|
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
101 |
// Release and invalidate any locks that we still hold |
2 | 102 |
if (fileLockTable != null) { |
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
103 |
for (FileLock fl: fileLockTable.removeAll()) { |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
104 |
synchronized (fl) { |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
105 |
if (fl.isValid()) { |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
106 |
nd.release(fd, fl.position(), fl.size()); |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
107 |
((FileLockImpl)fl).invalidate(); |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
108 |
} |
2 | 109 |
} |
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
110 |
} |
2 | 111 |
} |
112 |
||
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
113 |
nd.preClose(fd); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
114 |
threads.signalAndWait(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
115 |
|
2 | 116 |
if (parent != null) { |
117 |
||
118 |
// Close the fd via the parent stream's close method. The parent |
|
119 |
// will reinvoke our close method, which is defined in the |
|
120 |
// superclass AbstractInterruptibleChannel, but the isOpen logic in |
|
121 |
// that method will prevent this method from being reinvoked. |
|
122 |
// |
|
47
c8f0e41aea68
6631352: File{OutputStream,Writer} should implement atomic append mode using FILE_APPEND_DATA (win)
martin
parents:
2
diff
changeset
|
123 |
((java.io.Closeable)parent).close(); |
2 | 124 |
} else { |
125 |
nd.close(fd); |
|
126 |
} |
|
127 |
||
128 |
} |
|
129 |
||
130 |
public int read(ByteBuffer dst) throws IOException { |
|
131 |
ensureOpen(); |
|
132 |
if (!readable) |
|
133 |
throw new NonReadableChannelException(); |
|
134 |
synchronized (positionLock) { |
|
135 |
int n = 0; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
136 |
int ti = -1; |
2 | 137 |
try { |
138 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
139 |
ti = threads.add(); |
2 | 140 |
if (!isOpen()) |
141 |
return 0; |
|
142 |
do { |
|
16921
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
143 |
n = IOUtil.read(fd, dst, -1, nd); |
2 | 144 |
} while ((n == IOStatus.INTERRUPTED) && isOpen()); |
145 |
return IOStatus.normalize(n); |
|
146 |
} finally { |
|
147 |
threads.remove(ti); |
|
148 |
end(n > 0); |
|
149 |
assert IOStatus.check(n); |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
||
6301 | 154 |
public long read(ByteBuffer[] dsts, int offset, int length) |
155 |
throws IOException |
|
156 |
{ |
|
157 |
if ((offset < 0) || (length < 0) || (offset > dsts.length - length)) |
|
158 |
throw new IndexOutOfBoundsException(); |
|
2 | 159 |
ensureOpen(); |
160 |
if (!readable) |
|
161 |
throw new NonReadableChannelException(); |
|
162 |
synchronized (positionLock) { |
|
163 |
long n = 0; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
164 |
int ti = -1; |
2 | 165 |
try { |
166 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
167 |
ti = threads.add(); |
2 | 168 |
if (!isOpen()) |
169 |
return 0; |
|
170 |
do { |
|
6301 | 171 |
n = IOUtil.read(fd, dsts, offset, length, nd); |
2 | 172 |
} while ((n == IOStatus.INTERRUPTED) && isOpen()); |
173 |
return IOStatus.normalize(n); |
|
174 |
} finally { |
|
175 |
threads.remove(ti); |
|
176 |
end(n > 0); |
|
177 |
assert IOStatus.check(n); |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
public int write(ByteBuffer src) throws IOException { |
|
183 |
ensureOpen(); |
|
184 |
if (!writable) |
|
185 |
throw new NonWritableChannelException(); |
|
186 |
synchronized (positionLock) { |
|
187 |
int n = 0; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
188 |
int ti = -1; |
2 | 189 |
try { |
190 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
191 |
ti = threads.add(); |
2 | 192 |
if (!isOpen()) |
193 |
return 0; |
|
194 |
do { |
|
16921
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
195 |
n = IOUtil.write(fd, src, -1, nd); |
2 | 196 |
} while ((n == IOStatus.INTERRUPTED) && isOpen()); |
197 |
return IOStatus.normalize(n); |
|
198 |
} finally { |
|
199 |
threads.remove(ti); |
|
200 |
end(n > 0); |
|
201 |
assert IOStatus.check(n); |
|
202 |
} |
|
203 |
} |
|
204 |
} |
|
205 |
||
6301 | 206 |
public long write(ByteBuffer[] srcs, int offset, int length) |
207 |
throws IOException |
|
208 |
{ |
|
209 |
if ((offset < 0) || (length < 0) || (offset > srcs.length - length)) |
|
210 |
throw new IndexOutOfBoundsException(); |
|
2 | 211 |
ensureOpen(); |
212 |
if (!writable) |
|
213 |
throw new NonWritableChannelException(); |
|
214 |
synchronized (positionLock) { |
|
215 |
long n = 0; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
216 |
int ti = -1; |
2 | 217 |
try { |
218 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
219 |
ti = threads.add(); |
2 | 220 |
if (!isOpen()) |
221 |
return 0; |
|
222 |
do { |
|
6301 | 223 |
n = IOUtil.write(fd, srcs, offset, length, nd); |
2 | 224 |
} while ((n == IOStatus.INTERRUPTED) && isOpen()); |
225 |
return IOStatus.normalize(n); |
|
226 |
} finally { |
|
227 |
threads.remove(ti); |
|
228 |
end(n > 0); |
|
229 |
assert IOStatus.check(n); |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
||
234 |
// -- Other operations -- |
|
235 |
||
236 |
public long position() throws IOException { |
|
237 |
ensureOpen(); |
|
238 |
synchronized (positionLock) { |
|
239 |
long p = -1; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
240 |
int ti = -1; |
2 | 241 |
try { |
242 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
243 |
ti = threads.add(); |
2 | 244 |
if (!isOpen()) |
245 |
return 0; |
|
246 |
do { |
|
8402
41789c995fe2
6526860: (fc) FileChannel.position returns 0 when FileOutputStream opened in append mode
alanb
parents:
7668
diff
changeset
|
247 |
// in append-mode then position is advanced to end before writing |
41789c995fe2
6526860: (fc) FileChannel.position returns 0 when FileOutputStream opened in append mode
alanb
parents:
7668
diff
changeset
|
248 |
p = (append) ? nd.size(fd) : position0(fd, -1); |
2 | 249 |
} while ((p == IOStatus.INTERRUPTED) && isOpen()); |
250 |
return IOStatus.normalize(p); |
|
251 |
} finally { |
|
252 |
threads.remove(ti); |
|
253 |
end(p > -1); |
|
254 |
assert IOStatus.check(p); |
|
255 |
} |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
public FileChannel position(long newPosition) throws IOException { |
|
260 |
ensureOpen(); |
|
261 |
if (newPosition < 0) |
|
262 |
throw new IllegalArgumentException(); |
|
263 |
synchronized (positionLock) { |
|
264 |
long p = -1; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
265 |
int ti = -1; |
2 | 266 |
try { |
267 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
268 |
ti = threads.add(); |
2 | 269 |
if (!isOpen()) |
270 |
return null; |
|
271 |
do { |
|
272 |
p = position0(fd, newPosition); |
|
273 |
} while ((p == IOStatus.INTERRUPTED) && isOpen()); |
|
274 |
return this; |
|
275 |
} finally { |
|
276 |
threads.remove(ti); |
|
277 |
end(p > -1); |
|
278 |
assert IOStatus.check(p); |
|
279 |
} |
|
280 |
} |
|
281 |
} |
|
282 |
||
283 |
public long size() throws IOException { |
|
284 |
ensureOpen(); |
|
285 |
synchronized (positionLock) { |
|
286 |
long s = -1; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
287 |
int ti = -1; |
2 | 288 |
try { |
289 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
290 |
ti = threads.add(); |
2 | 291 |
if (!isOpen()) |
292 |
return -1; |
|
293 |
do { |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
294 |
s = nd.size(fd); |
2 | 295 |
} while ((s == IOStatus.INTERRUPTED) && isOpen()); |
296 |
return IOStatus.normalize(s); |
|
297 |
} finally { |
|
298 |
threads.remove(ti); |
|
299 |
end(s > -1); |
|
300 |
assert IOStatus.check(s); |
|
301 |
} |
|
302 |
} |
|
303 |
} |
|
304 |
||
14401
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
305 |
public FileChannel truncate(long newSize) throws IOException { |
2 | 306 |
ensureOpen(); |
14401
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
307 |
if (newSize < 0) |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
308 |
throw new IllegalArgumentException("Negative size"); |
2 | 309 |
if (!writable) |
310 |
throw new NonWritableChannelException(); |
|
311 |
synchronized (positionLock) { |
|
312 |
int rv = -1; |
|
313 |
long p = -1; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
314 |
int ti = -1; |
2 | 315 |
try { |
316 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
317 |
ti = threads.add(); |
2 | 318 |
if (!isOpen()) |
319 |
return null; |
|
320 |
||
14401
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
321 |
// get current size |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
322 |
long size; |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
323 |
do { |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
324 |
size = nd.size(fd); |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
325 |
} while ((size == IOStatus.INTERRUPTED) && isOpen()); |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
326 |
if (!isOpen()) |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
327 |
return null; |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
328 |
|
2 | 329 |
// get current position |
330 |
do { |
|
331 |
p = position0(fd, -1); |
|
332 |
} while ((p == IOStatus.INTERRUPTED) && isOpen()); |
|
333 |
if (!isOpen()) |
|
334 |
return null; |
|
335 |
assert p >= 0; |
|
336 |
||
14401
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
337 |
// truncate file if given size is less than the current size |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
338 |
if (newSize < size) { |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
339 |
do { |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
340 |
rv = nd.truncate(fd, newSize); |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
341 |
} while ((rv == IOStatus.INTERRUPTED) && isOpen()); |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
342 |
if (!isOpen()) |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
343 |
return null; |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
344 |
} |
2 | 345 |
|
14401
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
346 |
// if position is beyond new size then adjust it |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
347 |
if (p > newSize) |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
348 |
p = newSize; |
2 | 349 |
do { |
350 |
rv = (int)position0(fd, p); |
|
351 |
} while ((rv == IOStatus.INTERRUPTED) && isOpen()); |
|
352 |
return this; |
|
353 |
} finally { |
|
354 |
threads.remove(ti); |
|
355 |
end(rv > -1); |
|
356 |
assert IOStatus.check(rv); |
|
357 |
} |
|
358 |
} |
|
359 |
} |
|
360 |
||
361 |
public void force(boolean metaData) throws IOException { |
|
362 |
ensureOpen(); |
|
363 |
int rv = -1; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
364 |
int ti = -1; |
2 | 365 |
try { |
366 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
367 |
ti = threads.add(); |
2 | 368 |
if (!isOpen()) |
369 |
return; |
|
370 |
do { |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
371 |
rv = nd.force(fd, metaData); |
2 | 372 |
} while ((rv == IOStatus.INTERRUPTED) && isOpen()); |
373 |
} finally { |
|
374 |
threads.remove(ti); |
|
375 |
end(rv > -1); |
|
376 |
assert IOStatus.check(rv); |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
// Assume at first that the underlying kernel supports sendfile(); |
|
381 |
// set this to false if we find out later that it doesn't |
|
382 |
// |
|
383 |
private static volatile boolean transferSupported = true; |
|
384 |
||
385 |
// Assume that the underlying kernel sendfile() will work if the target |
|
386 |
// fd is a pipe; set this to false if we find out later that it doesn't |
|
387 |
// |
|
388 |
private static volatile boolean pipeSupported = true; |
|
389 |
||
390 |
// Assume that the underlying kernel sendfile() will work if the target |
|
391 |
// fd is a file; set this to false if we find out later that it doesn't |
|
392 |
// |
|
393 |
private static volatile boolean fileSupported = true; |
|
394 |
||
395 |
private long transferToDirectly(long position, int icount, |
|
396 |
WritableByteChannel target) |
|
397 |
throws IOException |
|
398 |
{ |
|
399 |
if (!transferSupported) |
|
400 |
return IOStatus.UNSUPPORTED; |
|
401 |
||
402 |
FileDescriptor targetFD = null; |
|
403 |
if (target instanceof FileChannelImpl) { |
|
404 |
if (!fileSupported) |
|
405 |
return IOStatus.UNSUPPORTED_CASE; |
|
406 |
targetFD = ((FileChannelImpl)target).fd; |
|
407 |
} else if (target instanceof SelChImpl) { |
|
408 |
// Direct transfer to pipe causes EINVAL on some configurations |
|
409 |
if ((target instanceof SinkChannelImpl) && !pipeSupported) |
|
410 |
return IOStatus.UNSUPPORTED_CASE; |
|
411 |
targetFD = ((SelChImpl)target).getFD(); |
|
412 |
} |
|
413 |
if (targetFD == null) |
|
414 |
return IOStatus.UNSUPPORTED; |
|
415 |
int thisFDVal = IOUtil.fdVal(fd); |
|
416 |
int targetFDVal = IOUtil.fdVal(targetFD); |
|
417 |
if (thisFDVal == targetFDVal) // Not supported on some configurations |
|
418 |
return IOStatus.UNSUPPORTED; |
|
419 |
||
420 |
long n = -1; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
421 |
int ti = -1; |
2 | 422 |
try { |
423 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
424 |
ti = threads.add(); |
2 | 425 |
if (!isOpen()) |
426 |
return -1; |
|
427 |
do { |
|
428 |
n = transferTo0(thisFDVal, position, icount, targetFDVal); |
|
429 |
} while ((n == IOStatus.INTERRUPTED) && isOpen()); |
|
430 |
if (n == IOStatus.UNSUPPORTED_CASE) { |
|
431 |
if (target instanceof SinkChannelImpl) |
|
432 |
pipeSupported = false; |
|
433 |
if (target instanceof FileChannelImpl) |
|
434 |
fileSupported = false; |
|
435 |
return IOStatus.UNSUPPORTED_CASE; |
|
436 |
} |
|
437 |
if (n == IOStatus.UNSUPPORTED) { |
|
438 |
// Don't bother trying again |
|
439 |
transferSupported = false; |
|
440 |
return IOStatus.UNSUPPORTED; |
|
441 |
} |
|
442 |
return IOStatus.normalize(n); |
|
443 |
} finally { |
|
444 |
threads.remove(ti); |
|
445 |
end (n > -1); |
|
446 |
} |
|
447 |
} |
|
448 |
||
6319
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
449 |
// Maximum size to map when using a mapped buffer |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
450 |
private static final long MAPPED_TRANSFER_SIZE = 8L*1024L*1024L; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
451 |
|
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
452 |
private long transferToTrustedChannel(long position, long count, |
2 | 453 |
WritableByteChannel target) |
454 |
throws IOException |
|
455 |
{ |
|
6319
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
456 |
boolean isSelChImpl = (target instanceof SelChImpl); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
457 |
if (!((target instanceof FileChannelImpl) || isSelChImpl)) |
2 | 458 |
return IOStatus.UNSUPPORTED; |
459 |
||
460 |
// Trusted target: Use a mapped buffer |
|
6319
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
461 |
long remaining = count; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
462 |
while (remaining > 0L) { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
463 |
long size = Math.min(remaining, MAPPED_TRANSFER_SIZE); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
464 |
try { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
465 |
MappedByteBuffer dbb = map(MapMode.READ_ONLY, position, size); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
466 |
try { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
467 |
// ## Bug: Closing this channel will not terminate the write |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
468 |
int n = target.write(dbb); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
469 |
assert n >= 0; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
470 |
remaining -= n; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
471 |
if (isSelChImpl) { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
472 |
// one attempt to write to selectable channel |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
473 |
break; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
474 |
} |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
475 |
assert n > 0; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
476 |
position += n; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
477 |
} finally { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
478 |
unmap(dbb); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
479 |
} |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
7025
diff
changeset
|
480 |
} catch (ClosedByInterruptException e) { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
7025
diff
changeset
|
481 |
// target closed by interrupt as ClosedByInterruptException needs |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
7025
diff
changeset
|
482 |
// to be thrown after closing this channel. |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
7025
diff
changeset
|
483 |
assert !target.isOpen(); |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
7025
diff
changeset
|
484 |
try { |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
7025
diff
changeset
|
485 |
close(); |
8539
eeb9fc5a68c1
7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents:
8402
diff
changeset
|
486 |
} catch (Throwable suppressed) { |
eeb9fc5a68c1
7020888: (file) Miscellaneous and trivial clean-ups (typos and opportunities to use suppressed exceptions)
alanb
parents:
8402
diff
changeset
|
487 |
e.addSuppressed(suppressed); |
7177
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
7025
diff
changeset
|
488 |
} |
0113db4feebc
6979009: (fc) FileChannel.read() fails to throw ClosedByInterruptException
alanb
parents:
7025
diff
changeset
|
489 |
throw e; |
6319
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
490 |
} catch (IOException ioe) { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
491 |
// Only throw exception if no bytes have been written |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
492 |
if (remaining == count) |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
493 |
throw ioe; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
494 |
break; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
495 |
} |
2 | 496 |
} |
6319
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
497 |
return count - remaining; |
2 | 498 |
} |
499 |
||
500 |
private long transferToArbitraryChannel(long position, int icount, |
|
501 |
WritableByteChannel target) |
|
502 |
throws IOException |
|
503 |
{ |
|
504 |
// Untrusted target: Use a newly-erased buffer |
|
505 |
int c = Math.min(icount, TRANSFER_SIZE); |
|
506 |
ByteBuffer bb = Util.getTemporaryDirectBuffer(c); |
|
507 |
long tw = 0; // Total bytes written |
|
508 |
long pos = position; |
|
509 |
try { |
|
510 |
Util.erase(bb); |
|
511 |
while (tw < icount) { |
|
512 |
bb.limit(Math.min((int)(icount - tw), TRANSFER_SIZE)); |
|
513 |
int nr = read(bb, pos); |
|
514 |
if (nr <= 0) |
|
515 |
break; |
|
516 |
bb.flip(); |
|
517 |
// ## Bug: Will block writing target if this channel |
|
518 |
// ## is asynchronously closed |
|
519 |
int nw = target.write(bb); |
|
520 |
tw += nw; |
|
521 |
if (nw != nr) |
|
522 |
break; |
|
523 |
pos += nw; |
|
524 |
bb.clear(); |
|
525 |
} |
|
526 |
return tw; |
|
527 |
} catch (IOException x) { |
|
528 |
if (tw > 0) |
|
529 |
return tw; |
|
530 |
throw x; |
|
531 |
} finally { |
|
532 |
Util.releaseTemporaryDirectBuffer(bb); |
|
533 |
} |
|
534 |
} |
|
535 |
||
536 |
public long transferTo(long position, long count, |
|
537 |
WritableByteChannel target) |
|
538 |
throws IOException |
|
539 |
{ |
|
540 |
ensureOpen(); |
|
541 |
if (!target.isOpen()) |
|
542 |
throw new ClosedChannelException(); |
|
543 |
if (!readable) |
|
544 |
throw new NonReadableChannelException(); |
|
545 |
if (target instanceof FileChannelImpl && |
|
546 |
!((FileChannelImpl)target).writable) |
|
547 |
throw new NonWritableChannelException(); |
|
548 |
if ((position < 0) || (count < 0)) |
|
549 |
throw new IllegalArgumentException(); |
|
550 |
long sz = size(); |
|
551 |
if (position > sz) |
|
552 |
return 0; |
|
553 |
int icount = (int)Math.min(count, Integer.MAX_VALUE); |
|
554 |
if ((sz - position) < icount) |
|
555 |
icount = (int)(sz - position); |
|
556 |
||
557 |
long n; |
|
558 |
||
559 |
// Attempt a direct transfer, if the kernel supports it |
|
560 |
if ((n = transferToDirectly(position, icount, target)) >= 0) |
|
561 |
return n; |
|
562 |
||
563 |
// Attempt a mapped transfer, but only to trusted channel types |
|
564 |
if ((n = transferToTrustedChannel(position, icount, target)) >= 0) |
|
565 |
return n; |
|
566 |
||
567 |
// Slow path for untrusted targets |
|
568 |
return transferToArbitraryChannel(position, icount, target); |
|
569 |
} |
|
570 |
||
571 |
private long transferFromFileChannel(FileChannelImpl src, |
|
572 |
long position, long count) |
|
573 |
throws IOException |
|
574 |
{ |
|
6545
9d2efd6ddd0c
6984545: (fc) transferFrom does not throw NonReadableChannelException when target is size 0 and non-readable
alanb
parents:
6319
diff
changeset
|
575 |
if (!src.readable) |
9d2efd6ddd0c
6984545: (fc) transferFrom does not throw NonReadableChannelException when target is size 0 and non-readable
alanb
parents:
6319
diff
changeset
|
576 |
throw new NonReadableChannelException(); |
2 | 577 |
synchronized (src.positionLock) { |
6319
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
578 |
long pos = src.position(); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
579 |
long max = Math.min(count, src.size() - pos); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
580 |
|
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
581 |
long remaining = max; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
582 |
long p = pos; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
583 |
while (remaining > 0L) { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
584 |
long size = Math.min(remaining, MAPPED_TRANSFER_SIZE); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
585 |
// ## Bug: Closing this channel will not terminate the write |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
586 |
MappedByteBuffer bb = src.map(MapMode.READ_ONLY, p, size); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
587 |
try { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
588 |
long n = write(bb, position); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
589 |
assert n > 0; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
590 |
p += n; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
591 |
position += n; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
592 |
remaining -= n; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
593 |
} catch (IOException ioe) { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
594 |
// Only throw exception if no bytes have been written |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
595 |
if (remaining == max) |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
596 |
throw ioe; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
597 |
break; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
598 |
} finally { |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
599 |
unmap(bb); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
600 |
} |
2 | 601 |
} |
6319
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
602 |
long nwritten = max - remaining; |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
603 |
src.position(pos + nwritten); |
47d9b9e70f99
6431344: (fc) FileChannel.transferTo() doesn't work if address space runs out
alanb
parents:
6301
diff
changeset
|
604 |
return nwritten; |
2 | 605 |
} |
606 |
} |
|
607 |
||
608 |
private static final int TRANSFER_SIZE = 8192; |
|
609 |
||
610 |
private long transferFromArbitraryChannel(ReadableByteChannel src, |
|
611 |
long position, long count) |
|
612 |
throws IOException |
|
613 |
{ |
|
614 |
// Untrusted target: Use a newly-erased buffer |
|
615 |
int c = (int)Math.min(count, TRANSFER_SIZE); |
|
616 |
ByteBuffer bb = Util.getTemporaryDirectBuffer(c); |
|
617 |
long tw = 0; // Total bytes written |
|
618 |
long pos = position; |
|
619 |
try { |
|
620 |
Util.erase(bb); |
|
621 |
while (tw < count) { |
|
622 |
bb.limit((int)Math.min((count - tw), (long)TRANSFER_SIZE)); |
|
623 |
// ## Bug: Will block reading src if this channel |
|
624 |
// ## is asynchronously closed |
|
625 |
int nr = src.read(bb); |
|
626 |
if (nr <= 0) |
|
627 |
break; |
|
628 |
bb.flip(); |
|
629 |
int nw = write(bb, pos); |
|
630 |
tw += nw; |
|
631 |
if (nw != nr) |
|
632 |
break; |
|
633 |
pos += nw; |
|
634 |
bb.clear(); |
|
635 |
} |
|
636 |
return tw; |
|
637 |
} catch (IOException x) { |
|
638 |
if (tw > 0) |
|
639 |
return tw; |
|
640 |
throw x; |
|
641 |
} finally { |
|
642 |
Util.releaseTemporaryDirectBuffer(bb); |
|
643 |
} |
|
644 |
} |
|
645 |
||
646 |
public long transferFrom(ReadableByteChannel src, |
|
647 |
long position, long count) |
|
648 |
throws IOException |
|
649 |
{ |
|
650 |
ensureOpen(); |
|
651 |
if (!src.isOpen()) |
|
652 |
throw new ClosedChannelException(); |
|
653 |
if (!writable) |
|
654 |
throw new NonWritableChannelException(); |
|
655 |
if ((position < 0) || (count < 0)) |
|
656 |
throw new IllegalArgumentException(); |
|
657 |
if (position > size()) |
|
658 |
return 0; |
|
659 |
if (src instanceof FileChannelImpl) |
|
660 |
return transferFromFileChannel((FileChannelImpl)src, |
|
661 |
position, count); |
|
662 |
||
663 |
return transferFromArbitraryChannel(src, position, count); |
|
664 |
} |
|
665 |
||
666 |
public int read(ByteBuffer dst, long position) throws IOException { |
|
667 |
if (dst == null) |
|
668 |
throw new NullPointerException(); |
|
669 |
if (position < 0) |
|
670 |
throw new IllegalArgumentException("Negative position"); |
|
671 |
if (!readable) |
|
672 |
throw new NonReadableChannelException(); |
|
673 |
ensureOpen(); |
|
16921
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
674 |
if (nd.needsPositionLock()) { |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
675 |
synchronized (positionLock) { |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
676 |
return readInternal(dst, position); |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
677 |
} |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
678 |
} else { |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
679 |
return readInternal(dst, position); |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
680 |
} |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
681 |
} |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
682 |
|
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
683 |
private int readInternal(ByteBuffer dst, long position) throws IOException { |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
684 |
assert !nd.needsPositionLock() || Thread.holdsLock(positionLock); |
2 | 685 |
int n = 0; |
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
686 |
int ti = -1; |
2 | 687 |
try { |
688 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
689 |
ti = threads.add(); |
2 | 690 |
if (!isOpen()) |
691 |
return -1; |
|
692 |
do { |
|
16921
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
693 |
n = IOUtil.read(fd, dst, position, nd); |
2 | 694 |
} while ((n == IOStatus.INTERRUPTED) && isOpen()); |
695 |
return IOStatus.normalize(n); |
|
696 |
} finally { |
|
697 |
threads.remove(ti); |
|
698 |
end(n > 0); |
|
699 |
assert IOStatus.check(n); |
|
700 |
} |
|
701 |
} |
|
702 |
||
703 |
public int write(ByteBuffer src, long position) throws IOException { |
|
704 |
if (src == null) |
|
705 |
throw new NullPointerException(); |
|
706 |
if (position < 0) |
|
707 |
throw new IllegalArgumentException("Negative position"); |
|
708 |
if (!writable) |
|
709 |
throw new NonWritableChannelException(); |
|
710 |
ensureOpen(); |
|
16921
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
711 |
if (nd.needsPositionLock()) { |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
712 |
synchronized (positionLock) { |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
713 |
return writeInternal(src, position); |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
714 |
} |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
715 |
} else { |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
716 |
return writeInternal(src, position); |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
717 |
} |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
718 |
} |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
719 |
|
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
720 |
private int writeInternal(ByteBuffer src, long position) throws IOException { |
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
721 |
assert !nd.needsPositionLock() || Thread.holdsLock(positionLock); |
2 | 722 |
int n = 0; |
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
723 |
int ti = -1; |
2 | 724 |
try { |
725 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
726 |
ti = threads.add(); |
2 | 727 |
if (!isOpen()) |
728 |
return -1; |
|
729 |
do { |
|
16921
e70261f11307
8012019: (fc) Thread.interrupt triggers hang in FileChannelImpl.pread (win)
alanb
parents:
14401
diff
changeset
|
730 |
n = IOUtil.write(fd, src, position, nd); |
2 | 731 |
} while ((n == IOStatus.INTERRUPTED) && isOpen()); |
732 |
return IOStatus.normalize(n); |
|
733 |
} finally { |
|
734 |
threads.remove(ti); |
|
735 |
end(n > 0); |
|
736 |
assert IOStatus.check(n); |
|
737 |
} |
|
738 |
} |
|
739 |
||
740 |
||
741 |
// -- Memory-mapped buffers -- |
|
742 |
||
743 |
private static class Unmapper |
|
744 |
implements Runnable |
|
745 |
{ |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
746 |
// may be required to close file |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
747 |
private static final NativeDispatcher nd = new FileDispatcherImpl(); |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7177
diff
changeset
|
748 |
|
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
749 |
// keep track of mapped buffer usage |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
750 |
static volatile int count; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
751 |
static volatile long totalSize; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
752 |
static volatile long totalCapacity; |
2 | 753 |
|
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
754 |
private volatile long address; |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
755 |
private final long size; |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
756 |
private final int cap; |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
757 |
private final FileDescriptor fd; |
2 | 758 |
|
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
759 |
private Unmapper(long address, long size, int cap, |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
760 |
FileDescriptor fd) |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
761 |
{ |
2 | 762 |
assert (address != 0); |
763 |
this.address = address; |
|
764 |
this.size = size; |
|
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
765 |
this.cap = cap; |
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
766 |
this.fd = fd; |
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
767 |
|
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
768 |
synchronized (Unmapper.class) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
769 |
count++; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
770 |
totalSize += size; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
771 |
totalCapacity += cap; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
772 |
} |
2 | 773 |
} |
774 |
||
775 |
public void run() { |
|
776 |
if (address == 0) |
|
777 |
return; |
|
778 |
unmap0(address, size); |
|
779 |
address = 0; |
|
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
780 |
|
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
781 |
// if this mapping has a valid file descriptor then we close it |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
782 |
if (fd.valid()) { |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
783 |
try { |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
784 |
nd.close(fd); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
785 |
} catch (IOException ignore) { |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
786 |
// nothing we can do |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
787 |
} |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
788 |
} |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
789 |
|
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
790 |
synchronized (Unmapper.class) { |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
791 |
count--; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
792 |
totalSize -= size; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
793 |
totalCapacity -= cap; |
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
794 |
} |
2 | 795 |
} |
796 |
} |
|
797 |
||
798 |
private static void unmap(MappedByteBuffer bb) { |
|
799 |
Cleaner cl = ((DirectBuffer)bb).cleaner(); |
|
800 |
if (cl != null) |
|
801 |
cl.clean(); |
|
802 |
} |
|
803 |
||
804 |
private static final int MAP_RO = 0; |
|
805 |
private static final int MAP_RW = 1; |
|
806 |
private static final int MAP_PV = 2; |
|
807 |
||
808 |
public MappedByteBuffer map(MapMode mode, long position, long size) |
|
809 |
throws IOException |
|
810 |
{ |
|
811 |
ensureOpen(); |
|
14401
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
812 |
if (mode == null) |
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
813 |
throw new NullPointerException("Mode is null"); |
2 | 814 |
if (position < 0L) |
815 |
throw new IllegalArgumentException("Negative position"); |
|
816 |
if (size < 0L) |
|
817 |
throw new IllegalArgumentException("Negative size"); |
|
818 |
if (position + size < 0) |
|
819 |
throw new IllegalArgumentException("Position + size overflow"); |
|
820 |
if (size > Integer.MAX_VALUE) |
|
821 |
throw new IllegalArgumentException("Size exceeds Integer.MAX_VALUE"); |
|
14401
1f9a8607f4df
8000330: (fc) FileChannel.truncate issues when given size > file size
alanb
parents:
9035
diff
changeset
|
822 |
|
2 | 823 |
int imode = -1; |
824 |
if (mode == MapMode.READ_ONLY) |
|
825 |
imode = MAP_RO; |
|
826 |
else if (mode == MapMode.READ_WRITE) |
|
827 |
imode = MAP_RW; |
|
828 |
else if (mode == MapMode.PRIVATE) |
|
829 |
imode = MAP_PV; |
|
830 |
assert (imode >= 0); |
|
831 |
if ((mode != MapMode.READ_ONLY) && !writable) |
|
832 |
throw new NonWritableChannelException(); |
|
833 |
if (!readable) |
|
834 |
throw new NonReadableChannelException(); |
|
835 |
||
836 |
long addr = -1; |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
837 |
int ti = -1; |
2 | 838 |
try { |
839 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
840 |
ti = threads.add(); |
2 | 841 |
if (!isOpen()) |
842 |
return null; |
|
843 |
if (size() < position + size) { // Extend file size |
|
844 |
if (!writable) { |
|
845 |
throw new IOException("Channel not open for writing " + |
|
846 |
"- cannot extend file to required size"); |
|
847 |
} |
|
848 |
int rv; |
|
849 |
do { |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
850 |
rv = nd.truncate(fd, position + size); |
2 | 851 |
} while ((rv == IOStatus.INTERRUPTED) && isOpen()); |
852 |
} |
|
853 |
if (size == 0) { |
|
854 |
addr = 0; |
|
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
855 |
// a valid file descriptor is not required |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
856 |
FileDescriptor dummy = new FileDescriptor(); |
2 | 857 |
if ((!writable) || (imode == MAP_RO)) |
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
858 |
return Util.newMappedByteBufferR(0, 0, dummy, null); |
2 | 859 |
else |
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
860 |
return Util.newMappedByteBuffer(0, 0, dummy, null); |
2 | 861 |
} |
862 |
||
863 |
int pagePosition = (int)(position % allocationGranularity); |
|
864 |
long mapPosition = position - pagePosition; |
|
865 |
long mapSize = size + pagePosition; |
|
866 |
try { |
|
867 |
// If no exception was thrown from map0, the address is valid |
|
868 |
addr = map0(imode, mapPosition, mapSize); |
|
869 |
} catch (OutOfMemoryError x) { |
|
870 |
// An OutOfMemoryError may indicate that we've exhausted memory |
|
871 |
// so force gc and re-attempt map |
|
872 |
System.gc(); |
|
873 |
try { |
|
874 |
Thread.sleep(100); |
|
875 |
} catch (InterruptedException y) { |
|
876 |
Thread.currentThread().interrupt(); |
|
877 |
} |
|
878 |
try { |
|
879 |
addr = map0(imode, mapPosition, mapSize); |
|
880 |
} catch (OutOfMemoryError y) { |
|
881 |
// After a second OOME, fail |
|
882 |
throw new IOException("Map failed", y); |
|
883 |
} |
|
884 |
} |
|
885 |
||
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
886 |
// On Windows, and potentially other platforms, we need an open |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
887 |
// file descriptor for some mapping operations. |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
888 |
FileDescriptor mfd; |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
889 |
try { |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
890 |
mfd = nd.duplicateForMapping(fd); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
891 |
} catch (IOException ioe) { |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
892 |
unmap0(addr, mapSize); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
893 |
throw ioe; |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
894 |
} |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
895 |
|
2 | 896 |
assert (IOStatus.checkAll(addr)); |
897 |
assert (addr % allocationGranularity == 0); |
|
898 |
int isize = (int)size; |
|
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
899 |
Unmapper um = new Unmapper(addr, mapSize, isize, mfd); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
900 |
if ((!writable) || (imode == MAP_RO)) { |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
901 |
return Util.newMappedByteBufferR(isize, |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
902 |
addr + pagePosition, |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
903 |
mfd, |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
904 |
um); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
905 |
} else { |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
906 |
return Util.newMappedByteBuffer(isize, |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
907 |
addr + pagePosition, |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
908 |
mfd, |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
909 |
um); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
6545
diff
changeset
|
910 |
} |
2 | 911 |
} finally { |
912 |
threads.remove(ti); |
|
913 |
end(IOStatus.checkAll(addr)); |
|
914 |
} |
|
915 |
} |
|
916 |
||
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
917 |
/** |
3066
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
918 |
* Invoked by sun.management.ManagementFactoryHelper to create the management |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
919 |
* interface for mapped buffers. |
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
920 |
*/ |
3066
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
921 |
public static sun.misc.JavaNioAccess.BufferPool getMappedBufferPool() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
922 |
return new sun.misc.JavaNioAccess.BufferPool() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
923 |
@Override |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
924 |
public String getName() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
925 |
return "mapped"; |
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
926 |
} |
3066
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
927 |
@Override |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
928 |
public long getCount() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
929 |
return Unmapper.count; |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
930 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
931 |
@Override |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
932 |
public long getTotalCapacity() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
933 |
return Unmapper.totalCapacity; |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
934 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
935 |
@Override |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
936 |
public long getMemoryUsed() { |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
937 |
return Unmapper.totalSize; |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
938 |
} |
cd3861104f4d
6844054: (bf) Eliminate dependency on javax.management.ObjectName
alanb
parents:
2594
diff
changeset
|
939 |
}; |
1143
645d4b930f93
6682020: (bf) Support monitoring of direct and mapped buffer usage
alanb
parents:
715
diff
changeset
|
940 |
} |
2 | 941 |
|
942 |
// -- Locks -- |
|
943 |
||
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
944 |
|
2 | 945 |
|
946 |
// keeps track of locks on this file |
|
947 |
private volatile FileLockTable fileLockTable; |
|
948 |
||
949 |
// indicates if file locks are maintained system-wide (as per spec) |
|
950 |
private static boolean isSharedFileLockTable; |
|
951 |
||
952 |
// indicates if the disableSystemWideOverlappingFileLockCheck property |
|
953 |
// has been checked |
|
954 |
private static volatile boolean propertyChecked; |
|
955 |
||
956 |
// The lock list in J2SE 1.4/5.0 was local to each FileChannel instance so |
|
957 |
// the overlap check wasn't system wide when there were multiple channels to |
|
958 |
// the same file. This property is used to get 1.4/5.0 behavior if desired. |
|
959 |
private static boolean isSharedFileLockTable() { |
|
960 |
if (!propertyChecked) { |
|
961 |
synchronized (FileChannelImpl.class) { |
|
962 |
if (!propertyChecked) { |
|
963 |
String value = AccessController.doPrivileged( |
|
964 |
new GetPropertyAction( |
|
965 |
"sun.nio.ch.disableSystemWideOverlappingFileLockCheck")); |
|
966 |
isSharedFileLockTable = ((value == null) || value.equals("false")); |
|
967 |
propertyChecked = true; |
|
968 |
} |
|
969 |
} |
|
970 |
} |
|
971 |
return isSharedFileLockTable; |
|
972 |
} |
|
973 |
||
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
974 |
private FileLockTable fileLockTable() throws IOException { |
2 | 975 |
if (fileLockTable == null) { |
976 |
synchronized (this) { |
|
977 |
if (fileLockTable == null) { |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
978 |
if (isSharedFileLockTable()) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
979 |
int ti = threads.add(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
980 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
981 |
ensureOpen(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
982 |
fileLockTable = FileLockTable.newSharedFileLockTable(this, fd); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
983 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
984 |
threads.remove(ti); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
985 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
986 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
987 |
fileLockTable = new SimpleFileLockTable(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
988 |
} |
2 | 989 |
} |
990 |
} |
|
991 |
} |
|
992 |
return fileLockTable; |
|
993 |
} |
|
994 |
||
995 |
public FileLock lock(long position, long size, boolean shared) |
|
996 |
throws IOException |
|
997 |
{ |
|
998 |
ensureOpen(); |
|
999 |
if (shared && !readable) |
|
1000 |
throw new NonReadableChannelException(); |
|
1001 |
if (!shared && !writable) |
|
1002 |
throw new NonWritableChannelException(); |
|
1003 |
FileLockImpl fli = new FileLockImpl(this, position, size, shared); |
|
1004 |
FileLockTable flt = fileLockTable(); |
|
1005 |
flt.add(fli); |
|
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1006 |
boolean completed = false; |
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
1007 |
int ti = -1; |
2 | 1008 |
try { |
1009 |
begin(); |
|
2441
228c040622a2
6824135: (ch) test/java/nio/channels/AsyncCloseAndInterrupt.java fails (lnx)
alanb
parents:
2057
diff
changeset
|
1010 |
ti = threads.add(); |
2 | 1011 |
if (!isOpen()) |
1012 |
return null; |
|
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1013 |
int n; |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1014 |
do { |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1015 |
n = nd.lock(fd, true, position, size, shared); |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1016 |
} while ((n == FileDispatcher.INTERRUPTED) && isOpen()); |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1017 |
if (isOpen()) { |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1018 |
if (n == FileDispatcher.RET_EX_LOCK) { |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1019 |
assert shared; |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1020 |
FileLockImpl fli2 = new FileLockImpl(this, position, size, |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1021 |
false); |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1022 |
flt.replace(fli, fli2); |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1023 |
fli = fli2; |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1024 |
} |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1025 |
completed = true; |
2 | 1026 |
} |
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1027 |
} finally { |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1028 |
if (!completed) |
2 | 1029 |
flt.remove(fli); |
1030 |
threads.remove(ti); |
|
1031 |
try { |
|
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1032 |
end(completed); |
2 | 1033 |
} catch (ClosedByInterruptException e) { |
1034 |
throw new FileLockInterruptionException(); |
|
1035 |
} |
|
1036 |
} |
|
1037 |
return fli; |
|
1038 |
} |
|
1039 |
||
1040 |
public FileLock tryLock(long position, long size, boolean shared) |
|
1041 |
throws IOException |
|
1042 |
{ |
|
1043 |
ensureOpen(); |
|
1044 |
if (shared && !readable) |
|
1045 |
throw new NonReadableChannelException(); |
|
1046 |
if (!shared && !writable) |
|
1047 |
throw new NonWritableChannelException(); |
|
1048 |
FileLockImpl fli = new FileLockImpl(this, position, size, shared); |
|
1049 |
FileLockTable flt = fileLockTable(); |
|
1050 |
flt.add(fli); |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1051 |
int result; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1052 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1053 |
int ti = threads.add(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1054 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1055 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1056 |
ensureOpen(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1057 |
result = nd.lock(fd, false, position, size, shared); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1058 |
} catch (IOException e) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1059 |
flt.remove(fli); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1060 |
throw e; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1061 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1062 |
if (result == FileDispatcher.NO_LOCK) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1063 |
flt.remove(fli); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1064 |
return null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1065 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1066 |
if (result == FileDispatcher.RET_EX_LOCK) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1067 |
assert shared; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1068 |
FileLockImpl fli2 = new FileLockImpl(this, position, size, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1069 |
false); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1070 |
flt.replace(fli, fli2); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1071 |
return fli2; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1072 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1073 |
return fli; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1074 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1075 |
threads.remove(ti); |
2 | 1076 |
} |
1077 |
} |
|
1078 |
||
1079 |
void release(FileLockImpl fli) throws IOException { |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1080 |
int ti = threads.add(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1081 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1082 |
ensureOpen(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1083 |
nd.release(fd, fli.position(), fli.size()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1084 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1085 |
threads.remove(ti); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1086 |
} |
2 | 1087 |
assert fileLockTable != null; |
1088 |
fileLockTable.remove(fli); |
|
1089 |
} |
|
1090 |
||
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1091 |
// -- File lock support -- |
2 | 1092 |
|
1093 |
/** |
|
1094 |
* A simple file lock table that maintains a list of FileLocks obtained by a |
|
1095 |
* FileChannel. Use to get 1.4/5.0 behaviour. |
|
1096 |
*/ |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1821
diff
changeset
|
1097 |
private static class SimpleFileLockTable extends FileLockTable { |
2 | 1098 |
// synchronize on list for access |
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1099 |
private final List<FileLock> lockList = new ArrayList<FileLock>(2); |
2 | 1100 |
|
1101 |
public SimpleFileLockTable() { |
|
1102 |
} |
|
1103 |
||
1104 |
private void checkList(long position, long size) |
|
1105 |
throws OverlappingFileLockException |
|
1106 |
{ |
|
1107 |
assert Thread.holdsLock(lockList); |
|
1108 |
for (FileLock fl: lockList) { |
|
1109 |
if (fl.overlaps(position, size)) { |
|
1110 |
throw new OverlappingFileLockException(); |
|
1111 |
} |
|
1112 |
} |
|
1113 |
} |
|
1114 |
||
1115 |
public void add(FileLock fl) throws OverlappingFileLockException { |
|
1116 |
synchronized (lockList) { |
|
1117 |
checkList(fl.position(), fl.size()); |
|
1118 |
lockList.add(fl); |
|
1119 |
} |
|
1120 |
} |
|
1121 |
||
1122 |
public void remove(FileLock fl) { |
|
1123 |
synchronized (lockList) { |
|
1124 |
lockList.remove(fl); |
|
1125 |
} |
|
1126 |
} |
|
1127 |
||
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1128 |
public List<FileLock> removeAll() { |
2 | 1129 |
synchronized(lockList) { |
2594
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1130 |
List<FileLock> result = new ArrayList<FileLock>(lockList); |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1131 |
lockList.clear(); |
3755ecdb395d
6543863: (fc) FileLock.release can deadlock with FileChannel.close
alanb
parents:
2441
diff
changeset
|
1132 |
return result; |
2 | 1133 |
} |
1134 |
} |
|
1135 |
||
1136 |
public void replace(FileLock fl1, FileLock fl2) { |
|
1137 |
synchronized (lockList) { |
|
1138 |
lockList.remove(fl1); |
|
1139 |
lockList.add(fl2); |
|
1140 |
} |
|
1141 |
} |
|
1142 |
} |
|
1143 |
||
1144 |
// -- Native methods -- |
|
1145 |
||
1146 |
// Creates a new mapping |
|
1147 |
private native long map0(int prot, long position, long length) |
|
1148 |
throws IOException; |
|
1149 |
||
1150 |
// Removes an existing mapping |
|
1151 |
private static native int unmap0(long address, long length); |
|
1152 |
||
1153 |
// Transfers from src to dst, or returns -2 if kernel can't do that |
|
1154 |
private native long transferTo0(int src, long position, long count, int dst); |
|
1155 |
||
1156 |
// Sets or reports this file's position |
|
1157 |
// If offset is -1, the current position is returned |
|
1158 |
// otherwise the position is set to offset |
|
1159 |
private native long position0(FileDescriptor fd, long offset); |
|
1160 |
||
1161 |
// Caches fieldIDs |
|
1162 |
private static native long initIDs(); |
|
1163 |
||
1164 |
static { |
|
19607
bee007586d06
8022594: Potential deadlock in <clinit> of sun.nio.ch.Util/IOUtil
alanb
parents:
16921
diff
changeset
|
1165 |
IOUtil.load(); |
2 | 1166 |
allocationGranularity = initIDs(); |
1167 |
} |
|
1168 |
||
1169 |
} |