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导入项目,保证可 ...
随机推荐
- json分别算出元素的个数和最多的元素
个数: var str = 'aaafsdsaaasasasasaa'; var json = {}; for (var i = 0; i < str.length; i++) { if(!js ...
- jquery捕捉文本域输入事件
<input type='text' /> change事件是在文本域光标失去焦点时才会触发,要监听正在输入内容事件用键盘事件监听如果想要捕捉文本域输入事件,可以使用$("inp ...
- grep正则表达式后面的单引号和双引号的区别
单引号''是全引用,被单引号括起的内容不管是常量还是变量者不会发生替换:双引号""是部分引用,被双引号括起的内容常量还是常量,变量则会发生替换,替换成变量内容! 一般常量用单引号' ...
- IDS 日志分析
[http://blog.csdn.net/cnbird2008/article/details/5792626] General Approach通用方法1. Identify which log ...
- ORA-00911 :无效字符
———————————————————————————————————————————————————— 附: 1 ORA-01790:表达式必须具有与对应表达式相同的数据类型 知识解析:SQL ...
- Trainning Guide的代码
今天无意间找到了训练指南的网上代码,都是刘汝佳写的,在这. 今天在做这题1400 - "Ray, Pass me the dishes!",我写的线段树的思路跟上次的Frequen ...
- C#+SQL数据库备份和还原
使用前要导入SQLDMO.dll(在com组件中导入Microsoft SQLDMO Object Library即可) /// /// DbOper类,主要应用SQLDMO实现对Microsoft ...
- HTTPConnection与HTTPClient的区别
HttpClient是个很不错的开源框架,封装了访问http的请求头,参数,内容体,响应等等.HttpURLConnection是java的标准类,什么都没封装,用起来太原始,不方便.比如重访问的自定 ...
- Go语言Revel框架 环境搭建
1.首先参考连个链接 http://blog.csdn.net/creak_phone/article/details/12620969 http://www.geek521.com/?p=616 2 ...
- windows下的go语言的环境搭建和初探
闲话不说,直入主题. 1.准备工具 a.windows下的Go语言开发安装包 官方下载地址:https://code.google.com/p/go/downloads/list b.Go语言中文官网 ...