Initial stab at implementing AOT support for run-test JDK-8152988-branch
authorerikj
Fri, 12 Oct 2018 16:37:22 -0700
branchJDK-8152988-branch
changeset 56961 007ce32735e3
parent 56960 02bf89d7a9cb
child 56965 1cad8c4161e3
Initial stab at implementing AOT support for run-test
make/RunTests.gmk
make/RunTestsPrebuilt.gmk
make/RunTestsPrebuiltSpec.gmk
make/conf/jib-profiles.js
--- 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) \
--- a/make/RunTestsPrebuilt.gmk	Fri Oct 12 16:35:06 2018 -0700
+++ b/make/RunTestsPrebuilt.gmk	Fri Oct 12 16:37:22 2018 -0700
@@ -95,12 +95,12 @@
 # $1: The output file name
 # $2..$N: The lines to output to the file
 define CreateNewSpec
-  $(if $(strip $(26)), \
+  $(if $(strip $(29)), \
     $(error Internal makefile error: \
       Too many arguments to macro, please update CreateNewSpec in RunTestsPrebuilt.gmk) \
   ) \
   $(shell $(RM) $1) \
-  $(foreach i, $(call sequence, 2, 25), \
+  $(foreach i, $(call sequence, 2, 28), \
     $(if $(strip $($i)), \
       $(call AppendFile, $(strip $($i)), $1) \
     ) \
@@ -235,6 +235,30 @@
   NUM_CORES := 1
 endif
 
+# Setup LD for AOT support
+ifneq ($(DEVKIT_HOME), )
+  ifeq ($(OPENJDK_TARGET_OS), windows)
+    LD := $(DEVKIT_HOME)/VC/bin/x64/link
+    LIBRARY_PREFIX :=
+    SHARED_LIBRARY_SUFFIX := .dll
+  else ifeq ($(OPENJDK_TARGET_OS), linux)
+    LD := $(DEVKIT_HOME)/bin/ld
+    LIBRARY_PREFIX := lib
+    SHARED_LIBRARY_SUFFIX := .so
+  else ifeq ($(OPENJDK_TARGET_OS), macosx)
+    LD := $(DEVKIT_HOME)/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
+    LIBRARY_PREFIX := lib
+    SHARED_LIBRARY_SUFFIX := .dylib
+  else ifeq ($(OPENJDK_TARGET_OS), solaris)
+    # Prefer system linker for AOT on Solaris.
+    LD := ld
+    LIBRARY_PREFIX := lib
+    SHARED_LIBRARY_SUFFIX := .so
+  endif
+else
+  LD := ld
+endif
+
 ################################################################################
 # Generate the ephemeral spec file
 ################################################################################
@@ -270,6 +294,9 @@
     OPENJDK_TARGET_CPU_BITS := $(OPENJDK_TARGET_CPU_BITS), \
     OPENJDK_TARGET_CPU_ENDIAN := $(OPENJDK_TARGET_CPU_ENDIAN), \
     NUM_CORES := $(NUM_CORES), \
+    LD := $(LD), \
+    LIBRARY_PREFIX := $(LIBRARY_PREFIX), \
+    SHARED_LIBRARY_SUFFIX := $(SHARED_LIBRARY_SUFFIX), \
     include $(TOPDIR)/make/RunTestsPrebuiltSpec.gmk, \
     $(CUSTOM_NEW_SPEC_LINE), \
 )
--- a/make/RunTestsPrebuiltSpec.gmk	Fri Oct 12 16:35:06 2018 -0700
+++ b/make/RunTestsPrebuiltSpec.gmk	Fri Oct 12 16:37:22 2018 -0700
@@ -182,3 +182,7 @@
   SED := gsed
   TAR := gtar
 endif
+
+################################################################################
+# Simple macros from spec.gmk.in
+SHARED_LIBRARY=$(LIBRARY_PREFIX)$1$(SHARED_LIBRARY_SUFFIX)
--- a/make/conf/jib-profiles.js	Fri Oct 12 16:35:06 2018 -0700
+++ b/make/conf/jib-profiles.js	Fri Oct 12 16:37:22 2018 -0700
@@ -755,7 +755,8 @@
         "run-test-prebuilt": {
             target_os: input.build_os,
             target_cpu: input.build_cpu,
-            dependencies: [ "jtreg", "gnumake", "boot_jdk", "jib", testedProfile + ".jdk",
+            dependencies: [
+                "jtreg", "gnumake", "boot_jdk", "devkit", "jib", testedProfile + ".jdk",
                 testedProfile + ".test"
             ],
             src: "src.conf",
@@ -789,7 +790,6 @@
     // This gives us a guaranteed working version of lldb for the jtreg failure handler.
     if (input.build_os == "macosx") {
         macosxRunTestExtra = {
-            dependencies: [ "devkit" ],
             environment_path: input.get("devkit", "install_path")
                 + "/Xcode.app/Contents/Developer/usr/bin"
         };
@@ -890,7 +890,10 @@
             organization: common.organization,
             ext: "tar.gz",
             module: "devkit-" + devkit_platform,
-            revision: devkit_platform_revisions[devkit_platform]
+            revision: devkit_platform_revisions[devkit_platform],
+            environment: {
+                "DEVKIT_HOME": input.get("devkit", "home_path"),
+            }
         },
 
         build_devkit: {
@@ -991,14 +994,6 @@
         },
     };
 
-    // Need to add a value for the Visual Studio tools variable to make
-    // jaot be able to pick up the Visual Studio linker in testing.
-    if (input.target_os == "windows") {
-        dependencies.devkit.environment = {
-            VS120COMNTOOLS: input.get("devkit", "install_path") + "/Common7/Tools"
-        };
-    }
-
     return dependencies;
 };