zoukankan      html  css  js  c++  java
  • 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:javajdk1.6.0_07jrelib t.jar;C:javajdk1.6.0_07jrelibjce.jar;C:javajdk1.6.0_07jrelibjsse.jar;C:javajdk1.6.0_07jrelib esources.jar;C:javajdk1.6.0_07jrelibcharsets.jar;C:javajdk1.6.0_07jrelibdeploy.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_HOMEjrelib, 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:javajdk1.6.0_07src.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

     
  • 相关阅读:
    springboot @ConfigurationProperties 中文乱码解决方案
    Centos 7安装Mysql 5.7详细教程,Linux安装Mysql 5.7详细教程
    Centos7 mysql Unit not found,Centos7 在线安装mysql 5.7
    Windows Tomcat安装配置,Tomcat 启动闪退,Windows Tomcat中文乱码解决
    ubuntu 切换到 root 用户
    一行代码完成定时任务调度,基于Quartz的UI可视化操作组件 GZY.Quartz.MUI
    快速实现一个室内空气质量检测仪
    外设驱动库开发笔记36:NTC负温度系数热电阻测温驱动
    外设驱动库开发笔记34:OLED显示屏驱动
    滤波器开发之五:基于算术平均的限幅滤波器
  • 原文地址:https://www.cnblogs.com/hansongjiang/p/4823844.html
Copyright © 2011-2022 走看看