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 isOpen JDK 9u
  • The installationHomebrew(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 itJDKSource code of eight brother (I use MScode)
  • To install aBoot JDKBecause:JDKThere is quite a bit of code inJavaWrite it, so I want to compile itJDKYou need another oneJDKTo assist (chicken and egg, chicken and egg/pull yourself up by your hair), I installed the official OracleJDK
  • The installationfreetype: This is a dependencybrew install freetype
  • The installationXcode

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 JDKSource: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

  1. Don’t compileJDK 8: because compile 8 requiresXcode 4nowXcode– 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)
  2. Try not to useMercurialTo theOpen JDKThe source code, while using the browser directly download the packaged source code: because you want to useMercurialDownload theOpen JDKAfter the top of the project, also need to execute one of themget_source.shTo 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)
  3. compileJDK 9uRather thanJDK 9Because I was compiling9There were a bunch of errors, so I thought I’d bring oneuOf will be better, of course, this has a great extent is my guess, I will take later9uI did. I didn’t try9If you’re interested, you can wade in this yourself
  4. configureBe sure to bring it with you--disable-warnings-as-errorsThis parameter is otherwise used during compilationwarningIt also interrupts the compilation process, actuallywarningDoes not affect the compiled targetJDKThe 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.cppSearch theif (base() > 0) {Instead ofif (base() ! = NULL) {
  • src/share/vm/opto/lcm.cppSearch theif (Universe::narrow_oop_base() > 0) {Instead ofif (Universe::narrow_oop_base() ! = NULL) {
  • src/share/vm/opto/loopPredicate.cppSearch 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