參考文章:
a. https://blog.csdn.net/manageer/article/details/72812149
b.https://blog.csdn.net/lizhengjava/article/details/60138890
c.https://www.cnblogs.com/Seeasunnyday/p/9368302.html(主要是參考這篇文章, 但是包error # <iostream> not found, 后來有參考的其他文章解決這個問題)
1.為什么要編譯JDK
2.選擇JDK
3.環境准備


(1). 修改generated-configure.sh(路徑:common/autoconf/generated-configure.sh)
注釋20061行
// as_fn_error $? "GCC compiler is required. Try setting --with-tools-dir." "$LINENO" 5
注釋21640行
// as_fn_error $? "GCC compiler is required. Try setting --with-tools-dir." "$LINENO" 5
(2). 修改relocInfo.hpp(路徑:hotspot/src/share/vm/code/relocInfo.hpp)
修改367行
inline friend relocInfo prefix_relocInfo(int datalen);
修改472行
inline relocInfo prefix_relocInfo(int datalen = 0) {
assert(relocInfo::fits_into_immediate(datalen), "datalen in limits");
return relocInfo(relocInfo::data_prefix_tag, relocInfo::RAW_BITS, relocInfo::datalen_tag | datalen);
}
(3). 修改openjdk/hotspot/src/share/vm/opto/loopPredicate.cpp
修改775行為
assert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int()->_lo >= 0, "must be");
(4).修改openjdk/hotspot/src/share/vm/runtime/virtualspace.cpp
修改331行為
if (base() != 0) {
4.設置環境變量
# 設定語言選項,必須設置
export LANG=C
# Mac平台,C編譯器不再是GCC,是clang
export CC=clang
# 跳過clang的一些嚴格的語法檢查,不然會將N多的警告作為Error
export COMPILER_WARNINGS_FATAL=false
# 鏈接時使用的參數
export LFLAGS='-Xlinker -lstdc++'
# 是否使用clang
export USE_CLANG=true
# 使用64位數據模型
export LP64=1
# 告訴編譯平台是64位,不然會按32位來編譯
export ARCH_DATA_MODEL=64
# 允許自動下載依賴
export ALLOW_DOWNLOADS=true
# 並行編譯的線程數,編譯時間長,為了不影響其他工作,我選擇為2
export HOTSPOT_BUILD_JOBS=2
export 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插件之類的部分的build
export BUILD_DEPLOY=false
export BUILD_INSTALL=false
最后干掉這兩個變量,不然會有詭異的事發生
unset JAVA_HOME
unset CLASSPATH
5.編譯, ( 遇到問題可以先看看下面的問題描述)
sh configure --with-debug-level=slowdebug --with-boot-jdk=`/usr/libexec/java_home -v 1.8` --with-freetype-include=/usr/local/include/freetype2 --with-freetype-lib=/usr/local/lib/ --with-target-bits=64 --with-jvm-variants=server --with-jdk-variant=normal --with-milestone=internal --with-update-version=b25 --with-build-number=b25 --with-zlib=system --with-num-cores=2 --with-jobs=4 CC=clang CXX=clang++
sh configure --with-debug-level=slowdebug --with-target-bits=64 --with-jvm-variants=server --with-jdk-variant=normal --with-milestone=internal --with-update-version=b25 --with-build-number=b25 --with-num-cores=2 --with-jobs=2 CC=clang CXX=clang++ --with-freetype-include=/usr/local/include/freetype2 --with-freetype-lib=/usr/local/lib/ --with-boot-jdk=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home --enable-ccache
1
————————————————
版權聲明:本文為CSDN博主「ykd2020」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/yuankundong/article/details/78876523
使用這種方式編譯, 在build文件夾生成兩個文件. 如果使用第一種, 只會生成一個
參考文章: https://blog.csdn.net/lizhengjava/article/details/60138890


6.我執行./configure和編譯遇到的問題:
問題1和問題2是原作者遇到的,我並沒有遇到. 后面的問題是我遇到的

Could not determine audit condition [Process completed]
[進程已完成]
處理辦法參考: https://www.jianshu.com/p/d764d2840071. 很多說是因為./bash_profile文件配置錯誤導致的, 但我這個不是. 將/usr/bin 下的login文件改名login1, 再打開終端, 然后執行sudo chown root:wheel /usr/bin/login
sudo chmod u+s /usr/bin/login
在將login1的名字改回login. 已經恢復了.

#include <iostream>
^~~~~~~~~~

