-
Bug
-
Resolution: Fixed
-
P4
-
11, 17, 21, 22
-
b16
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8317533 | 21.0.2 | Brian Burkhalter | P4 | Resolved | Fixed | b02 |
JDK-8355053 | 17.0.16 | Victor Rudometov | P4 | Resolved | Fixed | master |
```
try (FileChannel fc = FileChannel.open(file, CREATE, WRITE)) {
OutputStream out = Channels.newOutputStream(fc);
byte[] b = new byte[10*1024*1024];
out.write(b);
}
```
This will invoke FileChannel.write with a BB that is backed by the byte array, this needs to be copied into a direct buffer to do the actual I/O. In this case, it will allocate a temporary direct buffer of 10Mb.
There is an argument that the channel implementations should limit their direct memory usage but these are low-level classes. It may be better to limit the writes to the channels instead, e.g. ChannelOutputStream.writeFully could be work like this:
```
private void writeFully(ByteBuffer bb) throws IOException {
int pos = bb.position();
int rem = bb.limit() - pos;
while (rem > 0) {
bb.limit(pos + Integer.min(rem, DEFAULT_BUFFER_SIZE));
int n = ch.write(bb);
if (n <= 0)
throw new RuntimeException("no bytes written");
pos += n;
rem -=n;
}
}
```
- backported by
-
JDK-8317533 ByteArrayInputStream.transferTo causes MaxDirectMemorySize overflow
-
- Resolved
-
-
JDK-8355053 ByteArrayInputStream.transferTo causes MaxDirectMemorySize overflow
-
- Resolved
-
- caused by
-
JDK-8180451 ByteArrayInputStream should override readAllBytes, readNBytes, and transferTo
-
- Resolved
-
- links to
-
Commit openjdk/jdk21u/834c45cc
-
Commit openjdk/jdk/5cacf212
-
Commit(master) openjdk/jdk17u-dev/9bad4b45
-
Review openjdk/jdk21u/227
-
Review openjdk/jdk/15733
-
Review(master) openjdk/jdk17u-dev/3507