找到课题在JCK测试集中的位置,将对应的文件夹拷贝到需要单独进行调试的位置
cp $HOME/src/java/jck8b/JCK-runtime-8b/tests/vm/jvmti/Breakpoint/brkp001/brkp00102 $HOME/src/java/
然后使用IDEA在此文件夹下建立工程
打开brkp00102.java文件可以看到下面的代码
package javasoft.sqe.tests.vm.jvmti.brkp001.brkp00102;
根据Java语言可知,此文件应在javasoft.sqe.tests.vm.jvmti.brkp001.brkp00102包下方可正常编译,于是,在IDEA中创建对应的文件夹,并将文件移至此文件夹之下
除此之外,通过以下代码可知该程序须依赖类
import javasoft.sqe.jck.lib.jvmti.Agent; import javasoft.sqe.jck.lib.jvmti.SafeThread;
通过在JCK-runtime-8b文件夹下使用find命令查找对应的文件
find -name Agent.java ./src/javasoft/sqe/jck/lib/jvmti/Agent.java find -name SafeThread.java ./src/javasoft/sqe/jck/lib/jvmti/SafeThread.java
按照import代码指定的位置在IDEA中创建文件夹,并将Agent.java和SafeThread.java文件拷贝到对应的位置
同理,拷贝AttachConnector.java文件到对应的位置
通过分析程序可知,该程序使用了JNI,即.so文件,但使用了何种jni文件未知,通过打开brkp00102.ksh文件
"$JAVA_HOME/bin/java" -agentlib:jckjvmti=brkp00102 javasoft.sqe.tests.vm.jvmti.brkp001.brkp00102.brkp00102 -platform.jvmtiSupported $PLATFORM_JVMTISUPPORTED -platform.nativeLibsLinkage $PLATFORM_NATIVELIBSLINKAGE
该程序在运行时须依赖libjckjvmti.so库
注意:此时不必通过brkp00102.c文件把所有的关联文件放入到当前目录,并使用gcc去编译自己所需的.so文件,直接使用下面的命令编译出所需的.so文件
gcc -fPIC -shared -o libjckjvmti.so -I $HOME/src/java/jck8b/JCK-runtime-8b -I $HOME/src/java/jck8b/JCK-runtime-8b/src/share/lib/jvmti/include -I $HOME/src/java/jck8b/JCK-runtime-8b/src/share/lib/jni/include -I $HOME/src/java/jck8b/JCK-runtime-8b/src/share/lib/jni/include/solaris $HOME/src/java/jck8b/JCK-runtime-8b/src/share/lib/jvmti/jckjvmti.c
将此libjckjvmti.so拷贝至out/production对应的目录下即可
根据brkp00102.ksh中
"$JAVA_HOME/bin/java" -agentlib:jckjvmti=brkp00102 javasoft.sqe.tests.vm.jvmti.brkp001.brkp00102.brkp00102 -platform.jvmtiSupported $PLATFORM_JVMTISUPPORTED -platform.nativeLibsLinkage $PLATFORM_NATIVELIBSLINKAGE
可知,其运行的代码为
java -agentlib:jckjvmti=brkp00102 javasoft.sqe.tests.vm.jvmti.brkp001.brkp00102.brkp00102 -platform.jvmtiSupported true -platform.nativeLibsLinkage dynamic
其中 -platform.jvmtiSupported true和-platform.nativeLibsLinkage dynamic可通过GUI界面得到,也可通过分析代码得到
但是运行不会成功,因为-agentlib参数找不到libjckjvmti.so,此时需要使用下面的命令将路径导入
export LD_LIBRARY_PATH=libjckjvmti.so所在的路径:$LD_LIBRARY_PATH
以我本机为例
export LD_LIBRARY_PATH=/home/firewood/src/java/brkp00102/out/production/brkp00102/javasoft/sqe/tests/vm/jvmti/brkp001/brkp00102:$LD_LIBRARY_PATH
再运行
java -agentlib:jckjvmti=brkp00102 javasoft.sqe.tests.vm.jvmti.brkp001.brkp00102.brkp00102 -platform.jvmtiSupported true -platform.nativeLibsLinkage dynamic
查看运行结果
echo $? 95