Java教程

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.www.zyiz.net/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 ASM系列:(040)AnalyzerAdapter介绍的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!