make/RunTests.gmk
branchJDK-8152988-branch
changeset 56961 007ce32735e3
parent 56945 35914fe36a9c
child 56965 1cad8c4161e3
--- a/make/RunTests.gmk	Fri Oct 12 16:35:06 2018 -0700
+++ b/make/RunTests.gmk	Fri Oct 12 16:37:22 2018 -0700
@@ -45,7 +45,7 @@
 endif
 
 $(eval $(call ParseKeywordVariable, TEST_OPTS, \
-    SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR, \
+    SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR AOT_MODULES, \
     STRING_KEYWORDS := VM_OPTIONS JAVA_OPTIONS, \
 ))
 
@@ -104,6 +104,78 @@
 GTEST_VARIANTS := $(strip $(patsubst $(TEST_IMAGE_DIR)/hotspot/gtest/%, %, $(GTEST_LAUNCHER_DIRS)))
 
 ################################################################################
+# Optionally create AOT libraries for specified modules before running tests.
+################################################################################
+
+# Note, this could not be done during JDK build time.
+
+# Parameter 1 is the name of the rule.
+#
+# Remaining parameters are named arguments.
+#   MODULE      The module to generate a library for
+#   BIN         Output directory in which to put the library
+#   VM_OPTIONS  List of JVM arguments to use when creating library
+#   OPTIONS_VAR Name of variable to put AOT java options in
+#   PREREQS_VAR Name of variable to put all AOT prerequisite rule targets in
+#               for test rules to depend on
+#
+SetupAotModule = $(NamedParamsMacroTemplate)
+define SetupAotModuleBody
+  $1_AOT_LIB := $$($1_BIN)/$$(call SHARED_LIBRARY,$$($1_MODULE))
+  $1_AOT_CCLIST := $$(wildcard $$(TOPDIR)/test/hotspot/jtreg/compiler/aot/scripts/$1-list.txt)
+
+  $1_JAOTC_OPTS := \
+      -J-Xmx4g --info \
+      $$(addprefix -J, $$($1_VM_OPTIONS)) \
+      $$(addprefix --compile-commands, $$($1_AOT_CCLIST)) \
+      --linker-path $$(LD) \
+      #
+
+  $$($1_AOT_LIB): $$(JDK_IMAGE_DIR)/release \
+      $$(call DependOnVariable, $1_JAOTC_OPTS) \
+      $$(call DependOnVariable, JDK_IMAGE_DIR)
+	$$(call LogWarn, Generating $$(patsubst $$(OUTPUTDIR)/%, %, $$@))
+	$$(call MakeTargetDir)
+	$$(call ExecuteWithLog, $$@, \
+	    $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/jaotc \
+	    $$($1_JAOTC_OPTS) --output $$@ --module $$($1_MODULE) \
+	)
+	$$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/java \
+	    $$($1_JVM_OPTIONS) \
+	    -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=$$@ -version
+
+  $1_AOT_OPTIONS += -XX:AOTLibrary=$$($1_AOT_LIB)
+  $1_AOT_TARGETS += $$($1_AOT_LIB)
+endef
+
+# Parameter 1 is the name of the rule.
+#
+# Remaining parameters are named arguments.
+#   MODULES     The modules to generate a library for
+#   VM_OPTIONS  List of JVM arguments to use when creating libraries
+#
+# After calling this, the following variables are defined
+#   $1_AOT_OPTIONS List of all java options needed to use the AOT libraries
+#   $1_AOT_TARGETS List of all targets that the test rule will need to depend on
+#
+SetupAot = $(NamedParamsMacroTemplate)
+define SetupAotBody
+  ifneq ($$($1_MODULES), )
+    # Put aot libraries in a separate directory so they are not deleted between
+    # test runs and may be reused between make invocations.
+    $$(foreach m, $$($1_MODULES), \
+      $$(eval $$(call SetupAotModule, $1_$$m, \
+          MODULE := $$m, \
+          BIN := $$(TEST_SUPPORT_DIR)/aot/$1, \
+          VM_OPTIONS := $$($1_VM_OPTIONS), \
+      )) \
+      $$(eval $1_AOT_OPTIONS += $$($1_$$m_AOT_OPTIONS)) \
+      $$(eval $1_AOT_TARGETS += $$($1_$$m_AOT_TARGETS)) \
+    )
+  endif
+endef
+
+################################################################################
 # Setup global test running parameters
 ################################################################################
 
