OpenJDK 编译及常见问题

发布时间: 更新时间: 总字数:2533 阅读时间:6m 作者: IP上海 分享 网址

本文介绍 OpenJDK 源码下载;在 CentOS 环境编译 OpenJDK;以及编译过程中遇到的问题。

环境部署

yum groupinstall "Development Tools" -y
yum install cups-devel freetype-devel alsa-lib-devel ccache -y
yum install ant build-essential gawk zip xorg-dev -y
yum install libxtst-dev libxi-dev libxt-dev libxrender-dev  -y

官方 openjdk 编译方法

[root@xiexianbin-cn  ~]# hg clone http://hg.openjdk.java.net/jdk8/jdk8 openjdk8
requesting all changes
adding changesets
adding manifests
adding file changes
added 942 changesets with 1309 changes to 136 files
updating to branch default
82 files updated, 0 files merged, 0 files removed, 0 files unresolved
[root@xiexianbin-cn  ~]#
[root@xiexianbin-cn  ~]# cd openjdk8/
[root@xiexianbin-cn  openjdk8]# ll
total 348
-rw-r--r--. 1 root root   1503 Mar 18 01:19 ASSEMBLY_EXCEPTION
drwxr-xr-x. 6 root root     61 Mar 18 01:19 common
-rw-r--r--. 1 root root   1235 Mar 18 01:19 configure
-rw-r--r--. 1 root root   1384 Mar 18 01:19 get_source.sh
-rw-r--r--. 1 root root  19263 Mar 18 01:19 LICENSE
drwxr-xr-x. 6 root root    189 Mar 18 01:19 make
-rw-r--r--. 1 root root   6430 Mar 18 01:19 Makefile
-rw-r--r--. 1 root root   1549 Mar 18 01:19 README
-rw-r--r--. 1 root root 129333 Mar 18 01:19 README-builds.html
drwxr-xr-x. 2 root root     22 Mar 18 01:19 test
-rw-r--r--. 1 root root 178445 Mar 18 01:19 THIRD_PARTY_README
[root@xiexianbin-cn  openjdk8]# bash ./get_source.sh
# Repositories:  corba jaxp jaxws langtools jdk hotspot nashorn

                corba:   hg clone http://hg.openjdk.java.net/jdk8/jdk8/corba corba
                 jaxp:   hg clone http://hg.openjdk.java.net/jdk8/jdk8/jaxp jaxp
                corba:   requesting all changes
                 jaxp:   requesting all changes
                corba:   adding changesets
                 jaxp:   adding changesets
                corba:   adding manifests
                 jaxp:   adding manifests
                corba:   adding file changes
                 jaxp:   adding file changes
Waiting 5 secs before spawning next background command.
                corba:   added 581 changesets with 3574 changes to 1388 files
                corba:   updating to branch default
                corba:   1194 files updated, 0 files merged, 0 files removed, 0 files unresolved
                jaxws:   hg clone http://hg.openjdk.java.net/jdk8/jdk8/jaxws jaxws
            langtools:   hg clone http://hg.openjdk.java.net/jdk8/jdk8/langtools langtools
                jaxws:   requesting all changes
            langtools:   requesting all changes
                jaxws:   adding changesets
            langtools:   adding changesets
                jaxws:   adding manifests
Waiting 5 secs before spawning next background command.
                jaxws:   adding file changes
            langtools:   adding manifests
            langtools:   adding file changes
                  jdk:   hg clone http://hg.openjdk.java.net/jdk8/jdk8/jdk jdk
              hotspot:   hg clone http://hg.openjdk.java.net/jdk8/jdk8/hotspot hotspot
                  jdk:   requesting all changes
              hotspot:   requesting all changes
                  jdk:   adding changesets
              hotspot:   adding changesets
                 jaxp:   added 585 changesets with 6288 changes to 4230 files
                 jaxp:   updating to branch default
