JVM-Ubuntu18.04.1下编译OpenJDK [Ubuntu version -> 18.04 LTS openjdk9 bootjdk8]

1.使用Mercurial下载openJDK9的源代码,优点就是操作起来很简单,不需要再解压文件包。Mercurial也是一种版本管理工具
    apt install mercurial
    
2.创建下载jdk1.9的下载目录
    mkdir /juwenzhe
    cd /juwenzhe
    
3.获取openJDK9,大约需要30分钟
    hg clone http://hg.openjdk.java.net/jdk9/dev 9dev
    cd 9dev
    sh ./get_source.sh
    ---------------执行如下----------------
    root@ubuntu:/juwenzhe/9dev# sh get_source.sh 
    # Repositories:  corba jaxp jaxws langtools jdk hotspot nashorn 
                    corba:   hg clone http://hg.openjdk.java.net/jdk9/dev/corba corba
                     jaxp:   hg clone http://hg.openjdk.java.net/jdk9/dev/jaxp jaxp
                    corba:   requesting all changes
                    corba:   adding changesets
                     jaxp:   requesting all changes
                     jaxp:   adding changesets
                    corba:   adding manifests
                    corba:   adding file changes
                     jaxp:   adding manifests
                     jaxp:   adding file changes
                    corba:   added 876 changesets with 5451 changes to 2597 files
                    corba:   new changesets 55540e827aef:5666eba44ac6
                    corba:   updating to branch default
                    corba:   1201 files updated, 0 files merged, 0 files removed, 0 files unresolved
                    jaxws:   hg clone http://hg.openjdk.java.net/jdk9/dev/jaxws jaxws
                    jaxws:   requesting all changes
                    jaxws:   adding changesets
                    jaxws:   adding manifests
                    jaxws:   adding file changes
                     jaxp:   added 1153 changesets with 14751 changes to 8449 files
                     jaxp:   new changesets 6ce5f4757bde:364631d8ff2e
                     jaxp:   updating to branch default
                     jaxp:   3352 files updated, 0 files merged, 0 files removed, 0 files unresolved
                langtools:   hg clone http://hg.openjdk.java.net/jdk9/dev/langtools langtools
                langtools:   requesting all changes
                langtools:   adding changesets
                langtools:   adding manifests
                    jaxws:   added 801 changesets with 21839 changes to 10824 files
                    jaxws:   new changesets 0961a4a21176:a1d64f45f9d5
                    jaxws:   updating to branch default
                    jaxws:   3760 files updated, 0 files merged, 0 files removed, 0 files unresolved
                      jdk:   hg clone http://hg.openjdk.java.net/jdk9/dev/jdk jdk
                      jdk:   requesting all changes
                      jdk:   adding changesets
                langtools:   adding file changes
                      jdk:   adding manifests
                langtools:   added 4174 changesets with 38097 changes to 11847 files
                langtools:   new changesets 9a66ca7c79fa:65bfdabaab9c
                langtools:   updating to branch default
                langtools:   9464 files updated, 0 files merged, 0 files removed, 0 files unresolved
                  hotspot:   hg clone http://hg.openjdk.java.net/jdk9/dev/hotspot hotspot
                  hotspot:   requesting all changes
                  hotspot:   adding changesets
                  hotspot:   adding manifests
                  hotspot:   adding file changes
                      jdk:   adding file changes
                  hotspot:   added 12824 changesets with 78616 changes to 15832 files
                  hotspot:   new changesets a61af66fc99e:b756e7a2ec33
                  hotspot:   updating to branch default
                  hotspot:   9078 files updated, 0 files merged, 0 files removed, 0 files unresolved
                  nashorn:   hg clone http://hg.openjdk.java.net/jdk9/dev/nashorn nashorn
                  nashorn:   requesting all changes
                  nashorn:   adding changesets
                  nashorn:   adding manifests
                  nashorn:   adding file changes
                  nashorn:   added 1928 changesets with 14563 changes to 4181 files
                  nashorn:   new changesets b8a1b238c77c:17cc754c8936
                  nashorn:   updating to branch default
                  nashorn:   3293 files updated, 0 files merged, 0 files removed, 0 files unresolved
                      jdk:   added 17287 changesets with 152446 changes to 50650 files
                      jdk:   new changesets 37a05a11f281:65464a307408
                      jdk:   updating to branch default
                      jdk:   27295 files updated, 0 files merged, 0 files removed, 0 files unresolved
    # Repositories:  . corba jaxp jaxws langtools jdk hotspot nashorn 
                        .:   cd . && hg pull -u
                    corba:   cd corba && hg pull -u
                     jaxp:   cd jaxp && hg pull -u
                    jaxws:   cd jaxws && hg pull -u
                langtools:   cd langtools && hg pull -u
                      jdk:   cd jdk && hg pull -u
                  hotspot:   cd hotspot && hg pull -u
                  nashorn:   cd nashorn && hg pull -u
                      jdk:   pulling from http://hg.openjdk.java.net/jdk9/dev/jdk
                    corba:   pulling from http://hg.openjdk.java.net/jdk9/dev/corba
                langtools:   pulling from http://hg.openjdk.java.net/jdk9/dev/langtools
                        .:   pulling from http://hg.openjdk.java.net/jdk9/dev
                  nashorn:   pulling from http://hg.openjdk.java.net/jdk9/dev/nashorn
                     jaxp:   pulling from http://hg.openjdk.java.net/jdk9/dev/jaxp
                  hotspot:   pulling from http://hg.openjdk.java.net/jdk9/dev/hotspot
                    jaxws:   pulling from http://hg.openjdk.java.net/jdk9/dev/jaxws
                langtools:   searching for changes
                langtools:   no changes found
                      jdk:   searching for changes
                      jdk:   no changes found
                    corba:   searching for changes
                    corba:   no changes found
                    jaxws:   searching for changes
                    jaxws:   no changes found
                  hotspot:   searching for changes
                  hotspot:   no changes found
                     jaxp:   searching for changes
                     jaxp:   no changes found
                        .:   searching for changes
                        .:   no changes found
                  nashorn:   searching for changes
                  nashorn:   no changes found
    下载后的目录结构:
    drwxr-xr-x 14 root root  4096 Nov 18 19:41 ./
    drwxr-xr-x  5 root root  4096 Nov 18 19:47 ../
    -rw-r--r--  1 root root  1522 Nov 18 19:26 ASSEMBLY_EXCEPTION
    drwxr-xr-x  8 root root  4096 Nov 18 19:26 common/
    -rw-r--r--  1 root root  1651 Nov 18 19:26 configure
    drwxr-xr-x  6 root root  4096 Nov 18 19:28 corba/
    -rw-r--r--  1 root root  3107 Nov 18 19:26 get_source.sh
    drwxr-xr-x  4 root root  4096 Nov 18 19:53 .hg/
    -rw-r--r--  1 root root   104 Nov 18 19:26 .hgignore
    -rw-r--r--  1 root root 21451 Nov 18 19:26 .hgtags
    drwxr-xr-x  8 root root  4096 Nov 18 19:41 hotspot/
    drwxr-xr-x  7 root root  4096 Nov 18 19:30 jaxp/
    drwxr-xr-x  6 root root  4096 Nov 18 19:30 jaxws/
    drwxr-xr-x  2 root root  4096 Nov 18 19:26 .jcheck/
    drwxr-xr-x  7 root root  4096 Nov 18 19:52 jdk/
    drwxr-xr-x  7 root root  4096 Nov 18 19:32 langtools/
    -rw-r--r--  1 root root 19274 Nov 18 19:26 LICENSE
    drwxr-xr-x  8 root root  4096 Nov 18 19:26 make/
    -rw-r--r--  1 root root  2785 Nov 18 19:26 Makefile
    drwxr-xr-x 12 root root  4096 Nov 18 19:45 nashorn/
    -rw-r--r--  1 root root   321 Nov 18 19:26 README
    drwxr-xr-x  8 root root  4096 Nov 18 19:26 test/

