@@ -45,7 +45,7 @@ ifneq ($(TEST_VM_OPTS), )
4545endif
4646
4747$(eval $(call ParseKeywordVariable, TEST_OPTS, \
48- SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR JCOV JCOV_DIFF_CHANGESET, \
48+ SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR JCOV JCOV_DIFF_CHANGESET AOT_JDK , \
4949 STRING_KEYWORDS := VM_OPTIONS JAVA_OPTIONS, \
5050))
5151
@@ -202,11 +202,12 @@ $(eval $(call SetTestOpt,JOBS,JTREG))
202202$(eval $(call SetTestOpt,TIMEOUT_FACTOR,JTREG))
203203$(eval $(call SetTestOpt,FAILURE_HANDLER_TIMEOUT,JTREG))
204204$(eval $(call SetTestOpt,REPORT,JTREG))
205+ $(eval $(call SetTestOpt,AOT_JDK,JTREG))
205206
206207$(eval $(call ParseKeywordVariable, JTREG, \
207208 SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR FAILURE_HANDLER_TIMEOUT \
208209 TEST_MODE ASSERT VERBOSE RETAIN TEST_THREAD_FACTORY MAX_MEM RUN_PROBLEM_LISTS \
209- RETRY_COUNT REPEAT_COUNT MAX_OUTPUT REPORT $(CUSTOM_JTREG_SINGLE_KEYWORDS), \
210+ RETRY_COUNT REPEAT_COUNT MAX_OUTPUT REPORT AOT_JDK $(CUSTOM_JTREG_SINGLE_KEYWORDS), \
210211 STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS KEYWORDS \
211212 EXTRA_PROBLEM_LISTS LAUNCHER_OPTIONS \
212213 $(CUSTOM_JTREG_STRING_KEYWORDS), \
@@ -702,6 +703,58 @@ define SetJtregValue
702703 endif
703704endef
704705
706+
707+ # Parameter 1 is the name of the rule.
708+ #
709+ # Remaining parameters are named arguments.
710+ # VM_OPTIONS List of JVM arguments to use when creating AOT cache
711+ #
712+ # After calling this, the following variables are defined
713+ # $1_AOT_TARGETS List of all targets that the test rule will need to depend on
714+ # $1_AOT_JDK_CACHE The AOT cache file to be used to run the test with
715+ #
716+ SetupAot = $(NamedParamsMacroTemplate)
717+ define SetupAotBody
718+ $1_AOT_JDK_CONF := $$($1_TEST_SUPPORT_DIR)/aot/jdk.aotconf
719+ $1_AOT_JDK_CACHE := $$($1_TEST_SUPPORT_DIR)/aot/jdk.aotcache
720+
721+ $1_JAVA_TOOL_OPTS := $$(addprefix -J, $$($1_VM_OPTIONS))
722+
723+ $$($1_AOT_JDK_CACHE): $$(JDK_IMAGE_DIR)/release
724+ $$(call MakeDir, $$($1_TEST_SUPPORT_DIR)/aot)
725+
726+ $(foreach jtool, javac javap jlink jar, \
727+ $(info AOT: Create cache configuration for $(jtool)) \
728+ $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/aot.$(jtool), ( \
729+ $$(FIXPATH) $(JDK_UNDER_TEST)/bin/$(jtool) $$($1_JAVA_TOOL_OPTS) \
730+ -J-XX:AOTMode=record -J-XX:AOTConfiguration=$$($1_AOT_JDK_CONF).$(jtool) --help \
731+ ))
732+ )
733+
734+ $$(info AOT: Copy $(JDK_UNDER_TEST)/lib/classlist to $$($1_AOT_JDK_CONF).jdk )
735+ $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/aot, ( \
736+ $$(FIXPATH) $(CP) $(JDK_UNDER_TEST)/lib/classlist $$($1_AOT_JDK_CONF).jdk \
737+ ))
738+
739+ $$(FIXPATH) $$(CAT) $$($1_AOT_JDK_CONF).* > $$($1_AOT_JDK_CONF).temp
740+ $$(FIXPATH) $$(CAT) $$($1_AOT_JDK_CONF).temp | $(GREP) -v '#' | $(GREP) -v '@' | $(SORT) | \
741+ $(SED) -e 's/id:.*//g' | uniq \
742+ > $$($1_AOT_JDK_CONF)
743+ $$(FIXPATH) $$(CAT) $$($1_AOT_JDK_CONF).temp | $(GREP) '@cp' | $(SORT) \
744+ >> $$($1_AOT_JDK_CONF)
745+
746+ $$(info AOT: Generate AOT cache $$($1_AOT_JDK_CACHE) with flags: $$($1_VM_OPTIONS))
747+ $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/aot, ( \
748+ $$(FIXPATH) $(JDK_UNDER_TEST)/bin/java \
749+ $$($1_VM_OPTIONS) -Xlog:cds,cds+class=debug:file=$$($1_AOT_JDK_CACHE).log \
750+ -XX:AOTMode=create -XX:AOTConfiguration=$$($1_AOT_JDK_CONF) -XX:AOTCache=$$($1_AOT_JDK_CACHE) \
751+ ))
752+
753+ $1_AOT_TARGETS += $$($1_AOT_JDK_CACHE)
754+
755+ endef
756+
757+
705758SetupRunJtregTest = $(NamedParamsMacroTemplate)
706759define SetupRunJtregTestBody
707760 $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
@@ -762,6 +815,7 @@ define SetupRunJtregTestBody
762815 JTREG_RETRY_COUNT ?= 0
763816 JTREG_REPEAT_COUNT ?= 0
764817 JTREG_REPORT ?= files
818+ JTREG_AOT_JDK ?= false
765819
766820 ifneq ($$(JTREG_RETRY_COUNT), 0)
767821 ifneq ($$(JTREG_REPEAT_COUNT), 0)
@@ -891,6 +945,17 @@ define SetupRunJtregTestBody
891945 endif
892946 endif
893947
948+ ifeq ($$(JTREG_AOT_JDK), true)
949+ $$(info Add AOT target for $1)
950+ $$(eval $$(call SetupAot, $1, VM_OPTIONS := $$(JTREG_ALL_OPTIONS) ))
951+
952+ $$(info AOT_TARGETS=$$($1_AOT_TARGETS))
953+ $$(info AOT_JDK_CACHE=$$($1_AOT_JDK_CACHE))
954+
955+ $1_JTREG_BASIC_OPTIONS += -vmoption:-XX:AOTCache="$$($1_AOT_JDK_CACHE)"
956+ endif
957+
958+
894959 $$(eval $$(call SetupRunJtregTestCustom, $1))
895960
896961 # SetupRunJtregTestCustom might also adjust JTREG_AUTO_ variables
@@ -906,6 +971,7 @@ define SetupRunJtregTestBody
906971 JTREG_TIMEOUT_FACTOR ?= $$(JTREG_AUTO_TIMEOUT_FACTOR)
907972
908973 clean-outputdirs-$1:
974+ $$(call LogWarn, Clean up dirs for $1)
909975 $$(RM) -r $$($1_TEST_SUPPORT_DIR)
910976 $$(RM) -r $$($1_TEST_RESULTS_DIR)
911977
@@ -953,7 +1019,7 @@ define SetupRunJtregTestBody
9531019 done
9541020 endif
9551021
956- run-test-$1: pre-run-test clean-outputdirs-$1
1022+ run-test-$1: clean-outputdirs-$1 pre-run-test $$($1_AOT_TARGETS)
9571023 $$(call LogWarn)
9581024 $$(call LogWarn, Running test '$$($1_TEST)')
9591025 $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR) \
0 commit comments