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 # Param3 - _valhalla, or empty 135 define CreateCDSArchive 136 $1_$2_$3_DUMP_EXTRA_ARG := $(if $(filter _nocoops, $2),-XX:-UseCompressedOops,) $(if $(filter _valhalla, $3),--enable-preview,) 137 $1_$2_$3_DUMP_TYPE := $(if $(filter _nocoops, $2),-NOCOOPS,)$(if $(filter _valhalla, $3),-VALHALLA,) 138 139 # Only G1 supports dumping the shared heap, so explicitly use G1 if the JVM supports it. 140 $1_$2_$3_CDS_DUMP_FLAGS := $(CDS_DUMP_FLAGS) $(if $(filter g1gc, $(JVM_FEATURES_$1)),-XX:+UseG1GC) 141 142 ifeq ($(OPENJDK_TARGET_OS), windows) 143 $1_$2_$3_CDS_ARCHIVE := bin/$1/classes$2$3.jsa 144 else 145 $1_$2_$3_CDS_ARCHIVE := lib/$1/classes$2$3.jsa 146 endif 147 148 $$(eval $$(call SetupExecute, $1_$2_$3_gen_cds_archive_jdk, \ 149 WARN := Creating CDS$$($1_$2_$3_DUMP_TYPE) archive for jdk image for $1, \ 150 INFO := Using CDS flags for $1: $$($1_$2_$3_CDS_DUMP_FLAGS), \ 151 DEPS := $$(jlink_jdk), \ 152 OUTPUT_FILE := $$(JDK_IMAGE_DIR)/$$($1_$2_$3_CDS_ARCHIVE), \ 153 SUPPORT_DIR := $$(JDK_IMAGE_SUPPORT_DIR), \ 154 COMMAND := $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/java -Xshare:dump \ 155 -XX:SharedArchiveFile=$$(JDK_IMAGE_DIR)/$$($1_$2_$3_CDS_ARCHIVE) \ 156 -$1 $$($1_$2_$3_DUMP_EXTRA_ARG) $$($1_$2_$3_CDS_DUMP_FLAGS) $$(LOG_INFO), \ 157 )) 158 159 JDK_TARGETS += $$($1_$2_$3_gen_cds_archive_jdk) 160 161 $$(eval $$(call SetupExecute, $1_$2_$3_gen_cds_archive_jre, \ 162 WARN := Creating CDS$$($1_$2_$3_DUMP_TYPE) archive for jre image for $1, \ 163 INFO := Using CDS flags for $1: $$($1_$2_$3_CDS_DUMP_FLAGS), \ 164 DEPS := $$(jlink_jre), \ 165 OUTPUT_FILE := $$(JRE_IMAGE_DIR)/$$($1_$2_$3_CDS_ARCHIVE), \ 166 SUPPORT_DIR := $$(JRE_IMAGE_SUPPORT_DIR), \ 167 COMMAND := $$(FIXPATH) $$(JRE_IMAGE_DIR)/bin/java -Xshare:dump \ 168 -XX:SharedArchiveFile=$$(JRE_IMAGE_DIR)/$$($1_$2_$3_CDS_ARCHIVE) \ 169 -$1 $$($1_$2_$3_DUMP_EXTRA_ARG) $$($1_$2_$3_CDS_DUMP_FLAGS) $$(LOG_INFO), \ 170 )) 171 172 JRE_TARGETS += $$($1_$2_$3_gen_cds_archive_jre) 173 endef 174 175 # TODO: add these to below when CDS & --enable-preview is well tested. 176 # $(eval $(call CreateCDSArchive,$v,,_valhalla)) 177 # $(eval $(call CreateCDSArchive,$v,_nocoops,_valhalla)) 178 179 ifeq ($(BUILD_CDS_ARCHIVE), true) 180 $(foreach v, $(JVM_VARIANTS), \ 181 $(eval $(call CreateCDSArchive,$v,,)) \ 182 ) 183 184 ifeq ($(call isTargetCpuBits, 64), true) 185 $(foreach v, $(JVM_VARIANTS), \ 186 $(eval $(call CreateCDSArchive,$v,_nocoops,)) \ 187 ) 188 endif 189 endif 190 191 ################################################################################ 192 # src.zip 193 194 $(JDK_IMAGE_DIR)/lib/src.zip: $(SUPPORT_OUTPUTDIR)/src.zip 195 $(call LogInfo, Copying $(patsubst $(OUTPUTDIR)/%,%,$@)) 196 $(install-file) 197 198 JDK_TARGETS += $(JDK_IMAGE_DIR)/lib/src.zip 199 200 ################################################################################ 201 # /demo dir 202 # Avoid doing the expensive find unless called with "jdk" as target. 203 ifneq ($(filter jdk, $(MAKECMDGOALS)), ) 204 205 DEMO_FILES := \ 206 $(if $(wildcard $(SUPPORT_OUTPUTDIR)/demos/image), \ 207 $(shell $(FIND) $(SUPPORT_OUTPUTDIR)/demos/image \ 208 -type f -a ! \( -name "_the*" -o -name "javac_state" \) ) \ 209 ) 210 211 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true) 212 ifeq ($(call isTargetOs, macosx), true) 213 DEMO_FILES := $(call not-containing, .dSYM, $(DEMO_FILES)) 214 else 215 DEMO_FILES := $(filter-out %.debuginfo %.pdb %.map, $(DEMO_FILES)) 216 endif 217 endif 218 219 $(eval $(call SetupCopyFiles, JDK_COPY_DEMOS, \ 220 SRC := $(SUPPORT_OUTPUTDIR)/demos/image, \ 221 DEST := $(JDK_IMAGE_DIR)/demo, \ 222 FILES := $(DEMO_FILES), \ 223 )) 224 225 JDK_TARGETS += $(JDK_COPY_DEMOS) 226 endif 227 228 ################################################################################ 229 # Code coverage data files 230 231 ifeq ($(GCOV_ENABLED), true) 232 233 $(eval $(call SetupCopyFiles,COPY_GCOV_GCNO, \ 234 SRC := $(OUTPUTDIR), \ 235 DEST := $(SYMBOLS_IMAGE_DIR)/gcov, \ 236 FILES := $(call FindFiles, $(HOTSPOT_OUTPUTDIR) \ 237 $(SUPPORT_OUTPUTDIR)/native, *.gcno) \ 238 )) 239 240 SYMBOLS_TARGETS += $(COPY_GCOV_GCNO) 241 242 endif 243 244 ################################################################################ 245 # Debug symbols 246 # Since debug symbols are not included in the jmod files, they need to be copied 247 # in manually after generating the images. 248 249 ALL_JDK_MODULES := $(JDK_MODULES) 250 ALL_JRE_MODULES := $(sort $(JRE_MODULES), $(foreach m, $(JRE_MODULES), \ 251 $(call FindTransitiveDepsForModule, $m))) 252 ALL_SYMBOLS_MODULES := $(JDK_MODULES) 253 254 ifeq ($(call isTargetOs, windows), true) 255 LIBS_TARGET_SUBDIR := bin 256 else 257 LIBS_TARGET_SUBDIR := lib 258 endif 259 CMDS_TARGET_SUBDIR := bin 260 261 # Param 1 - dir to find debuginfo files in 262 FindDebuginfoFiles = \ 263 $(wildcard $(addprefix $1/*, $(DEBUGINFO_SUFFIXES)) \ 264 $(addprefix $1/*/*, $(DEBUGINFO_SUFFIXES)) \ 265 $(addprefix $1/*/*/*, $(DEBUGINFO_SUFFIXES))) 266 267 # Pick the correct debug info files to copy, either zipped or not. 268 ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), true) 269 DEBUGINFO_SUFFIXES += .diz 270 else 271 DEBUGINFO_SUFFIXES := .debuginfo .pdb .map 272 # On Macosx, if debug symbols have not been zipped, find all files inside *.dSYM 273 # dirs. 274 ifeq ($(call isTargetOs, macosx), true) 275 $(call FillFindCache, \ 276 $(SUPPORT_OUTPUTDIR)/modules_libs $(SUPPORT_OUTPUTDIR)/modules_cmds) 277 FindDebuginfoFiles = \ 278 $(if $(wildcard $1), $(call containing, .dSYM/, $(call FindFiles, $1))) 279 endif 280 endif 281 282 # Param 1 - either JDK or JRE 283 SetupCopyDebuginfo = \ 284 $(foreach m, $(ALL_$1_MODULES), \ 285 $(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \ 286 SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \ 287 DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \ 288 FILES := $(call FindDebuginfoFiles, \ 289 $(SUPPORT_OUTPUTDIR)/modules_libs/$m), \ 290 )) \ 291 $(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \ 292 $(eval $(call SetupCopyFiles, COPY_$1_CMDS_DEBUGINFO_$m, \ 293 SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds/$m, \ 294 DEST := $($1_IMAGE_DIR)/$(CMDS_TARGET_SUBDIR), \ 295 FILES := $(call FindDebuginfoFiles, \ 296 $(SUPPORT_OUTPUTDIR)/modules_cmds/$m), \ 297 )) \ 298 $(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \ 299 ) 300 301 # No space before argument to avoid having to put $(strip ) everywhere in 302 # implementation above. 303 $(call SetupCopyDebuginfo,JDK) 304 $(call SetupCopyDebuginfo,JRE) 305 $(call SetupCopyDebuginfo,SYMBOLS) 306 307 ################################################################################ 308 309 # Include custom post hook here to make it possible to augment the target lists 310 # before actual target prerequisites are declared. 311 $(eval $(call IncludeCustomExtension, Images-post.gmk)) 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: default all jdk jre symbols