jdk源码调试功能
最近在研究jdk源码,发现debug时无法查看源码里的变量值。 因为sun提供的jdk并不能查看运行中的局部变量,需要重新编译一下rt.jar。
下面这六步是编译jdk的具体步骤:
Step 1: Locate the JDK source
First navigate to the JDK install directory, and locate the src.zip file. This file contains the JDK sources – and is absolutely invaluable for the rest of this process.
Next, unzip this folder to some location, such as c:\src.
Step 2: List all the source files to be compiled
Generate a list of all .java files in the unzipped folder, out to a separate file:
dir /B /S /X c:\src\*.java > jdk-src.txt
Step 3: Compile the source
Compile the source files named in this file, using the –g option.
javac-verbose -nowarn -g -source 1.6 -target 1.6 -J-Xms512m -J-Xmx1024m -bootclasspath C:\java\jdk1.6.0_07\jre\lib\rt.jar;C:\java\jdk1.6.0_07\jre\lib\jce.jar;C:\java\jdk1.6.0_07\jre\lib\jsse.jar;C:\java\jdk1.6.0_07\jre\lib\resources.jar;C:\java\jdk1.6.0_07\jre\lib\charsets.jar;C:\java\jdk1.6.0_07\jre\lib\deploy.jar -sourcepath src -classpath src -d jdk-class @jdk-src.txt
Note the presence of the –bootclasspath flag which makes the stated JARs available to the compiler. This is absolutely critical when trying to build the source distribution of JDK 6.
Step 4: Extract rt.jar
Extract the original rt.jar file, that is found in JAVA_HOME\jre\lib, into a temporary folder.
Step 5: Generate a composite build
Copy the newly compiled .class files from our jdk-class over the folder where the rt.jar file was expanded. This ensures that the final set has old classes overwritten by newer classes with debug information, while still retaining class files that we couldn't compile.
Step 6: Regenerate rt.jar
Finally, recompress all the files from the composite folder into a new rt.jar file, and overwrite the original rt.jar file with this new one.
如果想在eclipse中跟踪调试,需要在Windows -> Preferences -> Java-Installed JRE下,选择安装的jdk,点edit,然后在列出的jre system libraries列表中选择rt.jar,设置其中的Source attachment为C:\java\jdk1.6.0_07\src.zip。
------------------------------------------------------------------------------------------------------
下面是一个方便的linux脚本, 只要设置了JAVA_HOME, 就可以轻松搞定上面的事情了:)
#!/bin/sh
if [ -z "$JAVA_HOME" ]
then
echo "Must set JAVA_HOME"
exit 1
fi
cd $JAVA_HOME
mkdir temp
cp src.zip temp/
cd temp/
mkdir out
unzip src.zip
rm src.zip
find . -name *.java > filelist
echo "$(wc -l filelist) java files to compile"
javac -g -d out/ -J-Xmx1024m -cp "../jre/lib/tools.jar:../jre/lib/rt.jar" @filelist
if [ $? != 0 ]
then
echo "compile error!"
exit 1
fi
unzip $JAVA_HOME/jre/lib/rt.jar -d $JAVA_HOME/temp/old_classes
cp -r $JAVA_HOME/temp/out/* $JAVA_HOME/temp/old_classes/
cd $JAVA_HOME/temp/old_classes/
jar cf rt_debug.jar *
cp rt_debug.jar $JAVA_HOME/jre/lib/
mv $JAVA_HOME/jre/lib/rt.jar $JAVA_HOME/lib/rt_old.jar
cd $JAVA_HOME/jre/lib/
ln -s rt_debug.jar rt.jar
rm -rf $JAVA_HOME/temp
原文:http://hi.baidu.com/austincao/item/e6e91329892497c1a4275a1a
jdk源码调试功能的更多相关文章
- JDK源码调试
1.首先遇到了一个问题line unavailable,然后通过以下方式解决: http://blog.csdn.net/xuefeng0707/article/details/8738869 对于想 ...
- eclipse中jdk源码调试步骤
分析源码是学习一项技术内幕最有效的手段.由于正常的引入JAr包源码没法进行对源码打断点,想要深入了解源码不方便.下面就开始介绍源码调试的步骤. 1.在eclipse新建一个JAVA项目compare_ ...
- jdk源码调试进去形参没有值
https://blog.csdn.net/u010407050/article/details/76690478 1.在你的D:盘新建jdk文件夹,然后在文件夹里面分别创建两个文件夹jdk_src( ...
- JDK源码调试常见错误。
1.删除不需要的代码,即swing相关的代码 2.执行命令时要将前提环境进入文件夹如下: 起初没有完全执行第一条,因为网上说可以根据需要选择相关的代码,于是就没有删除,以后第一次模仿网上的例子的时候要 ...
- 震惊!我竟然发现了JDK源码的问题
读源码时的思考 最近在看concurrent包下线程池的源码,当我看到ThreadPoolExecutor类的时候,发现了JDK源码的一个问题.以下是ThreadPoolExecutor类的addWo ...
- 跟踪调试JDK源码时遇到的问题及解决方法
目录 问题描述 解决思路 在IntelliJ IDEA中调试JDK源码 在eclipse中调试JDK源码 总结 问题描述 最近在研究MyBatis的缓存机制,需要回顾一下HashMap的实现原理.于是 ...
- eclipse调试jdk源码
摘要 介绍使用eclipse调试jdk源码 java是一门开源的程序设计语言,喜欢研究源码的java开发者总会忍不住debug一下jdk源码.虽然官方的jdk自带了源码包src.zip,然而在debu ...
- JDK源码重新编译——支持eclipse调试JDK源码--转载
最近在研究jdk源码,发现debug时无法查看源码里的变量值. 因为sun提供的jdk并不能查看运行中的局部变量,需要重新编译一下rt.jar. 下面这六步是编译jdk的具体步骤: Step 1: ...
- eclipse如何debug调试jdk源码(任何源码)并显示局部变量
最近要看struts2源码 仿照了一下查看jdk源码的方式 首先你要有strtus2的jar包和源码,在struts官网上下载时,选择full版本,里面会有src也就是源码了. jar导入项目,保证可 ...
随机推荐
- C# 5.0 TAP 模式下的HTTP Get和Post
标题有点瘆人,换了工作之后很少写代码了,之前由于签了保密协议,不敢把代码拿出来分享给大家,只能摘抄网上的, 今斗胆拿出来晒晒,跪求指点,直接上代码吧 public class HTTPHelper : ...
- org.hibernate.LazyInitializationException
1.org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.c ...
- [转载]test后跟je
今天俺也用OD(OllyDbg)反汇编了个小软件,其中里面有下面两条指令: 没太明白什么意思,google一下,在看雪论坛上发现了一个大虾的解释很详细,记录一下: 1.test a,b 是a与b相与的 ...
- 【C++基础】关键字static 局部变量
1.局部变量 static局部变量和普通局部变量有什么区别:static局部变量只被初始化一次,下一次依据上一次结果值: int test(int j){ static int i=10; i=i+j ...
- CyanogenMod刷机以及Google Play应用商店安装方法介绍
http://blog.csdn.net/zcynical/article/details/19241595 写在前面: 本文介绍的方法除第一步外,适用于所有CM系统支持的设备,第一步由于用到了PC上 ...
- c缺陷与陷阱笔记-第六章 预处理器
1.这一章貌似有个小错误,开始时定义 #define f (x) ((x)-1),然后f(x)代表什么,书上说是(x) ((x)-1),应该是 (x) ((x)-1)(x) 2.关于宏定义中参数的2次 ...
- EXPORT_SYMBOL的作用是什么
http://www.cnblogs.com/riskyer/p/3221805.html EXPORT_SYMBOL只出现在2.6内核中,在2.4内核默认的非static 函数和变量都会自动 导入到 ...
- eCos中的线程与同步
http://blog.csdn.net/ooaven/article/details/6280018 先看一下eCos线程的创建.控制以及优先级的操作这三个方面的知识,主要是对它的实现方式及API做 ...
- 命令格式 kill -3 pid
命令格式 kill -3 pid 作用 打印进程号为pid的进程中,每个线程的执行日志 到 nohup文件 中,如果nohup的输出做了重定向,那么输出到重定向以后的文件中. 命令格式 top -Hp ...
- Microsoft SQL Server 2012 数据库安装图解教程
本文部分引用以下文章: SQL Server 2012 安装图解教程(附sql2012下载地址)_MsSql_脚本之家 http://www.jb51.net/article/36049.htm SQ ...