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