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,裴银祥的分享,最后会列出相应的参考链接

二、下载

  1. openjdk-7u40-fcs-src-b43-26_aug_2013.zip
  2. openjdk-8-src-b132-03_mar_2014.zip
  3. OpenJDK7 Build README
  4. OpenJDK8 Build README
  5. Eclipse CPP NEON

三、 系统环境

Key Value
OS10.11.5 El Capitan
Apple LLVM version7.3.0 (clang-703.0.31)
makeGNU Make 3.81
Xcode7.3.1
Ant1.9.7
LLVM GCC(clang)4.2.1
zip3.0
unzip5.52
freeType2.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)

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 设定语言选项,必须设置
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
# FreeType
export 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
# ANT
export ANT_HOME=/Users/zhongmingmao/Downloads/apache-ant-1.9.7
# 取消环境变量的设置,减少警告
unset JAVA_HOME
unset CLASSPATH
unset LD_LIBRARY_PATH
3. 加载并检查环境变量

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# 加载环境变量
source ../../openjdk7.bash

# 检查环境变量
make sanity

# 检查结果(仅仅显示关键信息)
Build Machine Information:
   build machine = Mac

Build Directory Structure:
   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

Build Directives:
   BUILD_LANGTOOLS = true
   BUILD_JAXP = true
   BUILD_JAXWS = true
   BUILD_CORBA = true
   BUILD_HOTSPOT = true
   BUILD_JDK    = true

Hotspot Settings:
      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

Bootstrap Settings:
  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

Build Tool Settings:
  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

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

Build Platform Settings:
  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 Make Settings:
  MAKE = /Applications/Xcode.app/Contents/Developer/usr/bin/make
  MAKE_VER = 3.81 [requires at least 3.81]
  MAKECMDGOALS = sanity
  SHELL = /bin/sh

Target Build Versions:
  JDK_VERSION = 1.7.0
  MILESTONE = internal
  RELEASE = 1.7.0-internal-debug
  FULL_VERSION = 1.7.0-internal-debug-b25
  BUILD_NUMBER = b25

External File/Binary Locations:
  LANGTOOLS_DIST =
    ALT_LANGTOOLS_DIST = /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/langtools/dist
  CORBA_DIST =
    ALT_CORBA_DIST = /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/corba/dist
  JAXP_DIST =
    ALT_JAXP_DIST = /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/jaxp/dist
  JAXWS_DIST =
    ALT_JAXWS_DIST = /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/jaxws/dist
  HOTSPOT_IMPORT_PATH = /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/hotspot/import
    ALT_HOTSPOT_IMPORT_PATH = /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/hotspot/import
  HOTSPOT_SERVER_PATH = /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk/build/hotspot/import/jre/lib/server
  CACERTS_FILE = ./../src/share/lib/security/cacerts
  CUPS_HEADERS_PATH = /usr/include

OpenJDK-specific settings:
  FREETYPE_HEADERS_PATH = /usr/local/Cellar/freetype/2.6_1/include
    ALT_FREETYPE_HEADERS_PATH = /usr/local/Cellar/freetype/2.6_1/include
  FREETYPE_LIB_PATH = /usr/local/Cellar/freetype/2.6_1/lib
    ALT_FREETYPE_LIB_PATH = /usr/local/Cellar/freetype/2.6_1/lib

Previous JDK Settings:
  PREVIOUS_JDK_VERSION = 1.6.0
  PREVIOUS_RELEASE_IMAGE = /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

Sanity check passed.
4. 编译Debug版本

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 编译命令
make debug_build 2>&1 |tee $ALT_OUTPUTDIR/build.log

# 编译结果
#-- Build times ----------
Target debug_build
Start 2016-07-13 00:21:16
End   2016-07-13 00:30:25
00:00:12 corba
00:00:10 hotspot
00:00:02 jaxp
00:00:05 jaxws
00:08:35 jdk
00:00:03 langtools
00:09:09 TOTAL
-------------------------

# 运行编译结果
./build-debug/j2sdk-image/bin/java -version

openjdk version "1.7.0-internal-debug"
OpenJDK Runtime Environment (build 1.7.0-internal-debug-b25)
OpenJDK 64-Bit Server VM (build 24.0-b56-jvmg, mixed mode)
5. 编译过程中遇到的坑(按出现顺序记录)
5.1 乱码问题

 
 
