2
# Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
26
################################################################################
28
################################################################################
36
include JavaCompilation.gmk
38
################################################################################
39
# Create a jar with our generator class. Using a jar is intentional since it
40
# will load more classes
42
$(eval $(call SetupJavaCompilation, CLASSLIST_JAR, \
43
SMALL_JAVA := false, \
44
SRC := $(TOPDIR)/make/jdk/src/classes, \
45
INCLUDES := build/tools/classlist, \
46
DISABLED_WARNINGS := dangling-doc-comments, \
47
BIN := $(BUILDTOOLS_OUTPUTDIR)/classlist_classes, \
48
JAR := $(SUPPORT_OUTPUTDIR)/classlist.jar, \
51
TARGETS += $(CLASSLIST_JAR)
53
################################################################################
55
LINK_OPT_DIR := $(SUPPORT_OUTPUTDIR)/link_opt
56
CLASSLIST_FILE := $(LINK_OPT_DIR)/classlist
57
JLI_TRACE_FILE := $(LINK_OPT_DIR)/default_jli_trace.txt
59
# If an external buildjdk has been supplied, we don't build a separate interim
60
# image, so just use the external build jdk instead.
61
ifeq ($(EXTERNAL_BUILDJDK), true)
62
INTERIM_IMAGE_DIR := $(BUILD_JDK)
65
# To make the classlist deterministic:
66
# - The classlist can be influenced by locale. Always set it to en/US.
67
# - Concurrency in the core libraries can cause constant pool resolution
68
# to be non-deterministic. Since the benefits of resolved CP references in the
69
# default classlist is minimal, let's filter out the '@cp' lines until we can
70
# find a proper solution.
71
CLASSLIST_FILE_VM_OPTS = \
72
-Duser.language=en -Duser.country=US
74
# Save the stderr output of the command and print it along with stdout in case
75
# something goes wrong.
76
$(CLASSLIST_FILE): $(INTERIM_IMAGE_DIR)/bin/java$(EXECUTABLE_SUFFIX) $(CLASSLIST_JAR)
77
$(call MakeDir, $(LINK_OPT_DIR))
78
$(call LogInfo, Generating $(patsubst $(OUTPUTDIR)/%, %, $@))
79
$(call LogInfo, Generating $(patsubst $(OUTPUTDIR)/%, %, $(JLI_TRACE_FILE)))
80
$(FIXPATH) $(INTERIM_IMAGE_DIR)/bin/java -XX:DumpLoadedClassList=$@.raw \
81
$(CLASSLIST_FILE_VM_OPTS) \
82
-cp $(SUPPORT_OUTPUTDIR)/classlist.jar \
83
build.tools.classlist.HelloClasslist $(LOG_DEBUG)
84
$(GREP) -v HelloClasslist $@.raw > $@.interim
85
$(FIXPATH) $(INTERIM_IMAGE_DIR)/bin/java -Xshare:dump \
86
-XX:SharedClassListFile=$@.interim -XX:SharedArchiveFile=$@.jsa \
87
-Xmx128M -Xms128M $(LOG_INFO)
88
$(FIXPATH) $(INTERIM_IMAGE_DIR)/bin/java -XX:DumpLoadedClassList=$@.raw.2 \
89
-XX:SharedClassListFile=$@.interim -XX:SharedArchiveFile=$@.jsa \
90
-Djava.lang.invoke.MethodHandle.TRACE_RESOLVE=true \
91
$(CLASSLIST_FILE_VM_OPTS) \
92
--module-path $(SUPPORT_OUTPUTDIR)/classlist.jar \
93
-cp $(SUPPORT_OUTPUTDIR)/classlist.jar \
94
build.tools.classlist.HelloClasslist \
95
2> $(LINK_OPT_DIR)/stderr > $(JLI_TRACE_FILE) \
98
$(ECHO) "ERROR: Failed to generate link optimization data." \
99
"This is likely a problem with the newly built JVM/JDK." ; \
100
$(CAT) $(LINK_OPT_DIR)/stderr $(JLI_TRACE_FILE) ; \
103
$(GREP) -v HelloClasslist $@.raw.2 > $@.raw.3
104
$(GREP) -v @cp $@.raw.3 > $@.raw.4
105
$(FIXPATH) $(INTERIM_IMAGE_DIR)/bin/java \
106
-cp $(SUPPORT_OUTPUTDIR)/classlist.jar \
107
build.tools.classlist.SortClasslist $@.raw.4 > $@
109
# The jli trace is created by the same recipe as classlist. By declaring these
110
# dependencies, make will correctly rebuild both jli trace and classlist
111
# incrementally using the single recipe above.
112
$(CLASSLIST_FILE): $(JLI_TRACE_FILE)
113
$(JLI_TRACE_FILE): $(INTERIM_IMAGE_DIR)/bin/java$(EXECUTABLE_SUFFIX) $(CLASSLIST_JAR)
115
TARGETS += $(CLASSLIST_FILE) $(JLI_TRACE_FILE)
117
# Copy the classlist file into java.base libs
118
$(eval $(call SetupCopyFiles, COPY_CLASSLIST, \
119
FILES := $(CLASSLIST_FILE), \
120
DEST := $(SUPPORT_OUTPUTDIR)/modules_libs/java.base, \
123
TARGETS += $(COPY_CLASSLIST)
125
# In case of shipping public debug symbols on windows, there is another temporary
126
# location from where jmods are compiled - need to deploy classlist there, too.
127
ifeq ($(call isTargetOs, windows)+$(SHIP_DEBUG_SYMBOLS), true+public)
128
$(eval $(call SetupCopyFiles, COPY_CLASSLIST_TO_FILTERED, \
129
FILES := $(CLASSLIST_FILE), \
130
DEST := $(SUPPORT_OUTPUTDIR)/modules_libs_filtered/java.base, \
133
TARGETS += $(COPY_CLASSLIST_TO_FILTERED)
136
# Copy the default_jli_trace.txt file into jdk.jlink
137
$(eval $(call SetupCopyFiles, COPY_JLI_TRACE, \
138
FILES := $(JLI_TRACE_FILE), \
139
DEST := $(JDK_OUTPUTDIR)/modules/jdk.jlink/jdk/tools/jlink/internal/plugins, \
142
# Because of the single recipe for jli trace and classlist above, the
143
# COPY_JLI_TRACE rule needs to explicitly add the classlist file as a
145
$(COPY_JLI_TRACE): $(CLASSLIST_FILE)
147
TARGETS += $(COPY_JLI_TRACE)
149
################################################################################