参考: https://blog.csdn.net/qq_38505969/article/details/123446310
1、下载源码并进行方法扩展
2、pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol-parent</artifactId>
<version>0.9</version>
</parent>
<!--自定义 jar 包名称-->
<artifactId>jol-core-0.9-summer-extend</artifactId>
<packaging>jar</packaging>
<name>Java Object Layout: Core</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
3、打包
扩展 toPrintableSimple() 方法代码
// 扩展方法
public String toPrintableSimple() {
return toPrintableSimple(classData.instance());
}
public String toPrintableSimple(Object instance) {
StringBuffer stringBuffer = new StringBuffer();
if (instance != null) {
VirtualMachine vm = VM.current();
for (long off = 4; off >= 0; off -= 4) {
int word = vm.getInt(instance, off);
stringBuffer.append(toBinary((word >> 24) & 0xFF) + " " + toBinary((word >> 16) & 0xFF) + " " + toBinary((word >> 8) & 0xFF) + " " + toBinary((word >> 0) & 0xFF) + " ");
}
}
return stringBuffer.toString();
}
扩展好的 jar 包下载链接:https://pan.baidu.com/s/1cr5R1OxwFU4WEtb3w1zpUw 提取码:i3qm