Warning??: This article takes a long time, so be mentally prepared; compile openjdk The source code requires a lot of patience, because there are many pits to solve many problems. I spent two days from the beginning of the compilation to the end. According to this tutorial, I will step on the pits a little; thank you for watching
brew install ccache //speed up compilation
brew install freetype //Font engine, which will be relied upon during compilation
Three: Environment Compilation (It should be noted here that the mac system version should correspond to the xcode version and openjdk version, otherwise there will be a lot of problems!!!)< /span>
Directly search for version 9.2, and then Download and install)
Note: Point –with-freetype to your own freetype installation path, There may be insufficient permissions: Please add -bash to ./config (or find a solution by yourself)
Output the following content, basically indicating that your environment is fine:
A new configuration has been successfully created in /Users/yourname/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug using configure arguments '--with-target-bits=64 --with-freetype =/usr/local/Cellar/freetype/2.9.1 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs='-Xlint:deprecation -Xlint:unchecked' --disable-warnings-as-errors --with-debug-level=slowdebug' span>. Configuration summary: * Debug level: slowdebug * HS debug level: debug * JDK variant: normal * JVM variants: server client * OpenJD K target: OS: macosx, CPU architecture: x86, address length: 64 * Version string: 9-internal+0-adhoc.daiyongzhi.jdk9 (9-internal) Tools summary: * Boot JDK: java version "1.8.0_101" Java( TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home) * Toolchain: clang (clang/LLVM from Xcode 9.2< span style="color: #000000;">) * C Compiler: Version 9.0.0 (at /usr/bin/clang) * C++ Compiler: Version 9.0< /span>.0 (at /usr/bin/clang++) Build performance summary: * Cores to use: 8 * Memory limit: 16384 MB * ccache status: Active (3.5) NOTE: You have requested to build more than one version of the JVM, which will result in longer build times.
< /span>
Compile openjdk1.9 :
export LANG=C
make all LOG=debug 2>&1 | tee make_mac_x64.log
If everything goes well, the compilation is successful if you see this result:
< /div>
Finally, verify:
cd openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/jdk/bin
Execution: ./java -version
Warning??: Problems encountered during compilation (here are a few common errors, if there are other errors, please find solutions by yourself):
To summarize the problems encountered during the compilation process:
vi src/share/vm/memory/virtualspace.cpp (char *):
vi src/sha re/vm/opto/loopPredicate.cpp (const TypeInt *):
< span style="font-size: 15px;"> vi src/share/vm/opto/loopPredicate.cpp (const TypeInt * ):
1.Write a Java program and use the openjdk version compiled by yourself
< span style="background-color: #ffff00; font-size: 15px;">Modify the jdk of the idea compiler: Change to build/macosx-x86_64-normal-serverANDclient-slowdebug/images/jdk
java code:
public class Main {
public static int size_1m = 1024*1024;
public static List list = new ArrayList<>();
public static void main(String[] args) throws Exception {
System.out.println("Hello World!");
for(int i=0;i<10;i++){
System.out.println(i+1);
list.add(new byte[size_1m]);
Thread.sleep(1000L);
}
}
}
Pour the hotspot in the openjdk directory into CLion
Configure parameters and run:
< p>
Executable is the java command generated by your compilation, such as my directory is build/macosx-x86_64-normal-serverANDclient-slowdebug/images/jdk/bin/ java
Program arguments are the parameters for you to start the Java program, use IDEA to run the Java program written above When running, IDEA will print the running instructions as follows:
Modify the source code method at will, and Called in the java source code (the method of obtaining the openjdk source code is modified here), the display effect is as follows:
p>
As shown above: the entire compilation and joint debugging are complete, you can do whatever you want with the source code;
Bonus: compile openjdk under centOs: (This method is provided by a friend, I have not really tested it, just for reference):< /p>
1, install the code management tool mercurial /Get your own code package2, install the plug-in: yum install alsa-lib-devel cups-devel libX* gcc gcc-c++ freetype-devel libstdc++-static ant make 3, view the current path[***@VM_0_3_centos openjdk-jdk8u-jdk8u]$ pwd /home/liangding/openjdk-jdk8u-jdk8u [***@VM_0_3_centos openjdk-jdk8u-jdk8u]$ 4 span>, modify the parameter configuration[***@VM_0_3_centos openjdk-jdk8u-jdk8u]$ chmod +x configure [***@VM_0_3_centos openjdk-jdk8u-jdk8u]$ ./configure —prefix=/home/liangding/jdk8u —enable-debug 5, compile[***@VM_0_3_centos openjdk-jdk8u-jdk8u]$ make If you see the following message, it means the compilation was successful.## Finished jdk (build time 00:06:20) —— Build times ——— Start 2019- 07-0822:07:16 End 2019-07-0822:36:47 00:00:52 corba 00:20:13 hotspot 00:00:33 jaxp 00:00: 42 jaxws 00:06:20 jdk 00:00:51 langtools 00:29:31 TOTAL ———————————— 6, test the path to generate jdk after compiling[***@VM_0_3_centos build]$ pwd /home/liangding/openjdk -jdk8u-jdk8u/build [***@VM_0_3_centos build]$ ls -lrt total 4 drwxrwxr-x 9 liangding liangding 4096 Jul 822:30 linux-x86_64-normal-server-fastdebug 7, write a test program [***@VM_0_3_centos ~]$ ls- lrt total 127804 -rw-rw-r———————————— 1 liangding liangding 130719042 Jul 821:09 jdk8u.zip drwxrwxr-x 2 liangding liangding 4096 Jul 821 :48 jdk8u drwxrwxr-x 14 liangding liangding 4096 Jul 821:53 openjdk-jdk8u-jdk8u span>-rw-rw-r———————————— 1 liangding liangding 147 Jul 822:41 HelloWorld.java -rw-rw-r———————————— < span style="color: #800080;">1 liangding liangding 432 Jul 8< /span> 22:45 HelloWorld.class [***@VM_0_3_centos ~]$ cat HelloWorld.java span>publicclass HelloWorld { publicstatic void main(String[] args) {System.out.println("HelloWorld openJDK");}} 8, test[***@VM_0_3_centos ~]$ ./openjdk-jdk8u-jdk8u/build/linux-x86_64-normal-server-fastdebug/jdk/bin/javac HelloWorld.java 9, run [* **@VM_0_3_centos ~]$ ./openjdk-jdk8u-jdk8u/build/linux-x86_64-normal-server-fastdebug/jdk/bin/java HelloWorld HelloWorld openJDK [ span>***@VM_0_3_centos ~]$
The original is not easy, please indicate the source for reprinting, thank you
Official website address: http://jdk.java.net/
/usr/bin/ruby- e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install ccache //speed up compilation
brew install freetype //Font engine, which will be relied upon during compilation
Mac os: 10.14.4
xcode:9.2
official link to download xcode: Sign In-Apple ( Directly search for version 9.2, then download and install )
Note: Point –with-freetype to your own freetype installation path, There may be insufficient permissions: Please add -bash to ./config (or find a solution by yourself)
Output the following content, basically indicating that your environment is fine:
A new configuration has been successfully created in /Users/yourname/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug using configure arguments '--with-target-bits=64 --with-freetype =/usr/local/Cellar/freetype/2.9.1 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs='-Xlint:deprecation -Xlint:unchecked' --disable-warnings-as-errors --with-debug-level=slowdebug' span>. Configuration summary: * Debug level: slowdebug * HS debug level: debug * JDK variant: normal * JVM variants: server client * OpenJD K target: OS: macosx, CPU architecture: x86, address length: 64 * Version string: 9-internal+0-adhoc.daiyongzhi.jdk9 (9-internal) Tools summary: * Boot JDK: java version "1.8.0_101" Java( TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home) * Toolchain: clang (clang/LLVM from Xcode 9.2< span style="color: #000000;">) * C Compiler: Version 9.0.0 (at /usr/bin/clang) * C++ Compiler: Version 9.0< /span>.0 (at /usr/bin/clang++) Build performance summary: * Cores to use: 8 * Memory limit: 16384 MB * ccache status: Active (3.5) NOTE: You have requested to build more than one version of the JVM, which will result in longer build times.
< /span>
进行编译 openjdk1.9 :
export LANG=C
make all LOG=debug 2>&1 | tee make_mac_x64.log
A new configuration has been successfully created in /Users/yourname/jdk9/build/macosx-x86_64-normal-serverANDclient-slowdebug using configure arguments ‘--with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.9.1 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs=‘-Xlint:deprecation -Xlint:unchecked‘ --disable-warnings-as-errors --with-debug-level=slowdebug‘. Configuration summary: * Debug level: slowdebug * HS debug level: debug * JDK variant: normal * JVM variants: server client * OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64 * Version string: 9-internal+0-adhoc.daiyongzhi.jdk9 (9-internal) Tools summary: * Boot JDK: java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode) (at /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home) * Toolchain: clang (clang/LLVM from Xcode 9.2) * C Compiler: Version 9.0.0 (at /usr/bin/clang) * C++ Compiler: Version 9.0.0 (at /usr/bin/clang++) Build performance summary: * Cores to use: 8 * Memory limit: 16384 MB * ccache status: Active (3.5) NOTE: You have requested to build more than one version of the JVM, which will result in longer build times.
export LANG=C
make all LOG=debug 2>&1 | tee make_mac_x64.log
cd openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/jdk/bin
执行: ./java -version
public class Main {
public static int size_1m = 1024*1024;
public static List list = new ArrayList<>();
public static void main(String[] args) throws Exception {
System.out.println("Hello World!");
for(int i=0;i<10;i++){
System.out.println(i+1);
list.add(new byte[size_1m]);
Thread.sleep(1000L);
}
}
}