I'm new to byte code so I've been looking at examples online of Java code and its byte code conversions. My confusion lies with the incrementation pattern of the instruction number. For example, refer to a byte code snippet from https://salilsurendran.wordpress.com/2015/01/01/jvm-memory-barriers/:
//The byte code generated for our for loop
0: iconst_0 <-- Push '0' on the operand stack
1: istore_1 <-- Pop '0' out of the operand stack and set it as the value of local variable 1
2: iload_1 <-- Push the value of the local variable 1 onto the operand stack
3: ldc #2 // int 1000000 <-- Push the constant no. 2 from the constant pool onto the operand stack
5: if_icmpge 14 <-- Pop the top two values out of the operand stack if the first value
popped is greater than or equal to the second jump to step 14 -->
8: iinc 1, 1 <-- Increment local variable 1 which is i by 1
11: goto 2 <-- jump to step 2
//End of the for loop
Instructions 1 to 3 seem to be incrementing by 1 each time, though instruction 3 goes to 5 and 5 goes to 8.
My question is, why doesn't 3 go to 4? What's the reason for 3 going to 5 and 5 going to 8? Is there a set of general rules for this which I can be pointed towards?
It's not an 'instruction number'. It is an instruction address, and it is incremented by the length of the previous instruction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With