2
# Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
# This code is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 2 only, as
7
# published by the Free Software Foundation. Oracle designates this
8
# particular file as subject to the "Classpath" exception as provided
9
# by Oracle in the LICENSE file that accompanied this code.
11
# This code is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
# version 2 for more details (a copy is included in the LICENSE file that
15
# accompanied this code).
17
# You should have received a copy of the GNU General Public License version
18
# 2 along with this work; if not, write to the Free Software Foundation,
19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
# or visit www.oracle.com if you need additional information or have any
39
# Hook to include the corresponding custom file, if present.
40
$(eval $(call IncludeCustomExtension, Images-pre.gmk))
42
################################################################################
44
# All modules for the current target platform.
45
ALL_MODULES := $(call FindAllModules) $(EXTRA_MODULES)
47
$(eval $(call ReadImportMetaData))
49
JRE_MODULES += $(filter $(ALL_MODULES), $(BOOT_MODULES) \
50
$(PLATFORM_MODULES) jdk.jdwp.agent)
51
JDK_MODULES += $(ALL_MODULES)
53
JRE_MODULES_LIST := $(call CommaList, $(JRE_MODULES))
54
JDK_MODULES_LIST := $(call CommaList, $(JDK_MODULES))
56
################################################################################
58
BASE_RELEASE_FILE := $(JDK_OUTPUTDIR)/release
60
JMODS_DIRS := $(EXTRA_JMODS_DIR) $(IMAGES_OUTPUTDIR)/jmods
62
JDK_JMODS := $(foreach m, $(JDK_MODULES), $(firstword $(wildcard $(addsuffix /$m.jmod, $(JMODS_DIRS)))))
63
JRE_JMODS := $(foreach m, $(JRE_MODULES), $(firstword $(wildcard $(addsuffix /$m.jmod, $(JMODS_DIRS)))))
65
JLINK_ORDER_RESOURCES := **module-info.class
67
ifeq ($(ENABLE_GENERATE_CLASSLIST), true)
68
JLINK_ORDER_RESOURCES += @$(SUPPORT_OUTPUTDIR)/link_opt/classlist
69
JLINK_JLI_CLASSES := --generate-jli-classes=@$(SUPPORT_OUTPUTDIR)/link_opt/default_jli_trace.txt
71
JLINK_ORDER_RESOURCES += \
79
JLINK_TOOL := $(JLINK) -J-Djlink.debug=true \
80
--module-path $(call PathList, $(JMODS_DIRS)) \
81
--endian $(OPENJDK_TARGET_CPU_ENDIAN) \
82
--release-info $(BASE_RELEASE_FILE) \
83
--order-resources=$(call CommaList, $(JLINK_ORDER_RESOURCES)) \
84
--dedup-legal-notices=error-if-not-same-content \
85
$(JLINK_JLI_CLASSES) \
88
JLINK_JRE_EXTRA_OPTS := --no-man-pages --no-header-files --strip-debug
90
ifeq ($(JLINK_KEEP_PACKAGED_MODULES), true)
91
JLINK_JDK_EXTRA_OPTS := --keep-packaged-modules $(JDK_IMAGE_DIR)/jmods
94
JLINK_DISABLE_WARNINGS := | ( $(GREP) -v -e "WARNING: Using incubator module" || test "$$?" = "1" )
96
JDK_IMAGE_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jdk
97
JRE_IMAGE_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jre
99
$(eval $(call SetupExecute, jlink_jdk, \
100
WARN := Creating jdk image, \
101
DEPS := $(JDK_JMODS) $(BASE_RELEASE_FILE) \
102
$(call DependOnVariable, JDK_MODULES_LIST, $(JDK_IMAGE_SUPPORT_DIR)/_jlink_jdk.vardeps), \
103
OUTPUT_DIR := $(JDK_IMAGE_DIR), \
104
SUPPORT_DIR := $(JDK_IMAGE_SUPPORT_DIR), \
105
PRE_COMMAND := $(RM) -r $(JDK_IMAGE_DIR), \
106
COMMAND := $(JLINK_TOOL) --add-modules $(JDK_MODULES_LIST) \
107
$(JLINK_JDK_EXTRA_OPTS) --output $(JDK_IMAGE_DIR) \
108
$(JLINK_DISABLE_WARNINGS), \
111
JLINK_JDK_TARGETS := $(jlink_jdk)
113
$(eval $(call SetupExecute, jlink_jre, \
114
WARN := Creating legacy jre image, \
115
DEPS := $(JRE_JMODS) $(BASE_RELEASE_FILE) \
116
$(call DependOnVariable, JRE_MODULES_LIST, $(JRE_IMAGE_SUPPORT_DIR)/_jlink_jre.vardeps), \
117
OUTPUT_DIR := $(JRE_IMAGE_DIR), \
118
SUPPORT_DIR := $(JRE_IMAGE_SUPPORT_DIR), \
119
PRE_COMMAND := $(RM) -r $(JRE_IMAGE_DIR), \
120
COMMAND := $(JLINK_TOOL) --add-modules $(JRE_MODULES_LIST) \
121
$(JLINK_JRE_EXTRA_OPTS) --output $(JRE_IMAGE_DIR), \
124
JLINK_JRE_TARGETS := $(jlink_jre)
126
# Optimize CDS shared heap for small heap sizes, which are typically used
127
# for small cloud-based apps that have the most critical start-up requirement.
128
# The trade-off is that when larger heap sizes are used, the shared heap
129
# may need to be relocated at runtime.
130
CDS_DUMP_FLAGS = -Xmx128M -Xms128M
132
# Helper function for creating the CDS archives for the JDK and JRE
134
# Param1 - VM variant (e.g., server, client, zero, ...)
135
# Param2 - _nocoops, or empty
136
define CreateCDSArchive
137
$1_$2_DUMP_EXTRA_ARG := $(if $(filter _nocoops, $2),-XX:-UseCompressedOops,)
138
$1_$2_DUMP_TYPE := $(if $(filter _nocoops, $2),-NOCOOPS,)
140
# Only G1 supports dumping the shared heap, so explicitly use G1 if the JVM supports it.
141
$1_$2_CDS_DUMP_FLAGS := $(CDS_DUMP_FLAGS) $(if $(filter g1gc, $(JVM_FEATURES_$1)),-XX:+UseG1GC)
143
ifeq ($(OPENJDK_TARGET_OS), windows)
144
$1_$2_CDS_ARCHIVE := bin/$1/classes$2.jsa
146
$1_$2_CDS_ARCHIVE := lib/$1/classes$2.jsa
149
ifneq ($(COMPARE_BUILD), )
150
DEBUG_CDS_ARCHIVE := true
153
ifeq ($(DEBUG_CDS_ARCHIVE), true)
154
$1_$2_CDS_DUMP_FLAGS += -Xlog:cds+map*=trace:file=$$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE).cdsmap:none:filesize=0
157
$$(eval $$(call SetupExecute, $1_$2_gen_cds_archive_jdk, \
158
WARN := Creating CDS$$($1_$2_DUMP_TYPE) archive for jdk image for $1, \
159
INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \
160
DEPS := $$(jlink_jdk), \
161
OUTPUT_FILE := $$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \
162
SUPPORT_DIR := $$(JDK_IMAGE_SUPPORT_DIR), \
163
COMMAND := $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/java -Xshare:dump \
164
-XX:SharedArchiveFile=$$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \
165
-$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \
168
JDK_TARGETS += $$($1_$2_gen_cds_archive_jdk)
170
$$(eval $$(call SetupExecute, $1_$2_gen_cds_archive_jre, \
171
WARN := Creating CDS$$($1_$2_DUMP_TYPE) archive for jre image for $1, \
172
INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \
173
DEPS := $$(jlink_jre), \
174
OUTPUT_FILE := $$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \
175
SUPPORT_DIR := $$(JRE_IMAGE_SUPPORT_DIR), \
176
COMMAND := $$(FIXPATH) $$(JRE_IMAGE_DIR)/bin/java -Xshare:dump \
177
-XX:SharedArchiveFile=$$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \
178
-$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \
181
JRE_TARGETS += $$($1_$2_gen_cds_archive_jre)
184
ifeq ($(BUILD_CDS_ARCHIVE), true)
185
$(foreach v, $(JVM_VARIANTS), \
186
$(eval $(call CreateCDSArchive,$v,)) \
189
ifeq ($(call isTargetCpuBits, 64), true)
190
$(foreach v, $(JVM_VARIANTS), \
191
$(eval $(call CreateCDSArchive,$v,_nocoops)) \
196
################################################################################
199
$(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
200
$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
203
JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
205
################################################################################
207
# Avoid doing the expensive find unless called with "jdk" as target.
208
ifneq ($(filter jdk, $(MAKECMDGOALS)), )
211
$(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
212
$(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
213
-type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
216
ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
217
ifeq ($(call isTargetOs, macosx), true)
218
DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
220
DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
224
$(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
225
SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
226
DEST := $(JDK_IMAGE_DIR)/demo, \
227
FILES := $(DEMO_FILES), \
230
JDK_TARGETS += $(JDK_COPY_DEMOS)
233
################################################################################
234
# Code coverage data files
236
ifeq ($(GCOV_ENABLED), true)
238
$(eval $(call SetupCopyFiles,COPY_GCOV_GCNO, \
239
SRC := $(OUTPUTDIR), \
240
DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
241
FILES := $(call FindFiles, $(HOTSPOT_OUTPUTDIR) \
242
$(SUPPORT_OUTPUTDIR)/native, *.gcno) \
245
SYMBOLS_TARGETS += $(COPY_GCOV_GCNO)
249
################################################################################
251
# Since debug symbols are not included in the jmod files, they need to be copied
252
# in manually after generating the images.
254
ALL_JDK_MODULES := $(JDK_MODULES)
255
ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \
256
$(call FindTransitiveDepsForModule, $m)))
257
ALL_SYMBOLS_MODULES := $(JDK_MODULES)
259
ifeq ($(call isTargetOs, windows), true)
260
LIBS_TARGET_SUBDIR := bin
262
LIBS_TARGET_SUBDIR := lib
264
CMDS_TARGET_SUBDIR := bin
266
# Param 1 - dir to find debuginfo files in
267
FindDebuginfoFiles = \
268
$(wildcard $(addprefix $1/*, $(DEBUGINFO_SUFFIXES)) \
269
$(addprefix $1/*/*, $(DEBUGINFO_SUFFIXES)) \
270
$(addprefix $1/*/*/*, $(DEBUGINFO_SUFFIXES)))
272
# Pick the correct debug info files to copy, either zipped or not.
273
ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
274
DEBUGINFO_SUFFIXES += .diz
276
DEBUGINFO_SUFFIXES := .debuginfo .pdb .map
277
# On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM
279
ifeq ($(call isTargetOs, macosx), true)
280
$(call FillFindCache, \
281
$(SUPPORT_OUTPUTDIR)/modules_libs $(SUPPORT_OUTPUTDIR)/modules_cmds)
282
FindDebuginfoFiles = \
283
$(if $(wildcard $1), $(call containing, .dSYM/, $(call FindFiles, $1)))
287
# Param 1 - either JDK or JRE
288
SetupCopyDebuginfo = \
289
$(foreach m, $(ALL_$1_MODULES), \
290
$(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
291
SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
292
DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
293
FILES := $(call FindDebuginfoFiles, \
294
$(SUPPORT_OUTPUTDIR)/modules_libs/$m), \
296
$(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
297
$(eval $(call SetupCopyFiles, COPY_$1_CMDS_DEBUGINFO_$m, \
298
SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds/$m, \
299
DEST := $($1_IMAGE_DIR)/$(CMDS_TARGET_SUBDIR), \
300
FILES := $(call FindDebuginfoFiles, \
301
$(SUPPORT_OUTPUTDIR)/modules_cmds/$m), \
303
$(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \
306
# No space before argument to avoid having to put $(strip ) everywhere in
307
# implementation above.
308
$(call SetupCopyDebuginfo,JDK)
309
$(call SetupCopyDebuginfo,JRE)
310
$(call SetupCopyDebuginfo,SYMBOLS)
312
################################################################################
314
# Include custom post hook here to make it possible to augment the target lists
315
# before actual target prerequisites are declared.
316
$(eval $(call IncludeCustomExtension, Images-post.gmk))
318
################################################################################
320
$(JRE_TARGETS): $(JLINK_JRE_TARGETS)
321
$(JDK_TARGETS): $(JLINK_JDK_TARGETS)
323
jdk: $(JLINK_JDK_TARGETS) $(JDK_TARGETS)
324
jre: $(JLINK_JRE_TARGETS) $(JRE_TARGETS)
325
symbols: $(SYMBOLS_TARGETS)
329
.PHONY: default all jdk jre symbols