Linux 下編譯openjdk

操做系統ubuntu14.04html

openjdk版本 7u4java

openjdk7u4能夠在https://jdk7.java.net/source.html下載linux

 

一.構建編譯環境

sudo apt-get install build-essential gawk m4 openjdk-6-jdk
libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev
x11proto-print-dev binutils libmotif3 libmotif-dev ant

 

二.設置環境變量

export LANG=C

#編譯openjdk7所須要的jdk目錄,注意jdk的版本
#試過jdk1.8和1.7的其餘版本,在運行時就出現bug
export ALT_BOOTDIR=/home/foreverenjoy/Program/jdk1.7.0_04

export ALLOW_DOWNLOADS=true
export USE_PRECOMPILED_HEADER=true
export SKIP_DEBUG_BUILD=false
export SKIP_FASTDEBUG_BUILD=true
export DEBUG_NAME=debug

unset CLASSPATH
unset JAVA_HOME

 

三.檢查設置是否正確

在終端輸入make sanityubuntu

  1 ( cd  ./jdk/make && \
  2       make sanity HOTSPOT_IMPORT_CHECK=false JDK_TOPDIR=/home/foreverenjoy/Program/openjdk/jdk JDK_MAKE_SHARED_DIR=/home/foreverenjoy/Program/openjdk/jdk/make/common/shared EXTERNALSANITYCONTROL=true SOURCE_LANGUAGE_VERSION=7 TARGET_CLASS_VERSION=7 MILESTONE=internal BUILD_NUMBER=b00 JDK_BUILD_NUMBER=b00 FULL_VERSION=1.7.0-internal-debug-foreverenjoy_2016_07_03_19_04-b00 PREVIOUS_JDK_VERSION=1.6.0 JDK_VERSION=1.7.0 JDK_MKTG_VERSION=7 JDK_MAJOR_VERSION=1 JDK_MINOR_VERSION=7 JDK_MICRO_VERSION=0 PREVIOUS_MAJOR_VERSION=1 PREVIOUS_MINOR_VERSION=6 PREVIOUS_MICRO_VERSION=0 ARCH_DATA_MODEL=64 VARIANT=DBG DEBUG_CLASSFILES=true COOKED_BUILD_NUMBER=0 ALT_OUTPUTDIR=/home/foreverenjoy/Program/openjdk/build/linux-amd64 ALT_LANGTOOLS_DIST=/home/foreverenjoy/Program/openjdk/build/linux-amd64/langtools/dist ALT_CORBA_DIST=/home/foreverenjoy/Program/openjdk/build/linux-amd64/corba/dist ALT_JAXP_DIST=/home/foreverenjoy/Program/openjdk/build/linux-amd64/jaxp/dist ALT_JAXWS_DIST=/home/foreverenjoy/Program/openjdk/build/linux-amd64/jaxws/dist ALT_HOTSPOT_IMPORT_PATH=/home/foreverenjoy/Program/openjdk/build/linux-amd64/hotspot/import BUILD_HOTSPOT=true ; )
  3 INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
  4 INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
  5 INFO: STRIP_POLICY=min_strip
  6 INFO: ZIP_DEBUGINFO_FILES=1
  7 make[1]: Entering directory `/home/foreverenjoy/Program/openjdk/jdk/make'
  8 INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
  9 INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
 10 INFO: STRIP_POLICY=min_strip
 11 INFO: ZIP_DEBUGINFO_FILES=1
 12 make[1]: Leaving directory `/home/foreverenjoy/Program/openjdk/jdk/make'
 13 
 14 Build Machine Information:
 15    build machine = foreverenjoy
 16 
 17 Build Directory Structure:
 18    CWD = /home/foreverenjoy/Program/openjdk
 19    TOPDIR = .
 20    LANGTOOLS_TOPDIR = ./langtools
 21    JAXP_TOPDIR = ./jaxp
 22    JAXWS_TOPDIR = ./jaxws
 23    CORBA_TOPDIR = ./corba
 24    HOTSPOT_TOPDIR = ./hotspot
 25    JDK_TOPDIR = ./jdk
 26 
 27 Build Directives:
 28    BUILD_LANGTOOLS = true 
 29    BUILD_JAXP = true 
 30    BUILD_JAXWS = true 
 31    BUILD_CORBA = true 
 32    BUILD_HOTSPOT = true 
 33    BUILD_JDK    = true 
 34    DEBUG_CLASSFILES =  
 35    DEBUG_BINARIES =  
 36 
 37 Hotspot Settings: 
 38       HOTSPOT_BUILD_JOBS  =  
 39       HOTSPOT_OUTPUTDIR   = /home/foreverenjoy/Program/openjdk/build/linux-amd64/hotspot/outputdir 
 40       HOTSPOT_EXPORT_PATH = /home/foreverenjoy/Program/openjdk/build/linux-amd64/hotspot/import 
 41  
 42 
 43 
 44 
 45 Bootstrap Settings:
 46   BOOTDIR = /usr/lib/jvm/java-6-openjdk-amd64
 47     ALT_BOOTDIR = /usr/lib/jvm/java-6-openjdk-amd64
 48   BOOT_VER = 1.6.0 [requires at least 1.6]
 49   OUTPUTDIR = /home/foreverenjoy/Program/openjdk/build/linux-amd64
 50     ALT_OUTPUTDIR = /home/foreverenjoy/Program/openjdk/build/linux-amd64
 51   ABS_OUTPUTDIR = /home/foreverenjoy/Program/openjdk/build/linux-amd64
 52  
 53 Build Tool Settings:
 54   SLASH_JAVA = /NOT-SET
 55     ALT_SLASH_JAVA = 
 56   VARIANT = DBG
 57   JDK_DEVTOOLS_DIR = /NOT-SET/devtools
 58     ALT_JDK_DEVTOOLS_DIR = 
 59   ANT_HOME = 
 60   UNIXCOMMAND_PATH = /bin/
 61     ALT_UNIXCOMMAND_PATH = 
 62   COMPILER_PATH = /usr/bin/
 63     ALT_COMPILER_PATH = 
 64   DEVTOOLS_PATH = /usr/bin/
 65     ALT_DEVTOOLS_PATH = 
 66   UNIXCCS_PATH = /usr/ccs/bin/
 67     ALT_UNIXCCS_PATH = 
 68   USRBIN_PATH = /usr/bin/
 69     ALT_USRBIN_PATH = 
 70   COMPILER_NAME = GCC4
 71   COMPILER_VERSION = GCC4
 72   CC_VER = 4.8 [requires at least 4.3.0]
 73   ZIP_VER = 3.0 [requires at least 2.2]
 74   UNZIP_VER = 6.00 [requires at least 5.12]
 75   ANT_VER = 1.9.3 [requires at least 1.7.1]
 76   TEMPDIR = /home/foreverenjoy/Program/openjdk/build/linux-amd64/tmp
 77  
 78 Build Directives:
 79   OPENJDK = true
 80   USE_HOTSPOT_INTERPRETER_MODE = 
 81   PEDANTIC = 
 82   DEV_ONLY = 
 83   NO_DOCS = 
 84   NO_IMAGES = 
 85   TOOLS_ONLY = 
 86   INSANE = 
 87   COMPILE_APPROACH = parallel
 88   PARALLEL_COMPILE_JOBS = 2
 89     ALT_PARALLEL_COMPILE_JOBS = 
 90   FASTDEBUG = 
 91   COMPILER_WARNINGS_FATAL = false
 92   COMPILER_WARNING_LEVEL = 
 93   SHOW_ALL_WARNINGS = 
 94   INCREMENTAL_BUILD = false
 95   CC_HIGHEST_OPT = 
 96   CC_HIGHER_OPT = 
 97   CC_LOWER_OPT = 
 98   CXXFLAGS =  -g -fPIC -DCC_NOEX -W -Wall  -Wno-unused -Wno-parentheses -fno-omit-frame-pointer -D_LITTLE_ENDIAN  
 99   CFLAGS =  -g   -fno-strict-aliasing -fPIC -W -Wall  -Wno-unused -Wno-parentheses -pipe -fno-omit-frame-pointer -D_LITTLE_ENDIAN  
