- How to trace JDK source code
- 1、 Compile source code
- 2、 Associated source code
- 3、 Be accomplished
How to Track the JDK Source
Looking at this title, you probably wonder who’s tracking a source code, breaking a point in eclipse, running in debug, and thenF5Entry method, F6 skip method, F7 skip method。But I don’t know if you noticed that if you tracked the JDK source code, for example
putMethod,Even if you get F5 inside the method, you can’t see the actual value of your put key and value.But since we’re tracking the source code, we’re sure to see how keys and values we set went through the ninety-eighty-one difficulties before we got there.
HashMap thisbucketAmong them. Why is it a bucket? If you are interested in it, you can go into HashMap for yourself. I won’t introduce it too much here.
This is what we saw when we tracked the source code:
This is what we want to see:
Next is today’s topic.
1.1, Brief Introduction
First we need to know that a jar is
rt.jar, It’s the JAVA base class library, which is the class file of all the classes you see in Java doc, but
orcale To reduce the size of the jar package when compiling JDK source code, the
javac -g:none That is, without any debugging information.That’s why we’re tracking JDK source code, but we can’t see the value of variables, but God closes a door for you and opens a window for you. Now I’ll show you how the window was opened.
The picture above is the JDK installation directory. You can see that this one has one
src.zip，It is today’s protagonist: JDK source code, you can decompress it to see the content inside, in fact, is a Java class by class.
1.2, start compiling source code
- We need to decompress it, as for where to look at your mood, as long as you can find it, because we are today’s top show. The decompressed ones are the following
- Open eclipse and create a new Java project. Naming also depends on your mood.
- Copy all the 6 folders extracted from the first step into the SRC of your project (actually not all, some can be deleted, but all of them are copied in order to save time). )
- There’s an error, but you don’t have to worry about it. You just have to wait until eclipse compiles the project.Export to jar file。Selection
src-->Right-click - & gt; select Export
- Take your name, choose where to put it, and then
FinishThat’s all right. So far we have completed the first step.
2, Associated Source Code
- Choose from your eclipse toolbar
Installed JREs, Select the JDK click you use
- Click in the Edit Window
Add External JARsSelect the jar package that we just compiled and exported.
The red jar is the jar we export ourselves. We’re going to move the jar we export up to the blue one.
Associate our compiled jar with src. zip. Choice
JRE System LibraryFind the jar we compiled inside, right-click –& gt; Propertites.
External File...Find our original src. zip and select it. Then?
ok。Everything is over.
3. Great Achievement
Now you can happily track the source code and see how your variables are located.
javaThe world roamed.