实践编译OpenJDK12

编译

参考在线版,源码的doc/building.htmlCommunity builds using source code from OpenJDK project

OS:Deepin 20.1 Community (1030) 64 bit kernel 5.4.70-amd64-desktop

准备编译环境

sourcecode

1
2
3
4
5
# openjdk sourcecode
$ git clone git@github.com:openjdk/jdk.git
# checkout tag jdk-12-ga
$ git branch branch-jdk-12-ga jdk-12-ga
$ git checkout branch-jdk-12-ga

dependencies

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# gcc
$ sudo apt-get install build-essential
# FreeType
$ sudo apt install libfreetype6-dev
# CUPS
$ sudo apt install libcups2-dev
# X11
$ sudo apt install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev
# ALSA
$ sudo apt install libasound2-dev
# libffi
$ sudo apt install libffi-dev
# Autoconf
$ sudo apt install autoconf

# bootstrap jdk, 11 or newer
$ sudo apt install openjdk-11-jdk
# 或
$ sdk install java 11.0.10-open
$ java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment 18.9 (build 11.0.10+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.10+9, mixed mode)

配置

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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
$ bash configure 
configure: Configuration created at Mon Mar 15 13:37:02 CST 2021.
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 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 gunzip... /usr/bin/gunzip
checking for pigz... no
checking for gzip... /usr/bin/gzip
checking for ln... /usr/bin/ln
checking for ls... /usr/bin/ls
checking for gmkdir... no
checking for mkdir... /usr/bin/mkdir
checking for mktemp... /usr/bin/mktemp
checking for mv... /usr/bin/mv
checking for nawk... /usr/bin/nawk
checking for printf... /usr/bin/printf
checking for greadlink... no
checking for readlink... /usr/bin/readlink
checking for rm... /usr/bin/rm
checking for rmdir... /usr/bin/rmdir
checking for sh... /usr/bin/sh
checking for sort... /usr/bin/sort
checking for tail... /usr/bin/tail
checking for gtar... no
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 cygpath... no
checking for df... /usr/bin/df
checking for cpio... /usr/bin/cpio
checking for nice... /usr/bin/nice
checking for pandoc... /usr/bin/pandoc
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 top-level directory... /home/ray/practice/jdk/openjdk/jdk
checking if custom source is suppressed (openjdk-only)... no
checking which debug level to use... release
checking which variants of the JVM to build... server
checking for sysroot... 
checking for toolchain path... 
checking for extra path... 
checking where to store configuration... in default location
checking what configuration name to use... linux-x86_64-server-release
checking for apt-get... apt-get
checking for gmake... no
checking for make... /usr/bin/make
configure: Testing potential make at /usr/bin/make, found using make in PATH
configure: Using GNU make at /usr/bin/make (version: GNU Make 4.2.1)
checking if make --output-sync is supported... yes
checking for output-sync value... none
checking if find supports -delete... yes
checking what type of tar was found... gnu
checking that grep (/usr/bin/grep) -Fx handles empty lines in the pattern list correctly... yes
checking for unzip... /usr/bin/unzip
checking for zip... /usr/bin/zip
checking for ldd... /usr/bin/ldd
checking for greadelf... no
checking for readelf... /usr/bin/readelf
checking for dot... no
checking for hg... no
checking for git... /usr/bin/git
checking for stat... /usr/bin/stat
checking for time... no
checking for flock... /usr/bin/flock
checking for dtrace... no
checking for gpatch... no
checking for patch... /usr/bin/patch
checking bash version... 5.0.3
checking if bash supports pipefail... yes
checking if bash supports errexit (-e)... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for default LOG value... 
checking headless only... no
checking for graphviz dot... no, cannot generate full docs
checking for pandoc... yes
checking full docs... no, missing dependencies
checking for cacerts file... default
checking for jni library path... default
checking if packaged modules are kept... yes (default)
checking for version string... 12-internal+0-adhoc.ray.jdk
configure: Found potential Boot JDK using JAVA_HOME
checking for Boot JDK... /home/ray/.sdkman/candidates/java/current
checking Boot JDK version... openjdk version "11.0.2" 2019-01-15 OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode) 
checking for java in Boot JDK... ok
checking for javac in Boot JDK... ok
checking for javadoc in Boot JDK... ok
checking for jar in Boot JDK... ok
checking for jarsigner in Boot JDK... ok
checking if Boot JDK is 32 or 64 bits... 64
checking for local Boot JDK Class Data Sharing (CDS)... yes, created
checking for Build JDK... yes, will use output dir
configure: Using default toolchain gcc (GNU Compiler Collection)
checking for gcc... /usr/bin/gcc
checking resolved symbolic links for CC... /usr/bin/x86_64-linux-gnu-gcc-8
configure: Using gcc C compiler version 8.3.0 [gcc (Uos 8.3.0.3-3+rebuild) 8.3.0]
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++
checking resolved symbolic links for CXX... /usr/bin/x86_64-linux-gnu-g++-8
configure: Using gcc C++ compiler version 8.3.0 [g++ (Uos 8.3.0.3-3+rebuild) 8.3.0]
checking whether we are using the GNU C++ compiler... yes
checking whether /usr/bin/g++ accepts -g... yes
checking how to run the C preprocessor... /usr/bin/gcc -E
checking how to run the C++ preprocessor... /usr/bin/g++ -E
configure: Using gcc linker version 2.31.1 [GNU ld (GNU Binutils for Uos) 2.31.1]
checking for ar... ar
configure: Rewriting AR to "/usr/bin/ar"
checking for strip... strip
configure: Rewriting STRIP to "/usr/bin/strip"
checking for nm... nm
configure: Rewriting NM to "/usr/bin/nm"
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 c++filt... c++filt
configure: Rewriting CXXFILT to "/usr/bin/c++filt"
checking for jtreg... no
checking for jtreg test harness... no, not found
checking for jmh (Java Microbenchmark Harness)... no, disabled
checking for jib... no
checking if @file is supported by gcc... yes
checking if the C compiler supports "-m64"... yes
checking if the C++ compiler supports "-m64"... yes
checking if both compilers support "-m64"... yes
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 native warnings are errors... true (default)
checking if the C++ compiler supports "-std=gnu++98 -Werror"... yes
checking for library containing clock_gettime... none required
configure: GCC >= 6 detected; adding -fno-delete-null-pointer-checks and -fno-lifetime-dse
configure: GCC >= 6 detected; adding -fno-delete-null-pointer-checks and -fno-lifetime-dse
checking if the C compiler supports "-ffp-contract=off"... yes
checking if the C++ compiler supports "-ffp-contract=off"... yes
checking if both compilers support "-ffp-contract=off"... yes
checking what type of native debug symbols to use... external
checking for dtrace tool... not found, cannot build dtrace
checking sys/sdt.h usability... no
checking sys/sdt.h presence... no
checking for sys/sdt.h... no
checking if dtrace should be built... no, missing dependencies
checking if Hotspot gtest unit tests should be built... yes
checking if static link of stdc++ is possible... yes
checking how to link with libstdc++... static
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 for X11/extensions/Xrandr.h... yes
checking if XlinearGradient is defined in Xrender.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 fontconfig/fontconfig.h usability... yes
checking fontconfig/fontconfig.h presence... yes
checking for fontconfig/fontconfig.h... yes
checking for FREETYPE... yes
checking for freetype... yes (using pkg-config)
Using freetype: system
checking for ALSA... yes
checking for which libjpeg to use... bundled
checking for which giflib to use... bundled
checking for PNG... yes
checking for which libpng to use... bundled
checking for compress in -lz... yes
checking for which zlib to use... system
checking for system zlib functionality... ok
checking for which lcms to use... bundled
checking for cos in -lm... yes
checking for dlopen in -ldl... yes
checking if shenandoah can be built... yes
checking if zgc can be built... yes
checking if jvmci module jdk.internal.vm.ci should be built... yes
checking if graal module jdk.internal.vm.compiler should be built... yes
checking if aot should be enabled... yes
checking if cds should be enabled... yes
checking if elliptic curve crypto implementation is present... yes
checking if jtreg failure handler should be built... no, missing jtreg
checking if the CDS classlist generation should be enabled... yes
checking if any translations should be excluded... no
checking if static man pages should be copied... yes
checking if a default CDS archive should be generated... yes
checking for number of cores... 8
checking for memory size... 15838 MB
checking for appropriate number of jobs to run in parallel... 8
checking flags for boot jdk java command ...  -Duser.language=en -Duser.country=US  -XX:+UnlockDiagnosticVMOptions -XX:-VerifySharedSpaces -XX:SharedArchiveFile=/home/ray/practice/jdk/openjdk/jdk/build/linux-x86_64-server-release/configure-support/classes.jsa -Xshare:auto 
checking flags for boot jdk java command for big workloads...  -Xms64M -Xmx1600M -XX:ThreadStackSize=1536
checking flags for bootcycle boot jdk java command for big workloads... -Xms64M -Xmx1600M -XX:ThreadStackSize=1536
checking flags for boot jdk java command for small workloads...  -XX:+UseSerialGC -Xms32M -Xmx512M -XX:TieredStopAtLevel=1
checking whether to use sjavac... no
checking whether to use javac server... yes
checking If precompiled header is enabled... yes
checking that precompiled headers work... yes
checking is ccache enabled... no
checking if build directory is on local disk... yes
checking JVM features for JVM variant 'server'... "aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc"
configure: creating /home/ray/practice/jdk/openjdk/jdk/build/linux-x86_64-server-release/configure-support/config.status
config.status: creating /home/ray/practice/jdk/openjdk/jdk/build/linux-x86_64-server-release/spec.gmk
config.status: creating /home/ray/practice/jdk/openjdk/jdk/build/linux-x86_64-server-release/bootcycle-spec.gmk
config.status: creating /home/ray/practice/jdk/openjdk/jdk/build/linux-x86_64-server-release/buildjdk-spec.gmk
config.status: creating /home/ray/practice/jdk/openjdk/jdk/build/linux-x86_64-server-release/compare.sh
config.status: creating /home/ray/practice/jdk/openjdk/jdk/build/linux-x86_64-server-release/Makefile

