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 define CreateCDSArchive
137   $1_$2_DUMP_EXTRA_ARG := $(if $(filter _nocoops, $2), -XX:-UseCompressedOops, )
138   $1_$2_DUMP_TYPE      := $(if $(filter _nocoops, $2), -NOCOOPS, )
139 
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)
142 
143   ifeq ($(OPENJDK_TARGET_OS), windows)
144     $1_$2_CDS_ARCHIVE := bin/$1/classes$2.jsa
145   else
146     $1_$2_CDS_ARCHIVE := lib/$1/classes$2.jsa
147   endif
148 
149   ifneq ($(COMPARE_BUILD), )
150     DEBUG_CDS_ARCHIVE := true
151   endif
152 
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
155   endif
156 
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), \
166   ))
167 
168   JDK_TARGETS += $$($1_$2_gen_cds_archive_jdk)
169 
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), \
179   ))
180 
181   JRE_TARGETS += $$($1_$2_gen_cds_archive_jre)
182 endef
183 
184 ifeq ($(BUILD_CDS_ARCHIVE), true)
185   $(foreach v, $(JVM_VARIANTS), \
186     $(eval $(call CreateCDSArchive,$v,)) \
187   )
188 
189   ifeq ($(call isTargetCpuBits, 64), true)
190     $(foreach v, $(JVM_VARIANTS), \
191       $(eval $(call CreateCDSArchive,$v,_nocoops)) \
192     )
193   endif
194 endif
195 
196 ################################################################################
197 # src.zip
198 
199 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
200 	$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
201 	$(install-file)
202 
203 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
204 
205 ################################################################################
206 # /demo dir
207 # Avoid doing the expensive find unless called with "jdk" as target.
208 ifneq ($(filter jdk, $(MAKECMDGOALS)), )
209 
210   DEMO_FILES := \
211       $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
212         $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
213             -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
214       )
215 
216   ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
217     ifeq ($(call isTargetOs, macosx), true)
218       DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
219     else
220       DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
221     endif
222   endif
223 
224   $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
225       SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
226       DEST := $(JDK_IMAGE_DIR)/demo, \
227       FILES := $(DEMO_FILES), \
228   ))
229 
230   JDK_TARGETS += $(JDK_COPY_DEMOS)
231 endif
232 
233 ################################################################################
234 # Code coverage data files
235 
236 ifeq ($(GCOV_ENABLED), true)
237 
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) \
243   ))
244 
245   SYMBOLS_TARGETS += $(COPY_GCOV_GCNO)
246 
247 endif
248 
249 ################################################################################
250 # Debug symbols
251 # Since debug symbols are not included in the jmod files, they need to be copied
252 # in manually after generating the images.
253 
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)
258 
259 ifeq ($(call isTargetOs, windows), true)
260   LIBS_TARGET_SUBDIR := bin
261 else
262   LIBS_TARGET_SUBDIR := lib
263 endif
264 CMDS_TARGET_SUBDIR := bin
265 
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)))
271 
272 # Pick the correct debug info files to copy, either zipped or not.
273 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
274   DEBUGINFO_SUFFIXES += .diz
275 else
276   DEBUGINFO_SUFFIXES := .debuginfo .pdb .map
277   # On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM
278   # dirs.
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)))
284   endif
285 endif
286 
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), \
295       )) \
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), \
302       )) \
303       $(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \
304     )
305 
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)
311 
312 ################################################################################
313 
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))
317 
318 ################################################################################
319 
320 $(JRE_TARGETS): $(JLINK_JRE_TARGETS)
321 $(JDK_TARGETS): $(JLINK_JDK_TARGETS)
322 
323 jdk: $(JLINK_JDK_TARGETS) $(JDK_TARGETS)
324 jre: $(JLINK_JRE_TARGETS) $(JRE_TARGETS)
325 symbols: $(SYMBOLS_TARGETS)
326 
327 all: jdk jre symbols
328 
329 .PHONY: default all jdk jre symbols