1
2
3
4
5
6
7
8
# 具体报错
openjdk/build/../build-debug/corba/gensrc/org/omg/PortableServer/AdapterActivatorOperations.java:8: ´íÎó: ±àÂëasciiµÄ
    ²»¿ÉÓ³Éä×Ö·û
* 2016??7??12?? ?????? ????05??39??22?? CST

# 解决办法
find build-debug/corba/gensrc/org/ -name '*.java' | while read p; do native2ascii -encoding UTF-8 $p > tmpj; mv tmpj $p; done
export _JAVA_OPTIONS=-Dfile.encoding=ASCII
5.2 clang不支持参数-fpch-deps

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 具体报错
clang: error: unknown argument: '-fpch-deps'

# 解决方法
1. 首先查找对应的配置文件
find . -type f ! -name "*.java" | xargs grep -r "\-fpch\-deps"
1.1 匹配的查找结果如下(Mac来源于BSD,选择BSD
./hotspot/make/bsd/makefiles/gcc.make:DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)
./hotspot/make/linux/makefiles/gcc.make:DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)
./hotspot/make/solaris/makefiles/gcc.make:DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)

2 修改hotspot/make/bsd/makefiles/gcc.make
2.1 注释216-218
# Flags for generating make dependency flags.
# ifneq ("${CC_VER_MAJOR}", "2")
# DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)
# endif
2.2 218行下添加下面代码
DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)
ifeq ($(USE_CLANG),)
  ifneq ($(CC_VER_MAJOR), 2)
    DEPFLAGS += -fpch-deps
  endif
endif
5.3 形参默认值问题

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 具体报错
openjdk/hotspot/src/share/vm/code/relocInfo.hpp:374:27: error: friend declaration specifying a default argument must
      be a definition
inline friend relocInfo prefix_relocInfo(int datalen = 0);

openjdk/hotspot/src/share/vm/code/relocInfo.hpp:469:18: error: friend declaration specifying a default argument must
      be the only declaration
inline relocInfo prefix_relocInfo(int datalen) {

openjdk/hotspot/src/share/vm/code/relocInfo.hpp:470:21: error: 'fits_into_immediate' is a protected member of 'reloc
     Info'
assert(relocInfo::fits_into_immediate(datalen), "datalen in limits");

openjdk/hotspot/src/share/vm/code/relocInfo.hpp:471:59: error: 'RAW_BITS' is a protected member of 'relocInfo'
return relocInfo(relocInfo::data_prefix_tag, relocInfo::RAW_BITS, relocInfo::datalen_tag | datalen);

openjdk/hotspot/src/share/vm/code/relocInfo.hpp:471:10: error: calling a protected constructor of class 'relocInfo'
return relocInfo(relocInfo::data_prefix_tag, relocInfo::RAW_BITS, relocInfo::datalen_tag | datalen);

# 解决办法
# 修改relocInfo.hpp(路径:hotspot/src/share/vm/code/relocInfo.hpp)
修改374
inline friend relocInfo prefix_relocInfo(int datalen);
修改469
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);
}
5.4 十年问题

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 具体报错
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)

# 解决办法
# 修改CurrencyData.properties(路径:jdk/src/share/classes/java/util/CurrencyData.properties)
修改108
AZ=AZM;2009-12-31-20-00-00;AZN
修改381
MZ=MZM;2009-06-30-22-00-00;MZN
修改443
RO=ROL;2009-06-30-21-00-00;RON
修改535
TR=TRL;2009-12-31-22-00-00;TRY
修改561
VE=VEB;2009-01-01-04-00-00;VEF
5.5 非空函数不返回值的问题一

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 具体报错
../../../src/solaris/native/java/net/net_util_md.c:117:9: error: non-void function 'getDefaultScopeID' should return a value [-Wreturn-type]
        CHECK_NULL(c);
        ^
../../../src/share/native/java/net/net_util.h:45:40: note: expanded from macro 'CHECK_NULL'
#define CHECK_NULL(x) if ((x) == NULL) return;
                                       ^
../../../src/solaris/native/java/net/net_util_md.c:119:9: error: non-void function 'getDefaultScopeID' should return a value [-Wreturn-type]
        CHECK_NULL(c);
        ^
../../../src/share/native/java/net/net_util.h:45:40: note: expanded from macro 'CHECK_NULL'
#define CHECK_NULL(x) if ((x) == NULL) return;

# 解决办法
# 修改net_util_md.c(路径:jdk/src/solaris/native/java/net/net_util_md.c)
修改117119
CHECK_NULL_RETURN(c , 0);
5.6 权限问题

 
 
