-
Bug
-
Resolution: Unresolved
-
P4
-
7
-
x86
-
linux
FULL PRODUCT VERSION :
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
FULL OS VERSION :
Linux io 2.6.37.6-0.11-desktop #1 SMP PREEMPT 2011-12-19 23:39:38 +0100 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When using the constructor Color(ColorSpace cspace, float[] components, float alpha)
in a thread the JVM creates a new memory mapping as shown in the following pmap output:
00007f6a84d87000 4K 0K 0K 0K 0K rw-s /dev/shm/sem.wQhtI8
Unfortunately this mapping is never released.
When the kernel limit vm.max_map_count is reached (cat /proc/sys/vm/max_map_count)
- which is 65530 on my system - the JVM starts to emit the following warning messages:
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
Once these messages are emitted the kernel does not allow additional mappings
for this process which causes all sorts of additional problems in real world
applications (failure to load classes, failure to create new threads etc.).
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the attached test class:
javac ColorTest.java
2. Run the test class:
java -server ColorTest
or
java -client ColorTest
or
java -Xint ColorTest
3. See how the number of mappings increases with:
pmap <pid> | grep -c "/dev/shm/sem"
while the test is running
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected:
The code should run without any warnings.
No mappings should be leaked.
(could be checked with pmap <pid> | grep -c "/dev/shm/sem" while running the test case)
Actual
While the test code is running pmap <pid> | grep -c "/dev/shm/sem"
shows an increasing number of mappings. When the kernel limit vm.max_map_count
is reached (cat /proc/sys/vm/max_map_count) the JVM starts to emit the following
warning messages:
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
Sometimes the JVM is no longer able to create new threads:
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:691)
at ColorTest.main(ColorTest.java:8)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
(the lines above are repeated several thousand times)
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:691)
at ColorTest.main(ColorTest.java:8)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
public final class ColorTest {
public static void main(String[] args) {
for (int i = 1; i < 500000; i++) {
final ColorRunnable r = new ColorRunnable(i, Color.RED);
final Thread t = new Thread(r);
t.start();
try {
t.join();
} catch (InterruptedException ex) {
System.exit(-1);
}
}
}
private static final class ColorRunnable implements Runnable {
private final int count;
private final Color baseColor;
private ColorRunnable(int count, Color baseColor) {
this.count = count;
this.baseColor = baseColor;
}
public void run() {
final Color derivedColor = new Color(
baseColor.getColorSpace(),
baseColor.getColorComponents(null),
1.0f);
System.out.println(count + ". Color: " + derivedColor);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't use the constructor Color(ColorSpace cspace, float[] components, float alpha).
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
FULL OS VERSION :
Linux io 2.6.37.6-0.11-desktop #1 SMP PREEMPT 2011-12-19 23:39:38 +0100 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When using the constructor Color(ColorSpace cspace, float[] components, float alpha)
in a thread the JVM creates a new memory mapping as shown in the following pmap output:
00007f6a84d87000 4K 0K 0K 0K 0K rw-s /dev/shm/sem.wQhtI8
Unfortunately this mapping is never released.
When the kernel limit vm.max_map_count is reached (cat /proc/sys/vm/max_map_count)
- which is 65530 on my system - the JVM starts to emit the following warning messages:
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
Once these messages are emitted the kernel does not allow additional mappings
for this process which causes all sorts of additional problems in real world
applications (failure to load classes, failure to create new threads etc.).
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the attached test class:
javac ColorTest.java
2. Run the test class:
java -server ColorTest
or
java -client ColorTest
or
java -Xint ColorTest
3. See how the number of mappings increases with:
pmap <pid> | grep -c "/dev/shm/sem"
while the test is running
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected:
The code should run without any warnings.
No mappings should be leaked.
(could be checked with pmap <pid> | grep -c "/dev/shm/sem" while running the test case)
Actual
While the test code is running pmap <pid> | grep -c "/dev/shm/sem"
shows an increasing number of mappings. When the kernel limit vm.max_map_count
is reached (cat /proc/sys/vm/max_map_count) the JVM starts to emit the following
warning messages:
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
Sometimes the JVM is no longer able to create new threads:
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:691)
at ColorTest.main(ColorTest.java:8)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
Java HotSpot(TM) 64-Bit Server VM warning: Attempt to allocate stack guard pages failed.
(the lines above are repeated several thousand times)
Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:691)
at ColorTest.main(ColorTest.java:8)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
public final class ColorTest {
public static void main(String[] args) {
for (int i = 1; i < 500000; i++) {
final ColorRunnable r = new ColorRunnable(i, Color.RED);
final Thread t = new Thread(r);
t.start();
try {
t.join();
} catch (InterruptedException ex) {
System.exit(-1);
}
}
}
private static final class ColorRunnable implements Runnable {
private final int count;
private final Color baseColor;
private ColorRunnable(int count, Color baseColor) {
this.count = count;
this.baseColor = baseColor;
}
public void run() {
final Color derivedColor = new Color(
baseColor.getColorSpace(),
baseColor.getColorComponents(null),
1.0f);
System.out.println(count + ". Color: " + derivedColor);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't use the constructor Color(ColorSpace cspace, float[] components, float alpha).