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导入项目,保证可 ...
随机推荐
- 1176: [Balkan2007]Mokia - BZOJ
Description维护一个W*W的矩阵,每次操作可以增加某格子的权值,或询问某子矩阵的总权值. 修改操作数M<=160000,询问数Q<=10000,W<=2000000.Inp ...
- localStorage 便签功能实现
之前利用localStorage写过手机便签应用,因为蛋疼的换了台三星的屌丝级手机,木 有了测试的工具,没能继续优化维护下去.而在网页上实现便签功能目前来说似乎没有太大 的意义,因为不论是 Firef ...
- [转]LINQ操作数据库
查询表达式(LINQ)简介 C#3.0新语特性和改进,这些新特性在我们编写程序时为我们提供了非常大的帮助.从这篇开始,我们开始一起来探讨LINQ. LINQ是Language Integrated Q ...
- 论反馈信息如何推动 IT 运维团队进步?
我们还记得<快乐大本营>中经典游戏----快乐传真吗?游戏规则是:很多人站一排,只有第一个人才看到最准确的信息,用东西隔着,戴耳机,一一将从前一个人获得的信息传递下去,最后一个人说出推测的 ...
- struts2 标签的使用之二 s:iterator
struts2的s:iterator 可以遍历 数据栈里面的任何数组,集合等等 以下几个简单的demo:s:iterator 标签有3个属性: value:被迭代的集合 id :指定集 ...
- android dialog点击其他区域消失
只需调用dialog对象的setCanceledOnTouchOutside方法,传入参数为true即可. 如下代码实现: //点击其他区域dialog消失 menuDialog.setCancele ...
- jstack和线程dump分析
转自:http://jameswxx.iteye.com/blog/1041173 一:jstack jstack命令的语法格式: jstack <pid>.可以用jps查看java进程 ...
- POJ1265——Area(Pick定理+多边形面积)
Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...
- 一篇文章教会你,如何做到招聘要求中的“要有扎实的Java基础
来历 本文来自于一次和群里猿友的交流,具体的情况且听LZ慢慢道来. 一日,LZ在群里发话,“招人啦.” 然某群友曰,“群主,俺想去.” LZ回之,“你年几何?” 群友曰,“两年也.” LZ憾言之,“惜 ...
- allegro飞线隐藏
这些都是最基本的操作,你说的应该是飞线的显示和隐藏,命令在display下面,display>show rats>net(component/all) display>blank r ...