8303703: Add support of execution tests using virtual thread factory jtreg plugin

Reviewed-by: erikj, jpai
This commit is contained in:
Leonid Mesnik 2023-04-21 13:31:45 +00:00
parent 5a00617b1b
commit be6031b87d
9 changed files with 182 additions and 3 deletions

View File

@ -426,6 +426,14 @@ GB/2</em>.</p>
<p>Sets the argument <code>-timeoutHandlerTimeout</code> for JTReg. The
default value is 0. This is only valid if the failure handler is
built.</p>
<h4 id="jtreg_test_thread_factory">JTREG_TEST_THREAD_FACTORY</h4>
<p>Sets the <code>-testThreadFactory</code> for JTReg. It should be the
fully qualified classname of a class which implements
<code>java.util.concurrent.ThreadFactory</code>. One such implementation
class, named Virtual, is currently part of the JDK build in the
<code>test/jtreg_test_thread_factory/</code> 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.</p>
<h4 id="test_mode">TEST_MODE</h4>
<p>The test mode (<code>agentvm</code> or <code>othervm</code>).</p>
<p>Defaults to <code>agentvm</code>.</p>

View File

@ -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`).

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)
])

View File

@ -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@

View File

@ -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

View File

@ -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);
}
}