java开发一阵子了,想深入了解下jvm,所以在ubuntu下本地编译学习一下openjdk代码
1,java虚拟机有很多不稳定参数,以xx开头可以使用java -XX:+PrintFlagsFinal 查看;
2,编译java
下载open jdk 源码;http://download.java.net/openjdk/jdk8/
放到ubuntu 虚拟机,解压,根据readme.build操作
configure: error: Could not find freetype! You might be able to fix this by running 'sudo apt-get install libfreetype6-dev'.
安装完依然这个鸟样。FUCK!最近工作忙,找个时间继续
--------------------------------------
开始重编译一次
1,在ubuntu 14.04 64b,先安装需要的软件
sudo apt-get install build-essential gawk m4 libasound2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils libmotif3 libmotif-dev ant
2,下载openjdk,1.7 http://www.java.net/download/openjdk/jdk7u40/promoted/b43/openjdk-7u40-fcs-src-b43-26_aug_2013.zip
下载上传服务器,解压缩;
3,
make sanity
----------------------------------------------
ERROR: You do not have access to valid Cups header files. Please check your access to /usr/include/cups/cups.h and/or check your value of ALT_CUPS_HEADERS_PATH, CUPS is frequently pre-installed on many systems, or may be downloaded from http://www.cups.org安装解决:sudo apt-get install libcups2-dev
ERROR: HOTSPOT_SERVER_PATH does not point to a valid HotSpot VM. Please check your access to /NOT-SET/re/jdk/1.7.0/promoted/latest/binaries/linux-amd64/jre/lib/amd64/server/libjvm.so and/or check your value of ALT_HOTSPOT_SERVER_PATH.执行目录不对,应该在open jdk根目录运行
运行后显示:Sanity check passed.
运行命令:make
/jvm/openjdk/langtools/make/build.xml:860: Error running /usr/lib/jvm/java-7-openjdk-amd64/bin/javac compiler
安装openjdk sudo apt-get install openjdk-7-jdk再运行命令:
make ALT_BOOTDIR=/usr/lib/jvm/jdk1.7.0_80
开始编译
/bin/sh: 2: zip: not found
apt-get install zip
再运行命令: make ALT_BOOTDIR=/usr/lib/jvm/jdk1.7.0_80
再报错
make[5]: Entering directory `/jvm/openjdk/build/linux-amd64/hotspot/outputdir'
>&2 echo "*** This OS is not supported:" `uname -a`; exit 1; *** This OS is not supported: Linux 466e7b25085c 4.4.52-1.el7.elrepo.x86_64 #1 SMP Sun Feb 26 08:48:14 EST 2017 x86_64 x86_64 x86_64 GNU/Linux make[5]: *** [check_os_version] Error 1 make[5]: Leaving directory `/jvm/openjdk/build/linux-amd64/hotspot/outputdir' make[4]: *** [linux_amd64_compiler2/debug] Error 2 make[4]: Leaving directory `/jvm/openjdk/build/linux-amd64/hotspot/outputdir' make[3]: *** [generic_build2] Error 2 make[3]: Leaving directory `/jvm/openjdk/hotspot/make' make[2]: *** [product] Error 2 make[2]: Leaving directory `/jvm/openjdk/hotspot/make' make[1]: *** [hotspot-build] Error 2 make[1]: Leaving directory `/jvm/openjdk' make: *** [build_product_image] Error 2真是日了狗了,原来是hot spot makefile版本指定太低,
修改文件/jvm/openjdk/hotspot/make/linux# vi Makefile
SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 3% 这后面添加自己的linux版本 4%
继续 make 命令:make ALT_BOOTDIR=/usr/lib/jvm/java-7-openjdk-amd64
程序开始正常编译,过了大约5-6分钟,又报错:
Using java runtime atError occurred during initialization of VMjava.lang.NullPointerException at java.util.Hashtable.hash(Hashtable.java:262) at java.util.Hashtable.remove(Hashtable.java:585) at java.lang.System.initProperties(Native Method) at java.lang.System.initializeSystemClass(System.java:1119)
真是日了狗了,这个明显是代码空指针异常,更改使用jdk1.6
make ALT_BOOTDIR=/jvm/jdk1.6.0_45
注:此处至少说明oracle jdk和openjdk 此处文件
java.lang.System.initializeSystemClass(System.java:1119)有较大改动。
编译通过,继续往下走:
又报错:
/jvm/jdk1.6.0_45/bin/java -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput -Xmx512m -Xms512m -XX:PermSize=32m -XX:MaxPermSize=160m -jar /jvm/openjdk/build/linux-amd64/btjars/generatecurrencydata.jar -o /jvm/openjdk/build/linux-amd64/lib/currency.data.temp \ < ../../../src/share/classes/java/util/CurrencyData.propertiesError: time is more than 10 years from present: 1136059200000java.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[4]: *** [/jvm/openjdk/build/linux-amd64/lib/currency.data] Error 1make[4]: Leaving directory `/jvm/openjdk/jdk/make/java/java'
时间过长?查看文件,发现如下注释:
# Mappings from ISO 3166 country codes to ISO 4217 currency codes.## Three forms are used:# Form 1:= # Form 2: = ;
修改文件如下:
## Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.## This code is free software; you can redistribute it and/or modify it# under the terms of the GNU General Public License version 2 only, as# published by the Free Software Foundation. Oracle designates this# particular file as subject to the "Classpath" exception as provided# by Oracle in the LICENSE file that accompanied this code.## This code is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License# version 2 for more details (a copy is included in the LICENSE file that# accompanied this code).## You should have received a copy of the GNU General Public License version# 2 along with this work; if not, write to the Free Software Foundation,# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.## Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA# or visit www.oracle.com if you need additional information or have any# questions.#formatVersion=1# Version of the currency code information in this class.# It is a serial number that accompanies with each amendment, such as # 'MAxxx.doc'dataVersion=151# List of all valid ISO 4217 currency codes.# To ensure compatibility, do not remove codes.all=ADP020-AED784-AFA004-AFN971-ALL008-AMD051-ANG532-AOA973-ARS032-ATS040-AUD036-\ AWG533-AYM945-AZM031-AZN944-BAM977-BBD052-BDT050-BEF056-BGL100-BGN975-BHD048-BIF108-\ BMD060-BND096-BOB068-BOV984-BRL986-BSD044-BTN064-BWP072-BYB112-BYR974-\ BZD084-CAD124-CDF976-CHF756-CLF990-CLP152-CNY156-COP170-CRC188-CSD891-CUP192-CUC931-\ CVE132-CYP196-CZK203-DEM276-DJF262-DKK208-DOP214-DZD012-EEK233-EGP818-\ ERN232-ESP724-ETB230-EUR978-FIM246-FJD242-FKP238-FRF250-GBP826-GEL981-\ GHC288-GHS936-GIP292-GMD270-GNF324-GRD300-GTQ320-GWP624-GYD328-HKD344-HNL340-\ HRK191-HTG332-HUF348-IDR360-IEP372-ILS376-INR356-IQD368-IRR364-ISK352-\ ITL380-JMD388-JOD400-JPY392-KES404-KGS417-KHR116-KMF174-KPW408-KRW410-\ KWD414-KYD136-KZT398-LAK418-LBP422-LKR144-LRD430-LSL426-LTL440-LUF442-\ LVL428-LYD434-MAD504-MDL498-MGA969-MGF450-MKD807-MMK104-MNT496-MOP446-MRO478-\ MTL470-MUR480-MVR462-MWK454-MXN484-MXV979-MYR458-MZM508-MZN943-NAD516-NGN566-\ NIO558-NLG528-NOK578-NPR524-NZD554-OMR512-PAB590-PEN604-PGK598-PHP608-\ PKR586-PLN985-PTE620-PYG600-QAR634-ROL946-RON946-RSD941-RUB643-RUR810-RWF646-SAR682-\ SBD090-SCR690-SDD736-SDG938-SEK752-SGD702-SHP654-SIT705-SKK703-SLL694-SOS706-\ SRD968-SRG740-STD678-SVC222-SYP760-SZL748-THB764-TJS972-TMM795-TMT934-TND788-TOP776-\ TPE626-TRL792-TRY949-TTD780-TWD901-TZS834-UAH980-UGX800-USD840-USN997-USS998-\ UYU858-UZS860-VEB862-VEF937-VND704-VUV548-WST882-XAF950-XAG961-XAU959-XBA955-\ XBB956-XBC957-XBD958-XCD951-XDR960-XFO000-XFU000-XOF952-XPD964-XPF953-\ XPT962-XSU994-XTS963-XUA965-XXX999-YER886-YUM891-ZAR710-ZMK894-ZWD716-ZWL932-ZWN942-ZWR935# Mappings from ISO 3166 country codes to ISO 4217 currency codes.## Three forms are used:# Form 1:= # Form 2: = ;
编译通过,继续往下走
结束编译。
/jvm/openjdk/build/linux-amd64/bin# ./java -version
openjdk version "1.7.0-internal" OpenJDK Runtime Environment (build 1.7.0-internal-root_2017_04_06_05_42-b00) OpenJDK 64-Bit Server VM (build 24.0-b56, mixed mode)上传一个Test.java;
./javac ./Test.java
/jvm/openjdk/build/linux-amd64/bin# ./java Test
hi jvm.Thu Apr 06 06:27:40 UTC 2017总结:编译openjdk1.7,建议ALT_BOOTDIR使用sun jdk1.6较高版本进行编译。