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, _coh, _nocoops_coh, or empty
136 define CreateCDSArchive
137   $1_$2_COOPS_OPTION := $(if $(findstring _nocoops, $2),-XX:-UseCompressedOops)
138   # enable and also explicitly disable coh as needed.
139   ifeq ($(call isTargetCpuBits, 64), true)
140     $1_$2_COH_OPTION := -XX:+UnlockExperimentalVMOptions \
141                         $(if $(findstring _coh, $2),-XX:+UseCompactObjectHeaders,-XX:-UseCompactObjectHeaders)
142   endif
143   $1_$2_DUMP_EXTRA_ARG := $$($1_$2_COOPS_OPTION) $$($1_$2_COH_OPTION)
144   $1_$2_DUMP_TYPE      := $(if $(findstring _nocoops, $2),-NOCOOPS,)$(if $(findstring _coh, $2),-COH,)
145 
146   # Only G1 supports dumping the shared heap, so explicitly use G1 if the JVM supports it.
147   $1_$2_CDS_DUMP_FLAGS := $(CDS_DUMP_FLAGS) $(if $(filter g1gc, $(JVM_FEATURES_$1)),-XX:+UseG1GC)
148 
149   ifeq ($(OPENJDK_TARGET_OS), windows)
150     $1_$2_CDS_ARCHIVE := bin/$1/classes$2.jsa
151   else
152     $1_$2_CDS_ARCHIVE := lib/$1/classes$2.jsa
153   endif
154 
155   ifneq ($(COMPARE_BUILD), )
156     DEBUG_CDS_ARCHIVE := true
157   endif
158 
159   ifeq ($(DEBUG_CDS_ARCHIVE), true)
160     $1_$2_CDS_DUMP_FLAGS += -Xlog:cds+map*=trace:file=$$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE).cdsmap:none:filesize=0
161   endif
162 
163   $$(eval $$(call SetupExecute, $1_$2_gen_cds_archive_jdk, \
164       WARN := Creating CDS$$($1_$2_DUMP_TYPE) archive for jdk image for $1, \
165       INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \
166       DEPS := $$(jlink_jdk), \
167       OUTPUT_FILE := $$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \
168       SUPPORT_DIR := $$(JDK_IMAGE_SUPPORT_DIR), \
169       COMMAND := $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/java -Xshare:dump \
170           -XX:SharedArchiveFile=$$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \
171           -$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \
172   ))
173 
174   JDK_TARGETS += $$($1_$2_gen_cds_archive_jdk)
175 
176   $$(eval $$(call SetupExecute, $1_$2_gen_cds_archive_jre, \
177       WARN := Creating CDS$$($1_$2_DUMP_TYPE) archive for jre image for $1, \
178       INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \
179       DEPS := $$(jlink_jre), \
180       OUTPUT_FILE := $$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \
181       SUPPORT_DIR := $$(JRE_IMAGE_SUPPORT_DIR), \
182       COMMAND := $$(FIXPATH) $$(JRE_IMAGE_DIR)/bin/java -Xshare:dump \
183           -XX:SharedArchiveFile=$$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \
184           -$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \
185   ))
186 
187   JRE_TARGETS += $$($1_$2_gen_cds_archive_jre)
188 endef
189 
190 ifeq ($(BUILD_CDS_ARCHIVE), true)
191   $(foreach v, $(JVM_VARIANTS), \
192     $(eval $(call CreateCDSArchive,$v,)) \
193   )
194 
195   ifeq ($(call isTargetCpuBits, 64), true)
196     $(foreach v, $(JVM_VARIANTS), \
197       $(eval $(call CreateCDSArchive,$v,_nocoops)) \
198     )
199     ifeq ($(BUILD_CDS_ARCHIVE_COH), true)
200       $(foreach v, $(JVM_VARIANTS), \
201         $(eval $(call CreateCDSArchive,$v,_coh)) \
202       )
203       $(foreach v, $(JVM_VARIANTS), \
204         $(eval $(call CreateCDSArchive,$v,_nocoops_coh)) \
205       )
206     endif
207   endif
208 endif
209 
210 ################################################################################
211 # src.zip
212 
213 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
214 	$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
215 	$(install-file)
216 
217 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
218 
219 ################################################################################
220 # /demo dir
221 # Avoid doing the expensive find unless called with "jdk" as target.
222 ifneq ($(filter jdk, $(MAKECMDGOALS)), )
223 
224   DEMO_FILES := \
225       $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
226         $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
227             -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
228       )
229 
230   ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
231     ifeq ($(call isTargetOs, macosx), true)
232       DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
233     else
234       DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
235     endif
236   endif
237 
238   $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
239       SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
240       DEST := $(JDK_IMAGE_DIR)/demo, \
241       FILES := $(DEMO_FILES), \
242   ))
243 
244   JDK_TARGETS += $(JDK_COPY_DEMOS)
245 endif
246 
247 ################################################################################
248 # Code coverage data files
249 
250 ifeq ($(GCOV_ENABLED), true)
251 
252   $(eval $(call SetupCopyFiles,COPY_GCOV_GCNO, \
253       SRC := $(OUTPUTDIR), \
254       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
255       FILES := $(call FindFiles, $(HOTSPOT_OUTPUTDIR) \
256           $(SUPPORT_OUTPUTDIR)/native, *.gcno) \
257   ))
258 
259   SYMBOLS_TARGETS += $(COPY_GCOV_GCNO)
260 
261 endif
262 
263 ################################################################################
264 # Debug symbols
265 # Since debug symbols are not included in the jmod files, they need to be copied
266 # in manually after generating the images.
267 
268 ALL_JDK_MODULES := $(JDK_MODULES)
269 ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \
270     $(call FindTransitiveDepsForModule, $m)))
271 ALL_SYMBOLS_MODULES := $(JDK_MODULES)
272 
273 ifeq ($(call isTargetOs, windows), true)
274   LIBS_TARGET_SUBDIR := bin
275 else
276   LIBS_TARGET_SUBDIR := lib
277 endif
278 CMDS_TARGET_SUBDIR := bin
279 
280 # Param 1 - dir to find debuginfo files in
281 FindDebuginfoFiles = \
282     $(wildcard $(addprefix $1/*, $(DEBUGINFO_SUFFIXES)) \
283         $(addprefix $1/*/*, $(DEBUGINFO_SUFFIXES)) \
284         $(addprefix $1/*/*/*, $(DEBUGINFO_SUFFIXES)))
285 
286 # Pick the correct debug info files to copy, either zipped or not.
287 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
288   DEBUGINFO_SUFFIXES += .diz
289 else
290   DEBUGINFO_SUFFIXES := .debuginfo .pdb .map
291   # On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM
292   # dirs.
293   ifeq ($(call isTargetOs, macosx), true)
294     $(call FillFindCache, \
295         $(SUPPORT_OUTPUTDIR)/modules_libs $(SUPPORT_OUTPUTDIR)/modules_cmds)
296     FindDebuginfoFiles = \
297         $(if $(wildcard $1), $(call containing, .dSYM/, $(call FindFiles, $1)))
298   endif
299 endif
300 
301 # Param 1 - either JDK or JRE
302 SetupCopyDebuginfo = \
303     $(foreach m, $(ALL_$1_MODULES), \
304       $(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
305           SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
306           DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
307           FILES := $(call FindDebuginfoFiles, \
308               $(SUPPORT_OUTPUTDIR)/modules_libs/$m), \
309       )) \
310       $(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
311       $(eval $(call SetupCopyFiles, COPY_$1_CMDS_DEBUGINFO_$m, \
312           SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds/$m, \
313           DEST := $($1_IMAGE_DIR)/$(CMDS_TARGET_SUBDIR), \
314           FILES := $(call FindDebuginfoFiles, \
315               $(SUPPORT_OUTPUTDIR)/modules_cmds/$m), \
316       )) \
317       $(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \
318     )
319 
320 # No space before argument to avoid having to put $(strip ) everywhere in
321 # implementation above.
322 $(call SetupCopyDebuginfo,JDK)
323 $(call SetupCopyDebuginfo,JRE)
324 $(call SetupCopyDebuginfo,SYMBOLS)
325 
326 ################################################################################
327 
328 # Include custom post hook here to make it possible to augment the target lists
329 # before actual target prerequisites are declared.
330 $(eval $(call IncludeCustomExtension, Images-post.gmk))
331 
332 ################################################################################
333 
334 $(JRE_TARGETS): $(JLINK_JRE_TARGETS)
335 $(JDK_TARGETS): $(JLINK_JDK_TARGETS)
336 
337 jdk: $(JLINK_JDK_TARGETS) $(JDK_TARGETS)
338 jre: $(JLINK_JRE_TARGETS) $(JRE_TARGETS)
339 symbols: $(SYMBOLS_TARGETS)
340 
341 all: jdk jre symbols
342 
343 .PHONY: default all jdk jre symbols