I\'m debugging the JDK source like:
public static int codePointAt(CharSequence seq, int index) {
char c1 = seq.charAt(index++);
if (isHighSu
c-s's jre\lib\endorsed solution is great. Easier to build is with Eclipse: create a Java project, put javax*, java* into src and let Eclipse compile. Then export the jar.
Just so you know, the endorsed override mechanism is deprecated and will be removed in a future release (http://docs.oracle.com/javase/8/docs/technotes/guides/standards/).
Use this pom.xml
to get JDK 1.8.0_111
sources with debug information:
<project>
<modelVersion>4.0.0</modelVersion>
<name>JDK sources with debug information</name>
<groupId>ex.jdk.debug</groupId>
<artifactId>jdk-debug-sources</artifactId>
<version>1.8.0_111</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>jdk-rt</artifactId>
<version>1.8.0_111</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
<source>1.8</source>
<target>1.8</target>
<excludes>
<exclude>com/sun/java/swing/**</exclude>
<exclude>com/sun/source/util/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
You'll have to do a manual install of the original rt.jar
to be able to run mvn clean install
mvn install:install-file -Dfile=rt.jar -DgroupId=com.oracle -DartifactId=jdk-rt -Dversion=1.8.0_111 -Dpackaging=jar
The rt.jar
I copied to the endorsed
directory is the original rt.jar
but with the original classes replaced by my newly generated classes.
This article http://www.thejavageek.com/2016/04/03/debug-jdk-source-code/ describe the same but in simple and nice way. You do stuff(compile,make jar) by using eclipse only.
In case anybody needs this with tomcat. You need to set up the VM argument Djava.endorsed.dirs and put your compiled jdk jar in it. You can do this c-s's solution or exported with eclipse(all the Java Compiler ClassFile Generation used by de debugger must be active)
Go to Run Configurations > Arguments > VM arguments
Djava.endorsed.dirs="/your/folder/apache-tomcat-xxx/endorsed"
Generally speaking, to be able to watch the variables while stepping through JDK source code, you need the class files to be compiled with debug information i.e. compile using javac -g
.
So your best bet is to either find an already compiled version with debug information (I couldn't find anything for JDK 7) or you can try compiling the source for yourself.
According to this post (please note that I haven't tried it) you don't need to compile all sources, only the ones you need. Putting your newly compiled classes in the $jdk/jre/lib/
ext/endorsed
directory, the new classes would be used instead the ones in the original rt.jar
.
I believe that should get you started.
Update: Actually I have just tried this process and it is not hard at all. Tested on Windows, JDK 1.7.0_11. All the commands are invoked from command line:
d:\
root folderjdk7_src
and output folder jdk_debug
JDK_HOME
folder get the src.zip
file and unzip it inside jdk7_src
java
javax
org
JDK_HOME\jre\lib
get the file rt.jar
and put in the work folder (this is only for convenience to not specify too large file names in the command line).dir /B /S /X jdk7_src\*.java > filelist.txt
to create a file named filelist.txt
with the list of all java files that will be compiled. This will be given as input to javac
javac
using the command:javac -J-Xms16m -J-Xmx1024m -sourcepath d:\jdk7_src -cp d:\rt.jar -d d:\jdk_debug -g @filelist.txt >> log.txt 2>&1
This will compile all the files in the jdk_debug
folder and will generate a log.txt
file in your working folder. Check the log contents. You should get a bunch of warnings but no error. jdk_debug
folder and run the command: jar cf0 rt_debug.jar *
. This will generate your new runtime library with degug information.JDK_HOME\jre\lib\endorsed
. If the endorsed
folder does not exist, create it.Debug your program in Eclipse. Note how the variables are named normally (no more arg0, arg1 etc). Happy debugging :)