1 #
  2 # Copyright (c) 2014, 2023, 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   $(foreach v, $(JVM_VARIANTS), \
176     $(eval $(call CreateCDSArchive,$v,)) \
177   )
178 
179   ifeq ($(call isTargetCpuBits, 64), true)
180     $(foreach v, $(JVM_VARIANTS), \
181       $(eval $(call CreateCDSArchive,$v,_nocoops)) \
182     )
183   endif
184 endif
185 
186 ################################################################################
187 # src.zip
188 
189 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
190 	$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
191 	$(install-file)
192 
193 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
194 
195 ################################################################################
196 # /demo dir
197 # Avoid doing the expensive find unless called with "jdk" as target.
198 ifneq ($(filter jdk, $(MAKECMDGOALS)), )
199 
200   DEMO_FILES := \
201       $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
202         $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
203             -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
204       )
205 
206   ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
207     ifeq ($(call isTargetOs, macosx), true)
208       DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
209     else
210       DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
211     endif
212   endif
213 
214   $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
215       SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
216       DEST := $(JDK_IMAGE_DIR)/demo, \
217       FILES := $(DEMO_FILES), \
218   ))
219 
220   JDK_TARGETS += $(JDK_COPY_DEMOS)
221 endif
222 
223 ################################################################################
224 # Code coverage data files
225 
226 ifeq ($(GCOV_ENABLED), true)
227 
228   $(eval $(call SetupCopyFiles,COPY_GCOV_GCNO, \
229       SRC := $(OUTPUTDIR), \
230       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
231       FILES := $(call FindFiles, $(HOTSPOT_OUTPUTDIR) \
232           $(SUPPORT_OUTPUTDIR)/native, *.gcno) \
233   ))
234 
235   SYMBOLS_TARGETS += $(COPY_GCOV_GCNO)
236 
237 endif
238 
239 ################################################################################
240 # Debug symbols
241 # Since debug symbols are not included in the jmod files, they need to be copied
242 # in manually after generating the images.
243 
244 ALL_JDK_MODULES := $(JDK_MODULES)
245 ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \
246     $(call FindTransitiveDepsForModule, $m)))
247 ALL_SYMBOLS_MODULES := $(JDK_MODULES)
248 
249 ifeq ($(call isTargetOs, windows), true)
250   LIBS_TARGET_SUBDIR := bin
251 else
252   LIBS_TARGET_SUBDIR := lib
253 endif
254 CMDS_TARGET_SUBDIR := bin
255 
256 # Param 1 - dir to find debuginfo files in
257 FindDebuginfoFiles = \
258     $(wildcard $(addprefix $1/*, $(DEBUGINFO_SUFFIXES)) \
259         $(addprefix $1/*/*, $(DEBUGINFO_SUFFIXES)) \
260         $(addprefix $1/*/*/*, $(DEBUGINFO_SUFFIXES)))
261 
262 # Pick the correct debug info files to copy, either zipped or not.
263 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
264   DEBUGINFO_SUFFIXES += .diz
265 else
266   DEBUGINFO_SUFFIXES := .debuginfo .pdb .map
267   # On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM
268   # dirs.
269   ifeq ($(call isTargetOs, macosx), true)
270     $(call FillFindCache, \
271         $(SUPPORT_OUTPUTDIR)/modules_libs $(SUPPORT_OUTPUTDIR)/modules_cmds)
272     FindDebuginfoFiles = \
273         $(if $(wildcard $1), $(call containing, .dSYM/, $(call FindFiles, $1)))
274   endif
275 endif
276 
277 # Param 1 - either JDK or JRE
278 SetupCopyDebuginfo = \
279     $(foreach m, $(ALL_$1_MODULES), \
280       $(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
281           SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
282           DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
283           FILES := $(call FindDebuginfoFiles, \
284               $(SUPPORT_OUTPUTDIR)/modules_libs/$m), \
285       )) \
286       $(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
287       $(eval $(call SetupCopyFiles, COPY_$1_CMDS_DEBUGINFO_$m, \
288           SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds/$m, \
289           DEST := $($1_IMAGE_DIR)/$(CMDS_TARGET_SUBDIR), \
290           FILES := $(call FindDebuginfoFiles, \
291               $(SUPPORT_OUTPUTDIR)/modules_cmds/$m), \
292       )) \
293       $(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \
294     )
295 
296 # No space before argument to avoid having to put $(strip ) everywhere in
297 # implementation above.
298 $(call SetupCopyDebuginfo,JDK)
299 $(call SetupCopyDebuginfo,JRE)
300 $(call SetupCopyDebuginfo,SYMBOLS)
301 
302 ################################################################################
303 
304 # Include custom post hook here to make it possible to augment the target lists
305 # before actual target prerequisites are declared.
306 $(eval $(call IncludeCustomExtension, Images-post.gmk))
307 
308 ################################################################################
309 
310 $(JRE_TARGETS): $(JLINK_JRE_TARGETS)
311 $(JDK_TARGETS): $(JLINK_JDK_TARGETS)
312 
313 jdk: $(JLINK_JDK_TARGETS) $(JDK_TARGETS)
314 jre: $(JLINK_JRE_TARGETS) $(JRE_TARGETS)
315 symbols: $(SYMBOLS_TARGETS)
316 
317 all: jdk jre symbols
318 
319 .PHONY: default all jdk jre symbols