FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta2-b74)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b74, mixed mode, sharing)
FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When sample program is run with "-server -XX:+DoEscapeAnalysis" Hotspot prints "*** Unlock prevents locking optimization" messages.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: No
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class UnlockPrevents
{
public static void main(String args[])
{
for (int n = 0; n < 5; n++)
doit();
}
public static void doit()
{
for (int n = 0; n < 10000; n++) {
Histogram h = new Histogram();
assertTrue(h.foo() == 1);
h.add(3);
assertTrue(h.bar() == 0);
}
}
static void assertTrue(boolean x)
{
}
}
class Histogram
{
private int count;
private double min;
public synchronized void add(double value)
{
if (count++ == 0) {
min = value;
} else {
if (min > value)
min = value;
}
}
public int foo()
{
return 1;
}
public synchronized int bar()
{
return 0;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't use -XX:+DoEscapeAnalysis.