100   BOOT_JAVA_CMD = /usr/lib/jvm/java-6-openjdk-amd64/bin/java -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput -Xmx512m -Xms512m -XX:PermSize=32m -XX:MaxPermSize=160m
101   BOOT_JAVAC_CMD = /usr/lib/jvm/java-6-openjdk-amd64/bin/javac  -J-XX:ThreadStackSize=1536 -J-XX:-PrintVMOptions -J-XX:+UnlockDiagnosticVMOptions -J-XX:-LogVMOutput -J-Xmx512m -J-Xms512m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -encoding ascii -source 6 -target 6 -XDignore.symbol.file=true
102   BOOT_JAR_CMD = /usr/lib/jvm/java-6-openjdk-amd64/bin/jar
103   BOOT_JARSIGNER_CMD = /usr/lib/jvm/java-6-openjdk-amd64/bin/jarsigner
104   JAVAC_CMD = /NOT-SET/re/jdk/1.7.0/promoted/latest/binaries/linux-amd64/bin/javac  -J-XX:ThreadStackSize=1536 -J-XX:-PrintVMOptions -J-XX:+UnlockDiagnosticVMOptions -J-XX:-LogVMOutput -J-Xmx512m -J-Xms512m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m  -g -source 7 -target 7 -encoding ascii -Xbootclasspath:/home/foreverenjoy/Program/openjdk/build/linux-amd64/classes 
105   JAVAH_CMD = /NOT-SET/re/jdk/1.7.0/promoted/latest/binaries/linux-amd64/bin/javah -bootclasspath /home/foreverenjoy/Program/openjdk/build/linux-amd64/classes
106   JAVADOC_CMD = /NOT-SET/re/jdk/1.7.0/promoted/latest/binaries/linux-amd64/bin/javadoc -J-XX:-PrintVMOptions -J-XX:+UnlockDiagnosticVMOptions -J-XX:-LogVMOutput -J-Xmx512m -J-Xms512m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -bootclasspath /home/foreverenjoy/Program/openjdk/build/linux-amd64/classes
107  
108 Build Platform Settings:
109   USER = foreverenjoy
110   PLATFORM = linux
111   ARCH = amd64
112   LIBARCH = amd64
113   ARCH_FAMILY = amd64
114   ARCH_DATA_MODEL = 64
115   ARCHPROP = amd64
116   ALSA_VERSION = 1.0.27.2
117   OS_VERSION = 3.19.0-59-generic [requires at least 2.6]
118   OS_VARIANT_NAME = Ubuntu
119   OS_VARIANT_VERSION = 14.04
120   MB_OF_MEMORY = 7555
121  
122 GNU Make Settings:
123   MAKE = make
124   MAKE_VER = 3.81 [requires at least 3.81]
125   MAKECMDGOALS = sanity
126   MAKEFLAGS = w
127   SHELL = /bin/sh
128  
129 Target Build Versions:
130   JDK_VERSION = 1.7.0
131   MILESTONE = internal
132   RELEASE = 1.7.0-internal-debug
133   FULL_VERSION = 1.7.0-internal-debug-foreverenjoy_2016_07_03_19_04-b00
134   BUILD_NUMBER = b00
135  
136 External File/Binary Locations:
137   USRJDKINSTANCES_PATH = /opt/java
138   BUILD_JDK_IMPORT_PATH = /NOT-SET/re/jdk/1.7.0/promoted/latest/binaries
139     ALT_BUILD_JDK_IMPORT_PATH = 
140   JDK_IMPORT_PATH = /NOT-SET/re/jdk/1.7.0/promoted/latest/binaries/linux-amd64
141     ALT_JDK_IMPORT_PATH = 
142   LANGTOOLS_DIST = 
143     ALT_LANGTOOLS_DIST = /home/foreverenjoy/Program/openjdk/build/linux-amd64/langtools/dist
144   CORBA_DIST = 
145     ALT_CORBA_DIST = /home/foreverenjoy/Program/openjdk/build/linux-amd64/corba/dist
146   JAXP_DIST = 
147     ALT_JAXP_DIST = /home/foreverenjoy/Program/openjdk/build/linux-amd64/jaxp/dist
148   JAXWS_DIST = 
149     ALT_JAXWS_DIST = /home/foreverenjoy/Program/openjdk/build/linux-amd64/jaxws/dist
150   HOTSPOT_DOCS_IMPORT_PATH = /NO_DOCS_DIR
151     ALT_HOTSPOT_DOCS_IMPORT_PATH = 
152   HOTSPOT_IMPORT_PATH = /home/foreverenjoy/Program/openjdk/build/linux-amd64/hotspot/import
153     ALT_HOTSPOT_IMPORT_PATH = /home/foreverenjoy/Program/openjdk/build/linux-amd64/hotspot/import
154   HOTSPOT_SERVER_PATH = /home/foreverenjoy/Program/openjdk/build/linux-amd64/hotspot/import/jre/lib/amd64/server
155     ALT_HOTSPOT_SERVER_PATH = 
156   CACERTS_FILE = ./../src/share/lib/security/cacerts
157     ALT_CACERTS_FILE = 
158   CUPS_HEADERS_PATH = /usr/include
159     ALT_CUPS_HEADERS_PATH = 
160  
161 OpenJDK-specific settings:
162   FREETYPE_HEADERS_PATH = /usr/include
163     ALT_FREETYPE_HEADERS_PATH = 
164   FREETYPE_LIB_PATH = /usr/lib
165     ALT_FREETYPE_LIB_PATH = 
166  
167 Previous JDK Settings:
168   PREVIOUS_RELEASE_PATH = USING-PREVIOUS_RELEASE_IMAGE
169     ALT_PREVIOUS_RELEASE_PATH = 
170   PREVIOUS_JDK_VERSION = 1.6.0
171     ALT_PREVIOUS_JDK_VERSION = 
172   PREVIOUS_JDK_FILE = 
173     ALT_PREVIOUS_JDK_FILE = 
174   PREVIOUS_JRE_FILE = 
175     ALT_PREVIOUS_JRE_FILE = 
176   PREVIOUS_RELEASE_IMAGE = /usr/lib/jvm/java-6-openjdk-amd64
177     ALT_PREVIOUS_RELEASE_IMAGE = 
178 
179 
180 Sanity check passed.
View Code

