OpenJDK源码分析(一)—— Mac OpenJDK 编译

Mac OSX版本

10.14.6 (18G103)

xcode版本

Version 11.1 (11A1027)

编译依赖

brew install ccache
brew install freetype

LLVM编译器

➜  clang -v
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Boot JDK

Oracle JaveEE 12

➜  ~ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    12.0.2, x86_64: "Java SE 12.0.2"    /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
    1.8.0_221, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home

下载源码——OpenJDK 12

OpenJDK的源码是托管在mercurial上,但是由于网络问题,下载会非常慢,所以推荐从以下地址去下载源码。
如果想要研究CMS垃圾回收器,请下载早起版本(OpenJDK 7 / 8 / 9)

git clone https://gitee.com/eric_fei/openjdk-jdk12u.git

configure

build makefile 注意OpenJDK 12 不要显示指定freetype

➜  pwd
/Users/ericfei/Code/opensource/openjdk-jdk12u

./configure --with-target-bits=64 --enable-ccache --with-jvm-variants=server,client --disable-warnings-as-errors --with-debug-level=slowdebug 2>&1 | tee configure_mac_x64.log

configure: Configuration created at Tue Oct  8 13:52:30 CST 2019.
checking for basename... /usr/bin/basename
checking for bash... /bin/bash
checking for cat... /bin/cat
checking for chmod... /bin/chmod
checking for cmp... /usr/bin/cmp
checking for comm... /usr/bin/comm
...
...
A new configuration has been successfully created in
/Users/ericfei/Code/opensource/openjdk-jdk12u/build/macosx-x86_64-serverANDclient-slowdebug
using configure arguments '--with-target-bits=64 --enable-ccache --with-jvm-variants=server,client --disable-warnings-as-errors --with-debug-level=slowdebug'.

Configuration summary:
* Debug level:    slowdebug
* HS debug level: debug
* JVM variants:   server client
* 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' client: 'cds cmsgc compiler1 dtrace epsilongc g1gc jfr jni-check jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs' 
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64
* Version string: 12.0.2-internal+0-adhoc.ericfei.openjdk-jdk12u (12.0.2-internal)

编译

export LANG=C
sudo make all 2>&1 | tee make_mac_x64.log

Building target 'all' in configuration 'macosx-x86_64-serverANDclient-slowdebug'
Warning: No SCM configuration present and no .src-rev
Compiling 162 files for BUILD_TOOLS_JDK
Compiling 3 files for BUILD_VM_COMPILER_MATCH_PROCESSOR
Creating support/modules_libs/java.base/server/libjvm.dylib from 921 file(s)
Compiling 5 files for BUILD_VM_COMPILER_NODEINFO_PROCESSOR
Compiling 3 files for BUILD_VM_COMPILER_OPTIONS_PROCESSOR
Compiling 14 files for BUILD_VM_COMPILER_REPLACEMENTS_PROCESSOR
Compiling 3 files for BUILD_VM_COMPILER_SERVICEPROVIDER_PROCESSOR
...
...
Creating jdk image
Creating CDS archive for jdk image
Finished building target 'all' in configuration 'macosx-x86_64-serverANDclient-slowdebug'

验证Binary

➜  pwd
/Users/ericfei/Code/opensource/openjdk-jdk12u/build/macosx-x86_64-serverANDclient-slowdebug/jdk/bin

➜  ./java -version
openjdk version "12.0.2-internal" 2019-07-16
OpenJDK Runtime Environment (slowdebug build 12.0.2-internal+0-adhoc.ericfei.openjdk-jdk12u)
OpenJDK 64-Bit Server VM (slowdebug build 12.0.2-internal+0-adhoc.ericfei.openjdk-jdk12u, mixed mode)

[参考资料]
https://www.jianshu.com/p/ee7e9176632c

你可能感兴趣的:(OpenJDK源码分析(一)—— Mac OpenJDK 编译)