OpenJDK 編譯-Linux環境


說明:筆者是在Ubuntu 16.04虛擬機中編譯 OpenJDK 8

源碼下載

http://download.java.net/openjdk/jdk8/

推薦直接下載openjdk-8-src-b132-03_mar_2014.zip

環境准備:

安裝bootstrap JDK,筆者安裝的jdk7

在環境變量PATH中添加jdk的bin目錄,不添加的話,在編譯第一步時需要帶參數

解壓后閱讀README-builds.html,按照要求安裝Linux環境需要的軟件。不清楚要安裝哪些,在編譯第一步失敗的時候會提示你安裝。

#如果之前有設置的話,這兩個環境變量需要去掉,不然會出問題。

unset JAVA_HOME

unset CLASSPATH

 

編譯

切換到解壓后目錄

第一步:

bash ./configure

或者帶jdk目錄,path為bootstrap JDK的目錄

bash ./configure --with-boot-jdk=path

第二步:

make all

*遇到的坑爹問題

1,版本問題,recipe for target 'check_os_version' failed

 方案一:直接注釋檢查

nano hotspot/make/linux/Makefile

 check_os_version: 

#ifeq($(DISABLE_HOTSPOT_OS_VERSION_CHECK)$(EMPTY_IF_NOT_SUPPORTED),) 

#   $(QUIETLY) >&2 echo "*** This OS is not supported:" `uname -a`; exit 1; 

#endif 

 方案二:添加版本支持

nano hotspot/make/linux/Makefile

SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 3% 4%

2,make參數語法,添加'I'

nano hotspot/make/linux/makefiles/adjust-mflags.sh
# line 67. (新版本make語法有變動)
 s/ -\([^        I][^    ]*\)j/ -\1 -j/

3,undefine symbols錯誤

提升一個模板函數定義至頭文件,避免出現undefined symbols錯誤。

# 將 hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp 中的template <class T> void write_ref_array_pre_work(T* dst, int count)方法,提升到對應的 頭文件g1SATBCardTableModRefBS.hpp中。 # 模板函數定義需要出現在頭文件中,以便編譯器為其生成特化版本。若無此修改,運行編譯后的java程序,將出現undefine symbols錯誤。 

編譯成功標識

驗證

1,the build result. This directory typically looks like:

build/linux-x64-normal-server-release

2,JDK輸出目錄:

In particular, the build/*/images/j2sdk-image/bin directory should contain executables for the OpenJDK tools and utilities for that configuration.

 3,查看版本

3.1直接在bin目錄下運行  ./java -version

 

3.2將編譯好的JDK復制到適當目錄,配置JAVA_HOME指向該目錄,使環境變量生效后,執行java -version命令,就能看到帶用戶機器名的jdk版本。

cp build/linux-x86_64-normal-server-release/images/j2sdk-image/ -r /usr/lib/jdk/openjdk8
sunil@ubuntu:~/Downloads/openjdk$ java -version
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-sunil_2016_11_21_18_06-b00)
OpenJDK 64-Bit Server VM (build 25.0-b70, mixed mode)
sunil@ubuntu:~/Downloads/openjdk$ 

 

參考文檔

README

深入理解Java虛擬機(第2版)

https://blog.mlworks.cn/tech/compile-openjdk8-ubuntu-16.04.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM