编程语言
首页 > 编程语言> > Java ASM系列:(040)AnalyzerAdapter介绍

Java ASM系列:(040)AnalyzerAdapter介绍

作者:互联网

本文属于[Java ASM系列一:Core API](https://blog.51cto.com/lsieun/2924583)当中的一篇。 对于`AnalyzerAdapter`类来说,它的特点是“可以模拟frame的变化”,或者说“可以模拟local variables和operand stack的变化”。 The `AnalyzerAdapter` is a `MethodVisitor` that keeps track of stack map frame changes between `visitFrame(int, int, Object[], int, Object[])` calls. This `AnalyzerAdapter` adapter must be used with the `Cla***eader.EXPAND_FRAMES` option. This method adapter computes the **stack map frames** before each instruction, based on the frames visited in `visitFrame`. Indeed, `visitFrame` is only called before some specific instructions in a method, in order to save space, and because "the other frames can be easily and quickly inferred from these ones". This is what this adapter does. ![JVM Stack Frame](http://www.icode9.com/i/li/?n=2&i=images/20210623/1624446269398923.png?,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=) ## 1. AnalyzerAdapter类 ### 1.1 class info 第一个部分,`AnalyzerAdapter`类的父类是`MethodVisitor`类。 ```java public class AnalyzerAdapter extends MethodVisitor { } ``` ### 1.2 fields 第二个部分,`AnalyzerAdapter`类定义的字段有哪些。 我们将以下列出的字段分成3个组: - 第1组,包括`locals`、`stack`、`maxLocals`和`maxStack`字段,它们是与local variables和operand stack直接相关的字段。 - 第2组,包括`labels`和`uninitializedTypes`字段,它们记录的是未初始化的对象类型,是属于一些特殊情况。 - 第3组,是`owner`字段,表示当前类的名字。 ```java public class AnalyzerAdapter extends MethodVisitor { // 第1组字段:local variables和operand stack public List locals; public List stack; private int maxLocals; private int maxStack; // 第2组字段:uninitialized类型 private List

标签:Java,String,int,public,AnalyzerAdapter,locals,stack,ASM
来源: https://blog.51cto.com/lsieun/2994287