微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何计算 StackMapTable 的框架地图框架?

如何解决如何计算 StackMapTable 的框架地图框架?

我正在研究类文件的 StackMapTable 属性我有一些问题,堆栈映射帧是如何计算的?

这里我举两个例子:
示例 1

public class Foo {  
    public void foo() {  
        int i = 0;  
        int j = 0;  
        if (i > 0) {  
          int k = 0;  
        }  
        int l = 0;  
    }  
}  

//byte code:
public void foo();  
  Code:  
   Stack=1,Locals=4,Args_size=1  
   0:   iconst_0  
   1:   istore_1  
   2:   iconst_0  
   3:   istore_2  
   4:   iload_1  
   5:   ifle    10  
   8:   iconst_0  
   9:   istore_3  
   10:  iconst_0 
   11:  istore_3  
   12:  return  

  
  LocalVariableTable:  
   Start  Length  Slot  Name   Signature  
   10      0      3    k       I  
   0      13      0    this       LFoo;  
   2      11      1    i       I  
   4      9      2    j       I  
   12      1      3    l       I  
  
  StackMapTable: number_of_entries = 1  
   frame_type = 253 /* append */  
     offset_delta = 10  
     locals = [ int,int ]  

示例 2

public static void chop() {
        int i = 0;
        int j = 0;
        if (i > 0) {
            long k = 0;
            if (j == 0) {
                k++;
                int s=1111;
            }
            int t = 0;
        }
    }


 //bytecode
 public static void chop();
    descriptor: ()V
    flags: ACC_PUBLIC,ACC_STATIC
    Code:
      stack=4,locals=5,args_size=0
         0: iconst_0
         1: istore_0
         2: iconst_0
         3: istore_1
         4: iload_0
         5: ifle          26
         8: lconst_0
         9: lstore_2
        10: iload_1
        11: ifne          23
        14: lload_2
        15: lconst_1
        16: ladd
        17: lstore_2
        18: sipush        1111
        21: istore        4
        23: iconst_0
        24: istore        4
        26: return
      LineNumberTable:
        line 34: 0
        line 35: 2
        line 36: 4
        line 37: 8
        line 38: 10
        line 39: 14
        line 40: 18
        line 42: 23
        line 44: 26
      StackMapTable: number_of_entries = 2
        frame_type = 254 /* append */
          offset_delta = 23
          locals = [ int,int,long ]
        frame_type = 250 /* chop */
          offset_delta = 2

谁能介绍一下如何根据这两个例子计算堆栈图帧?
这个问题一直困扰我很长时间,任何帮助将不胜感激!谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。