1. 程式人生 > >Mac編譯OpenJDK7(8)和Eclipse除錯Hotspot

Mac編譯OpenJDK7(8)和Eclipse除錯Hotspot

一、前言

  1. Java是我主要的生產語言,但對JVM不是很瞭解,最近也在看《深入理解Java虛擬機器 第二版》,所以想親手編譯OpenJDK和除錯HotSpot虛擬機器
  2. 系統是15年的Mac OS X(10.11.5),而OpenJDK7卻是13的,完全按照書本來,肯定是編譯不過的,本文記錄了在這個痛苦過程中遇到的坑,希望對其他人能有所幫助
  3. OpenJDK8使用configure && make的方式,比較容易就編譯通過
  4. 感謝westion717,chenjingbo,裴銀祥的分享,最後會列出相應的參考連結

二、下載

三、 系統環境

Key Value
OS 10.11.5 El Capitan
Apple LLVM version 7.3.0 (clang-703.0.31)
make GNU Make 3.81
Xcode 7.3.1
Ant 1.9.7
LLVM GCC(clang) 4.2.1
zip 3.0
unzip 5.52
freeType 2.6.1

四、編譯OpenJDK7

1. 環境依賴

Key Value
GNU make ≧ 3.81
Bootstrap JDK ≧ JDK6 , < JDK7
XCode ≧ 4.1
Ant ≧ 1.7.1
LLVM GCC ≧ 4.2.1
zip ≧ 2.2
unzip ≧ 5.12
freeType ≧ 2.3

2. 環境變數(openjdk7.bash)

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
# 設定語言選項,必須設定
export LANG=C # Mac平臺,C編譯器不再是GCC,是clangexport CC=clang # 跳過clang的一些嚴格的語法檢查,不然會將N多的警告作為Errorexport COMPILER_WARNINGS_FATAL=false# 連結時使用的引數export LFLAGS='-Xlinker -lstdc++'# 是否使用clangexport USE_CLANG=true# 使用64位資料模型export LP64=1# 告訴編譯平臺是64位,不然會按32位來編譯export ARCH_DATA_MODEL=64# 允許自動下載依賴export ALLOW_DOWNLOADS=true# 並行編譯的執行緒數,編譯時間長,為了不影響其他工作,我選擇為2export HOTSPOT_BUILD_JOBS=2export ALT_PARALLEL_COMPILE_JOBS=2# 是否跳過與先前版本的比較export SKIP_COMPARE_IMAGES=true# 是否使用預編譯標頭檔案,加快編譯速度export USE_PRECOMPILED_HEADER=true# 是否使用增量編譯export INCREMENTAL_BUILD=true# 編譯內容export BUILD_LANGTOOLS=true export BUILD_JAXP=true export BUILD_JAXWS=true export BUILD_CORBA=true export BUILD_HOTSPOT=true export BUILD_JDK=true# 編譯版本export SKIP_DEBUG_BUILD=true export SKIP_FASTDEBUG_BUILD=false export DEBUG_NAME=debug # 避開javaws和瀏覽器Java外掛之類的部分的buildexport BUILD_DEPLOY=false export BUILD_INSTALL=false# FreeTypeexport FREETYPE_LIB_PATH=/usr/X11R6/lib export FREETYPE_HEADERS_PATH=/usr/X11R6/include export ALT_FREETYPE_LIB_PATH=/usr/local/Cellar/freetype/2.6_1/lib export ALT_FREETYPE_HEADERS_PATH=/usr/local/Cellar/freetype/2.6_1/include # 目標編譯版本資訊export MILESTONE=internal export BUILD_NUMBER=b25 # 指定bootstrap jdk的路徑。反引號的意思是執行這段shell程式碼後得到的結果作為該環境變數的值export ALT_BOOTDIR=/usr/libexec/java_home -v 1.6# 編譯結果的輸出路徑export ALT_OUTPUTDIR=/Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build # ANTexport ANT_HOME=/Users/zhongmingmao/Downloads/apache-ant-1.9.7# 取消環境變數的設定,減少警告unset JAVA_HOME unset CLASSPATH unset LD_LIBRARY_PATH

3. 載入並檢查環境變數

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
# 載入環境變數source../../openjdk7.bash

# 檢查環境變數
make sanity

# 檢查結果(僅僅顯示關鍵資訊)BuildMachineInformation:
   build machine =MacBuildDirectoryStructure:
   CWD =/Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk
   TOPDIR =.
   LANGTOOLS_TOPDIR =./langtools
   JAXP_TOPDIR =./jaxp
   JAXWS_TOPDIR =./jaxws
   CORBA_TOPDIR =./corba
   HOTSPOT_TOPDIR =./hotspot
   JDK_TOPDIR =./jdk

BuildDirectives:
   BUILD_LANGTOOLS =true
   BUILD_JAXP =true
   BUILD_JAXWS =true
   BUILD_CORBA =true
   BUILD_HOTSPOT =true
   BUILD_JDK    =true

HotspotSettings:
      HOTSPOT_BUILD_JOBS  =2
      HOTSPOT_OUTPUTDIR   =/Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/hotspot/outputdir
      HOTSPOT_EXPORT_PATH =/Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/hotspot/import

BootstrapSettings:
  BOOTDIR =/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    ALT_BOOTDIR =/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  BOOT_VER =1.6.0[requires at least 1.6]
  OUTPUTDIR =/Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build
    ALT_OUTPUTDIR =/Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build
  ABS_OUTPUTDIR =/Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build

BuildToolSettings:
  ANT_HOME =/Users/zhongmingmao/Downloads/apache-ant-1.9.7
  COMPILER_PATH =/Applications/Xcode.app/Contents/Developer/usr/bin/
  COMPILER_NAME = LLVM-GCC4
  COMPILER_VERSION = LLVM-GCC4
  CC_VER =4.2.1[requires at least 4.2.1]
  ZIP_VER =3.0[requires at least 2.2]
  UNZIP_VER =5.52[requires at least 5.12]
  ANT_VER =1.9.7[requires at least 1.7.1]
  TEMPDIR =/Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/tmp

BuildDirectives:
  OPENJDK =true
  COMPILE_APPROACH = parallel
  PARALLEL_COMPILE_JOBS =2
    ALT_PARALLEL_COMPILE_JOBS =2
  COMPILER_WARNINGS_FATAL =false
  INCREMENTAL_BUILD =true

BuildPlatformSettings:
  USER = zhongmingmao
  PLATFORM = macosx
  ARCH = x86_64
  LIBARCH = x86_64
  ARCH_FAMILY = x86_64
  ARCH_DATA_MODEL =64
  ARCHPROP = x86_64
  OS_VERSION =15.5.0[requires at least 11.2]
  OS_VARIANT_NAME =MacOSX
  OS_VARIANT_VERSION =10.11.5
  MB_OF_MEMORY =8192

GNU MakeSettings:
  MAKE =/Applications/Xcode.app/Contents/Developer/usr/bin/make
  MAKE_VER =3.81[requires at least