@@ -703,6 +703,9 @@ define SetJtregValue
703703 endif
704704endef
705705
706+ ################################################################################
707+ # Helper function for creating a customized AOT cache for running tests
708+ ################################################################################
706709
707710# Parameter 1 is the name of the rule.
708711#
@@ -713,48 +716,47 @@ endef
713716# $1_AOT_TARGETS List of all targets that the test rule will need to depend on
714717# $1_AOT_JDK_CACHE The AOT cache file to be used to run the test with
715718#
716- SetupAot = $(NamedParamsMacroTemplate)
717- define SetupAotBody
718- $1_AOT_JDK_CONF := $$($1_TEST_SUPPORT_DIR)/aot/jdk.aotconf
719+ SetupAOT = $(NamedParamsMacroTemplate)
720+ define SetupAOTBody
721+ $1_AOT_JDK_CONF := $$($1_TEST_SUPPORT_DIR)/aot/jdk.aotconf
719722 $1_AOT_JDK_CACHE := $$($1_TEST_SUPPORT_DIR)/aot/jdk.aotcache
720-
721- $1_JAVA_TOOL_OPTS := $$(addprefix -J, $$($1_VM_OPTIONS))
723+ $1_AOT_JDK_LOG := $$($1_TEST_SUPPORT_DIR)/aot/TestSetupAOT.log
724+
725+ # We execute the training run with $(TEST_IMAGE_DIR)/setup_aot/TestSetupAOT.class
726+ # to touch a fair number of classes inside the JDK. Note that we can't specify a classpath,
727+ # or else the AOT cache cannot be used with jtreg test cases that use a different value
728+ # for their classpaths. Instead, we run in the $(TEST_IMAGE_DIR)/setup_aot/ directory.
729+ # The "java" launcher will have an implicit classpath of ".", so it can pick up the TestSetupAOT
730+ # class from the JVM's current directory.
731+ #
732+ # The TestSetupAOT class (or any other classes that are loaded from ".") will be excluded
733+ # from the the AOT cache as "." is an unsupported location. As a result, the AOT cache will contain
734+ # only classes from the JDK.
722735
723736 $$($1_AOT_JDK_CACHE): $$(JDK_IMAGE_DIR)/release
724737 $$(call MakeDir, $$($1_TEST_SUPPORT_DIR)/aot)
725738
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 )
739+ $$(call LogWarn, AOT: Create cache configuration) \
735740 $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/aot, ( \
736- $$(FIXPATH) $(CP) $(JDK_UNDER_TEST)/lib/classlist $$($1_AOT_JDK_CONF).jdk \
741+ $(CD) $(TEST_IMAGE_DIR)/setup_aot; \
742+ $$(FIXPATH) $(JDK_UNDER_TEST)/bin/java $$($1_VM_OPTIONS) \
743+ -Xlog:cds,cds+class=debug:file=$$($1_AOT_JDK_CONF).log -Xlog:cds*=error \
744+ -XX:AOTMode=record -XX:AOTConfiguration=$$($1_AOT_JDK_CONF) \
745+ TestSetupAOT > $$($1_AOT_JDK_LOG) \
737746 ))
738747
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))
748+ $$(call LogWarn, AOT: Generate AOT cache $$($1_AOT_JDK_CACHE) with flags: $$($1_VM_OPTIONS))
747749 $$(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) \
750+ $$(FIXPATH) $(JDK_UNDER_TEST)/bin/java \
751+ $$($1_VM_OPTIONS) -Xlog:cds,cds+class=debug:file=$$($1_AOT_JDK_CACHE).log -Xlog:cds*=error \
752+ -XX:ExtraSharedClassListFile=$(JDK_UNDER_TEST)/lib/classlist \
753+ -XX:AOTMode=create -XX:AOTConfiguration=$$($1_AOT_JDK_CONF) -XX:AOTCache=$$($1_AOT_JDK_CACHE) \
751754 ))
752755
753756 $1_AOT_TARGETS += $$($1_AOT_JDK_CACHE)
754757
755758endef
756759
757-
758760SetupRunJtregTest = $(NamedParamsMacroTemplate)
759761define SetupRunJtregTestBody
760762 $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
@@ -946,11 +948,10 @@ define SetupRunJtregTestBody
946948 endif
947949
948950 ifeq ($$(JTREG_AOT_JDK), true)
949- $$(info Add AOT target for $1)
950- $$(eval $$(call SetupAot , $1, VM_OPTIONS := $$(JTREG_ALL_OPTIONS) ))
951+ $$(call LogWarn, Add AOT target for $1)
952+ $$(eval $$(call SetupAOT , $1, VM_OPTIONS := $$(JTREG_ALL_OPTIONS) ))
951953
952- $$(info AOT_TARGETS=$$($1_AOT_TARGETS))
953- $$(info AOT_JDK_CACHE=$$($1_AOT_JDK_CACHE))
954+ $$(call LogWarn, AOT_JDK_CACHE=$$($1_AOT_JDK_CACHE))
954955
955956 $1_JTREG_BASIC_OPTIONS += -vmoption:-XX:AOTCache="$$($1_AOT_JDK_CACHE)"
956957 endif
0 commit comments