源代码为:
package com.test19; public class Test04 { void spin(){ int i; for(i=0;i<100;i++){ ; } i = 0; } }
生成的class如下:
public class com.test19.Test04 SourceFile: "Test04.java" minor version: 0 major version: 51 flags: ACC_PUBLIC, ACC_SUPER Constant pool: #1 = Methodref #3.#17 // java/lang/Object."<init>":()V #2 = Class #18 // com/test19/Test04 #3 = Class #19 // java/lang/Object #4 = Utf8 <init> #5 = Utf8 ()V #6 = Utf8 Code #7 = Utf8 LineNumberTable #8 = Utf8 LocalVariableTable #9 = Utf8 this #10 = Utf8 Lcom/test19/Test04; #11 = Utf8 spin #12 = Utf8 i #13 = Utf8 I #14 = Utf8 StackMapTable #15 = Utf8 SourceFile #16 = Utf8 Test04.java #17 = NameAndType #4:#5 // "<init>":()V #18 = Utf8 com/test19/Test04 #19 = Utf8 java/lang/Object { public com.test19.Test04(); flags: ACC_PUBLIC Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return LineNumberTable: line 2: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this Lcom/test19/Test04; void spin(); flags: Code: stack=2, locals=2, args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 14 8: iinc 1, 1 11: goto 2 14: iconst_0 15: istore_1 16: return LineNumberTable: line 5: 0 line 9: 14 line 10: 16 LocalVariableTable: Start Length Slot Name Signature 0 17 0 this Lcom/test19/Test04; 2 15 1 i I StackMapTable: number_of_entries = 2 frame_type = 252 /* append */ offset_delta = 2 locals = [ int ] frame_type = 11 /* same */ }
Code编码为:
03 3C 1B 10 64 A2 00 09 84 01 01 A7 FF F7 03 3C B1
opcode [03] - 0000: iconst_0
opcode [3C] - 0001: istore_1
opcode [1B] - 0002: iload_1
opcode [10] - 0003: bipush 100
opcode [A2] - 0005: if_icmpge 9
opcode [84] - 0008: iinc 1 1 ; index const
opcode [A7] - 0011: goto -9
opcode [03] - 0014: iconst_0
opcode [3C] - 0015: istore_1
opcode [B1] - 0016: return
3 60 27 16 100
-94 0 9 -124 1
1 -89 -1 -9 -79