ADDITIONAL SYSTEM INFORMATION :
Windows 10, openjdk-14-ea+30_windows-x64
A DESCRIPTION OF THE PROBLEM :
Source code:
void m(Object obj) {
if (obj instanceof String s) {
s.hashCode();
}
}
Emitted code:
void m(java.lang.Object);
Code:
0: aload_1
1: astore_3
2: aload_3
3: instanceof #7 // class java/lang/String
6: ifeq 27
9: aload_3
10: checkcast #7 // class java/lang/String
13: dup
14: astore_2
15: aload_3
16: checkcast #7 // class java/lang/String
19: if_acmpne 27
22: aload_2
23: invokevirtual #9 // Method java/lang/String.hashCode:()I
26: pop
27: return
For me it looks like instructions 9-19 produce code:
if ((String)obj == (String)obj) {...}
which seems pointless.
FREQUENCY : always
Windows 10, openjdk-14-ea+30_windows-x64
A DESCRIPTION OF THE PROBLEM :
Source code:
void m(Object obj) {
if (obj instanceof String s) {
s.hashCode();
}
}
Emitted code:
void m(java.lang.Object);
Code:
0: aload_1
1: astore_3
2: aload_3
3: instanceof #7 // class java/lang/String
6: ifeq 27
9: aload_3
10: checkcast #7 // class java/lang/String
13: dup
14: astore_2
15: aload_3
16: checkcast #7 // class java/lang/String
19: if_acmpne 27
22: aload_2
23: invokevirtual #9 // Method java/lang/String.hashCode:()I
26: pop
27: return
For me it looks like instructions 9-19 produce code:
if ((String)obj == (String)obj) {...}
which seems pointless.
FREQUENCY : always
- duplicates
-
JDK-8237528 Inefficient compilation of Pattern Matching for instanceof
- Resolved