1. 下载openjdk12源码
直接访问OpenJDK 12 下载地址,然后点击左边Browse
按钮,将显示源码根目录页面,如下图:
到该页面后可以选择用zip
,bz2
,gz
这些按钮进行压缩文件下载。
解压后便得到 openJDK 12
源码
2.构建编译环境
1 安装JDK11
因为OpenJDK内部包含(HotSpot、JDK类库、JAXWS……),其中一部分使用c、c++编写,而更多的部分则是使用java来编写,编译需要另外一个JDK支持,官方称为Bootstrap JDK
,所以想要编译一个N版本的JDK,需要另外准备一个大版本至少为N-1的JDK。
安装JDK直接给个下载链接 华为镜像 不进行过多描述。
这两个都是apple官方配置的,可以到 Apple Developer 上免费下载 。
3 安装依赖库
这里用Homebrew安装(如果没有Homebrew,可以参考Homebrew安装与使用,或者自行百度)
安装好了执行下列命令
1 2 3
| brew install ccache brew install freetype brew install autoconf
|
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
| # 第一步 cd到openjdk12的根目录 # 这里用 /Users/admin/Downloads/jdk12 到代替真实目录 cd /Users/admin/Downloads/jdk12 # 查询编译参数(可以逃过) bash configure --help # 第二步 检查依赖 bash configure --enable-debug --with-jvm-variants=server # 如果环境正常则输出以下 # ==================================================== # A new configuration has been successfully created in # /Users/admin/Downloads/jdk12/build/macosx-x86_64-server-fastdebug # using configure arguments '--enable-debug --with-jvm-variants=server'. #
# * Debug level: fastdebug # * HS debug level: fastdebug # * JVM variants: server # * JVM features: server: 'aot cds cmsgc compiler1 compiler2 dtrace epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs' # * OpenJDK target: OS: macosx, CPU architecture: x86, address length: 64 # * Version string: 12-internal+0-adhoc.admin.jdk12 (12-internal) #
# * Boot JDK: java version "12" 2019-03-19 Java(TM) SE Runtime Environment (build 12+33) Java HotSpot(TM) 64-Bit Server VM (build 12+33, mixed mode, sharing) (at /Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home) # * Toolchain: clang (clang/LLVM from Xcode 12.5) # * C Compiler: Version 12.0.5 (at /usr/bin/clang) # * C++ Compiler: Version 12.0.5 (at /usr/bin/clang++) #
# * Cores to use: 8 # * Memory limit: 16384 MB
# 第三步make # bash configure参数不同会在build目录下生成不同版本 # 多个版本则需要带上参数CONF明确make哪一个, # make images CONF=macosx-x86_64-server-fastdebug make images # 如果出现以下字样表示成功 # Finished building target 'images' in configuration 'macosx-x86_64-server-fastdebug' # 如果出现error 记得用以下命令清理目录(对应问题可参考下文的问题总结) # make dist-clean 或 make clean
|
4 问题总结
这里用 /Users/admin/Downloads/jdk12 到代替真实目录,以下本人编译时碰到的问题
问题一
/Users/admin/Downloads/jdk12/src/hotspot/share/runtime/arguments.cpp的1452行
1 2 3
| if (old_java_vendor_url_bug != DEFAULT_VENDOR_URL_BUG) {
if (strcmp(old_java_vendor_url_bug, DEFAULT_VENDOR_URL_BUG) != 0) {
|
问题二
/Users/admin/Downloads/jdk12/test/hotspot/gtest/classfile/test_symbolTable.cpp的62行,将
问题三
/Users/admin/Downloads/jdk12/src/hotspot/share/runtime/sharedRuntime.cpp的2873行,将
1 2 3
| buffer.insts()->initialize_shared_locs((relocInfo*)locs_buf, sizeof(locs_buf) / sizeof(relocInfo));
buffer.insts()->initialize_shared_locs((relocInfo*)locs_buf, (sizeof(locs_buf)) / sizeof((relocInfo)));
|
问题四
/Users/admin/Downloads/jdk12/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m的134行,将
1 2 3
| if (colorIndex < (useAppleColor) ? sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS : java_awt_SystemColor_NUM_COLORS) {
if (colorIndex < ((useAppleColor) ? sun_lwawt_macosx_LWCToolkit_NUM_APPLE_COLORS : java_awt_SystemColor_NUM_COLORS)) {
|
问题五
/Users/admin/Downloads/jdk12/src/jdk.base/share/native/libfdlibm/e_asin.c的106,将eles缺少的花括号补上就可以了。
问题六
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| === Output from failing command(s) repeated here === * For target support_native_java.desktop_libjsound_PLATFORM_API_MacOSX_MidiUtils.o: /Users/admin/Desktop/OpenJDK/jdk12/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_MidiUtils.c:263:31: error: cast to smaller integer type 'MIDIClientRef' (aka 'unsigned int') from 'void *' [-Werror,-Wvoid-pointer-to-int-cast] static MIDIClientRef client = (MIDIClientRef) NULL; ^~~~~~~~~~~~~~~~~~~~ /Users/admin/Desktop/OpenJDK/jdk12/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_MidiUtils.c:264:29: error: cast to smaller integer type 'MIDIPortRef' (aka 'unsigned int') from 'void *' [-Werror,-Wvoid-pointer-to-int-cast] static MIDIPortRef inPort = (MIDIPortRef) NULL; ^~~~~~~~~~~~~~~~~~ /Users/admin/Desktop/OpenJDK/jdk12/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_MidiUtils.c:265:30: error: cast to smaller integer type 'MIDIPortRef' (aka 'unsigned int') from 'void *' [-Werror,-Wvoid-pointer-to-int-cast] static MIDIPortRef outPort = (MIDIPortRef) NULL; ^~~~~~~~~~~~~~~~~~ /Users/admin/Desktop/OpenJDK/jdk12/src/java.desktop/macosx/native/libjsound/PLATFORM_API_MacOSX_MidiUtils.c:471:32: error: cast to smaller integer type 'MIDIEndpointRef' (aka 'unsigned int') from 'void *' [-Werror,-Wvoid-pointer-to-int-cast] MIDIEndpointRef endpoint = (MIDIEndpointRef) NULL; ^~~~~~~~~~~~~~~~~~~~~~ ... (rest of output omitted) * All command lines available in /Users/admin/Desktop/OpenJDK/jdk12/build/macosx-x86_64-server-release/make-support/failure-logs. === End of repeated output ===
|
解决方案:
方案一:找到对应文件把括号里改成了unsigned long 运行
方案二:
1 2 3 4 5 6 7 8
| /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreMIDI.framework/Versions/A/Headers/MIDIServeice.h
make clean make images
|
问题七
1 2 3 4 5 6
| Building target 'images' in configuration 'macosx-x86_64-server-fastdebug' Warning: No SCM configuration present and no .src-rev Compiling 8 files for BUILD_TOOLS_LANGTOOLS 警告: [path] 错误的路径元素 "/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home/lib/tools.jar": 没有这种文件或目录 警告: [path] 错误的路径元素 "/Library/Java/JavaVirtualMachines/jdk-12.jdk/Contents/Home/lib/dt.jar": 没有这种文件或目录 错误: 发现警告, 但指定了 -Werror
|
解决方案: 直接将旧版本jdk里的tools.jar
和dt.jar
复制过来就行