若是看到"Sanity check passend.",說明檢查經過。數據結構

 

四.開始編譯

在終端輸入make 框架

等一段時間jvm

#-- Build times ----------
Target debug_build
Start 2016-07-03 19:25:12
End   2016-07-03 19:41:06
00:01:19 corba
00:05:24 hotspot
00:00:15 jaxp
00:00:18 jaxws
00:08:11 jdk
00:00:27 langtools
00:15:54 TOTAL
-------------------------
編譯完成

 

在OpenJDK目錄下有個build文件夾是編譯的output文件夾  ide

foreverenjoy@foreverenjoy:~/Program/openjdk$ cd build/
foreverenjoy@foreverenjoy:~/Program/openjdk/build$ ls -l
total 8
drwxrwxr-x 29 foreverenjoy foreverenjoy 4096  7月  3 19:41 linux-amd64
drwxrwxr-x 28 foreverenjoy foreverenjoy 4096  7月  3 19:25 linux-amd64-debug
foreverenjoy@foreverenjoy:~/Program/openjdk/build$ cd linux-amd64/bin/
foreverenjoy@foreverenjoy:~/Program/openjdk/build/linux-amd64/bin$ ./java -version
openjdk version "1.7.0-internal-debug"
OpenJDK Runtime Environment (build 1.7.0-internal-debug-foreverenjoy_2016_07_03_19_19-b00)
OpenJDK 64-Bit Server VM (build 24.0-b56-jvmg, mixed mode)
編譯結果

 

