background
Recently, I want to analyze several native methods, so I need to have a JDK that can debug at hand. Therefore, I have been doing a lot of things in the past two days, including 10+ pits, 10+ articles and 10+ attempts. Finally, I have compiled the JDK. When I run javac-version on my own JDK and output the familiar text, I feel a sense of accomplishment.
preparation
- Learn about OpenJDK: What we want to compile is
Open JDK 9u
- The installation
Homebrew
(optional) - Fan Yu tu Sik: Because if the compilation is wrong and you need to search for the wrong solution, you need to go through a non-existent website
- Have a good source editor: with any luck we may need to modify it
JDK
Source code of eight brother (I use MScode) - To install a
Boot JDK
Because:JDK
There is quite a bit of code inJava
Write it, so I want to compile itJDK
You need another oneJDK
To assist (chicken and egg, chicken and egg/pull yourself up by your hair), I installed the official OracleJDK
- The installation
freetype
: This is a dependencybrew install freetype
- The installation
Xcode
Environment description
- Operating system:
MacOS High Sierra Version: 10.13.3 (17D47)
Boot JDK
:1.8.0 comes with _161
freetype
:2.9
Xcode
:Version 9.2 (9 c40b)
Open JDK
Source:jdk9u-2e265b4b8622
corba-2ef36e70f490
hotspot-bb73b31e70e3
jaxp-95a71f690b44
jaxws-f4f878b5f01c
jdk-a779673ab57d
langtools-e2bf77b3f002
nashorn-fb3f7ae74bf6
The pit where others walked/the pit where I walked
- Don’t compile
JDK 8
: because compile 8 requiresXcode 4
nowXcode
– the version is now much higher than 4 (this hole was waded out by others, of course I am not convinced, then I waded through it myself and found it is indeed a hole) - Try not to use
Mercurial
To theOpen JDK
The source code, while using the browser directly download the packaged source code: because you want to useMercurial
Download theOpen JDK
After the top of the project, also need to execute one of themget_source.sh
To download the source code of the sub-project, this process is long and high failure rate (the key has not executed percentage tips, dry, etc.), with the browser to download all the sub-project compression package is much faster, and the success rate100%
I waded it out myself, having been told to use it in several previous articlesMercurial
, the result is a pit) - compile
JDK 9u
Rather thanJDK 9
Because I was compiling9
There were a bunch of errors, so I thought I’d bring oneu
Of will be better, of course, this has a great extent is my guess, I will take later9u
I did. I didn’t try9
If you’re interested, you can wade in this yourself configure
Be sure to bring it with you--disable-warnings-as-errors
This parameter is otherwise used during compilationwarning
It also interrupts the compilation process, actuallywarning
Does not affect the compiled targetJDK
The operation of the
Walk the process
If front of the preparation time you are ready, you also pay attention to the note, then begin to go process compilation, if an error (there is a big risk) don’t fall off the keyboard, there can be described with we mentioned earlier website to find the answer, my own feeling the stones across the river, repeatedly tried 2 genius, lu xun said good: “As long as kung fu deep, iron pestle ground into a needle”, I wish you good luck!!
step0
All the preparations mentioned above
step1
Download the source code package
step2
Run sh configure –with-debug-level=slowdebug –disable-warnings-as-errors at the top level of the source directory – with – freetype – include = / usr/local/Cellar/freetype / 2.9 / include/freetype2 – with – freetype – lib = / usr/local/Cellar/freetype 2.9 / lib/(with the version number of place oneself notice according to the actual situation in) if this step no problem should see the output:
step3
If you have the same build environment and source code version as mine, make all should fix a bug :error: Ordered comparison between pointer and zero (‘char *’ and ‘int’)… Is omitted
Open the hotspot directory
src/share/vm/memory/virtualspace.cpp
Search theif (base() > 0) {
Instead ofif (base() ! = NULL) {
src/share/vm/opto/lcm.cpp
Search theif (Universe::narrow_oop_base() > 0) {
Instead ofif (Universe::narrow_oop_base() ! = NULL) {
src/share/vm/opto/loopPredicate.cpp
Search theassert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int() >= 0, "must be");
Instead ofassert(rng->Opcode() == Op_LoadRange || iff->is_RangeCheck() || _igvn.type(rng)->is_int()->_lo >= 0, "must be");
step4
The compilation time of make all is a little longer, my machine is a 2017 MacBook Pro, it takes about 20 minutes +(not carefully calculated), and the fan is running wildly during the compilation process, note the remaining power and heat dissipation of the laptop, if the compilation is successful, specify javac full path to run javac-version to see
If error is reported, specific error specific analysis, because the compilation environment is different, error may be different, go to the non-existent website to find a solution, patience + luck you will be able to succeed.
conclusion
How hard you thought it would be to write a JDK turned out to be: Is easy, but the pit, more trouble, back and forth 10 times, spent two days in total, from try to compile the JDK 8 to 9 in the middle of the problem, once want to give up, but because want to use it to achieve the goal of further, so I insisted on down, and finally with the help of search engines and previous successful, so still that sentence: “As long as kung fu deep iron pestle grinding into a needle”, according to the correct direction, repeated attempts, will eventually succeed.
The resources
Building OpenJDK 8 on Mac OS X Mavericks
Building and Packaging OpenJDK9 for OSX
Compilation errors with clang to 4.0
OpenJDK / jdk10 / jdk10 / hotspot changeset 13502:316854ef2fa2
Ordered comparison between pointer and zero (‘char *’ and ‘int’) error #5
MAC compile OpenJDK8
Compile&Debug openjdk
openjdk code compilation/ IDE setup
Debug small JVM source code using Clion(GDB)
Fixed GDB debugging failure on Mac
xcode-select active developer directory error
Mac OsX Sierra – Stuck on binaryTreeDictionary.hpp compilation