@@ -142,12 +214,15 @@
 $(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
 $(eval $(call SetTestOpt,JAVA_OPTIONS,GTEST))
 
+$(eval $(call SetTestOpt,AOT_MODULES,JTREG))
+$(eval $(call SetTestOpt,AOT_MODULES,GTEST))
+
 $(eval $(call SetTestOpt,JOBS,JTREG))
 $(eval $(call SetTestOpt,TIMEOUT_FACTOR,JTREG))
 
 $(eval $(call ParseKeywordVariable, JTREG, \
     SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR TEST_MODE ASSERT VERBOSE RETAIN MAX_MEM \
-        EXTRA_PROBLEM_LISTS KEYWORDS, \
+        EXTRA_PROBLEM_LISTS KEYWORDS AOT_MODULES, \
     STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS, \
 ))
 
@@ -157,7 +232,7 @@
 endif
 
 $(eval $(call ParseKeywordVariable, GTEST, \
-    SINGLE_KEYWORDS := REPEAT, \
+    SINGLE_KEYWORDS := REPEAT AOT_MODULES, \
     STRING_KEYWORDS := OPTIONS VM_OPTIONS JAVA_OPTIONS, \
 ))
 
@@ -387,7 +462,12 @@
     $1_GTEST_REPEAT :=--gtest_repeat=$$(GTEST_REPEAT)
   endif
 
-  run-test-$1: $(TEST_PREREQS)
+  $$(eval $$(call SetupAot, $1, \
+      MODULES := $$(GTEST_AOT_MODULES), \
+      VM_OPTIONS := $$(GTEST_VM_OPTIONS) $$(GTEST_JAVA_OPTIONS), \
+  ))
+
+  run-test-$1: $$($1_AOT_TARGETS)
 	$$(call LogWarn)
 	$$(call LogWarn, Running test '$$($1_TEST)')
 	$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
@@ -396,7 +476,7 @@
 	        -jdk $(JDK_IMAGE_DIR) $$($1_GTEST_FILTER) \
 	        --gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
 	        $$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) $$(GTEST_VM_OPTIONS) \
-	        $$($1_GTEST_JAVA_OPTIONS) \
+	        $$(GTEST_JAVA_OPTIONS) $$($1_AOT_OPTIONS) \
 	        > >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) \
 	    && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 	    || $$(ECHO) $$$$? > $$($1_EXITCODE) \
@@ -580,10 +660,15 @@
     endif
   endif
 
+  $$(eval $$(call SetupAot, $1, \
+      MODULES := $$(JTREG_AOT_MODULES), \
+      VM_OPTIONS := $$(JTREG_VM_OPTIONS) $$(JTREG_JAVA_OPTIONS), \
+  ))
+
   clean-workdir-$1:
 	$$(RM) -r $$($1_TEST_SUPPORT_DIR)
 
-  run-test-$1: clean-workdir-$1 $(TEST_PREREQS)
+  run-test-$1: clean-workdir-$1 $$($1_AOT_TARGETS)
 	$$(call LogWarn)
 	$$(call LogWarn, Running test '$$($1_TEST)')
 	$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
@@ -597,6 +682,7 @@
 	        -workDir:$$($1_TEST_SUPPORT_DIR) \
 	        $$(JTREG_OPTIONS) \
 	        $$(JTREG_FAILURE_HANDLER_OPTIONS) \
+	        $$(addprefix -vmoption:, $$($1_AOT_OPTIONS)) \
 	        $$($1_TEST_NAME) \
 	    && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 	    || $$(ECHO) $$$$? > $$($1_EXITCODE) \