wujiuye / bytecode-book Goto Github PK
View Code? Open in Web Editor NEW《Java虚拟机字节码从入门到实战》一书的配套代码
《Java虚拟机字节码从入门到实战》一书的配套代码
问题:
Gradle 无法识别 compile() 方法。这是因为在 Gradle 7.0 及更高版本中,compile 配置已被弃用,取而代之的是 implementation 和 api。
解决:
将 build.gradle 文件中的 compile 替换为 implementation。修改后的 dependencies 部分应如下所示:
dependencies {
// asm
implementation group: 'org.ow2.asm', name: 'asm', version: '6.2'
// cglib
implementation files("libs/cglib-3.2.5.jar")
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
这里144行和145行应该换一下,测试double入参的时候发现执行dload_3指令
JDK版本:JDK8
代码如下:
public class SimpleDemo {
public static final String TEST = "ZZ";
public static final int TEST2 = 1;
public static final float TEST3 = 2.0F;
public static final double TEST4 = 3.0;
public static final long TEST5 = 4L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void run() {
System.out.println("run");
}
}
解析常量池时,最后两个解析不了
错误信息:
Exception in thread "main" java.lang.Exception: 没有找到该TAG=0对应的常量类型
我把剩下的打印出来,发现还有一些没有解析成功:
常量池个数:54
序号: 0,内容 -- CONSTANT_Methodref_info{tag=10, classIndex=0x0007, nameAndTypeIndex=0x0029}
序号: 1,内容 -- CONSTANT_Fieldref_info{tag=9, classIndex=0x0006, nameAndTypeIndex=0x002a}
序号: 2,内容 -- CONSTANT_Fieldref_info{tag=9, classIndex=0x002b, nameAndTypeIndex=0x002c}
序号: 3,内容 -- CONSTANT_String_info{tag=8, stringIndex=0x0026}
序号: 4,内容 -- CONSTANT_Methodref_info{tag=10, classIndex=0x002d, nameAndTypeIndex=0x002e}
序号: 5,内容 -- CONSTANT_Class_info{tag=7, nameIndex=0x002f}
序号: 6,内容 -- CONSTANT_Class_info{tag=7, nameIndex=0x0030}
序号: 7,内容 -- CONSTANT_Utf8_info{tag=1, length=4, bytes=TEST}
序号: 8,内容 -- CONSTANT_Utf8_info{tag=1, length=18, bytes=Ljava/lang/String;}
序号: 9,内容 -- CONSTANT_Utf8_info{tag=1, length=13, bytes=ConstantValue}
序号: 10,内容 -- CONSTANT_String_info{tag=8, stringIndex=0x0031}
序号: 11,内容 -- CONSTANT_Utf8_info{tag=1, length=5, bytes=TEST2}
序号: 12,内容 -- CONSTANT_Utf8_info{tag=1, length=1, bytes=I}
序号: 13,内容 -- CONSTANT_Integer_info{, tag=3, bytes=0x00000001}
序号: 14,内容 -- CONSTANT_Utf8_info{tag=1, length=5, bytes=TEST3}
序号: 15,内容 -- CONSTANT_Utf8_info{tag=1, length=1, bytes=F}
序号: 16,内容 -- CONSTANT_Float_info{, tag=4, bytes=0x40000000}
序号: 17,内容 -- CONSTANT_Utf8_info{tag=1, length=5, bytes=TEST4}
序号: 18,内容 -- CONSTANT_Utf8_info{tag=1, length=1, bytes=D}
序号: 19,内容 -- CONSTANT_Double_info{tag=6, highBytes=0x40080000, lowBytes=0x00000000, value=4.6139378182410732E18}
序号: 20,内容 -- CONSTANT_Utf8_info{tag=1, length=5, bytes=TEST5}
序号: 21,内容 -- CONSTANT_Utf8_info{tag=1, length=1, bytes=J}
序号: 22,内容 -- CONSTANT_Long_info{tag=5, highBytes=0x00000000, lowBytes=0x00000004, value=4}
序号: 23,内容 -- CONSTANT_Utf8_info{tag=1, length=4, bytes=name}
序号: 24,内容 -- CONSTANT_Utf8_info{tag=1, length=6, bytes=<init>}
序号: 25,内容 -- CONSTANT_Utf8_info{tag=1, length=3, bytes=()V}
序号: 26,内容 -- CONSTANT_Utf8_info{tag=1, length=4, bytes=Code}
序号: 27,内容 -- CONSTANT_Utf8_info{tag=1, length=15, bytes=LineNumberTable}
序号: 28,内容 -- CONSTANT_Utf8_info{tag=1, length=18, bytes=LocalVariableTable}
序号: 29,内容 -- CONSTANT_Utf8_info{tag=1, length=4, bytes=this}
序号: 30,内容 -- CONSTANT_Utf8_info{tag=1, length=38, bytes=Lme/mingshan/bytecode/test/SimpleDemo;}
序号: 31,内容 -- CONSTANT_Utf8_info{tag=1, length=7, bytes=getName}
序号: 32,内容 -- CONSTANT_Utf8_info{tag=1, length=20, bytes=()Ljava/lang/String;}
序号: 33,内容 -- CONSTANT_Utf8_info{tag=1, length=7, bytes=setName}
序号: 34,内容 -- CONSTANT_Utf8_info{tag=1, length=21, bytes=(Ljava/lang/String;)V}
序号: 35,内容 -- CONSTANT_Utf8_info{tag=1, length=3, bytes=run}
序号: 36,内容 -- CONSTANT_Utf8_info{tag=1, length=10, bytes=SourceFile}
序号: 37,内容 -- CONSTANT_Utf8_info{tag=1, length=15, bytes=SimpleDemo.java}
序号: 38,内容 -- CONSTANT_NameAndType_info{tag=12, nameIndex=0x001b, descriptorIndex=0x001c}
序号: 39,内容 -- CONSTANT_NameAndType_info{tag=12, nameIndex=0x001a, descriptorIndex=0x0009}
序号: 40,内容 -- CONSTANT_Class_info{tag=7, nameIndex=0x0032}
序号: 41,内容 -- CONSTANT_NameAndType_info{tag=12, nameIndex=0x0033, descriptorIndex=0x0034}
序号: 42,内容 -- CONSTANT_Class_info{tag=7, nameIndex=0x0035}
序号: 43,内容 -- CONSTANT_NameAndType_info{tag=12, nameIndex=0x0036, descriptorIndex=0x0025}
序号: 44,内容 -- CONSTANT_Utf8_info{tag=1, length=36, bytes=me/mingshan/bytecode/test/SimpleDemo}
序号: 45,内容 -- CONSTANT_Utf8_info{tag=1, length=16, bytes=java/lang/Object}
序号: 46,内容 -- CONSTANT_Utf8_info{tag=1, length=2, bytes=ZZ}
序号: 47,内容 -- CONSTANT_Utf8_info{tag=1, length=16, bytes=java/lang/System}
序号: 48,内容 -- CONSTANT_Utf8_info{tag=1, length=3, bytes=out}
序号: 49,内容 -- CONSTANT_Utf8_info{tag=1, length=21, bytes=Ljava/io/PrintStream;}
序号: 50,内容 -- CONSTANT_Utf8_info{tag=1, length=19, bytes=java/io/PrintStream}
序号: 51,内容 -- CONSTANT_Utf8_info{tag=1, length=7, bytes=println}
无效的tag:0
无效的tag:33
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.