gpt4 book ai didi

java - JVM Bytecode,如何找到局部变量的类型?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:12:45 24 4
gpt4 key购买 nike

我正在研究 a fork来自 Jetbrains 的 FernFlower,我一直在对其进行小的改进。

关于 FernFlower 真正让我恼火的一件事是,它根据局部变量在 bpush/spush 等中的值来确定局部变量的类型。而 Jode 和 Procyon 以某种方式找到了找到局部变量原始值的方法。

这是原始源代码。

public static void main(String[] args) throws Exception {
int hello = 100;
char a2 = 100;
short y1o = 100;
int hei = 100;

System.out.println(a2+" "+y1o+", "+hei+", "+hello);
}

当用 FernFlower 反编译时,它输出如下:

public static void main(String[] args) throws Exception {
byte hello = 100;
char a2 = 100;
byte y1o = 100;
byte hei = 100;
System.out.println(a2 + " " + y1o + ", " + hei + ", " + hello);
}

但是当使用 Jode/Procyon 反编译时,它会输出原始的局部变量类型:

  public static void main(String[] args)
throws Exception
{
int hello = 100;
char a2 = 'd';
short y1o = 100;
byte hei = 100;

System.out.println(a2 + " " + y1o + ", " + hei + ", " + hello);
}

我想知道这怎么可能,因为我认为在编译时没有存储局部变量类型信息?如何向 FernFlower 添加相同的功能?

最佳答案

.class文件可选择包含用于调试目的的“LocalVariableTable”属性。如果您调用命令 javap -l <Class>.class您可以看到数据(如果存在)。

关于java - JVM Bytecode,如何找到局部变量的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com