MacOS 編譯OpenJDK13

官方說明 :

  1. Get the complete source code:
    hg clone http://hg.openjdk.java.net/jdk/jdk

  2. Run configure:
    bash configure

    If configure fails due to missing dependencies (to either the toolchainbuild toolsexternal libraries or the boot JDK), most of the time it prints a suggestion on how to resolve the situation on your platform. Follow the instructions, and try running bash configure again.

  3. Run make:
    make images

  4. Verify your newly built JDK:
    ./build/*/images/jdk/bin/java -version

  5. Run basic tests:
    make run-test-tier1

  6.  

如何構建,可以查看裏面的文檔說明: doc/building.html

 

 

============  以下爲操作實例 ==============================================

 

1. 準備安裝環境:

 

1.首先需要準備一個Xcode

我用的是Xcode9.4.1 版本 .  [如果用其他高版本尚未測試.我編譯OpenJDK10的時候是報錯的.]

官方下載地址:   https://developer.apple.com/download/more/

網盤下載地址:    https://pan.baidu.com/s/1yp0eqLJtHV0X-ppcxeUewg  密碼:nnlt

 

2.JDK版本要求 12 或者13

 

3. brew 這個命令我就不說了, 去查一下,怎麼安裝.

brew install freetype ccache

brew install mercurial

 

在命令行輸入 hg 命令有如下輸出:

 

2.拉取源碼包:

 

git clone  [email protected]:openjdk/jdk13u.git

注: 這個超級難下載,易炸毛.   不過比 hg 下載容易多了...

下載完的目錄:

 

3.配置參數

 

接下來配置編譯參數,以下是相關選項說明

  • --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 忽略警告  , mac 使用 xcode 編譯, 官方要求加上這個參數.
  • --with-freetype  設置freetype的路徑, 這個路徑必須爲你機器上的路徑,記得修改 !!!! 

 

$ bash configure --with-debug-level=slowdebug --enable-dtrace --with-jvm-variants=server --with-target-bits=64 --enable-ccache --with-num-cores=4 --with-memory-size=8000 --disable-warnings-as-errors

編譯完輸出:

 

A new configuration has been successfully created in
/workspace/openjdk-13/build/macosx-x86_64-server-slowdebug
using configure arguments '--with-debug-level=slowdebug --enable-dtrace --with-jvm-variants=server --with-target-bits=64 --enable-ccache --with-num-cores=4 --with-memory-size=8000 --disable-warnings-as-errors'.

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: 13.0.4-internal+0-adhoc.sysadmin.openjdk-13 (13.0.4-internal)

Tools summary:
* Boot JDK:       java version "13.0.2" 2020-01-14 Java(TM) SE Runtime Environment (build 13.0.2+8) Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)  (at /Library/Java/JavaVirtualMachines/jdk-13.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:   4
* Memory limit:   8000 MB
* ccache status:  Active (3.7.10)

 

 

 

執行編譯

$ make images

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
Stopping sjavac server
Finished building target 'images' in configuration 'macosx-x86_64-server-slowdebug'

 

 

測試

編譯後的jdk目錄: /workspace/openjdk-13/build/macosx-x86_64-server-slowdebug/jdk

$ ./build/*/images/jdk/bin/java -version

bogon:openjdk-13 sysadmin$
bogon:openjdk-13 sysadmin$ ./build/*/images/jdk/bin/java -version
openjdk version "13.0.4-internal" 2020-07-14
OpenJDK Runtime Environment (slowdebug build 13.0.4-internal+0-adhoc.sysadmin.openjdk-13)
OpenJDK 64-Bit Server VM (slowdebug build 13.0.4-internal+0-adhoc.sysadmin.openjdk-13, mixed mode, sharing)
bogon:openjdk-13 sysadmin$
bogon:openjdk-13 sysadmin$

 

 

 

參考:

https://zhangboyi.blog.csdn.net/article/details/89207433

https://wiki.openjdk.java.net/display/Build/Supported+Build+Platforms

https://github.com/openjdk/jdk13u

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章