Mac 10.14.4 Compile OpenJDK1.9 source code and integrated CLION dynamic debugging

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

1. Get the openjdk source code:

Official website address: http://jdk.java.net/

  share picture

share picture

Two, prepare the environment

Install homwbrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew /install/master/install)"

Installation dependencies:

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)

Compile:
 ./conf igure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.10.1 --enable-ccache --with-jvm-variants=server,client --with-boot- jdk-jvmargs="-Xlint:deprecation -Xlint:unchecked" 
--disable-warnings-as-errors --with-debug-level =slowdebug 2>&1 | tee configure_mac_x64.log

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

share picture

Finally, verify:

 cd openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/jdk/bin
Execution: ./java -version

share picture

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 *):

share picture

vi src/sha re/vm/opto/loopPredicate.cpp (const TypeInt *):

share picture

< span style="font-size: 15px;"> vi src/share/vm/opto/loopPredicate.cpp (const TypeInt * ):

share picture

< !--?xml version="1.0" encoding="UTF-8"?-->

Modify the error message ( Error solution):

< pre>#1\. src/hotspot/share/memory/virtualspace.cpp # l585 if (base() != NULL ) {
#
2\. src/hotspot/share/opto/lcm .cpp # l42 if (Universe::narrow_oop_base() != NULL) {/ / Implies UseCompressedOops.



#3\. src/hotspot/share/opto/loopPredicate.cpp # l915 assert (rng->Opcode() == Op_LoadRange || iff->is_RangeCheck() || _igvn.type(rng)->is_int()->_lo >= 0, must be);


Four. Debug after successful compilation:

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);
        }
    }
}

  

Configure idea virtual machine parameters:

-XX:NewSize=6m
-XX:SurvivorRatio=4
-XX:MaxNewSize=6m
-Xlog:gc*:stdout:time,level,tags
-XX:+UseParallelGC

The location is shown in the figure below:

Share a picture

Then run:

share picture


2. Debug openjdk by running the Java program:

Pour the hotspot in the openjdk directory into CLion

Configure parameters and run:

share picture

< 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:
/Users/yourname/jvm /openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/images/jdk/bin/java -XX:NewSize=6m -XX:SurvivorRatio=4 -XX:MaxNewSize =6m -Xlog:gc*:stdout:time,level,tags -XX:+UseParallelGC -Dfile.encoding=UTF-8 -classpath /Users/yourname /IdeaProjects/mytest_projects/test_myjdk9/out/production/test_myjdk9 Main

share pictures

Compile java:

Share pictures

Build Jvm:

share picture

share pictures

Parameters:

COMPILER_WARNINGS_FATAL=false LFLAGS="'-Xlinker -lstdc++'"< /span> CC=clang USE_CLANG=true LP64=1

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:

 Share picture 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, 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-08 22:07:16 End 2019-07-08 22: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 8 22: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 8 21:09 jdk8u.zip drwxrwxr-x 2 liangding liangding 4096 Jul 8 21 :48 jdk8u drwxrwxr-x 14 liangding liangding 4096 Jul 8 21:53 openjdk-jdk8u-jdk8u span>-rw-rw-r———————————— 1 liangding liangding 147 Jul 8 22: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 public class HelloWorld { public static 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 [***@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 )

Compile :

./ configure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.10.1 --enable-ccache --with-jvm-variants=server,client --with-boot- jdk-jvmargs="-Xlint:deprecation -Xlint:unchecked" 
--disable-warnings-as-errors --with-debug-level =slowdebug 2>&1 | tee configure_mac_x64.log

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

如果一切顺利,看到此结果就算编译成功了:

./configure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.10.1 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs="-Xlint:deprecation -Xlint:unchecked" 
--disable-warnings-as-errors --with-debug-level=slowdebug 2>&1 | tee configure_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

#1\. src/hotspot/share/memory/virtualspace.cpp # l585 if (base() != NULL) {
#
2\. src/hotspot/share/opto/lcm.cpp # l42 if (Universe::narrow_oop_base() != NULL) { // Implies UseCompressedOops.


#3\. src/hotspot/share/opto/loopPredicate.cpp # l915 assert(rng->Opcode() == Op_LoadRange || iff->is_RangeCheck() || _igvn.type(rng)->is_int()->_lo >= 0, "must be");

1.编写Java程序并使用自己编译的openjdk版本

 

修改idea编译器的jdk: 改为build/macosx-x86_64-normal-serverANDclient-slowdebug/images/jdk

 

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);
        }
    }
}

