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