Studying bytecode, I noticed that javac seems to duplicate checkcast instructions when casting to array types.
Cast.java: class Cast { void test(Object a) { Object[] b = (Object[])b; } }
javap disassembler compiled javac version
void test(java.lang.Object); Code: 0: aload_1 1: checkcast #2; //class "[Ljava/lang/Object;" 4: checkcast #2; //class "[Ljava/lang/Object;" 7: astore_2 8: return
Testing jikes shows expected single throw
void test(java.lang.Object); Code: 0: aload_1 1: checkcast #10;
checkcast should checkcast an exception if the object cannot be considered the requested type and otherwise does nothing, so I donβt understand why this can help double the action. I did not look at the JDK sources to see how this happens, and if it helps explain why (perhaps it meant as a hint).
jvm bytecode javac jikes
Brandon
source share