Java Magazine, September/October 2017
ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2017 45 java 9 Next the two bytes 00 02 appear in the byte stream These are combined into a 16 bit number 2 in this case that is used as an ofset into a table called the constant pool within the class file All constant pool indices are 16 bits so whenever an opcode needs to refer to an entry in the pool there will always be two subsequent bytes that encode the ofset of the entry The decompiler helpfully includes a comment that lets you know which method ofset 2 corresponds to In this case as expected its the method System currentTimeMillis In the decompiled output javap shows the name of the called method the types of parameters the method takes in parentheses followed by the return type of the method Upon return the result of the call is placed on the stack and at ofset 3 you see the single argument less opcode lstore_ 1 which saves the return value in a local variable of type long Human readers are of course able to see that this value is never used again However one of the design goals of the Java compiler is to represent the contents of the Java source code as faithfully as possible whether it makes logical sense or not Therefore the return value of System currentTimeMillis is stored even though it is not used after this point in the program Lets look at the next chunk of the decompiled code 4 new 3 class java util HashMap 7 dup 8 invokespecial 4 Method java util HashMap init V 11 astore_ 3 12 aload_ 3 13 ldc 5 String now 15 ldc 6 String bar 17 invokevirtual 7 Method java util HashMap put Ljava lang Object Ljava lang Object Ljava lang Object 20 pop Bytecodes 4 to 10 create a new HashMap instance before instruction 11 saves a copy of it in a local
You must have JavaScript enabled to view digital editions.