-
Enhancement
-
Resolution: Won't Fix
-
P4
-
20
While analyzing our big data Apps, we observed unexpected deoptimizations in loop exit due to incorrect branch profiling.
Here is a reproducer.
```
public class UnexpectedLoopExitDeopt {
public static final int N = 20000000;
public static int d1[] = new int[N];
public static int d2[] = new int[N];
public static void main(String[] args) {
System.out.println(test(d1));
System.out.println(test(d2));
}
public static int test(int[] a) {
int sum = 0;
for(int i = 0; i < a.length; i++) {
sum += a[i];
}
return sum;
}
}
```
The following is the compilation sequence.
```
77 1 3 java.lang.Object::<init> (1 bytes)
83 2 3 java.lang.String::isLatin1 (19 bytes)
84 6 3 jdk.internal.util.Preconditions::checkIndex (18 bytes)
84 3 3 java.lang.String::charAt (25 bytes)
85 4 3 java.lang.StringLatin1::charAt (15 bytes)
86 7 3 java.lang.String::coder (15 bytes)
86 8 3 java.lang.String::hashCode (60 bytes)
87 5 3 java.lang.String::checkIndex (10 bytes)
87 9 3 java.lang.String::length (11 bytes)
93 10 n 0 java.lang.invoke.MethodHandle::linkToStatic(LLLLLLL)L (native) (static)
96 11 n 0 java.lang.invoke.MethodHandle::linkToSpecial(LLLL)L (native) (static)
96 12 n 0 java.lang.Object::hashCode (native)
97 13 n 0 java.lang.invoke.MethodHandle::invokeBasic(LLLLLL)L (native)
98 14 3 java.util.Objects::requireNonNull (14 bytes)
98 15 n 0 java.lang.invoke.MethodHandle::linkToSpecial(LLLLLLLL)L (native) (static)
98 16 1 java.lang.Enum::ordinal (5 bytes)
101 17 n 0 java.lang.invoke.MethodHandle::linkToSpecial(LLLL)V (native) (static)
102 18 n 0 java.lang.invoke.MethodHandle::invokeBasic(LL)L (native)
212 19 % 3 UnexpectedLoopExitDeopt::test @ 4 (24 bytes)
213 20 % 4 UnexpectedLoopExitDeopt::test @ 4 (24 bytes)
221 19 % 3 UnexpectedLoopExitDeopt::test @ 4 (24 bytes) made not entrant
221 21 4 UnexpectedLoopExitDeopt::test (24 bytes)
230 20 % 4 UnexpectedLoopExitDeopt::test @ 4 (24 bytes) made not entrant <--- Unexpected deopt
0
242 21 4 UnexpectedLoopExitDeopt::test (24 bytes) made not entrant <--- Unexpected deopt
0
```
The last two deopts (made not entrant) happened in the loop exit which are unexpected.
It would be better to to fix it.
Here is a reproducer.
```
public class UnexpectedLoopExitDeopt {
public static final int N = 20000000;
public static int d1[] = new int[N];
public static int d2[] = new int[N];
public static void main(String[] args) {
System.out.println(test(d1));
System.out.println(test(d2));
}
public static int test(int[] a) {
int sum = 0;
for(int i = 0; i < a.length; i++) {
sum += a[i];
}
return sum;
}
}
```
The following is the compilation sequence.
```
77 1 3 java.lang.Object::<init> (1 bytes)
83 2 3 java.lang.String::isLatin1 (19 bytes)
84 6 3 jdk.internal.util.Preconditions::checkIndex (18 bytes)
84 3 3 java.lang.String::charAt (25 bytes)
85 4 3 java.lang.StringLatin1::charAt (15 bytes)
86 7 3 java.lang.String::coder (15 bytes)
86 8 3 java.lang.String::hashCode (60 bytes)
87 5 3 java.lang.String::checkIndex (10 bytes)
87 9 3 java.lang.String::length (11 bytes)
93 10 n 0 java.lang.invoke.MethodHandle::linkToStatic(LLLLLLL)L (native) (static)
96 11 n 0 java.lang.invoke.MethodHandle::linkToSpecial(LLLL)L (native) (static)
96 12 n 0 java.lang.Object::hashCode (native)
97 13 n 0 java.lang.invoke.MethodHandle::invokeBasic(LLLLLL)L (native)
98 14 3 java.util.Objects::requireNonNull (14 bytes)
98 15 n 0 java.lang.invoke.MethodHandle::linkToSpecial(LLLLLLLL)L (native) (static)
98 16 1 java.lang.Enum::ordinal (5 bytes)
101 17 n 0 java.lang.invoke.MethodHandle::linkToSpecial(LLLL)V (native) (static)
102 18 n 0 java.lang.invoke.MethodHandle::invokeBasic(LL)L (native)
212 19 % 3 UnexpectedLoopExitDeopt::test @ 4 (24 bytes)
213 20 % 4 UnexpectedLoopExitDeopt::test @ 4 (24 bytes)
221 19 % 3 UnexpectedLoopExitDeopt::test @ 4 (24 bytes) made not entrant
221 21 4 UnexpectedLoopExitDeopt::test (24 bytes)
230 20 % 4 UnexpectedLoopExitDeopt::test @ 4 (24 bytes) made not entrant <--- Unexpected deopt
0
242 21 4 UnexpectedLoopExitDeopt::test (24 bytes) made not entrant <--- Unexpected deopt
0
```
The last two deopts (made not entrant) happened in the loop exit which are unexpected.
It would be better to to fix it.
- links to
-
Review openjdk/jdk/10200