今天有問題需要研究一下JVM,但系統掛了,只能重裝。在ubuntu下再次編譯JDK,大約2個半小時,將遇到的問題筆記整理一下。
1.下載Openjdk Source Code
我用的是http://download.java.net/openjdk/jdk7。(一般https://jdk7.java.net/source.html也可以,但遇到的問題不一樣)
2.依賴安裝
我的鏡像源選擇的是中科大鏡像:mirrors.ustc.edu.cn(在super->software&update->點擊download from后面的選擇->china->mirrors.ustc.edu.cn)
apt-get update apt-get install build-essential gawk m4 libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev xllproto-print-dev binutils libmotif3 libmotif-dev ant
我不用openjdk做bootstrap JDK,編譯的時候有Bug,建議使用Oracle JDK,我用的是1.7.0_80,去官方網站JDK->JDK Archive中JDK 7下載的。
如果上面第二條命令出現問題,可以換163,阿里雲的鏡像試試,實在不行,去pkgs.org下載失敗的deb(Ubuntu14.04),使用dpkg -i software_name 安裝。
3.環境變量
根據自己的路徑設置有些地方可能需要修改:
export LANG=C export ALT_BOOTDIR=/home/softwares/jdk1.7.0_80/ # Automatically download dependacies export ALLOW_DOWNLOADS=true # 並行編譯線程數,與CPU核數一致 export HOTSPOT_JOBS=8 export ALT_PARALLEL_COMPILE_JOBS=8 # export SKIP_COMPARE_IMGAGES=true # export USE_PRECOMPILED_HEADER=true # Compiling contents export BUILD_LANGTOOLS=true export BUILD_HOTSOPT=true export BUILD_JDK=true # Compiling version # Avoid javaws & applet build BUILD_DEPLOY=false # Avoid installation build BUILD_INSTALL=false # Result ouput export ALT_OUTPUTDIR=/home/advance/JVM/jdkBuild/openjdk_7/build # Necessity unset JAVA_HOME unset CLASSPATH
以上設置成功,在openjdk源碼文件夾下:
make sanity 一次過。
4.編譯make
在openjdk源碼文件夾下:
#Ubuntu14.04居然check不同過,有點暈,只能加參數 make DISABLE_HOTSPOT_OS_VERSION_CHECK=OK
遇到的其他錯誤及解決方案:
1-----------------------------------------------------------------------------------------
ERROR: echo "*** This OS is not supported:" 'uname -a'; exit 1;
make DISABLE_HOTSPOT_OS_VERSION_CHECK=OK
2-----------------------------------------------------------------------------------------
/openjdk/hotspot/srcmps/constantPoolOop.cpp:272:39: error: converting 'false' to pointer type 'methodOop'
修改/openjdk/hotspot/src/share/vm/oops/constantPoolOop.cpp 第272行 return false改為return (methodOop)false; 或者 return NULL;
3-----------------------------------------------------------------------------------------
openjdk/hotspot/srcm/opto/loopnode.cpp:896:50: error: converting 'false' to pointer type 'Node*
SOLUTION: 修改openjdk/hotspot/src/share/vm/opto/loopnode.cpp: 第896行 return false改為return (Node*)false; 或者 return NULL;
4-----------------------------------------------------------------------------------------
Error occurred during initialization of VM Unable to load native library: /home/softwaresk1.8.0_101/jre/lib/amd64/libjava.so: symbol JVM_GetClassTypeAnnotations, version SUNWprivate_1.1 not defined in file libjvm.so with link time reference
SOLUTION: openjdk/hotspot/make/linux/Makefile 去掉所有的 && ./test_gamma
5-----------------------------------------------------------------------------------------
/home/mengxiansen/openjdk/openjdk/hotspot/src/share/vm/runtime/interfaceSupport.hpp:430:0: error: "__LEAF" redefined [-Werror]
SOLUTION:
#define __LEAF(result_type, header)
/usr/include/x86_64-linux-gnu/sys/cdefs.h:42:0: note: this is the location of the previous definition
# define __LEAF , __leaf__
在interfaceSupport.hpp增加
#ifdef __LEAF
#undef __LEAF
#define __LEAF(result_type, header) \
TRACE_CALL(result_type, header) \
debug_only(NoHandleMark __hm;) \
/* begin of body */
#endif
6-----------------------------------------------------------------------------------------
gcc: error: unrecognized command line option '-mimpure-text'
SOLUTION: gcc版本問題,這個命令在本機所用的4.7.2版的gcc中已經去除,既然不能降低gcc版本(本機ubuntu12.10內核用4.7.2版gcc編譯),那就在openjdk/jdk/make/common/shared/Compiler-gcc.gmk 中去掉-mimpure-text命令
7-----------------------------------------------------------------------------------------
Error: time is more than 10 years from present: 1136059200000
SOLUTION: 將 openjdk/jdk/src/share/classes/java/util/CurrencyData.properties 中所有的時間改為10年以內
8-----------------------------------------------------------------------------------------
collect2: error: ld returned 1 exit status
SOLUTION: openjdk/jdk/make/javax/sound/jsoundalsa/Makefile 里面
刪除 LDFLAGS += -lasound
加入 OTHER_LDLIBS += -lasound
5.編譯成功
-- Build times ---------- Target all_product_build Start 2016-08-31 22:10:08 End 2016-08-31 22:13:49 00:00:02 corba 00:00:02 hotspot 00:00:01 jaxp 00:00:02 jaxws 00:03:33 jdk 00:00:01 langtools 00:03:41 TOTAL ------------------------- make[1]: Leaving directory `/home/softwares/openjdk7'
JVM在/home/advance/JVM/jdkBuild/openjdk_7/build/hotspot/outputdir/linux_amd64_compiler2/product,可以在IDE工具中進行調試。
在ALT_OUTPUTDIR的build下面找類似的路徑linux_amd64_complier2是我的ubuntu64位系統,別的系統不一樣。
以上記錄在github中 https://github.com/dreamingodd/UnderstandingJVM ,其他問題可以去找來參考。
dreamingodd原創文章,如轉載請注明出處。