Waiting 5 secs before spawning next background command.
                 jaxp:   2078 files updated, 0 files merged, 0 files removed, 0 files unresolved
              nashorn:   hg clone http://hg.openjdk.java.net/jdk8/jdk8/nashorn nashorn
              nashorn:   requesting all changes
              nashorn:   adding changesets
              nashorn:   adding manifests
              hotspot:   adding manifests
              nashorn:   adding file changes
                  jdk:   adding manifests
              nashorn:   added 726 changesets with 5938 changes to 2096 files
              hotspot:   adding file changes
              nashorn:   updating to branch default
              nashorn:   1980 files updated, 0 files merged, 0 files removed, 0 files unresolved
                jaxws:   added 469 changesets with 12417 changes to 6727 files
                jaxws:   updating to branch default
                jaxws:   3710 files updated, 0 files merged, 0 files removed, 0 files unresolved
            langtools:   added 2255 changesets with 20630 changes to 6951 files
            langtools:   updating to branch default
            langtools:   6171 files updated, 0 files merged, 0 files removed, 0 files unresolved
              hotspot:   added 5821 changesets with 34543 changes to 5035 files
              hotspot:   updating to branch default
              hotspot:   4153 files updated, 0 files merged, 0 files removed, 0 files unresolved
                  jdk:   adding file changes
                  jdk:   added 9108 changesets with 89618 changes to 26411 files
                  jdk:   updating to branch default
                  jdk:   22175 files updated, 0 files merged, 0 files removed, 0 files unresolved
# Repositories:  ./corba . ./hotspot ./jaxp ./jaxws ./jdk ./langtools ./nashorn

              ./corba:   cd ./corba && hg pull -u
                    .:   cd . && hg pull -u
            ./hotspot:   cd ./hotspot && hg pull -u
               ./jaxp:   cd ./jaxp && hg pull -u
              ./jaxws:   cd ./jaxws && hg pull -u
                ./jdk:   cd ./jdk && hg pull -u
          ./langtools:   cd ./langtools && hg pull -u
            ./nashorn:   cd ./nashorn && hg pull -u
            ./hotspot:   pulling from http://hg.openjdk.java.net/jdk8/jdk8/hotspot
               ./jaxp:   pulling from http://hg.openjdk.java.net/jdk8/jdk8/jaxp
              ./corba:   pulling from http://hg.openjdk.java.net/jdk8/jdk8/corba
            ./nashorn:   pulling from http://hg.openjdk.java.net/jdk8/jdk8/nashorn
                    .:   pulling from http://hg.openjdk.java.net/jdk8/jdk8
              ./jaxws:   pulling from http://hg.openjdk.java.net/jdk8/jdk8/jaxws
                ./jdk:   pulling from http://hg.openjdk.java.net/jdk8/jdk8/jdk
          ./langtools:   pulling from http://hg.openjdk.java.net/jdk8/jdk8/langtools
               ./jaxp:   searching for changes
               ./jaxp:   no changes found
            ./hotspot:   searching for changes
            ./hotspot:   no changes found
              ./corba:   searching for changes
              ./corba:   no changes found
          ./langtools:   searching for changes
          ./langtools:   no changes found
                ./jdk:   searching for changes
                ./jdk:   no changes found
            ./nashorn:   searching for changes
            ./nashorn:   no changes found
                    .:   searching for changes
                    .:   no changes found
              ./jaxws:   searching for changes
              ./jaxws:   no changes found
