Article From:https://www.cnblogs.com/zc-programer/p/9938508.html

Catalog

  • 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 exampleHashMapOfputMethod,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 isrt.jar, It’s the JAVA base class library, which is the class file of all the classes you see in Java doc, butorcale To reduce the size of the jar package when compiling JDK source code, thejavac -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 onesrc.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

  1. 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

  1. Open eclipse and create a new Java project. Naming also depends on your mood.

  1. 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). )

  1. 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。Selectionsrc-->Right-click - & gt; select Export

  1. Take your name, choose where to put it, and thenFinishThat’s all right. So far we have completed the first step.

2, Associated Source Code

  1. Choose from your eclipse toolbarwindow-->preferences,findInstalled JREs, Select the JDK click you useEditEdit.

  1. Click in the Edit WindowAdd External JARs Select the jar package that we just compiled and exported.

  1. The red jar is the jar we export ourselves. We’re going to move the jar we export up to the blue one.rt.jar Above. Then?Finish

  2. Associate our compiled jar with src. zip. ChoiceJRE System Library Find the jar we compiled inside, right-click –& gt; Propertites.

  1. stayPropertites ChoiceExternal File... Find our original src. zip and select it. Then?Aplly 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.

Leave a Reply

Your email address will not be published. Required fields are marked *