FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
FULL OS VERSION :
Windows 7
A DESCRIPTION OF THE PROBLEM :
For the two functions (test1, and test2), one would expect that they would run in identical times in the presence of escape analysis. The only difference is that the accumulation is done into an Integer in the first, as opposed to an int in the second.
Yet on my machine, test1 is 16 times slower. Looks like escape analysis is doing absolutely nothing here which is very surprising since this is what it was designed and advertised to do.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Simply run the program included below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect the two runtimes to be about the same. Instead the version with the Integer is 16x slower.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No errors.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class LongTest {
public static int test1(int count) {
Integer sum = 0;
for(int i = 0; i <= count - 1; ++i)
sum += i;
return sum;
}
public static long test2(int count) {
int sum = 0;
for (int i = 0; i <= count - 1; ++i)
sum += i;
return sum;
}
}
public class Escape {
public static void main(String[] args) {
int k = 0;
int count = 200;
int N = 200000;
for (int i = 0; i != N; ++i) {
k += LongTest.test1(count);
k += LongTest.test2(count);
}
System.out.println(k);
{
long startTime = System.nanoTime();
k += LongTest.test1(Integer.MAX_VALUE);
long endTime = System.nanoTime();
System.out.println((endTime - startTime) / 1.0e9);
}
{
long startTime = System.nanoTime();
k += LongTest.test2(Integer.MAX_VALUE);
long endTime = System.nanoTime();
System.out.println((endTime - startTime) / 1.0e9);
}
System.out.println(k);
return;
}
}
---------- END SOURCE ----------
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
FULL OS VERSION :
Windows 7
A DESCRIPTION OF THE PROBLEM :
For the two functions (test1, and test2), one would expect that they would run in identical times in the presence of escape analysis. The only difference is that the accumulation is done into an Integer in the first, as opposed to an int in the second.
Yet on my machine, test1 is 16 times slower. Looks like escape analysis is doing absolutely nothing here which is very surprising since this is what it was designed and advertised to do.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Simply run the program included below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect the two runtimes to be about the same. Instead the version with the Integer is 16x slower.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No errors.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class LongTest {
public static int test1(int count) {
Integer sum = 0;
for(int i = 0; i <= count - 1; ++i)
sum += i;
return sum;
}
public static long test2(int count) {
int sum = 0;
for (int i = 0; i <= count - 1; ++i)
sum += i;
return sum;
}
}
public class Escape {
public static void main(String[] args) {
int k = 0;
int count = 200;
int N = 200000;
for (int i = 0; i != N; ++i) {
k += LongTest.test1(count);
k += LongTest.test2(count);
}
System.out.println(k);
{
long startTime = System.nanoTime();
k += LongTest.test1(Integer.MAX_VALUE);
long endTime = System.nanoTime();
System.out.println((endTime - startTime) / 1.0e9);
}
{
long startTime = System.nanoTime();
k += LongTest.test2(Integer.MAX_VALUE);
long endTime = System.nanoTime();
System.out.println((endTime - startTime) / 1.0e9);
}
System.out.println(k);
return;
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8049107 Regression in Escape Analysis
-
- Closed
-