环境 | 版本 |
---|---|
macOS | 10.14.5 |
今天想试试自己编译一下JDK
参考博文 Java虚拟机(JVM源码):编译OpenJDK源码
第一步: 拉取 Open JDK 的 源代码
# clone open jdk 的 源代码
git clone https://github.com/unofficial-openjdk/openjdk.git
第二步:配置构建
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
参数配置说明:
--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 忽略警告
---------------------
作者:熊本同学
来源:CSDN
原文:https://blog.csdn.net/wd2014610/article/details/81664062
版权声明:本文为博主原创文章,转载请附上博文链接!
第一次执行配置 提示 Could not find required tool for CCACHE
安装 CCACHE brew install ccache
第二次执行: 输出以下内容说明构建成功
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 shenandoahgc vm-structs'
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 14-internal+0-adhoc.shishifanbuxie.openjdk (14-internal)
Tools summary:
* Boot JDK: openjdk version "12.0.1" 2019-04-16 OpenJDK Runtime Environment (build 12.0.1+12) OpenJDK 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing) (at /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home)
* Toolchain: clang (clang/LLVM from Xcode 10.2.1)
* C Compiler: Version 10.0.1 (at /usr/bin/clang)
* C++ Compiler: Version 10.0.1 (at /usr/bin/clang++)
Build performance summary:
* Cores to use: 7
* Memory limit: 8000 MB
* ccache status: Active (3.7.1)
第三步:执行编译 make images
,大概20多分钟,编译完成
Creating support/demos/image/jfc/CodePointIM/CodePointIM.jar
Creating support/demos/image/jfc/FileChooserDemo/FileChooserDemo.jar
Creating support/demos/image/jfc/SwingSet2/SwingSet2.jar
Creating support/demos/image/jfc/Font2DTest/Font2DTest.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 jdk image
Creating CDS archive for jdk image
Finished building target 'images' in configuration 'macosx-x86_64-server-slowdebug'
进入 编译后的 目录 cd build/macosx-x86_64-server-slowdebug/images/jdk
查看java的版本
./java --version
openjdk 14-internal 2020-03-17
OpenJDK Runtime Environment (slowdebug build 14-internal+0-adhoc.shishifanbuxie.openjdk)
OpenJDK 64-Bit Server VM (slowdebug build 14-internal+0-adhoc.shishifanbuxie.openjdk, mixed mode, sharing)
看到输出了 jdk的信息,说明编译成功。