天天看點

Java虛拟機學習---Mac下編譯openJDK 1.9準備configuremake

準備

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

妥妥的~