====================================================
A new configuration has been successfully created in
/home/ray/practice/jdk/openjdk/jdk/build/linux-x86_64-server-release
using default settings.

Configuration summary:
* Debug level:    release
* HS debug level: product
* JVM variants:   server
* JVM features:   server: 'aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc' 
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
* Version string: 12-internal+0-adhoc.ray.jdk (12-internal)

Tools summary:
* Boot JDK:       openjdk version "11.0.10" 2021-01-19 OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)  (at /home/ray/.sdkman/candidates/java/current)
* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version 8.3.0 (at /usr/bin/gcc)
* C++ Compiler:   Version 8.3.0 (at /usr/bin/g++)

Build performance summary:
* Cores to use:   8
* Memory limit:   15838 MB

bash configure –help

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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
$ bash configure --help
`configure' configures OpenJDK openjdk to adapt to many kinds of systems.

Usage: /home/ray/practice/jdk/openjdk/jdk/configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/openjdk]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

X features:
  --x-includes=DIR    X include files are in DIR
  --x-libraries=DIR   X library files are in DIR

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-openjdk-only   suppress building custom source even if present
                          [disabled]
  --enable-debug          set the debug level to fastdebug (shorthand for
                          --with-debug-level=fastdebug) [disabled]
  --enable-headless-only  only build headless (no GUI) support [disabled]
  --enable-full-docs      build complete documentation [enabled if all tools
                          found]
  --disable-unlimited-crypto
                          Disable unlimited crypto policy [enabled]
  --disable-keep-packaged-modules
                          Do not keep packaged modules in jdk image [enable]
  --enable-static-build   enable static library build [disabled]
  --disable-warnings-as-errors
                          do not consider native warnings to be an error
                          [enabled]
  --enable-native-coverage
                          enable native compilation with code coverage
                          data[disabled]
  --enable-asan           enable AddressSanitizer if possible [disabled]
  --enable-dtrace[=yes/no/auto]
                          enable dtrace. Default is auto, where dtrace is
                          enabled if all dependencies are present.
  --enable-aot[=yes/no/auto]
                          enable ahead of time compilation feature. Default is
                          auto, where aot is enabled if all dependencies are
                          present.
  --enable-cds[=yes/no/auto]
                          enable class data sharing feature in non-minimal VM.
                          Default is auto, where cds is enabled if supported
                          on the platform.
  --disable-hotspot-gtest Disables building of the Hotspot unit tests
                          [enabled]
  --enable-libffi-bundling
                          enable bundling of libffi.so to make the built JDK
                          runnable on more systems
  --enable-jtreg-failure-handler
                          forces build of the jtreg failure handler to be
                          enabled, missing dependencies become fatal errors.
                          Default is auto, where the failure handler is built
                          if all dependencies are present and otherwise just
                          disabled.
  --disable-generate-classlist
                          forces enabling or disabling of the generation of a
                          CDS classlist at build time. Default is to generate
                          it when either the server or client JVMs are built
                          and enable-cds is true.
  --disable-manpages      Set to disable copy of static man pages [enabled]
  --disable-cds-archive   Set to disable generation of a default CDS archive
                          in the product image [enabled]
  --enable-sjavac         use sjavac to do fast incremental compiles
                          [disabled]
  --disable-javac-server  disable javac server [enabled]
  --enable-icecc          enable distribted compilation of native code using
                          icecc/icecream [disabled]
  --disable-precompiled-headers
                          disable using precompiled headers when compiling C++
                          [enabled]
  --enable-ccache         enable using ccache to speed up recompilations
                          [disabled]

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-target-bits      build 32-bit or 64-bit binaries (for platforms that
                          support it), e.g. --with-target-bits=32 [guessed]
  --with-debug-level      set the debug level (release, fastdebug, slowdebug,
                          optimized) [release]
  --with-jvm-variants     JVM variants (separated by commas) to build
                          (server,client,minimal,core,zero,custom) [server]
  --with-devkit           use this devkit for compilers, tools and resources
  --with-sys-root         alias for --with-sysroot for backwards compatability
  --with-sysroot          use this directory as sysroot
  --with-tools-dir        alias for --with-toolchain-path for backwards
                          compatibility
  --with-toolchain-path   prepend these directories when searching for
                          toolchain binaries (compilers etc)
  --with-extra-path       prepend these directories to the default path
  --with-sdk-name         use the platform SDK of the given name. [macosx]
  --with-conf-name        use this as the name of the configuration [generated
                          from important configuration options]
  --with-output-sync      set make output sync type if supported by make.
                          [recurse]
  --with-default-make-target
                          set the default make target [exploded-image]
  --with-log              [default vaue for make LOG argument [warn]]
  --with-cacerts-file     specify alternative cacerts file
  --with-copyright-year   Set copyright year value for build [current year]
  --with-jni-libpath      override default JNI library search path
  --with-vendor-name      Set vendor name. Among others, used to set the
                          'java.vendor' and 'java.vm.vendor' system
                          properties. [not specified]
  --with-vendor-url       Set the 'java.vendor.url' system property [not
                          specified]
  --with-vendor-bug-url   Set the 'java.vendor.url.bug' system property [not
                          specified]
  --with-vendor-vm-bug-url
                          Sets the bug URL which will be displayed when the VM
                          crashes [not specified]
  --with-version-string   Set version string [calculated]
  --with-version-pre      Set the base part of the version 'PRE' field
                          (pre-release identifier) ['internal']
  --with-version-opt      Set version 'OPT' field (build metadata)
                          [<timestamp>.<user>.<dirname>]
  --with-version-build    Set version 'BUILD' field (build number) [not
                          specified]
  --with-version-feature  Set version 'FEATURE' field (first number) [current
                          source value]
  --with-version-interim  Set version 'INTERIM' field (second number) [current
                          source value]
  --with-version-update   Set version 'UPDATE' field (third number) [current
                          source value]
  --with-version-patch    Set version 'PATCH' field (fourth number) [not
                          specified]
  --with-version-extra1   Set 1st version extra number [not specified]
  --with-version-extra2   Set 2nd version extra number [not specified]
  --with-version-extra3   Set 3rd version extra number [not specified]
  --with-version-date     Set version date [current source value]
  --with-vendor-version-string
                          Set vendor version string [not specified]
  --with-boot-jdk         path to Boot JDK (used to bootstrap build) [probed]
  --with-boot-jdk-jvmargs specify additional arguments to be passed to Boot
                          JDK tools [none]
  --with-build-jdk        path to JDK of same version as is being built[the
                          newly built JDK]
  --with-import-modules   import a set of prebuilt modules either as a zip
                          file or an exploded directory
  --with-toolchain-type   the toolchain type (or family) to use, use '--help'
                          to show possible values [platform dependent]
  --with-extra-cflags     extra flags to be used when compiling jdk c-files
  --with-extra-cxxflags   extra flags to be used when compiling jdk c++-files
  --with-extra-ldflags    extra flags to be used when linking jdk
  --with-toolchain-version
                          the version of the toolchain to look for, use
                          '--help' to show possible values [platform
                          dependent]
  --with-build-devkit     Devkit to use for the build platform toolchain
  --with-jtreg            Regression Test Harness [probed]
  --with-jmh              Java Microbenchmark Harness for building the OpenJDK
                          Microbenchmark Suite
  --with-jib              Jib dependency management tool [not used]
  --with-macosx-version-max
                          error on use of newer functionality. [macosx]
  --with-abi-profile      specify ABI profile for ARM builds
                          (arm-vfp-sflt,arm-vfp-hflt,arm-sflt,
                          armv5-vfp-sflt,armv6-vfp-hflt,aarch64) [toolchain
                          dependent]
  --with-native-debug-symbols
                          set the native debug symbol configuration (none,
                          internal, external, zipped) [varying]
  --with-jcov             jcov library location
  --with-jcov-input-jdk   jdk image to instrument
  --with-stdc++lib=<static>,<dynamic>,<default>
                          force linking of the C++ runtime on Linux to either
                          static or dynamic, default is static with dynamic as
                          fallback
  --with-msvcr-dll        path to microsoft C runtime dll (msvcr*.dll)
                          (Windows only) [probed]
  --with-msvcp-dll        path to microsoft C++ runtime dll (msvcp*.dll)
                          (Windows only) [probed]
  --with-ucrt-dll-dir     path to Microsoft Windows Kit UCRT DLL dir (Windows
                          only) [probed]
  --with-x                use the X Window System
  --with-cups             specify prefix directory for the cups package
                          (expecting the headers under PATH/include)
  --with-cups-include     specify directory for the cups include files
  --with-fontconfig       specify prefix directory for the fontconfig package
                          (expecting the headers under PATH/include)
  --with-fontconfig-include
                          specify directory for the fontconfig include files
  --with-freetype         specify whether to use 'system' or 'bundled'
                          freetype. Other values are errors. The selected
                          option applies to both build time and run time. The
                          default behaviour can be platform dependent. If
                          using 'system' and either the include files or
                          libraries cannot be located automatically, then
                          additionally specify both using
                          --with-freetype-include and --with-freetype-lib.
  --with-freetype-include specify directory for the freetype include files
  --with-freetype-lib     specify directory for the freetype library
  --with-alsa             specify prefix directory for the alsa package
                          (expecting the libraries under PATH/lib and the
                          headers under PATH/include)
  --with-alsa-include     specify directory for the alsa include files
  --with-alsa-lib         specify directory for the alsa library
  --with-libffi           specify prefix directory for the libffi package
                          (expecting the libraries under PATH/lib and the
                          headers under PATH/include)
  --with-libffi-include   specify directory for the libffi include files
  --with-libffi-lib       specify directory for the libffi library
  --with-libjpeg          use libjpeg from build system or OpenJDK source
                          (system, bundled) [bundled]
  --with-giflib           use giflib from build system or OpenJDK source
                          (system, bundled) [bundled]
  --with-libpng           use libpng from build system or OpenJDK source
                          (system, bundled) [bundled]
  --with-zlib             use zlib from build system or OpenJDK source
                          (system, bundled) [bundled]
  --with-lcms             use lcms2 from build system or OpenJDK source
                          (system, bundled) [bundled]
  --with-graalunit-lib    specify location of 3rd party libraries used by
                          Graal unit tests
  --with-jvm-features     JVM features to enable (foo) or disable (-foo),
                          separated by comma. Use '--help' to show possible
                          values [none]
  --with-with-cpu-port    Deprecated. Option is kept for backwards
                          compatibility and is ignored
  --with-exclude-translations
                          a comma separated list of locales to exclude
                          translations for. Default is to include all
                          translations present in the source.
  --with-num-cores        number of cores in the build system, e.g.
                          --with-num-cores=8 [probed]
  --with-memory-size      memory (in MB) available in the build system, e.g.
                          --with-memory-size=1024 [probed]
  --with-jobs             number of parallel jobs to let make run [calculated
                          based on cores and memory]
  --with-test-jobs        number of parallel tests jobs to run [based on build
                          jobs]
  --with-sjavac-server-java
                          use this java binary for running the sjavac
                          background server [Boot JDK java]
  --with-ccache-dir       where to store ccache files [~/.ccache]

Some influential environment variables:
  BASENAME    Override default value for BASENAME
  BASH        Override default value for BASH
  CAT         Override default value for CAT
  CHMOD       Override default value for CHMOD
  CMP         Override default value for CMP
  COMM        Override default value for COMM
  CP          Override default value for CP
  CUT         Override default value for CUT
  DATE        Override default value for DATE
  DIFF        Override default value for DIFF
  DIRNAME     Override default value for DIRNAME
  ECHO        Override default value for ECHO
  EXPR        Override default value for EXPR
  FILE        Override default value for FILE
  FIND        Override default value for FIND
  HEAD        Override default value for HEAD
  GUNZIP      Override default value for GUNZIP
  GZIP        Override default value for GZIP
  LN          Override default value for LN
  LS          Override default value for LS
  MKDIR       Override default value for MKDIR
  MKTEMP      Override default value for MKTEMP
  MV          Override default value for MV
  NAWK        Override default value for NAWK
  PRINTF      Override default value for PRINTF
  READLINK    Override default value for READLINK
  RM          Override default value for RM
  RMDIR       Override default value for RMDIR
  SH          Override default value for SH
  SORT        Override default value for SORT
  TAIL        Override default value for TAIL
  TAR         Override default value for TAR
  TEE         Override default value for TEE
  TOUCH       Override default value for TOUCH
  TR          Override default value for TR
  UNAME       Override default value for UNAME
  UNIQ        Override default value for UNIQ
  WC          Override default value for WC
  WHICH       Override default value for WHICH
  XARGS       Override default value for XARGS
  AWK         Override default value for AWK
  GREP        Override default value for GREP
  EGREP       Override default value for EGREP
  FGREP       Override default value for FGREP
  SED         Override default value for SED
  CYGPATH     Override default value for CYGPATH
  DF          Override default value for DF
  CPIO        Override default value for CPIO
  NICE        Override default value for NICE
  PANDOC      Override default value for PANDOC
  MAKE        Override default value for MAKE
  UNZIP       Override default value for UNZIP
  ZIPEXE      Override default value for ZIPEXE
  LDD         Override default value for LDD
  READELF     Override default value for READELF
  DOT         Override default value for DOT
  HG          Override default value for HG
  GIT         Override default value for GIT
  STAT        Override default value for STAT
  TIME        Override default value for TIME
  FLOCK       Override default value for FLOCK
  DTRACE      Override default value for DTRACE
  PATCH       Override default value for PATCH
  DSYMUTIL    Override default value for DSYMUTIL
  MIG         Override default value for MIG
  XATTR       Override default value for XATTR
  CODESIGN    Override default value for CODESIGN
  SETFILE     Override default value for SETFILE
  ELFEDIT     Override default value for ELFEDIT
  PKG_CONFIG  path to pkg-config utility
  JAVA        Override default value for JAVA
  JAVAC       Override default value for JAVAC
  JAVADOC     Override default value for JAVADOC
  JAR         Override default value for JAR
  JARSIGNER   Override default value for JARSIGNER
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  CPP         C preprocessor
  CXXCPP      C++ preprocessor
  AS          Override default value for AS
  AR          Override default value for AR
  LIPO        Override default value for LIPO
  OTOOL       Override default value for OTOOL
  INSTALL_NAME_TOOL
              Override default value for INSTALL_NAME_TOOL
  STRIP       Override default value for STRIP
  NM          Override default value for NM
  GNM         Override default value for GNM
  OBJCOPY     Override default value for OBJCOPY
  OBJDUMP     Override default value for OBJDUMP
  CXXFILT     Override default value for CXXFILT
  BUILD_CC    Override default value for BUILD_CC
  BUILD_CXX   Override default value for BUILD_CXX
  BUILD_NM    Override default value for BUILD_NM
  BUILD_AR    Override default value for BUILD_AR
  BUILD_OBJCOPY
              Override default value for BUILD_OBJCOPY
  BUILD_STRIP Override default value for BUILD_STRIP
  JTREGEXE    Override default value for JTREGEXE
  XMKMF       Path to xmkmf, Makefile generator for X Window System
  FREETYPE_CFLAGS
              C compiler flags for FREETYPE, overriding pkg-config
  FREETYPE_LIBS
              linker flags for FREETYPE, overriding pkg-config
  ALSA_CFLAGS C compiler flags for ALSA, overriding pkg-config
  ALSA_LIBS   linker flags for ALSA, overriding pkg-config
  LIBFFI_CFLAGS
              C compiler flags for LIBFFI, overriding pkg-config
  LIBFFI_LIBS linker flags for LIBFFI, overriding pkg-config
  PNG_CFLAGS  C compiler flags for PNG, overriding pkg-config
  PNG_LIBS    linker flags for PNG, overriding pkg-config
  LCMS_CFLAGS C compiler flags for LCMS, overriding pkg-config
  LCMS_LIBS   linker flags for LCMS, overriding pkg-config
  ICECC_CMD   Override default value for ICECC_CMD
  ICECC_CREATE_ENV
              Override default value for ICECC_CREATE_ENV
  ICECC_WRAPPER
              Override default value for ICECC_WRAPPER
  CCACHE      Override default value for CCACHE

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to <build-dev@openjdk.java.net>.
OpenJDK home page: <http://openjdk.java.net>.

Additional (non-autoconf) OpenJDK Options:
  --openjdk-target=TARGET cross-compile with TARGET as target platform
                          (i.e. the one you will run the resulting binary on).
                          Equivalent to --host=TARGET --target=TARGET
                          --build=<current platform>
  --debug-configure       Run the configure script with additional debug
                          logging enabled.

The following toolchains are available as arguments to --with-toolchain-type.
Which are valid to use depends on the build platform.
  gcc         GNU Compiler Collection
  clang       clang/LLVM
  solstudio   Oracle Solaris Studio
  xlc         IBM XL C/C++
  microsoft   Microsoft Visual Studio

The following JVM features are available as arguments to --with-jvm-features.
Which are valid to use depends on the target platform.
  compiler1 compiler2 zero minimal dtrace jvmti jvmci graal vm-structs jni-check services management cmsgc epsilongc g1gc parallelgc serialgc shenandoahgc zgc nmt cds static-build link-time-opt aot jfr 

Please be aware that, when cross-compiling, the OpenJDK configure script will
generally use 'target' where autoconf traditionally uses 'host'.

Also note that variables must be passed on the command line. Variables in the
environment will generally be ignored, unlike traditional autoconf scripts.
  • –with-debug-level:设置编译的级别,可选值为release、fastdebug、slowdebug,越往后进行的优化措施就越少,带的调试信息就越多。还有一些虚拟机调试参数必须在特定模式下才可以使用。默认值为release。

  • –enable-debug:等效于–with-debug-level=fastdebug。

  • –with-native-debug-symbols:确定调试符号信息的编译方式,可选值为none、internal、external、zipped。

  • –with-version-string:设置编译JDK的版本号,譬如java-version的输出就会显示该信息。这个参数还有–with-version-{part}={value}的形式,其中part可以是pre、opt、build、major、minor、security、patch之一,用于设置版本号的某一个部分。

  • –with-jvm-variants:编译特定模式(Variants)的HotSpot虚拟机,可以多个模式并存,可选值为server、client、minimal、core、zero、custom。

  • –with-jvm-features:针对–with-jvm-variants=custom时的自定义虚拟机特性列表(Features),可以多个特性并存,由于可选值较多,请参见help命令输出。

  • –with-target-bits:指明要编译32位还是64位的Java虚拟机,在64位机器上也可以通过交叉编译生成32位的虚拟机。

  • –with-{lib}={path}:用于指明依赖包的具体路径,通常使用在安装了多个不同版本的BootstrapJDK和依赖包的情况。其中lib的可选值包括boot-jd、freetype、cups、x、alsa、libffi、jtreg、libjpeg、giflib、libpng、lcms、zlib。

  • –with-extra-{flagtype}={flags}:用于设定C、C++和Java代码编译时的额外编译器参数,其中flagtype可选值为cflags、cxxflags、ldflags,分别代表C、C++和Java代码的参数。

  • –with-conf-name:指定编译配置名称,OpenJDK支持使用不同的配置进行编译,默认会根据编译的操作系统、指令集架构、调试级别自动生成一个配置名称,譬如“linux-x86_64-server-release”,如果在这些信息都相同的情况下保存不同的编译参数配置,就需要使用这个参数来自定义配置名称。

编译

1
2
3
4
5
6
7
$ make images
Building target 'images' in configuration 'linux-x86_64-server-release'
...
Creating jdk image
Creating CDS archive for jdk image
Stopping sjavac server
Finished building target 'images' in configuration 'linux-x86_64-server-release'
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
# 等价于make images
$ make product-images
# 只编译hotspot虚拟机
$ make hotspot
# 只编译特定模式的hotspot虚拟机
$ make hotspot-<variant>
# 编译jdk的文档镜像
$ make docs-image
# 编译jdk的测试镜像
$ make test-image
# 包括product,docs和test
$ make all-images
$ make bootcycle-images
# 清除make命令生成的临时文件
$ make clean
Building target 'clean' in configuration 'linux-x86_64-server-fastdebug'
Cleaning hotspot build artifacts ... done
Cleaning jdk build artifacts ... done
Cleaning bootcycle-build build artifacts ... done
Cleaning test-results build artifacts ... done
Cleaning test-support build artifacts ... done
Cleaning test build artifacts ... done
Cleaning buildtools build artifacts ... done
Cleaning support build artifacts ... done
Cleaning images build artifacts ... done
Cleaning make-support build artifacts ... done
Cleaning test-make build artifacts ... done
Cleaning bundles build artifacts ... done
Cleaning buildjdk build artifacts ... done
Cleaned all build artifacts.
Finished building target 'clean' in configuration 'linux-x86_64-server-fastdebug'

# 清理make和configure命令生成的临时文件
$ make dist-clean
Building target 'dist-clean' in configuration 'linux-x86_64-server-fastdebug'
Cleaning hotspot build artifacts ... done
Cleaning jdk build artifacts ... done
Cleaning bootcycle-build build artifacts ... done
Cleaning test-results build artifacts ... done
Cleaning test-support build artifacts ... done
Cleaning test build artifacts ... done
Cleaning buildtools build artifacts ... done
Cleaning support build artifacts ... done
Cleaning images build artifacts ... done
Cleaning make-support build artifacts ... done
Cleaning test-make build artifacts ... done
Cleaning bundles build artifacts ... done
Cleaning buildjdk build artifacts ... done
Cleaned all build artifacts.
Removing configuration directory for 'linux-x86_64-server-fastdebug'
Cleaned everything, you will have to re-run configure.
Finished building target 'dist-clean' in configuration 'linux-x86_64-server-fastdebug'

验证

1
2
3
4
$ ./java -version
openjdk version "12-internal" 2019-03-19
OpenJDK Runtime Environment (build 12-internal+0-adhoc.ray.jdk)
OpenJDK 64-Bit Server VM (build 12-internal+0-adhoc.ray.jdk, mixed mode)

QA

-Werror=stringop-truncation

make images时报错如下:

1
2
3
4
5
6
7
8
9
10
...
/home/ray/practice/jdk/openjdk/jdk/src/hotspot/share/runtime/arguments.cpp: In static member function ‘static jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs*, bool*, JVMFlag::Flags)’:
/home/ray/practice/jdk/openjdk/jdk/src/hotspot/share/runtime/arguments.cpp:2472:29: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
         char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtArguments), tail, len);
                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/ray/practice/jdk/openjdk/jdk/src/hotspot/share/runtime/arguments.cpp:2471:44: note: length computed here
         size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
                                      ~~~~~~^~~~~~
cc1plus: all warnings being treated as errors
...

引发错误的原因是这段[-Werror=stringop-truncation],GCC在8.0之后的版本加入了stringop truncation的验证警告,这里是因为出现了警告导致编译不通过,那就禁止掉警告再进行编译。

1
$ bash configure --disable-warnings-as-errors

重新配置

1
2
3
4
5
...
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.
...