JDK-4884817 : (fs) OutOfMemoryError thrown on very large writes
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,solaris_9
  • CPU: generic,sparc
  • Submitted: 2003-06-27
  • Updated: 2012-10-11
  • Resolved: 2003-08-23
Related Reports
Duplicate :  
Description
1. When I ran the 50MB persistence stress test with both j2sdk1.4.1_03 & j2sdk1.4.2 with the same parameters,
	i.e. rununixtest.sh 7<no. of clients> 7<no. of messages>

The test with j2sdk1.4.1_03 is running fine without any problems,
But with j2sdk1.4.2 broker is going out of memory pretty quickly.

Attaching the broker log..


-sarada.
###@###.### 2003-06-26

The reported problem (Broker is going out of memory very quickly with jdk version 1.4.2) is caused by bug in jdk 1.4.2.

The attached test program (testfc.java) shows that when jdk1.4.2 is used, OutOfMemoryError will be thrown if FileChannel is used to write a large amount of data.

% /usr/j2sdk1.4.2/bin/java -Xmx128m testfc file 70000000 fc
usefc=true
size=70000000
Exception in thread "main" java.lang.OutOfMemoryError
	at java.nio.Bits.reserveMemory(Bits.java:618)
	at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
	at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:285)
	at sun.nio.ch.Util.getTemporaryDirectBuffer(Util.java:54)
	at sun.nio.ch.IOUtil.write(IOUtil.java:69)
	at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:202)
	at testfc.main(testfc.java:38)
%

It works fine when FileChannel is not used or jdk1.4.1 is used.

%  /usr/j2sdk1.4.2/bin/java -Xmx128m testfc file 70000000
usefc=false
size=70000000
file size = 70000000
%
% /usr/j2sdk1.4.1_01/bin/java  -Xmx128m testfc file 70000000
usefc=false
size=70000000
file size = 70000000
%
%  /usr/j2sdk1.4.1_01/bin/java  -Xmx128m testfc file 70000000 fc
usefc=true
size=70000000
file size = 70000000
%

The version that exhibits the error is:

% /usr/j2sdk1.4.2/bin/java -version
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)


###@###.### 2003-06-26
The cutoff is 64 meg (67108864).

%  /usr/j2sdk1.4.2/bin/java -Xmx128m testfc file 67108864 fc
usefc=true
size=67108864
file size = 67108864
% /usr/j2sdk1.4.2/bin/java -Xmx128m testfc icfile 67108865 fc
usefc=true
size=67108865
Exception in thread "main" java.lang.OutOfMemoryError
	at java.nio.Bits.reserveMemory(Bits.java:618)
	at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
	at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:285)
	at sun.nio.ch.Util.getTemporaryDirectBuffer(Util.java:54)
	at sun.nio.ch.IOUtil.write(IOUtil.java:69)
	at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:202)
	at testfc.main(testfc.java:38)
%

Comments
WORK AROUND To increase the limit, set the following VM flag: -XX:MaxDirectMemorySize=<size> e.g.: -XX:MaxDirectMemorySize=1G
11-06-2004