Waiting 5 secs before spawning next background command.
[root@xiexianbin-cn  openjdk8]#
[root@xiexianbin-cn  openjdk8]# bash ./make/scripts/hgforest.sh status
# Repos:  ./corba . ./hotspot ./jaxp ./jaxws ./jdk ./langtools ./nashorn
Starting on ./corba
Starting on .
Starting on ./hotspot
Starting on ./jaxp
Starting on ./jaxws
Starting on ./jdk
Starting on ./langtools
Starting on ./nashorn
# cd ./jdk && hg status
# exit code 0
# cd . && hg status
# exit code 0
# cd ./jaxws && hg status
# exit code 0
# cd ./langtools && hg status
# exit code 0
# cd ./nashorn && hg status
# exit code 0
# cd ./hotspot && hg status
# exit code 0
# cd ./corba && hg status
# exit code 0
# cd ./jaxp && hg status
# exit code 0
[root@xiexianbin-cn  openjdk8]#
[root@xiexianbin-cn openjdk8]# bash ./configure
Running generated-configure.sh
configure: Configuration created at Sat Mar 18 14:47:06 CST 2017.
configure: configure script generated at timestamp 1389186094.
checking for basename... /usr/bin/basename
checking for bash... /usr/bin/bash
checking for cat... /usr/bin/cat
checking for chmod... /usr/bin/chmod
checking for cmp... /usr/bin/cmp
checking for comm... /usr/bin/comm
checking for cp... /usr/bin/cp
checking for cpio... /usr/bin/cpio
checking for cut... /usr/bin/cut
checking for date... /usr/bin/date
checking for gdiff... no
checking for diff... /usr/bin/diff
checking for dirname... /usr/bin/dirname
checking for echo... /usr/bin/echo
checking for expr... /usr/bin/expr
checking for file... /usr/bin/file
checking for find... /usr/bin/find
checking for head... /usr/bin/head
checking for ln... /usr/bin/ln
checking for ls... /usr/bin/ls
checking for mkdir... /usr/bin/mkdir
checking for mktemp... /usr/bin/mktemp
checking for mv... /usr/bin/mv
checking for printf... /usr/bin/printf
checking for rm... /usr/bin/rm
checking for sh... /usr/bin/sh
checking for sort... /usr/bin/sort
checking for tail... /usr/bin/tail
checking for tar... /usr/bin/tar
checking for tee... /usr/bin/tee
checking for touch... /usr/bin/touch
checking for tr... /usr/bin/tr
checking for uname... /usr/bin/uname
checking for uniq... /usr/bin/uniq
checking for wc... /usr/bin/wc
checking for which... /usr/bin/which
checking for xargs... /usr/bin/xargs
checking for gawk... gawk
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for a sed that does not truncate output... /usr/bin/sed
checking for nawk... no
checking for gawk... /usr/bin/gawk
checking for cygpath... no
checking for readlink... /usr/bin/readlink
checking for df... /usr/bin/df
checking for SetFile... no
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking openjdk-build os-cpu... linux-x86_64
checking openjdk-target os-cpu... linux-x86_64
checking compilation type... native
checking for presence of closed sources... no
checking if closed source is suppressed (openjdk-only)... no
checking which variant of the JDK to build... normal
checking which variants of the JVM to build... server
checking which debug level to use... release
checking what configuration name to use... linux-x86_64-normal-server-release
checking for apt-get... no
checking for yum... yum
checking for gmake... /usr/bin/gmake
configure: Testing potential make at /usr/bin/gmake, found using gmake in PATH
configure: Resolving FOUND_MAKE (as /usr/bin/gmake) failed, using /usr/bin/gmake directly.
configure: Using GNU make 3.81 (or later) at /usr/bin/gmake (version: GNU Make 3.82)
checking if find supports -delete... yes
checking for unzip... /usr/bin/unzip
checking for zip... /usr/bin/zip
checking for ldd... /usr/bin/ldd
checking for otool... no
checking for readelf... /usr/bin/readelf
checking for hg... /usr/bin/hg
checking for stat... /usr/bin/stat
checking for time... /usr/bin/time
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for 7z... no
checking for unzip... unzip
checking for wget... wget
checking headful support... include support for both headful and headless
checking for javac... /usr/lib/jvm/java-openjdk/bin/javac
checking for java... /usr/lib/jvm/java-openjdk/bin/java
configure: Found potential Boot JDK using java(c) in PATH
checking for Boot JDK... /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64
checking Boot JDK version... openjdk version "1.8.0_121" OpenJDK Runtime Environment (build 1.8.0_121-b13) OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
checking for java in Boot JDK... ok
checking for javac in Boot JDK... ok
checking for javah in Boot JDK... ok
checking for javap in Boot JDK... ok
checking for jar in Boot JDK... ok
checking for rmic in Boot JDK... ok
checking for native2ascii in Boot JDK... ok
checking for jtreg... no
checking for gcc... /usr/bin/gcc
configure: Resolving CC (as /usr/bin/gcc) failed, using /usr/bin/gcc directly.
checking resolved symbolic links for CC... /usr/bin/gcc
checking if CC is disguised ccache... no, keeping CC
configure: Using gcc (GCC) 4.8.5 20150623 (Red Hat-11) C compiler version 4.8.5-11) (located at /usr/bin/gcc)
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /usr/bin/gcc accepts -g... yes
checking for /usr/bin/gcc option to accept ISO C89... none needed
checking for g++... /usr/bin/g++
configure: Resolving CXX (as /usr/bin/g++) failed, using /usr/bin/g++ directly.
checking resolved symbolic links for CXX... /usr/bin/g++
checking if CXX is disguised ccache... no, keeping CXX
configure: Using g++ (GCC) 4.8.5 20150623 (Red Hat-11) C++ compiler version 4.8.5-11) (located at /usr/bin/g++)
checking whether we are using the GNU C++ compiler... yes
checking whether /usr/bin/g++ accepts -g... yes
checking for ar... ar
configure: Rewriting AR to "/usr/bin/ar"
checking how to run the C preprocessor... /usr/bin/gcc -E
configure: Resolving CPP (as /usr/bin/gcc) failed, using /usr/bin/gcc directly.
checking how to run the C++ preprocessor... /usr/bin/g++ -E
configure: Resolving CXXCPP (as /usr/bin/g++) failed, using /usr/bin/g++ directly.
checking for nm... nm
configure: Rewriting NM to "/usr/bin/nm"
checking for strip... strip
configure: Rewriting STRIP to "/usr/bin/strip"
checking for gobjcopy... no
checking for objcopy... objcopy
configure: Rewriting OBJCOPY to "/usr/bin/objcopy"
checking for gobjdump... no
checking for objdump... objdump
configure: Rewriting OBJDUMP to "/usr/bin/objdump"
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking stdio.h usability... yes
checking stdio.h presence... yes
checking for stdio.h... yes
checking size of int *... 8
checking for target address size... 64 bits
checking whether byte ordering is bigendian... no
checking if compiler supports "-m64"... yes
checking if compiler supports "-m64"... yes
checking if we should generate debug symbols... true
checking if we should zip debug-info files... yes
checking what is not needed on Linux?... pulse
checking for Mac OS X Java Framework... no
checking for X... libraries , headers
checking for gethostbyname... yes
checking for connect... yes
checking for remove... yes
checking for shmat... yes
checking for IceConnectionNumber in -lICE... yes
checking for X11/extensions/shape.h... yes
checking for X11/extensions/Xrender.h... yes
checking for X11/extensions/XTest.h... yes
checking for X11/Intrinsic.h... yes
checking cups/cups.h usability... yes
checking cups/cups.h presence... yes
checking for cups/cups.h... yes
checking cups/ppd.h usability... yes
checking cups/ppd.h presence... yes
checking for cups/ppd.h... yes
checking for FREETYPE... yes
checking for freetype... yes (using pkg-config)
checking if we can compile and link with freetype... yes
checking if we should bundle freetype... no
checking for ALSA... yes
checking for main in -ljpeg... no
configure: Will use jpeg decoder bundled with the OpenJDK source
checking for which giflib to use... bundled
checking for compress in -lz... yes
checking for which zlib to use... bundled
checking for cos in -lm... yes
checking for dlopen in -ldl... yes
checking if dynamic link of stdc++ is possible... yes
checking if static link of stdc++ is possible... no
checking how to link with libstdc++... dynamic
checking if elliptic curve crypto implementation is present... yes
checking for number of cores... 2
checking for memory size... 3774 MB
checking for appropriate number of jobs to run in parallel... 2
checking whether to use sjavac... no
checking that precompiled headers work... yes
checking for ccache... /usr/bin/ccache
checking if ccache supports precompiled headers... no, disabling ccache
checking if build directory is on local disk... yes
configure: creating /root/test/openjdk8/build/linux-x86_64-normal-server-release/config.status
config.status: creating /root/test/openjdk8/build/linux-x86_64-normal-server-release/spec.gmk
config.status: creating /root/test/openjdk8/build/linux-x86_64-normal-server-release/hotspot-spec.gmk
config.status: creating /root/test/openjdk8/build/linux-x86_64-normal-server-release/bootcycle-spec.gmk
config.status: creating /root/test/openjdk8/build/linux-x86_64-normal-server-release/compare.sh
config.status: creating /root/test/openjdk8/build/linux-x86_64-normal-server-release/spec.sh
config.status: creating /root/test/openjdk8/build/linux-x86_64-normal-server-release/Makefile
config.status: creating /root/test/openjdk8/build/linux-x86_64-normal-server-release/config.h
config.status: /root/test/openjdk8/build/linux-x86_64-normal-server-release/config.h is unchanged

