diff --git a/doc/testing.html b/doc/testing.html index 37d4df604f5..0f81647ecae 100644 --- a/doc/testing.html +++ b/doc/testing.html @@ -426,6 +426,14 @@ GB/2.

Sets the argument -timeoutHandlerTimeout for JTReg. The default value is 0. This is only valid if the failure handler is built.

+

JTREG_TEST_THREAD_FACTORY

+

Sets the -testThreadFactory for JTReg. It should be the +fully qualified classname of a class which implements +java.util.concurrent.ThreadFactory. One such implementation +class, named Virtual, is currently part of the JDK build in the +test/jtreg_test_thread_factory/ directory. This class gets +compiled during the test image build. The implementation of the Virtual +class creates a new virtual thread for executing each test class.

TEST_MODE

The test mode (agentvm or othervm).

Defaults to agentvm.

diff --git a/doc/testing.md b/doc/testing.md index 3de0c26c391..764fec15c8d 100644 --- a/doc/testing.md +++ b/doc/testing.md @@ -378,6 +378,15 @@ Defaults to 4. Sets the argument `-timeoutHandlerTimeout` for JTReg. The default value is 0. This is only valid if the failure handler is built. +#### JTREG_TEST_THREAD_FACTORY + +Sets the `-testThreadFactory` for JTReg. It should be the fully qualified classname +of a class which implements `java.util.concurrent.ThreadFactory`. +One such implementation class, named Virtual, is currently part of the JDK build +in the `test/jtreg_test_thread_factory/` directory. This class gets compiled during +the test image build. The implementation of the Virtual class creates a new virtual +thread for executing each test class. + #### TEST_MODE The test mode (`agentvm` or `othervm`). diff --git a/make/Main.gmk b/make/Main.gmk index 3c7c30caba7..5f647c963b0 100644 --- a/make/Main.gmk +++ b/make/Main.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -747,6 +747,22 @@ ifeq ($(BUILD_FAILURE_HANDLER), true) )) endif +ifeq ($(BUILD_JTREG_TEST_THREAD_FACTORY), true) + # Builds the test thread factory jtreg extension + $(eval $(call SetupTarget, build-test-test-thread-factory, \ + MAKEFILE := test/BuildJtregTestThreadFactory, \ + TARGET := build, \ + DEPS := interim-langtools exploded-image, \ + )) + + # Copies the jtreg test thread factory into the test image + $(eval $(call SetupTarget, test-image-test-thread-factory, \ + MAKEFILE := test/BuildJtregTestThreadFactory, \ + TARGET := images, \ + DEPS := build-test-test-thread-factory, \ + )) +endif + $(eval $(call SetupTarget, build-microbenchmark, \ MAKEFILE := test/BuildMicrobenchmark, \ DEPS := interim-langtools exploded-image, \ @@ -1227,6 +1243,10 @@ ifeq ($(BUILD_FAILURE_HANDLER), true) test-image: test-image-failure-handler endif +ifeq ($(BUILD_JTREG_TEST_THREAD_FACTORY), true) + test-image: test-image-test-thread-factory +endif + ifneq ($(JMH_CORE_JAR), ) test-image: build-microbenchmark endif diff --git a/make/RunTests.gmk b/make/RunTests.gmk index 50342077645..aba7b3a78f6 100644 --- a/make/RunTests.gmk +++ b/make/RunTests.gmk @@ -93,6 +93,9 @@ endif JTREG_FAILURE_HANDLER_DIR := $(TEST_IMAGE_DIR)/failure_handler JTREG_FAILURE_HANDLER := $(JTREG_FAILURE_HANDLER_DIR)/jtregFailureHandler.jar +JTREG_TEST_THREAD_FACTORY_DIR := $(TEST_IMAGE_DIR)/jtreg_test_thread_factory +JTREG_TEST_THREAD_FACTORY_JAR := $(JTREG_TEST_THREAD_FACTORY_DIR)/jtregTestThreadFactory.jar + JTREG_FAILURE_HANDLER_TIMEOUT ?= 0 ifneq ($(wildcard $(JTREG_FAILURE_HANDLER)), ) @@ -200,7 +203,7 @@ $(eval $(call SetTestOpt,REPORT,JTREG)) $(eval $(call ParseKeywordVariable, JTREG, \ SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR FAILURE_HANDLER_TIMEOUT \ - TEST_MODE ASSERT VERBOSE RETAIN MAX_MEM RUN_PROBLEM_LISTS \ + TEST_MODE ASSERT VERBOSE RETAIN TEST_THREAD_FACTORY MAX_MEM RUN_PROBLEM_LISTS \ RETRY_COUNT REPEAT_COUNT MAX_OUTPUT REPORT $(CUSTOM_JTREG_SINGLE_KEYWORDS), \ STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS KEYWORDS \ EXTRA_PROBLEM_LISTS LAUNCHER_OPTIONS \ @@ -752,6 +755,7 @@ define SetupRunJtregTestBody JTREG_VERBOSE ?= fail,error,summary JTREG_RETAIN ?= fail,error + JTREG_TEST_THREAD_FACTORY ?= JTREG_RUN_PROBLEM_LISTS ?= false JTREG_RETRY_COUNT ?= 0 JTREG_REPEAT_COUNT ?= 0 @@ -765,6 +769,14 @@ define SetupRunJtregTestBody endif endif + ifneq ($$(JTREG_TEST_THREAD_FACTORY), ) + $1_JTREG_BASIC_OPTIONS += -testThreadFactoryPath:$$(JTREG_TEST_THREAD_FACTORY_JAR) + $1_JTREG_BASIC_OPTIONS += -testThreadFactory:$$(JTREG_TEST_THREAD_FACTORY) + $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \ + $$(addprefix $$($1_TEST_ROOT)/, ProblemList-$$(JTREG_TEST_THREAD_FACTORY).txt) \ + )) + endif + ifneq ($$(JTREG_LAUNCHER_OPTIONS), ) $1_JTREG_LAUNCHER_OPTIONS += $$(JTREG_LAUNCHER_OPTIONS) endif diff --git a/make/autoconf/configure.ac b/make/autoconf/configure.ac index 5d48bd9aadd..2d6cb000d43 100644 --- a/make/autoconf/configure.ac +++ b/make/autoconf/configure.ac @@ -249,6 +249,7 @@ HOTSPOT_SETUP_MISC ############################################################################### LIB_TESTS_ENABLE_DISABLE_FAILURE_HANDLER +LIB_TESTS_ENABLE_DISABLE_JTREG_TEST_THREAD_FACTORY JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST JDKOPT_EXCLUDE_TRANSLATIONS diff --git a/make/autoconf/lib-tests.m4 b/make/autoconf/lib-tests.m4 index 4d771f7e5f2..6af9045a136 100644 --- a/make/autoconf/lib-tests.m4 +++ b/make/autoconf/lib-tests.m4 @@ -301,3 +301,22 @@ AC_DEFUN_ONCE([LIB_TESTS_ENABLE_DISABLE_FAILURE_HANDLER], ]) AC_SUBST(BUILD_FAILURE_HANDLER) ]) + +AC_DEFUN_ONCE([LIB_TESTS_ENABLE_DISABLE_JTREG_TEST_THREAD_FACTORY], +[ + UTIL_ARG_ENABLE(NAME: jtreg-test-thread-factory, DEFAULT: auto, + RESULT: BUILD_JTREG_TEST_THREAD_FACTORY, + DESC: [enable building of the jtreg test thread factory], + DEFAULT_DESC: [enabled if jtreg is present], + CHECKING_MSG: [if the jtreg test thread factory should be built], + CHECK_AVAILABLE: [ + AC_MSG_CHECKING([if the jtreg test thread factory is available]) + if test "x$JT_HOME" != "x"; then + AC_MSG_RESULT([yes]) + else + AVAILABLE=false + AC_MSG_RESULT([no (jtreg not present)]) + fi + ]) + AC_SUBST(BUILD_JTREG_TEST_THREAD_FACTORY) +]) diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in index ff073c78c92..550c196ed89 100644 --- a/make/autoconf/spec.gmk.in +++ b/make/autoconf/spec.gmk.in @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -358,6 +358,8 @@ BUILDJDK_OUTPUTDIR=$(OUTPUTDIR)/buildjdk BUILD_FAILURE_HANDLER := @BUILD_FAILURE_HANDLER@ +BUILD_JTREG_TEST_THREAD_FACTORY := @BUILD_JTREG_TEST_THREAD_FACTORY@ + ENABLE_GENERATE_CLASSLIST := @ENABLE_GENERATE_CLASSLIST@ EXCLUDE_TRANSLATIONS := @EXCLUDE_TRANSLATIONS@ diff --git a/make/test/BuildJtregTestThreadFactory.gmk b/make/test/BuildJtregTestThreadFactory.gmk new file mode 100644 index 00000000000..b096ae303ea --- /dev/null +++ b/make/test/BuildJtregTestThreadFactory.gmk @@ -0,0 +1,65 @@ +# +# Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +default: build + +include $(SPEC) +include MakeBase.gmk +include JavaCompilation.gmk + +TARGETS := + +################################################################################ + +TTF_BASEDIR := $(TOPDIR)/test/jtreg_test_thread_factory +TTF_SUPPORT := $(SUPPORT_OUTPUTDIR)/test/jtreg_test_thread_factory +TTF_JAR := $(TTF_SUPPORT)/jtregTestThreadFactory.jar + +$(eval $(call SetupJavaCompilation, BUILD_JTREG_TEST_THREAD_FACTORY, \ + TARGET_RELEASE := $(TARGET_RELEASE_NEWJDK_UPGRADED), \ + SRC := $(TTF_BASEDIR)/src/share/classes, \ + BIN := $(TTF_SUPPORT)/classes, \ + JAR := $(TTF_JAR), \ +)) + +TARGETS += $(BUILD_JTREG_TEST_THREAD_FACTORY) + +################################################################################ +# Targets for building test-image. +################################################################################ + +# Copy to hotspot jtreg test image +$(eval $(call SetupCopyFiles, COPY_TTF, \ + SRC := $(TTF_SUPPORT), \ + DEST := $(TEST_IMAGE_DIR)/jtreg_test_thread_factory, \ + FILES := $(TTF_JAR), \ +)) + +IMAGES_TARGETS += $(COPY_TTF) + +build: $(TARGETS) +images: $(IMAGES_TARGETS) + +.PHONY: all images diff --git a/test/jtreg_test_thread_factory/src/share/classes/Virtual.java b/test/jtreg_test_thread_factory/src/share/classes/Virtual.java new file mode 100644 index 00000000000..80b0b59fa1a --- /dev/null +++ b/test/jtreg_test_thread_factory/src/share/classes/Virtual.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.util.concurrent.ThreadFactory; + +public class Virtual implements ThreadFactory { + + static { + // This property is used by ProcessTools and some tests + try { + System.setProperty("main.wrapper", "Virtual"); + } catch (Throwable t) { + // might be thrown by security manager + } + } + + static final ThreadFactory VIRTUAL_TF = Thread.ofVirtual().factory(); + + @Override + public Thread newThread(Runnable task) { + return VIRTUAL_TF.newThread(task); + } +}