Java虚拟机学习---Mac下编译openJDK 1.9

准备

1、安装homebrew ,打开命令行工具:

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

2、安装必备工具:

brew install mercurial
brew install ccache
brew install freetype

3、下载jdk源码,注意提前创建好文件夹哦:

git clone https://github.com/dmlloyd/openjdk.git
cd openjdk
git checkout -b jdk9 origin/jdk9/jdk9

configure

  我们先进行编译前的配置(检查):

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

有日志,出问题查问题也很方便!
注意上面的freetype,需要替换成本机实际安装的版本,把上面的 --with-freetype=/usr/local/Cellar/freetype/2.8.1换成你实际安装的版本和目录就可以啦。

如果出现如下的提示,那么恭喜你,接下来就可以执行编译了:

====================================================
The existing configuration has been successfully updated in
/Users/rex/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug
using configure arguments '--with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.10.0 --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.rex.openjdk (9-internal)

Tools summary:
* Boot JDK:       java version "9" Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)  (at /Library/Java/JavaVirtualMachines/jdk-9.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:   4
* Memory limit:   8192 MB
* ccache status:  Active (3.6)

NOTE: You have requested to build more than one version of the JVM, which
will result in longer build times.

WARNING: The result of this configuration has overridden an older
configuration. You *should* run 'make clean' to make sure you get a
proper build. Failure to do so might result in strange build problems.

make

我们执行下面的操作:

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

如果出现如下的提示,那么恭喜你,你的运气太好了!!!

----- Build times -------
Start 2019-04-25 18:55:19
End   2019-04-25 19:00:57

00:05:38 TOTAL
-------------------------
if test -f /Users/rex/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/make-support/exit-with-error ; then \
        exit 1 ; \
      fi
/usr/bin/printf "Finished building target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-slowdebug'\n" > >(/usr/bin/tee -a /Users/rex/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log) 2> >(/usr/bin/tee -a /Users/rex/jvm/openjdk/build/macosx-x86_64-normal-serverANDclient-slowdebug/build.log >&2) && wait
Finished building target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-s

最后,验证一下

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

出现下面的提示就完美了:

openjdk version "9-internal"
OpenJDK Runtime Environment (slowdebug build 9-internal+0-adhoc.rex.openjdk)
OpenJDK 64-Bit Server VM (slowdebug build 9-internal+0-adhoc.rex.openjdk, mixed mode)

问题及解决办法:

Xcode版本问题:提示#include<new> 头文件缺失

XCode升级到10之后, 删除了底层目录下的libstdc++文件。导致在JDK的Make时会报错, 无法识别<new>类似这样的C++语法。而在XCode9时对应文件还是存在的。官方给出的意思是libstdc++已经被标记为过期5年了, 现在统一使用自己libc++。这个问题最简单的问题就是XCode版本回退到9之前即可。如果已经无法回退,只需要把xcode9中/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++和/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libstdc++.*复制到xcode10相同的目录即可,如果没有xcode9,可直接下载我上传的资源:文件地址,解压后放到上面的目录中即可。

ordered comparison between pointer and zero

 打开报错的文件,将 base() > 0 改为 base() != NULL

JVM crash:Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

说明是编译的jvm库出了问题,打开 hotspot/src/share/vm/runtime/perfData.cpp这个文件。把所有的"delete p;"注释掉可以正常停止了。或者参考 Building OpenJDK 9 on Mac os

妥妥的~

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值