1 #
  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.
  4 #
  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.
 10 #
 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).
 16 #
 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.
 20 #
 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
 23 # questions.
 24 #
 25 
 26 default: all
 27 
 28 include $(SPEC)
 29 include MakeBase.gmk
 30 
 31 include CopyFiles.gmk
 32 include Execute.gmk
 33 include Modules.gmk
 34 include Utils.gmk
 35 
 36 JDK_TARGETS :=
 37 JRE_TARGETS :=
 38 
 39 # Hook to include the corresponding custom file, if present.
 40 $(eval $(call IncludeCustomExtension, Images-pre.gmk))
 41 
 42 ################################################################################
 43 
 44 # All modules for the current target platform.
 45 ALL_MODULES := $(call FindAllModules) $(EXTRA_MODULES)
 46 
 47 $(eval $(call ReadImportMetaData))
 48 
 49 JRE_MODULES += $(filter $(ALL_MODULES), $(BOOT_MODULES) \
 50     $(PLATFORM_MODULES) jdk.jdwp.agent)
 51 JDK_MODULES += $(ALL_MODULES)
 52 
 53 JRE_MODULES_LIST := $(call CommaList, $(JRE_MODULES))
 54 JDK_MODULES_LIST := $(call CommaList, $(JDK_MODULES))
 55 
 56 ################################################################################
 57 
 58 BASE_RELEASE_FILE := $(JDK_OUTPUTDIR)/release
 59 
 60 JMODS_DIRS := $(EXTRA_JMODS_DIR) $(IMAGES_OUTPUTDIR)/jmods
 61 
 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)))))
 64 
 65 JLINK_ORDER_RESOURCES := **module-info.class
 66 JLINK_JLI_CLASSES :=
 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
 70 endif
 71 JLINK_ORDER_RESOURCES += \
 72     /java.base/java/** \
 73     /java.base/jdk/** \
 74     /java.base/sun/** \
 75     /java.base/com/** \
 76     /jdk.localedata/** \
 77     #
 78 
 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) \
 86     #
 87 
 88 JLINK_JRE_EXTRA_OPTS := --no-man-pages --no-header-files --strip-debug
 89 
 90 ifeq ($(JLINK_KEEP_PACKAGED_MODULES), true)
 91   JLINK_JDK_EXTRA_OPTS := --keep-packaged-modules $(JDK_IMAGE_DIR)/jmods
 92 endif
 93 
 94 JLINK_DISABLE_WARNINGS := | ( $(GREP) -v -e "WARNING: Using incubator module" || test "$$?" = "1" )
 95 
 96 JDK_IMAGE_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jdk
 97 JRE_IMAGE_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jre
 98 
 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), \
109 ))
110 
111 JLINK_JDK_TARGETS := $(jlink_jdk)
112 
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), \
122 ))
123 
124 JLINK_JRE_TARGETS := $(jlink_jre)
125 
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
131 
132 # Helper function for creating the CDS archives for the JDK and JRE
133 #
134 # Param1 - VM variant (e.g., server, client, zero, ...)
135 # Param2 - _nocoops, or empty
136 # Param3 - _valhalla, or empty
137 define CreateCDSArchive
138   $1_$2_$3_DUMP_EXTRA_ARG := $(if $(filter _nocoops, $2), -XX:-UseCompressedOops,) $(if $(filter _valhalla, $3), --enable-preview,)
139   $1_$2_$3_DUMP_TYPE      := $(if $(filter _nocoops, $2), -NOCOOPS,)$(if $(filter _valhalla, $3), -VALHALLA,)
140 
141   # Only G1 supports dumping the shared heap, so explicitly use G1 if the JVM supports it.
142   $1_$2_$3_CDS_DUMP_FLAGS := $(CDS_DUMP_FLAGS) $(if $(filter g1gc, $(JVM_FEATURES_$1)), -XX:+UseG1GC)
143 
144   ifeq ($(OPENJDK_TARGET_OS), windows)
145     $1_$2_$3_CDS_ARCHIVE := bin/$1/classes$2$3.jsa
146   else
147     $1_$2_$3_CDS_ARCHIVE := lib/$1/classes$2$3.jsa
148   endif
149 
150   ifneq ($(COMPARE_BUILD), )
151     DEBUG_CDS_ARCHIVE := true
152   endif
153 
154   ifeq ($(DEBUG_CDS_ARCHIVE), true)
155     $1_$2_CDS_DUMP_FLAGS += -Xlog:cds+map*=trace:file=$$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE).cdsmap:none:filesize=0
156   endif
157 
158   $$(eval $$(call SetupExecute, $1_$2_$3_gen_cds_archive_jdk, \
159       WARN := Creating CDS$$($1_$2_$3_DUMP_TYPE) archive for jdk image for $1, \
160       INFO := Using CDS flags for $1: $$($1_$2_$3_CDS_DUMP_FLAGS), \
161       DEPS := $$(jlink_jdk), \
162       OUTPUT_FILE := $$(JDK_IMAGE_DIR)/$$($1_$2_$3_CDS_ARCHIVE), \
163       SUPPORT_DIR := $$(JDK_IMAGE_SUPPORT_DIR), \
164       COMMAND := $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/java -Xshare:dump \
165           -XX:SharedArchiveFile=$$(JDK_IMAGE_DIR)/$$($1_$2_$3_CDS_ARCHIVE) \
166           -$1 $$($1_$2_$3_DUMP_EXTRA_ARG) $$($1_$2_$3_CDS_DUMP_FLAGS) $$(LOG_INFO), \
167   ))
168 
169   JDK_TARGETS += $$($1_$2_$3_gen_cds_archive_jdk)
170 
171   $$(eval $$(call SetupExecute, $1_$2_$3_gen_cds_archive_jre, \
172       WARN := Creating CDS$$($1_$2_$3_DUMP_TYPE) archive for jre image for $1, \
173       INFO := Using CDS flags for $1: $$($1_$2_$3_CDS_DUMP_FLAGS), \
174       DEPS := $$(jlink_jre), \
175       OUTPUT_FILE := $$(JRE_IMAGE_DIR)/$$($1_$2_$3_CDS_ARCHIVE), \
176       SUPPORT_DIR := $$(JRE_IMAGE_SUPPORT_DIR), \
177       COMMAND := $$(FIXPATH) $$(JRE_IMAGE_DIR)/bin/java -Xshare:dump \
178           -XX:SharedArchiveFile=$$(JRE_IMAGE_DIR)/$$($1_$2_$3_CDS_ARCHIVE) \
179           -$1 $$($1_$2_$3_DUMP_EXTRA_ARG) $$($1_$2_$3_CDS_DUMP_FLAGS) $$(LOG_INFO), \
180   ))
181 
182   JRE_TARGETS += $$($1_$2_$3_gen_cds_archive_jre)
183 endef
184 
185 ifeq ($(BUILD_CDS_ARCHIVE), true)
186   $(foreach v, $(JVM_VARIANTS), \
187     $(eval $(call CreateCDSArchive,$v,,)) \
188     $(eval $(call CreateCDSArchive,$v,,_valhalla)) \
189   )
190 
191   ifeq ($(call isTargetCpuBits, 64), true)
192     $(foreach v, $(JVM_VARIANTS), \
193       $(eval $(call CreateCDSArchive,$v,_nocoops,)) \
194       $(eval $(call CreateCDSArchive,$v,_nocoops,_valhalla)) \
195     )
196   endif
197 endif
198 
199 ################################################################################
200 # src.zip
201 
202 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
203 	$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
204 	$(install-file)
205 
206 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
207 
208 ################################################################################
209 # /demo dir
210 # Avoid doing the expensive find unless called with "jdk" as target.
211 ifneq ($(filter jdk, $(MAKECMDGOALS)), )
212 
213   DEMO_FILES := \
214       $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
215         $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
216             -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
217       )
218 
219   ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
220     ifeq ($(call isTargetOs, macosx), true)
221       DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
222     else
223       DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
224     endif
225   endif
226 
227   $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
228       SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
229       DEST := $(JDK_IMAGE_DIR)/demo, \
230       FILES := $(DEMO_FILES), \
231   ))
232 
233   JDK_TARGETS += $(JDK_COPY_DEMOS)
234 endif
235 
236 ################################################################################
237 # Code coverage data files
238 
239 ifeq ($(GCOV_ENABLED), true)
240 
241   $(eval $(call SetupCopyFiles, COPY_GCOV_GCNO, \
242       SRC := $(OUTPUTDIR), \
243       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
244       FILES := $(call FindFiles, $(HOTSPOT_OUTPUTDIR) \
245           $(SUPPORT_OUTPUTDIR)/native, *.gcno) \
246   ))
247 
248   SYMBOLS_TARGETS += $(COPY_GCOV_GCNO)
249 
250 endif
251 
252 ################################################################################
253 # Debug symbols
254 # Since debug symbols are not included in the jmod files, they need to be copied
255 # in manually after generating the images.
256 
257 ALL_JDK_MODULES := $(JDK_MODULES)
258 ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \
259     $(call FindTransitiveDepsForModule, $m)))
260 ALL_SYMBOLS_MODULES := $(JDK_MODULES)
261 
262 ifeq ($(call isTargetOs, windows), true)
263   LIBS_TARGET_SUBDIR := bin
264 else
265   LIBS_TARGET_SUBDIR := lib
266 endif
267 CMDS_TARGET_SUBDIR := bin
268 
269 # Param 1 - dir to find debuginfo files in
270 FindDebuginfoFiles = \
271     $(wildcard $(addprefix $1/*, $(DEBUGINFO_SUFFIXES)) \
272         $(addprefix $1/*/*, $(DEBUGINFO_SUFFIXES)) \
273         $(addprefix $1/*/*/*, $(DEBUGINFO_SUFFIXES)))
274 
275 # Pick the correct debug info files to copy, either zipped or not.
276 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
277   DEBUGINFO_SUFFIXES += .diz
278 else
279   DEBUGINFO_SUFFIXES := .debuginfo .pdb .map
280   # On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM
281   # dirs.
282   ifeq ($(call isTargetOs, macosx), true)
283     $(call FillFindCache, \
284         $(SUPPORT_OUTPUTDIR)/modules_libs $(SUPPORT_OUTPUTDIR)/modules_cmds)
285     FindDebuginfoFiles = \
286         $(if $(wildcard $1), $(call containing, .dSYM/, $(call FindFiles, $1)))
287   endif
288 endif
289 
290 # Param 1 - either JDK or JRE
291 SetupCopyDebuginfo = \
292     $(foreach m, $(ALL_$1_MODULES), \
293       $(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
294           SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
295           DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
296           FILES := $(call FindDebuginfoFiles, \
297               $(SUPPORT_OUTPUTDIR)/modules_libs/$m), \
298       )) \
299       $(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
300       $(eval $(call SetupCopyFiles, COPY_$1_CMDS_DEBUGINFO_$m, \
301           SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds/$m, \
302           DEST := $($1_IMAGE_DIR)/$(CMDS_TARGET_SUBDIR), \
303           FILES := $(call FindDebuginfoFiles, \
304               $(SUPPORT_OUTPUTDIR)/modules_cmds/$m), \
305       )) \
306       $(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \
307     )
308 
309 # No space before argument to avoid having to put $(strip ) everywhere in
310 # implementation above.
311 $(call SetupCopyDebuginfo,JDK)
312 $(call SetupCopyDebuginfo,JRE)
313 $(call SetupCopyDebuginfo,SYMBOLS)
314 
315 ################################################################################
316 
317 # Include custom post hook here to make it possible to augment the target lists
318 # before actual target prerequisites are declared.
319 $(eval $(call IncludeCustomExtension, Images-post.gmk))
320 
321 ################################################################################
322 
323 $(JRE_TARGETS): $(JLINK_JRE_TARGETS)
324 $(JDK_TARGETS): $(JLINK_JDK_TARGETS)
325 
326 jdk: $(JLINK_JDK_TARGETS) $(JDK_TARGETS)
327 jre: $(JLINK_JRE_TARGETS) $(JRE_TARGETS)
328 symbols: $(SYMBOLS_TARGETS)
329 
330 all: jdk jre symbols
331 
332 .PHONY: default all jdk jre symbols