-XX:NewSize=6m
-XX:SurvivorRatio=4
-XX:MaxNewSize=6m
-Xlog:gc*:stdout:time,level,tags
-XX:+UseParallelGC

Executable是你编译生成的java命令,如我的目录是 build/macosx-x86_64-normal-serverANDclient-slowdebug/images/jdk/bin/java 

Program arguments就是你启动Java程序的参数,用IDEA运行上边编写的Java程序时,IDEA会打印运行指令如下:

/Users/yourname/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/images/jdk/bin/java -XX:NewSize=6m -XX:SurvivorRatio=4 -XX:MaxNewSize=6m -Xlog:gc*:stdout:time,level,tags -XX:+UseParallelGC -Dfile.encoding=UTF-8 -classpath /Users/yourname/IdeaProjects/mytest_projects/test_myjdk9/out/production/test_myjdk9 Main

分享图片

与java联调:

分享图片

 

/Users/yourname/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/images/jdk/bin/java -XX:NewSize=6m -XX:SurvivorRatio=4 -XX:MaxNewSize=6m -Xlog:gc*:stdout:time,level,tags -XX:+UseParallelGC -Dfile.encoding=UTF-8 -classpath /Users/yourname/IdeaProjects/mytest_projects/test_myjdk9/out/production/test_myjdk9 Main

COMPILER_WARNINGS_FATAL=false LFLAGS="‘-Xlinker -lstdc++‘" CC=clang USE_CLANG=true LP64=1

1、安装代码管理工具mercurial/获取自己获取代码包 2、安装插件: yum install alsa-lib-devel cups-devel libX* gcc gcc-c++ freetype-devel libstdc++-static ant make 3、查看当前路径 [***@VM_0_3_centos openjdk-jdk8u-jdk8u]$ pwd /home/liangding/openjdk-jdk8u-jdk8u [***@VM_0_3_centos openjdk-jdk8u-jdk8u]$ 4、修改参数配置 [***@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、编译 [***@VM_0_3_centos openjdk-jdk8u-jdk8u]$ make 看到以下信息表示编译成功 ## Finished jdk (build time 00:06:20) —— Build times ——— Start 2019-07-08 22:07:16 End 2019-07-08 22: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、测试编译后生成jdk的路径 [***@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 8 22:30 linux-x86_64-normal-server-fastdebug 7、写一个测试程序 [***@VM_0_3_centos ~]$ ls -lrt total 127804
-rw-rw-r———————————— 1 liangding liangding 130719042 Jul 8 21:09 jdk8u.zip drwxrwxr-x 2 liangding liangding 4096 Jul 8 21:48 jdk8u drwxrwxr-x 14 liangding liangding 4096 Jul 8 21:53 openjdk-jdk8u-jdk8u -rw-rw-r———————————— 1 liangding liangding 147 Jul 8 22:41 HelloWorld.java -rw-rw-r———————————— 1 liangding liangding 432 Jul 8 22:45 HelloWorld.class [***@VM_0_3_centos ~]$ cat HelloWorld.java public class HelloWorld { public static void main(String[] args) { System.out.println(“HelloWorld openJDK”); } } 8、测试 [***@VM_0_3_centos ~]$ ./openjdk-jdk8u-jdk8u/build/linux-x86_64-normal-server-fastdebug/jdk/bin/javac HelloWorld.java 9、运行 [***@VM_0_3_centos ~]$ ./openjdk-jdk8u-jdk8u/build/linux-x86_64-normal-server-fastdebug/jdk/bin/java HelloWorld HelloWorld openJDK [***@VM_0_3_centos ~]$

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1135 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.