1 #
  2 # Copyright (c) 2014, 2026, 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, _nocoh, _nocoops_nocoh, 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_NOCOH_OPTION := $(if $(findstring _nocoh, $2),-XX:-UseCompactObjectHeaders,-XX:+UseCompactObjectHeaders)
146   endif
147   $1_$2_DUMP_EXTRA_ARG := $$($1_$2_COOPS_OPTION) $$($1_$2_NOCOH_OPTION)
148   $1_$2_DUMP_TYPE      := $(if $(findstring _nocoops, $2),-NOCOOPS,)$(if $(findstring _nocoh, $2),-NOCOH,)
149 
150   $1_$2_CDS_DUMP_FLAGS := $(CDS_DUMP_FLAGS) $(if $(filter g1gc, $(JVM_FEATURES_$1)), -XX:+UseG1GC)
151 
152   ifeq ($(OPENJDK_TARGET_OS), windows)
153     $1_$2_CDS_ARCHIVE := bin/$1/classes$2.jsa
154   else
155     $1_$2_CDS_ARCHIVE := lib/$1/classes$2.jsa
156   endif
157 
158   ifneq ($(COMPARE_BUILD), )
159     DEBUG_CDS_ARCHIVE := true
160   endif
161 
162   ifeq ($(DEBUG_CDS_ARCHIVE), true)
163     $1_$2_CDS_DUMP_FLAGS += -Xlog:aot+map*=trace:file=$$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE).cdsmap:none:filesize=0
164   endif
165 
166   $$(eval $$(call SetupExecute, $1_$2_gen_cds_archive_jdk, \
167       WARN := Creating CDS$$($1_$2_DUMP_TYPE) archive for jdk image for $1, \
168       INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \
169       DEPS := $$(jlink_jdk), \
170       OUTPUT_FILE := $$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \
171       SUPPORT_DIR := $$(JDK_IMAGE_SUPPORT_DIR), \
172       COMMAND := $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/java -Xshare:dump \
173           -XX:SharedArchiveFile=$$(JDK_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \
174           -$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \
175   ))
176 
177   JDK_TARGETS += $$($1_$2_gen_cds_archive_jdk)
178 
179   $$(eval $$(call SetupExecute, $1_$2_gen_cds_archive_jre, \
180       WARN := Creating CDS$$($1_$2_DUMP_TYPE) archive for jre image for $1, \
181       INFO := Using CDS flags for $1: $$($1_$2_CDS_DUMP_FLAGS), \
182       DEPS := $$(jlink_jre), \
183       OUTPUT_FILE := $$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE), \
184       SUPPORT_DIR := $$(JRE_IMAGE_SUPPORT_DIR), \
185       COMMAND := $$(FIXPATH) $$(JRE_IMAGE_DIR)/bin/java -Xshare:dump \
186           -XX:SharedArchiveFile=$$(JRE_IMAGE_DIR)/$$($1_$2_CDS_ARCHIVE) \
187           -$1 $$($1_$2_DUMP_EXTRA_ARG) $$($1_$2_CDS_DUMP_FLAGS) $$(LOG_INFO), \
188   ))
189 
190   JRE_TARGETS += $$($1_$2_gen_cds_archive_jre)
191 endef
192 
193 ifeq ($(BUILD_CDS_ARCHIVE), true)
194   $(foreach v, $(JVM_VARIANTS), \
195     $(eval $(call CreateCDSArchive,$v,)) \
196   )
197 
198   ifeq ($(call isTargetCpuBits, 64), true)
199     $(foreach v, $(JVM_VARIANTS), \
200       $(eval $(call CreateCDSArchive,$v,_nocoops)) \
201     )
202     ifeq ($(BUILD_CDS_ARCHIVE_NOCOH), true)
203       $(foreach v, $(JVM_VARIANTS), \
204         $(eval $(call CreateCDSArchive,$v,_nocoh)) \
205       )
206       $(foreach v, $(JVM_VARIANTS), \
207         $(eval $(call CreateCDSArchive,$v,_nocoops_nocoh)) \
208       )
209     endif
210   endif
211 endif
212 
213 ################################################################################
214 # src.zip
215 
216 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip
217 	$(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@))
218 	$(install-file)
219 
220 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip
221 
222 ################################################################################
223 # /demo dir
224 # Avoid doing the expensive find unless called with "jdk" as target.
225 ifneq ($(filter jdk, $(MAKECMDGOALS)), )
226 
227   DEMO_FILES := \
228       $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \
229         $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \
230             -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \
231       )
232 
233   ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true)
234     ifeq ($(call isTargetOs, macosx), true)
235       DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES))
236     else
237       DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES))
238     endif
239   endif
240 
241   $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \
242       SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \
243       DEST := $(JDK_IMAGE_DIR)/demo, \
244       FILES := $(DEMO_FILES), \
245   ))
246 
247   JDK_TARGETS += $(JDK_COPY_DEMOS)
248 endif
249 
250 ################################################################################
251 # Code coverage data files
252 
253 ifeq ($(GCOV_ENABLED), true)
254 
255   $(eval $(call SetupCopyFiles, COPY_GCOV_GCNO, \
256       SRC := $(OUTPUTDIR), \
257       DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \
258       FILES := $(call FindFiles, $(HOTSPOT_OUTPUTDIR) \
259           $(SUPPORT_OUTPUTDIR)/native, *.gcno) \
260   ))
261 
262   SYMBOLS_TARGETS += $(COPY_GCOV_GCNO)
263 
264 endif
265 
266 ################################################################################
267 # Debug symbols
268 # Since debug symbols are not included in the jmod files, they need to be copied
269 # in manually after generating the images.
270 
271 # These variables are read by SetupCopyDebuginfo
272 ALL_JDK_MODULES := $(JDK_MODULES)
273 ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \
274     $(call FindTransitiveDepsForModule, $m)))
275 ALL_SYMBOLS_MODULES := $(JDK_MODULES)
276 
277 ifeq ($(call isTargetOs, windows), true)
278   LIBS_TARGET_SUBDIR := bin
279 else
280   LIBS_TARGET_SUBDIR := lib
281 endif
282 CMDS_TARGET_SUBDIR := bin
283 
284 # Copy debug info files into symbols bundle.
285 # In case of Windows and --with-external-symbols-in-bundles=public, take care to remove *.stripped.pdb files
286 SetupCopyDebuginfo = \
287     $(foreach m, $(ALL_$1_MODULES), \
288       $(eval dbgfiles := $(call FindDebuginfoFiles, $(SUPPORT_OUTPUTDIR)/modules_libs/$m)) \
289       $(eval dbgfiles := $(if $(filter true+public,$(call isTargetOs,windows)+$(SHIP_DEBUG_SYMBOLS)), \
290         $(filter-out %.stripped.pdb,$(dbgfiles)),$(dbgfiles)) \
291       ) \
292       $(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
293           SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
294           DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
295           FILES := $(dbgfiles), \
296       )) \
297       $(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
298       $(eval dbgfiles := $(call FindDebuginfoFiles, $(SUPPORT_OUTPUTDIR)/modules_cmds/$m)) \
299       $(eval dbgfiles := $(if $(filter true+public,$(call isTargetOs,windows)+$(SHIP_DEBUG_SYMBOLS)), \
300         $(filter-out %.stripped.pdb,$(dbgfiles)),$(dbgfiles)) \
301       ) \
302       $(eval $(call SetupCopyFiles, COPY_$1_CMDS_DEBUGINFO_$m, \
303           SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds/$m, \
304           DEST := $($1_IMAGE_DIR)/$(CMDS_TARGET_SUBDIR), \
305           FILES := $(dbgfiles), \
306       )) \
307       $(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \
308     )
309 
310 # No space before argument to avoid having to put $(strip ) everywhere in implementation above.
311 $(call SetupCopyDebuginfo,SYMBOLS)
312 
313 ################################################################################
314 
315 $(JRE_TARGETS): $(JLINK_JRE_TARGETS)
316 $(JDK_TARGETS): $(JLINK_JDK_TARGETS)
317 
318 jdk: $(JLINK_JDK_TARGETS) $(JDK_TARGETS)
319 jre: $(JLINK_JRE_TARGETS) $(JRE_TARGETS)
320 symbols: $(SYMBOLS_TARGETS)
321 
322 all: jdk jre symbols
323 
324 .PHONY: jdk jre symbols
325 
326 ################################################################################
327 
328 include MakeFileEnd.gmk