4.下载BOOT JDK8 Oracle的官网jdk-8u191-linux-x64.tar.gz下载到/opt/
    cd /opt/
    mkdir java
    tar -zxvf jdk-8u191-linux-x64.tar.gz -C /opt/java/
    
    在/etc/profile文件末尾添加
    export JAVA_HOME=/opt/java/jdk1.8.0_191
    export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/
    export PATH=$PATH:$JAVA_HOME/bin
    
    保存退出,让profile立即生效
    source /etc/profile
    查看java -verison
    root@ubuntu:/juwenzhe/9dev# java -version
    java version "1.8.0_191"
    Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
5.检查依赖(没啥用,跳过)
    bash ./configure
6.安装工具包
    apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev
    apt-get install libcups2-dev
    [报错:
        ①E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
        E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
        参考:https://blog.csdn.net/u011596455/article/details/60322568 
        ②更新apt源:https://blog.csdn.net/skyie53101517/article/details/50450989
        ③Ubuntu18.04的网络配置:https://blog.csdn.net/weixin_42108484/article/details/82698877
    ]
7.进行编译
    bash configure --disable-warnings-as-errors --with-debug-level=slowdebug --with-native-debug-symbols=internal
    [报错:bash: configure: No such file or directory
        切到/juwenzhe/9dev
    ]
    通过上面的命令检查需要编译的包,还有一些需要安装的依赖包补齐即可
    The following warnings were produced. Repeated here for convenience:
    WARNING: libelf not found, cannot build AOT. You might be able to fix this by running 'sudo apt-get install libelf-dev'.
    configure: error: Could not find alsa! You might be able to fix this by running 'sudo apt-get install libasound2-dev'.
    configure exiting with result code 1

    检查编译配置成功:
    ====================================================
    A new configuration has been successfully created in
    /juwenzhe/9dev/build/linux-x86_64-normal-server-slowdebug
    using configure arguments '--disable-warnings-as-errors --with-debug-level=slowdebug --with-native-debug-symbols=internal'.

    Configuration summary:
    * Debug level:    slowdebug
    * HS debug level: debug
    * JDK variant:    normal
    * JVM variants:   server
    * OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
    * Version string: 9-internal+0-adhoc.root.9dev (9-internal)

    Tools summary:
    * Boot JDK:       java version "1.8.0_191" Java(TM) SE Runtime Environment (build 1.8.0_191-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)  (at /opt/java/jdk1.8.0_191)
    * Toolchain:      gcc (GNU Compiler Collection)
    * C Compiler:     Version 7.3.0 (at /usr/bin/gcc)
    * C++ Compiler:   Version 7.3.0 (at /usr/bin/g++)

    Build performance summary:
    * Cores to use:   2
    * Memory limit:   2268 MB

    开始编译(生成JRE和JDK镜像):make images


    [编译过程很耗内存,有如下报错:collect2: fatal error: ld terminated with signal 9 [Killed]
    参考:collect2: ld terminated with signal 9 错误解决办法 https://blog.csdn.net/wxxgoodjob/article/details/80600707
    https://help.ubuntu.com/community/SwapFaq#How%20do%20I%20add%20more%20swap?
    我是直接关闭虚拟机 ,加到3G物理内存(再大点更好)和30G的存储,编译成功
    ]


8.调试JDK
    cd /juwenzhe/9dev/build/linux-x86_64-normal-server-slowdebug/jdk/bin
    gdb -tui java
    

    
参考文献:
    [JVM] Ubuntu下手动编译调试Openjdk https://blog.csdn.net/zkp_java/article/details/79952214
    JVM-Ubuntu18.04.1下编译OpenJDK8 http://www.cnblogs.com/iou123lg/p/9696039.html
    深入理解Java虚拟机 自己编译JDK https://www.cnblogs.com/xkxf/p/8579562.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值