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 include Execute.gmk
 31 include Modules.gmk
 32 include Utils.gmk
 33 
 34 JDK_TARGETS :=
 35 JRE_TARGETS :=
 36 
 37 # Hook to include the corresponding custom file, if present.
 38 $(eval $(call IncludeCustomExtension, Images-pre.gmk))
 39 
 40 ################################################################################
 41 
 42 # All modules for the current target platform.
 43 ALL_MODULES := $(call FindAllModules) $(EXTRA_MODULES)
 44 
 45 $(eval $(call ReadImportMetaData))
 46 
 47 JRE_MODULES += $(filter $(ALL_MODULES), $(BOOT_MODULES) \
 48     $(PLATFORM_MODULES) jdk.jdwp.agent)
 49 JDK_MODULES += $(ALL_MODULES)
 50 
 51 JRE_MODULES_LIST := $(call CommaList, $(JRE_MODULES))
 52 JDK_MODULES_LIST := $(call CommaList, $(JDK_MODULES))
 53 
 54 ################################################################################
 55 
 56 BASE_RELEASE_FILE := $(JDK_OUTPUTDIR)/release
 57 
 58 JMODS_DIRS := $(EXTRA_JMODS_DIR) $(IMAGES_OUTPUTDIR)/jmods
 59 
 60 JDK_JMODS := $(foreach m, $(JDK_MODULES), $(firstword $(wildcard $(addsuffix /$m.jmod, $(JMODS_DIRS)))))
 61 JRE_JMODS := $(foreach m, $(JRE_MODULES), $(firstword $(wildcard $(addsuffix /$m.jmod, $(JMODS_DIRS)))))
 62 
 63 JLINK_ORDER_RESOURCES := **module-info.class
 64 JLINK_JLI_CLASSES :=
 65 ifeq ($(ENABLE_GENERATE_CLASSLIST), true)
 66   JLINK_ORDER_RESOURCES += @$(SUPPORT_OUTPUTDIR)/link_opt/classlist
 67   JLINK_JLI_CLASSES := --generate-jli-classes=@$(SUPPORT_OUTPUTDIR)/link_opt/default_jli_trace.txt
 68 endif
 69 JLINK_ORDER_RESOURCES += \
 70     /java.base/java/** \
 71     /java.base/jdk/** \
 72     /java.base/sun/** \
 73     /java.base/com/** \
 74     /jdk.localedata/** \
 75     #
 76 
 77 JLINK_TOOL := $(JLINK) -J-Djlink.debug=true \
 78     --module-path $(call PathList, $(JMODS_DIRS)) \
 79     --endian $(OPENJDK_TARGET_CPU_ENDIAN) \
 80     --release-info $(BASE_RELEASE_FILE) \
 81     --order-resources=$(call CommaList, $(JLINK_ORDER_RESOURCES)) \
 82     --dedup-legal-notices=error-if-not-same-content \
 83     $(JLINK_JLI_CLASSES) \
 84     #
 85 
 86 JLINK_JRE_EXTRA_OPTS := --no-man-pages --no-header-files --strip-debug
 87 
 88 ifeq ($(JLINK_KEEP_PACKAGED_MODULES), true)
 89   JLINK_JDK_EXTRA_OPTS := --keep-packaged-modules $(JDK_IMAGE_DIR)/jmods
 90 endif
 91 
 92 JLINK_DISABLE_WARNINGS := | ( $(GREP) -v -e "WARNING: Using incubator module" || test "$$?" = "1" )
 93 
 94 JDK_IMAGE_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jdk
 95 JRE_IMAGE_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/images/jre
 96 
 97 $(eval $(call SetupExecute, jlink_jdk, \
 98     WARN := Creating jdk image, \
 99     DEPS := $(JDK_JMODS) $(BASE_RELEASE_FILE) \
100         $(call DependOnVariable, JDK_MODULES_LIST, $(JDK_IMAGE_SUPPORT_DIR)/_jlink_jdk.vardeps), \
101     OUTPUT_DIR := $(JDK_IMAGE_DIR), \
102     SUPPORT_DIR := $(JDK_IMAGE_SUPPORT_DIR), \
103     PRE_COMMAND := $(RM) -r $(JDK_IMAGE_DIR), \
104     COMMAND := $(JLINK_TOOL) --add-modules $(JDK_MODULES_LIST) \
105         $(JLINK_JDK_EXTRA_OPTS) --output $(JDK_IMAGE_DIR) \
106         $(JLINK_DISABLE_WARNINGS), \
107 ))
108 
109 JLINK_JDK_TARGETS := $(jlink_jdk)
110 
111 $(eval $(call SetupExecute, jlink_jre, \
112     WARN := Creating legacy jre image, \
113     DEPS := $(JRE_JMODS) $(BASE_RELEASE_FILE) \
114         $(call DependOnVariable, JRE_MODULES_LIST, $(JRE_IMAGE_SUPPORT_DIR)/_jlink_jre.vardeps), \
115     OUTPUT_DIR := $(JRE_IMAGE_DIR), \
116     SUPPORT_DIR := $(JRE_IMAGE_SUPPORT_DIR), \
117     PRE_COMMAND := $(RM) -r $(JRE_IMAGE_DIR), \
118     COMMAND := $(JLINK_TOOL) --add-modules $(JRE_MODULES_LIST) \
119         $(JLINK_JRE_EXTRA_OPTS) --output $(JRE_IMAGE_DIR), \
120 ))
121 
122 JLINK_JRE_TARGETS := $(jlink_jre)
123 
124 # Optimize CDS shared heap for small heap sizes, which are typically used
125 # for small cloud-based apps that have the most critical start-up requirement.
126 # The trade-off is that when larger heap sizes are used, the shared heap
127 # may need to be relocated at runtime.
128 CDS_DUMP_FLAGS = -Xmx128M -Xms128M
129 
130 # Helper function for creating the CDS archives for the JDK and JRE
131 #
132 # Param1 - VM variant (e.g., server, client, zero, ...)
133 # Param2 - _nocoops, or empty
134 define CreateCDSArchive
135   $1_$2_DUMP_EXTRA_ARG := $(if $(filter _nocoops, $2),-XX:-UseCompressedOops,)
136   $1_$2_DUMP_TYPE      := $(if $(filter _nocoops, $2),-NOCOOPS,)
137 
138   # Only G1 supports dumping the shared heap, so explicitly use G1 if the JVM supports it.
139   $1_$2_CDS_DUMP_FLAGS := $(CDS_DUMP_FLAGS) $(if $(filter g1gc, $(JVM_FEATURES_$1)),-XX:+UseG1GC)
140 
141   ifeq ($(OPENJDK_TARGET_OS), windows)
142     $1_$2_CDS_ARCHIVE := bin/$1/classes$2.jsa
143   else
144     $1_$2_CDS_ARCHIVE := lib/$1/classes$2.jsa
145   endif
146 
147   $$(eval $$(call SetupExecute, $1_$2_gen_cds_archive_jdk, \
148       WARN := Creating CDS$$($1_$2_DUMP_TYPE) archive for jdk image for $1, \
149       INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \
150       DEPS := $$(jlink_jdk), \
151       OUTPUT_FILE := $$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \
152       SUPPORT_DIR := $$(JDK_IMAGE_SUPPORT_DIR), \
153       COMMAND := $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/java -Xshare:dump \
154           -XX:SharedArchiveFile=$$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \
155           -$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \
156   ))
157 
158   JDK_TARGETS += $$($1_$2_gen_cds_archive_jdk)
159 
160   $$(eval $$(call SetupExecute, $1_$2_gen_cds_archive_jre, \
161       WARN := Creating CDS$$($1_$2_DUMP_TYPE) archive for jre image for $1, \
162       INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \
163       DEPS := $$(jlink_jre), \
164       OUTPUT_FILE := $$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \
165       SUPPORT_DIR := $$(JRE_IMAGE_SUPPORT_DIR), \
166       COMMAND := $$(FIXPATH) $$(JRE_IMAGE_DIR)/bin/java -Xshare:dump \
167           -XX:SharedArchiveFile=$$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \
168           -$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \
169   ))
170 
171   JRE_TARGETS += $$($1_$2_gen_cds_archive_jre)
172 endef
173 
174 ifeq ($(BUILD_CDS_ARCHIVE), true)
175 
176 CLASSLIST_REFRESH := $(SUPPORT_OUTPUTDIR)/images/jdk/classlist.refresh
177 
178 # The classlist generated by GenerateLinkOptData.gmk uses the Holder classes from
179 # the intermin image, which are different than the ones in the final JDK image. So
180 # we need to generate the images/jdk/lib/classlist again, or else the @cp indices
181 # in the classlist will be incorrect.
182 #
183 # We also make sure that all @lambda-form-invoker lines are copied to the new classlist.
184 #
185 # FIXME: it's better to do this inside GenerateLinkOptData.gmk, but I don't know how ....
186 $(CLASSLIST_REFRESH): $(jlink_jdk)
187 	$(call LogWarn, Refresh classlist for jdk image)
188 	$(FIXPATH) $(JDK_IMAGE_DIR)/bin/java -Xshare:off \
189             -XX:DumpLoadedClassList=$@.raw \
190 	    -Duser.language=en -Duser.country=US \
191 	    -cp $(SUPPORT_OUTPUTDIR)/classlist.jar \
192 	    build.tools.classlist.HelloClasslist \
193 	    2> $@.stderr > $@.stdout
194 	$(CAT) $@.raw \
195 	    | $(GREP) -v HelloClasslist \
196 	    > $@.raw.2
197 	$(FIXPATH) $(INTERIM_IMAGE_DIR)/bin/java \
198 	    -cp $(SUPPORT_OUTPUTDIR)/classlist.jar \
199 	    build.tools.classlist.SortClasslist $@.raw.2 > $@
200 	$(CP) $(JDK_IMAGE_DIR)/lib/classlist $(JDK_IMAGE_DIR)/lib/classlist.saved
201 	cat $@ | $(GREP) -v '@lambda-form-invoker' > $(JDK_IMAGE_DIR)/lib/classlist
202 	cat $@ $(JDK_IMAGE_DIR)/lib/classlist.saved | $(GREP) '@lambda-form-invoker' \
203 	    | sort | uniq >> $(JDK_IMAGE_DIR)/lib/classlist
204 
205 JDK_TARGETS += $(CLASSLIST_REFRESH)
206 
207   $(foreach v, $(JVM_VARIANTS), \
208     $(eval $(call CreateCDSArchive,$v,)) \
209   )
210 
211   ifeq ($(call isTargetCpuBits, 64), true)
212     $(foreach v, $(JVM_VARIANTS), \
213       $(eval $(call CreateCDSArchive,$v,_nocoops)) \
214     )
215   endif
216 endif
217 
218 ################################################################################
219 # src.zip
220 
221 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
222 	$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
223 	$(install-file)
224 
225 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
226 
227 ################################################################################
228 # /demo dir
229 # Avoid doing the expensive find unless called with "jdk" as target.
230 ifneq ($(filter jdk, $(MAKECMDGOALS)), )
231 
232   DEMO_FILES := \
233       $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
234         $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
235             -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
236       )
237 
238   ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
239     ifeq ($(call isTargetOs, macosx), true)
240       DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
241     else
242       DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
243     endif
244   endif
245 
246   $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
247       SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
248       DEST := $(JDK_IMAGE_DIR)/demo, \
249       FILES := $(DEMO_FILES), \
250   ))
251 
252   JDK_TARGETS += $(JDK_COPY_DEMOS)
253 endif
254 
255 ################################################################################
256 # Code coverage data files
257 
258 ifeq ($(GCOV_ENABLED), true)
259 
260   $(eval $(call SetupCopyFiles,COPY_GCOV_GCNO, \
261       SRC := $(OUTPUTDIR), \
262       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
263       FILES := $(call FindFiles, $(HOTSPOT_OUTPUTDIR) \
264           $(SUPPORT_OUTPUTDIR)/native, *.gcno) \
265   ))
266 
267   SYMBOLS_TARGETS += $(COPY_GCOV_GCNO)
268 
269 endif
270 
271 ################################################################################
272 # Debug symbols
273 # Since debug symbols are not included in the jmod files, they need to be copied
274 # in manually after generating the images.
275 
276 ALL_JDK_MODULES := $(JDK_MODULES)
277 ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \
278     $(call FindTransitiveDepsForModule, $m)))
279 ALL_SYMBOLS_MODULES := $(JDK_MODULES)
280 
281 ifeq ($(call isTargetOs, windows), true)
282   LIBS_TARGET_SUBDIR := bin
283 else
284   LIBS_TARGET_SUBDIR := lib
285 endif
286 CMDS_TARGET_SUBDIR := bin
287 
288 # Param 1 - dir to find debuginfo files in
289 FindDebuginfoFiles = \
290     $(wildcard $(addprefix $1/*, $(DEBUGINFO_SUFFIXES)) \
291         $(addprefix $1/*/*, $(DEBUGINFO_SUFFIXES)) \
292         $(addprefix $1/*/*/*, $(DEBUGINFO_SUFFIXES)))
293 
294 # Pick the correct debug info files to copy, either zipped or not.
295 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
296   DEBUGINFO_SUFFIXES += .diz
297 else
298   DEBUGINFO_SUFFIXES := .debuginfo .pdb .map
299   # On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM
300   # dirs.
301   ifeq ($(call isTargetOs, macosx), true)
302     $(call FillFindCache, \
303         $(SUPPORT_OUTPUTDIR)/modules_libs $(SUPPORT_OUTPUTDIR)/modules_cmds)
304     FindDebuginfoFiles = \
305         $(if $(wildcard $1), $(call containing, .dSYM/, $(call FindFiles, $1)))
306   endif
307 endif
308 
309 # Param 1 - either JDK or JRE
310 SetupCopyDebuginfo = \
311     $(foreach m, $(ALL_$1_MODULES), \
312       $(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
313           SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
314           DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
315           FILES := $(call FindDebuginfoFiles, \
316               $(SUPPORT_OUTPUTDIR)/modules_libs/$m), \
317       )) \
318       $(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
319       $(eval $(call SetupCopyFiles, COPY_$1_CMDS_DEBUGINFO_$m, \
320           SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds/$m, \
321           DEST := $($1_IMAGE_DIR)/$(CMDS_TARGET_SUBDIR), \
322           FILES := $(call FindDebuginfoFiles, \
323               $(SUPPORT_OUTPUTDIR)/modules_cmds/$m), \
324       )) \
325       $(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \
326     )
327 
328 # No space before argument to avoid having to put $(strip ) everywhere in
329 # implementation above.
330 $(call SetupCopyDebuginfo,JDK)
331 $(call SetupCopyDebuginfo,JRE)
332 $(call SetupCopyDebuginfo,SYMBOLS)
333 
334 ################################################################################
335 
336 # Include custom post hook here to make it possible to augment the target lists
337 # before actual target prerequisites are declared.
338 $(eval $(call IncludeCustomExtension, Images-post.gmk))
339 
340 ################################################################################
341 
342 $(JRE_TARGETS): $(JLINK_JRE_TARGETS)
343 $(JDK_TARGETS): $(JLINK_JDK_TARGETS)
344 
345 jdk: $(JLINK_JDK_TARGETS) $(JDK_TARGETS)
346 jre: $(JLINK_JRE_TARGETS) $(JRE_TARGETS)
347 symbols: $(SYMBOLS_TARGETS)
348 
349 all: jdk jre symbols
350 
351 .PHONY: default all jdk jre symbols