If you download debug binaries, also try -XX:+PrintEscapeAnalysis
I’m decoding the output now…
For program
public class Test {
public static void main(String[] argv) {
for ( int i =0; i < 10; i++ ) {
test();
}
}
public static void test() {
int sum = 0;
for ( int i = 0; i < 1000000; i++ ) {
sum += new Integer(i%2).intValue();
}
}
}
Output is as follows
1 java.lang.Integer::<init> (10 bytes)
2 java.lang.Number::<init> (5 bytes)
1% Test::test @ 4 (33 bytes)
======== Connection graph for Test::test
60 JavaObject NoEscape [[ 129F]] 60 Allocate === 46 47 48 8 1 ( 53 54 _ 57 59 54 1 1 50 49 ) [[ 61 62 63 70 71 72 ]] rawptr:NotNull ( int+, java/lang/Object:NotNull *, rawptr:NotNull, rawptr:NotNull, rawptr:NotNull, rawptr:NotNull, rawptr:NotNull ) Test::test @ bci:11
72 LocalVar NoEscape [[ 60P]] 72 Proj === 60 [[ 73 ]] #5
3 Test::test (33 bytes)
======== Connection graph for Test::test
45 JavaObject NoEscape [[ 113F]] 45 Allocate === 31 32 33 8 1 ( 38 39 _ 42 44 39 1 1 35 34 ) [[ 46 47 48 55 56 57 ]] rawptr:NotNull ( int+, java/lang/Object:NotNull *, rawptr:NotNull, rawptr:NotNull, rawptr:NotNull, rawptr:NotNull, rawptr:NotNull ) Test::test @ bci:11
57 LocalVar NoEscape [[ 45P]] 57 Proj === 45 [[ 58 ]] #5
Edit:
After playing with
java -server -XX:+PrintOptoAssembly -XX:+PrintIdeal -XX:+DoEscapeAnalysis -XX:+PrintEscapeAnalysis
it seems that there is no difference in generated code - but EscapeAnalysis correctly detects that Integer allocation is local. Most probably you are right - they have implemented analysis, but part which performs stack allocation is missing.
I wonder if monitors synchronization is skipped for method local objects - will have to investigate