====================================================
A new configuration has been successfully created in
/root/test/openjdk8/build/linux-x86_64-normal-server-release
using default settings.

Configuration summary:
* Debug level:    release
* JDK variant:    normal
* JVM variants:   server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64

Tools summary:
* Boot JDK:       openjdk version "1.8.0_121" OpenJDK Runtime Environment (build 1.8.0_121-b13) OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)  (at /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64)
* C Compiler:     gcc (GCC) 4.8.5 20150623 (Red Hat-11) version 4.8.5-11) (at /usr/bin/gcc)
* C++ Compiler:   g++ (GCC) 4.8.5 20150623 (Red Hat-11) version 4.8.5-11) (at /usr/bin/g++)

Build performance summary:
* Cores to use:   2
* Memory limit:   3774 MB
* ccache status:  installed, but disabled (version older than 3.1.4)

WARNING: The result of this configuration has overridden an older
configuration. You *should* run 'make clean' to make sure you get a
proper build. Failure to do so might result in strange build problems.

[root@xiexianbin-cn openjdk8]# make all

...

----- Build times -------
Start 2017-03-18 15:14:39
End   2017-03-18 15:17:36
00:00:00 corba
00:00:00 demos
00:02:07 docs
00:00:00 hotspot
00:00:46 images
00:00:01 jaxp
00:00:00 jaxws
00:00:01 jdk
00:00:00 langtools
00:00:01 nashorn
00:02:57 TOTAL
-------------------------
Finished building OpenJDK for target 'all'