五.遇到的問題

1.函數

make[6]: Leaving directory /usr/local/openjdk/build/linux-amd64-debug/hotspot/outputdir/linux_amd64_compiler2/jvmg'
cd linux_amd64_compiler2/jvmg && ./test_gamma
Using java runtime at: /usr/lib/jvm/java-1.6.0-openjdk.x86_64/jre
./gamma: relocation error: /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.33.x86_64/jre/lib/amd64/libjava.so: symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference
make[5]: *** [jvmg] Error 127
make[5]: Leaving directory/usr/local/openjdk/build/linux-amd64-debug/hotspot/outputdir' make[4]: * [generic_build2] Error 2 make[4]: Leaving directory /usr/local/openjdk/hotspot/make'
make[3]: *** [jvmg] Error 2
make[3]: Leaving directory/usr/local/openjdk/hotspot/make' make[2]: * [hotspot-build] Error 2 make[2]: Leaving directory /usr/local/openjdk'
make[1]: *** [generic_debug_build] Error 2
make[1]: Leaving directory/usr/local/openjdk'
symbol JVM_FindClassFromCaller, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference

刪除hotspot/make/linux/Makefile中全部的test_gamma ( 即刪掉全部的&& ./test_gamma)工具

 

2.

m -XX:MaxPermSize=160m -jar /home/foreverenjoy/Program/openjdk/build/linux-amd64/../linux-amd64-debug/btjars/generatecurrencydata.jar -o /home/foreverenjoy/Program/openjdk/build/linux-amd64/../linux-amd64-debug/lib/currency.data.temp \
        < ../../../src/share/classes/java/util/CurrencyData.properties