1
2
3
4
5
# 具体报错
Permission denied - ./src/core/PrimitiveCoder.hs (Errno::EACCES)

# 解决办法
chmod 755 jdk/src/macosx/native/jobjc/src/core/PrimitiveCoder.hs
5.7 clang不支持GC的问题

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 具体报错
clang: error: garbage collection is no longer supported

# 解决办法
1. 首先查找相应的配置文件
find . -type f ! -name "*.log" | xargs grep -r "GCC_ENABLE_OBJC_GC"
1.1 匹配的查找结果如下
nary file ./build-debug/JObjC.dst/dgph matches
./jdk/src/macosx/native/jobjc/JObjC.xcodeproj/project.pbxproj:                                GCC_ENABLE_OBJC_GC = supported;
./jdk/src/macosx/native/jobjc/JObjC.xcodeproj/project.pbxproj:                                GCC_ENABLE_OBJC_GC = supported;

2. 修改project.pbxproj(路径:./jdk/src/macosx/native/jobjc/JObjC.xcodeproj/project.pbxproj
修改705713
GCC_ENABLE_OBJC_GC = "";
5.8 返回值大于返回类型精度的问题

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 具体报错
openjdk/build-debug/JObjC.build/src/jobjc/com/apple/jobjc/appkit/AppKitFramework.java:355: ?????
     public final float NSEventDurationForever(){ return 1.797693134862316E+308f; }

# 解决办法
1. 修改bridgesupport.gmk(路径:jdk/src/macosx/native/jobjc/bridgesupport.gmk
修改54
all:

2. 修改AppKitFull.bridgesupport(路径:build-debug/stable_bridge_metadata/AppKitFull.bridgesupport
修改1485
<enum name='NSEventDurationForever' value='3.40282E+38'/>

3. 修改AppKitFramework.java(路径:build-debug/JObjC.build/src/jobjc/com/apple/jobjc/appkit/AppKitFramework.java
修改355
public final double NSEventDurationForever(){ return 3.40282E+38d; }
5.9 非空函数不返回值的问题二

 
 
1
2
3
4
5
6
7
8
# 具体报错
openjdk/jdk/src/macosx/native/sun/awt/AWTEvent.m:385:24: error: non-void function 'NsGetDeadKeyChar' should return a value [-Wreturn-type]
    if (uchr == nil) { return; }

# 解决办法
# 修改AWTEvent.m(路径:jdk/src/macosx/native/sun/awt/AWTEvent.m)
修改385
if (uchr == nil) { return 0; }

五、Eclipse调试Hotspot

1. 导入项目

 
 
1
2
3
4
5
# 操作
file -> new -> Makefile Project with Existing Code

# 备注
hotspot目录 : OpenJDK源代码根目录下

图片失效

1. 修改项目属性

 
 
1
2
# 操作
项目右键 -> properites -> C/C++ Build
1.1 Builder Settings

 
 
1
2
3
4
# 备注
Build command : make -f Makefile ALT_BOOTDIR=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home ARCH_DATA_MODEL=64 LANG=C COMPILER_WARNINGS_FATAL=false LFLAGS='-Xlinker -lstdc++' USE_CLANG=true LP64=1 CC=clang HOTSPOT_BUILD_JOBS=2 SHOW_ALL_WARNINGS=false

Build directory : ${workspace_loc:/hotspot}/make

图片失效

1.2 Behavior

 
 
1
2
# 备注
Build(Incremental build) : jvmg

图片失效

2. 构建项目前准备

 
 
1
2
3
4
5
6
7
8
9
10
# 目的
防止进度条出现"Remote System Explorer Operation",导致Eclipse卡顿

# 操作一
Eclipse -> Preferences -> General -> Startup and Shutdown.
- Uncheck RSE UI.

# 操作二
Eclipse -> Preferences -> Remote Systems.
- Uncheck Re-open Remote Systems view to previous state.
3. 构建项目

 
 
1
2
3
4
5
6
7
8
9
10
11
12
# 操作
Project -> Build Project -> 漫长地等待

# 构建结果(只显示最后的内容)
.....
echo "Doing vm.make build:"
Doing vm.make build:
All done.
cd bsd_amd64_compiler2/jvmg && ./test_gamma
JAVA_HOME must point to a 64-bit OpenJDK.

19:49:47 Build Finished (took 11s.789ms)
4. 调试HotSpot
4.1 配置全局GDB路径

 
 
1
2
3
4
5
# 操作
Eclipse -> Preferences -> C/C++ -> Debug -> GDB

# 备注
GDB debugger : /usr/local/bin/gdb

图片失效

4.2 Debug配置
4.2.1 新建C/C++ Application

 
 
1
2
3
4
5
# 操作
Debug Configurations -> new -> C/C++ Application

# 启动程序
C/C++ Application : /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk_copy/hotspot/build/bsd/bsd_amd64_compiler2/jvmg/gamma

图片失效

4.2.2 配置Arguments

 
 
1
Program arguments : Hello # 自己编译的class文件

图片失效

4.2.3 配置Environment(新增三个环境变量)

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 1. 加上自己的class路径,否则会ClassNotFound
CLASSPATH : .:/Users/zhongmingmao/Documents/source_code/java/openjdk/my_class

# 2. 配置JAVA_HOME,即编译OpenJDK7时产生的目录,否则会报下面错误
  JAVA_HOME must point to a valid JDK/JRE to run gamma
  Error: could not find libjava.dylib
  Error: could not find Java 2 Runtime Environment.

JAVA_HOME : /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk_copy/build-debug/j2sdk-image

# 3. 配置LD_LIBRARY_PATH,即Eclipse编译HotSpot产生的目录,当然也可以使用编译OpenJDK7时产生的目录,否则会报下面的错误
  dyld: Library not loaded: @rpath/libjvm.dylib
    Referenced from: /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk_copy/hotspot/build/bsd/bsd_amd64_compiler2/jvmg/gamma
    Reason: image not found

LD_LIBRARY_PATH : /Users/zhongmingmao/Documents/source_code/java/openjdk/openjdk7/openjdk_copy/hotspot/build/bsd/bsd_amd64_compiler2/jvmg

图片失效

4.2.4 配置Debugger

 
 
1
GDB debugger : /usr/local/bin/gdb

图片失效

4.3 Debug视图

图片失效

六、编译OpenJDK8

1. 与OpenJDK7的区别
  • The build is now a configure && make style build
  • Ant is no longer used when building the OpenJDK
  • Any GNU make 3.81 or newer should work
  • Use of ALT_* environment variables for configuring the build is no longer supported
2. 环境依赖
Key Value
GNU make≧ 3.81
Bootstrap JDK≧ JDK7U7 , < JDK8
XCode≧ 4.5.2
3. 修改部分代码和配置

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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)
修改376
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);
}
4. configure

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 用法
sh ./configure --help=short

# 实际命令参数
sh configure --with-debug-level=slowdebug --with-boot-jdk=/usr/libexec/java_home -v 1.7 --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=4 CC=clang CXX=clang++

# 输出(仅显示关键信息)
Configuration summary:
* Debug level:    slowdebug
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64

Tools summary:
* Boot JDK:       java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)  (at /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home)
* C Compiler:     Apple LLVM version (clang-703.0.31) version 7.3.0 (clang-703.0.31) (at /usr/bin/clang)
* C++ Compiler:   Apple LLVM version (clang-703.0.31) version 7.3.0 (clang-703.0.31) (at /usr/bin/clang++)

Build performance summary:
* Cores to use:   4
* Memory limit:   8192 MB
* ccache status:  installed, but disabled (version older than 3.1.4)
5. make

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 用法
make help

# 实际命令参数
make COMPILER_WARNINGS_FATAL=false LFLAGS='-Xlinker -lstdc++' CC=clang USE_CLANG=true LP64=1

# 输出(仅显示关键信息)
----- Build times -------
Start 2016-07-10 16:05:19
End   2016-07-10 16:12:41
00:00:44 corba
00:01:32 hotspot
00:00:23 jaxp
00:00:36 jaxws
00:04:06 jdk
00:00:00 langtools
00:07:22 TOTAL
-------------------------
6. java -version

 
 
1
2
3
4
5
6
7
# 命令
build/macosx-x86_64-normal-server-slowdebug/jdk/bin/java -version

# 输出
openjdk version "1.8.0_b25-internal-debug"
OpenJDK Runtime Environment (build 1.8.0_b25-internal-debug-b25)
OpenJDK 64-Bit Server VM (build 25.0-b70-debug, mixed mode)

七、参考资料

  1. 自己动手编译JDK并单步调试hotspot(Mac)
  2. 在eclipse中调试hotspot
  3. mac上eclipse用gdb调试
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值