相关问题

问题描述:

## Starting nashorn
Compiling 435 files for BUILD_NASHORN
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Compiling 111 files for BUILD_NASGEN
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Running nasgen
Exception in thread "main" java.lang.VerifyError: class jdk.nashorn.internal.objects.ScriptFunctionImpl overrides final method setPrototype.(Ljava/lang/Object;)V
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at jdk.nashorn.internal.tools.nasgen.StringConstants.<clinit>(StringConstants.java:85)
    at jdk.nashorn.internal.tools.nasgen.ScriptClassInstrumentor$2.visitMethodInsn(ScriptClassInstrumentor.java:157)
    at jdk.internal.org.objectweb.asm.MethodVisitor.visitMethodInsn(MethodVisitor.java:509)
    at jdk.internal.org.objectweb.asm.ClassReader.readCode(ClassReader.java:1445)
    at jdk.internal.org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1046)
    at jdk.internal.org.objectweb.asm.ClassReader.accept(ClassReader.java:722)
    at jdk.internal.org.objectweb.asm.ClassReader.accept(ClassReader.java:535)
    at jdk.nashorn.internal.tools.nasgen.Main.process(Main.java:121)
    at jdk.nashorn.internal.tools.nasgen.Main.processAll(Main.java:88)
    at jdk.nashorn.internal.tools.nasgen.Main.main(Main.java:62)
gmake[1]: *** [/root/test/openjdk8/build/linux-x86_64-normal-server-release/nashorn/classes/_the.nasgen.run] Error 1
make: *** [nashorn-only] Error 2
[root@xiexianbin-cn openjdk8]#

解决方法:

修改nashorn/make/BuildNashorn.gmk文件,修改前:

 73 # Copy classes to final classes dir and run nasgen to modify classes in jdk.nashorn.internal.objects package
 74 $(NASHORN_OUTPUTDIR)/classes/_the.nasgen.run: $(BUILD_NASGEN)
 75         $(ECHO) Running nasgen
 76         $(MKDIR) -p $(@D)
 77         $(RM) -rf $(@D)/jdk $(@D)/netscape
 78         $(CP) -R -p $(NASHORN_OUTPUTDIR)/nashorn_classes/* $(@D)/
 79         $(FIXPATH) $(JAVA) \
 80             -cp "$(NASHORN_OUTPUTDIR)/nasgen_classes$(PATH_SEP)$(NASHORN_OUTPUTDIR)/nashorn_classes" \
 81             jdk.nashorn.internal.tools.nasgen.Main $(@D) jdk.nashorn.internal.objects $(@D)
 82         $(TOUCH) $@
 83

修改第80行,修改后:

 73 # Copy classes to final classes dir and run nasgen to modify classes in jdk.nashorn.internal.objects package
 74 $(NASHORN_OUTPUTDIR)/classes/_the.nasgen.run: $(BUILD_NASGEN)
 75         $(ECHO) Running nasgen
 76         $(MKDIR) -p $(@D)
 77         $(RM) -rf $(@D)/jdk $(@D)/netscape
 78         $(CP) -R -p $(NASHORN_OUTPUTDIR)/nashorn_classes/* $(@D)/
 79         $(FIXPATH) $(JAVA) \
 80             -Xbootclasspath/p:"$(NASHORN_OUTPUTDIR)/nasgen_classes$(PATH_SEP)$(NASHORN_OUTPUTDIR)/nashorn_classes" \
 81             jdk.nashorn.internal.tools.nasgen.Main $(@D) jdk.nashorn.internal.objects $(@D)
 82         $(TOUCH) $@
 83

https://github.com/xiexianbin/openjdk

Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数