Error: time is more than 10 years from present: 1136059200000
java.lang.RuntimeException: time is more than 10 years from present: 1136059200000
    at build.tools.generatecurrencydata.GenerateCurrencyData.makeSpecialCaseEntry(GenerateCurrencyData.java:285)
    at build.tools.generatecurrencydata.GenerateCurrencyData.buildMainAndSpecialCaseTables(GenerateCurrencyData.java:225)
    at build.tools.generatecurrencydata.GenerateCurrencyData.main(GenerateCurrencyData.java:154)
make[5]: *** [/home/foreverenjoy/Program/openjdk/build/linux-amd64/../linux-amd64-debug/lib/currency.data] Error 1
make[5]: Leaving directory `/home/foreverenjoy/Program/openjdk/jdk/make/java/java'
make[4]: *** [all] Error 1
make[4]: Leaving directory `/home/foreverenjoy/Program/openjdk/jdk/make/java'
make[3]: *** [all] Error 1
make[3]: Leaving directory `/home/foreverenjoy/Program/openjdk/jdk/make'
make[2]: *** [jdk-build] Error 2
make[2]: Leaving directory `/home/foreverenjoy/Program/openjdk'
make[1]: *** [generic_debug_build] Error 2
make[1]: Leaving directory `/home/foreverenjoy/Program/openjdk'
make: *** [build_debug_image] Error 2
time is more than 10 years from present: 1136059200000

將CurrencyData.properties內的時間改成10年內

 

六.在NetBeans編譯運行HotSpot

NetBeans下載地址:http://netbeans.org/   下載時選擇支持C/C++開發的版本。

 

首先新建項目,選擇 基於現有源代碼的C/C++選項

 

在 源碼文件夾中填入OpenJDK目錄下hotspot目錄的路徑,在下面的單選按鈕中選擇「定製」,點擊下一步

 

 

預構建模塊中的設置以下:

 

進入下一步,在Build Comman中輸入

#當前目錄爲hotspot,make後加參數-C make/ -f Makefile,make會在讀取Makefile以前改變到目錄hotspot/make/
${MAKE} -C make/ -f Makefile clean jvmg  ALT_BOOTDIR=/home/foreverenjoy/Program/jdk1.7.0_04 ARCH_DATA_MODEL=64 LANG=C

而後一直點擊下一步,結束後右擊項目,點擊Build。

 

Build成功以後,右擊項目,選擇項目屬性。

修改Run Cammand,Run Directory和添加Environment(環境變量)

 

Run Cammand:
#運行ClaA類
/home/foreverenjoy/Program/openjdk/hotspot/build/linux/linux_amd64_compiler2/jvmg/gamma ClaA

Run Directory:
/home/foreverenjoy/Program/openjdk/hotspot/build/linux/linux_amd64_compiler2/jvmg

ClASSPATH:
#/home/foreverenjoy/Program/javaProject是ClaA的目錄
.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/jre/lib/i18n.jar:/home/foreverenjoy/Program/javaProject

JAVA_HOME:
/home/foreverenjoy/Program/jdk1.7.0_04

LD_LIBRARY_PATH:
.:${JAVA_HOME}/jre/lib/amd64/native_threads:${JAVA_HOME}/jre/lib/amd64:

最後點擊Run就能夠了

 

最後附上hotspot的源碼結構

├─agent                    Serviceability Agent的客戶端實現
├─make                     用來build出HotSpot的各類配置文件
├─src                          HotSpot VM的源代碼
│  ├─cpu                       CPU相關代碼(彙編器、模板解釋器、ad文件、部分runtime函數在這裏實現)
│  ├─os                        操做系相關代碼
│  ├─os_cpu                    操做系統+CPU的組合相關的代碼
│  └─share                     平臺無關的共通代碼
│      ├─tools                    工具
│      │  ├─hsdis                    反彙編插件
│      │  ├─IdealGraphVisualizer     將server編譯器的中間代碼可視化的工具
│      │  ├─launcher                 啓動程序「Java」
│      │  ├─LogCompilation           將-XX:+LogCompilation輸出的日誌(hotspot.log)整理成更容易閱讀的格式的工具
│      │  └─ProjectCreator           生成Visual Studio的project文件的工具
│      └─vm                       HotSpot VM的核心代碼
│          ├─adlc                    平臺描述文件(上面的cpu或os_cpu裏的*.ad文件)的編譯器
│          ├─asm                     彙編器接口
│          ├─c1                      client編譯器(又稱「C1」)
│          ├─ci                      動態編譯器的公共服務/從動態編譯器到VM的接口
│          ├─classfile               類文件的處理(包括類加載和系統符號表等)
│          ├─code                    動態生成的代碼的管理
│          ├─compiler                從VM調用動態編譯器的接口
│          ├─gc_implementation       GC的實現
│          │  ├─concurrentMarkSweep      Concurrent Mark Sweep GC的實現
│          │  ├─g1                       Garbage-First GC的實現(不使用老的分代式GC框架)
│          │  ├─parallelScavenge         ParallelScavenge GC的實現(server VM默認,不使用老的分代式GC框架)
│          │  ├─parNew                   ParNew GC的實現
│          │  └─shared                   GC的共通實現
│          ├─gc_interface            GC的接口
│          ├─interpreter             解釋器,包括「模板解釋器」(官方版在用)和「C++解釋器」(官方版不在用)
│          ├─libadt                  一些抽象數據結構
│          ├─memory                  內存管理相關(老的分代式GC框架也在這裏)
│          ├─oops                    HotSpot VM的對象系統的實現
│          ├─opto                    server編譯器(又稱「C2」或「Opto」)
│          ├─prims                   HotSpot VM的對外接口,包括部分標準庫的native部分和JVMTI實現
│          ├─runtime                 運行時支持庫(包括線程管理、編譯器調度、鎖、反射等)
│          ├─services                主要是用來支持JMX之類的管理功能的接口
│          ├─shark                   基於LLVM的JIT編譯器(官方版裏沒有使用)
│          └─utilities               一些基本的工具類
└─test                         單元測試
HotSpot源碼結構

  

博客園(FOREVER_ENJOY):http://www.cnblogs.com/zyx1314/p/5638596.html 本文版權歸做者全部;歡迎轉載!請註明文章做者和原文鏈接

相關文章
相關標籤/搜索