Gen对于break、continue与return的处理

 

 

void tryItOut () {}
void wrapItUp () {}

void tryFinally() {
	for (int i = 0; i < 2; i++) {
		try {
			tryItOut();
		} finally {
			wrapItUp();
			return;
		}
	}
}

生成的class文件的内容如下:

void tryFinally();
    flags:
    Code:
      stack=2, locals=3, args_size=1
         
	 0: iconst_0  // 将0压入栈顶
         1: istore_1  // 将0存入本地变量表1的位置
         2: iload_1
         3: iconst_2
         4: if_icmpge     22

         // 进入try的body体 
         7: aload_0
         8: invokevirtual #2                  // Method tryItOut:()V

         // 进入finally的body体
        11: aload_0
        12: invokevirtual #3                  // Method wrapItUp:()V
        15: return

        16: astore_2 // 将throwable异常存储到本地变量表2的位置
        17: aload_0
        18: invokevirtual #3                  // Method wrapItUp:()V
        21: return

        22: return

      Exception table:
         from    to  target type
             7    11    16   any
            16    17    16   any

 

 

public void t(boolean a, int b) {
	E: {
		while (a) {
			if (b == 1) {
				continue;
			}
			if (b == 2) {
				break;
			}
			if (b == 3) {
				break E;
			}
		}
		
		int c=2;
	}
}

class文件内容如下:

public void t(boolean, int);
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=4, args_size=3
         0: iload_1
         1: ifeq          28 // 当栈顶int型数值等于0 时跳转

         // continue的处理
         4: iload_2          // 将形式参数变量b压入栈顶
         5: iconst_1         // 将常量1压入栈顶
         6: if_icmpne     12 //  比较栈顶两int型数值,当且仅当不相等时结果为真,为真后跳转到12
         9: goto          0

         // break的处理
        12: iload_2
        13: iconst_2
        14: if_icmpne     20
        17: goto          28

         // break的处理
        20: iload_2
        21: iconst_3
        22: if_icmpne     0
        25: goto          30

        28: iconst_2
        29: istore_3
        30: return

本地变量表的内容如下:

0:this
1:方法形式参数a
2:方法形式参数b

  

 

 

 

 

 

 

 

  

  

你可能感兴趣的:(Gen对于break、continue与return的处理)