Mac compilation OpenJDK8

Source: Internet
Author: User

Bought "in-depth understanding of Java Virtual Machine" Zhou Zhiming this book has not been seen, our programs are running with the JVM, so learning Java must master the JVM, in order to understand what our object is doing.  1. Why to compile the JDK to explore the internal implementation mechanism of the JDK, one of the most convenient path is to compile a set of JDK itself, through reading and tracking debugging JDK source code to understand the principles of Java technology system, although the threshold is higher, but certainly more than reading a variety of books, articles, Blogs are more pertinent, and many of the JDK's methods are localized (Native), and you need to compile a set of JDK yourself when you need to track the operation of these methods or hack the JDK.  2. Select JDK now there are many open source JDK implementations available on the web, such as Apache HARMONY,OPENJDK, considering that the Sun series JDK is now the most widely used JDK version, so we chose OpenJDK to compile.  About OPENJDK? OPENJDK is the project that Sun created Open source Java in late 2006. Open source is the usual sense of open source form, equivalent to the source code can be reused. The commercial version of Oracle JDK and open JDK except for the copyright note, the rest of the code is basically the same, is based on the two common components. Oracle JDK also has a few open JDK, commercial closed source functionality. Oracle's project release manager Joe Darcy's relationship to the two on OSCON2011 also confirms the proximity of the Oracle JDK and open JDK programs to the IPO.   3. Environment Preparation 1.openJDK Download, get OPENJDK source code there are two ways. (1) One of them is to get HG clone http://hg.openjdk.java.net/jdk8/jdk8 jdk8 CD Jkd8 Bash via a code version management mercurial./get_source.sh This is the most direct  Way, but due to a lot of files, the domestic network on Git SVN is not fast enough, often may fail, you can change the mirror to the domestic, this can find mercurial. (2) from the HTTPS://DOWNLOAD.JAVA.NET/OPENJDK/JDK8 direct download package Good source code file, here openjdk in the download source has a bug, the front of the domain here is wrong, should be HTTP// Download.java.net, the former domain name replaced, the following unchanged, you can download the package good source files.  2. Installing dependent software,If you do not have a brew command, you can first see how brew is installed before proceeding with the above installation commands. (1) Xcode-select: Install command:xcode-select–install   x11 link sudo ln-s/usr/x11/include/x11/usr/include/x11 or sudo ln- S/USR/LOCAL/X11/INCLUDE/X11/USR/INCLUDE/X11 (2) Install xquartz:https://www.xquartz.org/(3) Install FreeType, install command: Brew FreeType (4) Installing the GC installation command: Brew Install gcc49 is said to have an error on the installed version. (5) Install CCache Boost compilation speed brew install FreeType (6) Install Ant General Mac will have this environment, if not done: Brew install ant  3. Modify the source code

(1). Modify generated-configure.sh (path: common/autoconf/generated-configure.sh)
Note 20061 lines
As_fn_error $? "GCC compiler is required. Try setting--with-tools-dir. " "$LINENO" 5
Note 21640 lines
As_fn_error $? "GCC compiler is required. Try setting--with-tools-dir. " "$LINENO" 5

(2). Modify RELOCINFO.HPP (path: HOTSPOT/SRC/SHARE/VM/CODE/RELOCINFO.HPP)
Modify Line 367
Inline friend Relocinfo prefix_relocinfo (int datalen);
Modify Line 472
inline relocinfo prefix_relocinfo (int datalen = 0) {
ASSERT (Relocinfo::fits_into_immediate (datalen), "Datalen in Limits");
Return Relocinfo (relocinfo::d ata_prefix_tag, Relocinfo::raw_bits, Relocinfo::d atalen_tag | datalen);
}


(3). Modify Openjdk/hotspot/src/share/vm/opto/looppredicate.cpp
Modify 775 Behavior
ASSERT (Rng->opcode () = = Op_loadrange | | _igvn.type (RNG)->is_int ()->_lo >= 0, "must be");


(4). Modify Openjdk/hotspot/src/share/vm/runtime/virtualspace.cpp
Modify 331 behavior
if (base ()! = 0) {

4. Set the environment variable CD ~ Open. Bash_profile (this will be set in the JDK installation, if you do not have this file to see the JDK installation tutorial) add variables:

Export Lang=c
# Set Language Options, must be set
Export Lang=c
# Mac platform, C compiler is no longer gcc, is clang
Export Cc=clang
# Skip some of Clang's rigorous grammar checks, or you'll have n-more warnings as error
Export Compiler_warnings_fatal=false
# parameters to use when linking
Export lflags= '-xlinker-lstdc++ '
# whether to use Clang
Export Use_clang=true
# using a 64-bit data model
Export Lp64=1
# Tell the build platform to be 64 bits, otherwise it will be compiled by 32 bits
Export arch_data_model=64
# Allow automatic download dependencies
Export Allow_downloads=true
# The number of threads compiled in parallel, the compilation time is long, in order not to affect other work, I choose to 2
Export hotspot_build_jobs=2
Export alt_parallel_compile_jobs=2
# whether to skip comparisons to previous versions
Export Skip_compare_images=true
# Use Precompiled header files to speed up compilation
Export Use_precompiled_header=true
# whether to use incremental compilation
Export Incremental_build=true
# Compile Content
Export Build_langtools=true
Export Build_jaxp=true
Export Build_jaxws=true
Export Build_corba=true
Export Build_hotspot=true
Export Build_jdk=true
# compiled version
Export Skip_debug_build=true
Export Skip_fastdebug_build=false
Export Debug_name=debug
# avoid the build of parts like Javaws and browser Java plugins
Export Build_deploy=false
Export Build_install=false

and end up with these two variables, or something weird will happen.
unset java_home
Unset CLASSPATH

 5. Compile, (you may encounter the problem can first look at the following problem description) (1) The CD to the download Good OPENSDK directory, first grant permissions to openjdk directory such as: Chmod-r 777 openjdk  (2)./configure If no freetype can be found to execute./configure--with-freetype-include=/usr/local/include/freetype2--with-freetype-lib=/usr/local/ lib/   (3) Start the Make command: You need to specify the compilation environment in order to execute the make command, the environment path is under:./openjdk/build/there are generally two macosx-x86_64- Normal-server-release and Macosx-x86_64-normal-server-slowdebug If the general compilation fails there will be a failed file, for the sake of insurance first executed: Make conf=macosx-x86_64- Normal-server-release clean or make conf=macosx-x86_64-normal-server-slowdebug clean re-execute: Make Conf=macosx-x86_64-n Ormal-server-release Install or make Conf=macosx-x86_64-normal-server-slowdebug install build succeeded 6. I execute. Configure and compilation Problems encountered: (1)./configure problem: Configure:error:GCC compiler is required workaround: Jdk8/common/autoconf/generated-co Two codes are commented in the nfigure.sh file: No. 20061, line 21640 #as_fn_error $? "GCC compiler is required. Try setting--with-tools-dir. " "$LINENO" 5   (2) Make problem: Running Nasgen Exception in thread "main" Java.lang.VerifyError:class JDk.nashorn.internal.objects.ScriptFunctionImpl overrides final method Setprototype. (ljava/lang/object;) V Workaround: Modify: Vim./OPENJDK/NASHORN/MAKE/BUILDNASHORN.GMK 80 Line Original-CP modified to:-xbootclasspath/p:  & Nbsp;    7. Test whether the CD was compiled successfully./openjdk/build/macosx-x86_64-normal-server-release/jdk/bin Execute Java- Version is compiled successfully:       

Mac compilation OpenJDK8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.