Ubuntu下编译OpenJDK12

  • 内容
  • 评论
  • 相关

本文是在虚拟机VMware下的Ubuntu编译OpenJDK12
* 首先是获取OpenJDK源码

hg clone https://hg.openjdk.java.net/jdk/jdk12

当然需要首先安装mercurial,这个是比SVN还古老的版本管理软件

sudo apt-get install mercurial meld
  • 依赖库
    需要GCC,FreeType、CUPS等若干第三方库
sudo apt-get install build-essential
sudo apt-get install libfreetype6-dev
sudo apt-get install libcups2-dev
sudo apt-get install libx11-dev libxext-dev libxrender-dev libxrandr-dev sudo libxtst-dev libxt-dev
sudo apt-get install libasound2-dev
sudo apt-get install libffi-dev
sudo apt-get install autoconf
sudo apt-get install ccache
sudo apt-get install systemtap-sdt-dev
  • 构建配置
bash configure --with-debug-level=slowdebug --enable-dtrace --with-jvm-variants=server --with-target-bits=64 --enable-ccache --with-num-cores=8 --with-memory-size=8000  --disable-warnings-as-errors

配置参数说明:

```bash
--with-debug-level=slowdebug 启用slowdebug级别调试
--enable-dtrace 启用dtrace
--with-jvm-variants=server 编译server类型JVM
--with-target-bits=64 指定JVM为64位
--enable-ccache 启用ccache,加快编译
--with-num-cores=8 编译使用CPU核心数
--with-memory-size=8000 编译使用内存
--disable-warnings-as-errors 忽略警告
```
</code></pre>

构建成功后会显示如下:

<pre><code>```bash
Configuration summary:
* Debug level:    slowdebug
* HS debug level: debug
* JVM variants:   server
* JVM features:   server: 'aot cds cmsgc compiler1 compiler2 dtrace epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services vm-structs' 
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 12-internal+0-adhoc.wangdong.openjdk (12-internal)

Tools summary:
* Boot JDK:       java version "10.0.2" 2018-07-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)  (at /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home)
* Toolchain:      clang (clang/LLVM from Xcode 9.4.1)
* C Compiler:     Version 9.1.0 (at /usr/bin/clang)
* C++ Compiler:   Version 9.1.0 (at /usr/bin/clang++)

Build performance summary:
* Cores to use:   7
* Memory limit:   8000 MB
* ccache status:  Active (3.4.2)
```

编译:

make images

编译成功后如下:大概可能需要几分钟到十几分钟不等:

    Note: Recompile with -Xlint:unchecked for details.
    Creating support/demos/image/jfc/CodePointIM/CodePointIM.jar
    Creating support/demos/image/jfc/FileChooserDemo/FileChooserDemo.jar
    Creating support/demos/image/jfc/Font2DTest/Font2DTest.jar
    Creating support/demos/image/jfc/SwingSet2/SwingSet2.jar
    Creating support/demos/image/jfc/J2Ddemo/J2Ddemo.jar
    Creating support/demos/image/jfc/Metalworks/Metalworks.jar
    Creating support/demos/image/jfc/Notepad/Notepad.jar
    Creating support/demos/image/jfc/Stylepad/Stylepad.jar
    Creating support/demos/image/jfc/SampleTree/SampleTree.jar
    Creating support/demos/image/jfc/TableExample/TableExample.jar
    Creating support/demos/image/jfc/TransparentRuler/TransparentRuler.jar
    Creating support/classlist.jar
    Creating images/jmods/jdk.jlink.jmod
    Creating images/jmods/java.base.jmod
    Creating jdk image
    Stopping sjavac server
    Finished building target 'images' in configuration 'macosx-x86_64-normal-server-slowdebug'
  • 设置环境变量
vim /etc/profile

然后添加下面几行到文件最后

export JAVA_HOME=$HOME/jdk12/build/linux-x86_64-server-slowdebug/images/jdk
export PATH=$JAVA_HOME/bin:$PATH

然后

source /etc/profile

这时候可以查看是否安装成功

java -version

接下来就可以使用Clion来进行调试了
OpenJDK本身也没有为任何IDE提供支持,但如
果只是为了能够在CLion中跟踪、阅读源码,而不需要修改重新编译的话,那直接在Run/Debug
Configurations中增加一个CMake Application,然后Executable选择我们刚才编译出来的FastDebug或者
SlowDebug版的java命令,运行参数加上-version或者某个Class文件的路径,再把Before launch里面的
Build去掉,就可以开始运行调试了

评论

0条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注