Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk21 Public archive

Commit be6031b

Browse files
committed
8303703: Add support of execution tests using virtual thread factory jtreg plugin
Reviewed-by: erikj, jpai
1 parent 5a00617 commit be6031b

File tree

9 files changed

+182
-3
lines changed

9 files changed

+182
-3
lines changed

doc/testing.html

+8
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,14 @@ <h4 id="failure_handler_timeout">FAILURE_HANDLER_TIMEOUT</h4>
426426
<p>Sets the argument <code>-timeoutHandlerTimeout</code> for JTReg. The
427427
default value is 0. This is only valid if the failure handler is
428428
built.</p>
429+
<h4 id="jtreg_test_thread_factory">JTREG_TEST_THREAD_FACTORY</h4>
430+
<p>Sets the <code>-testThreadFactory</code> for JTReg. It should be the
431+
fully qualified classname of a class which implements
432+
<code>java.util.concurrent.ThreadFactory</code>. One such implementation
433+
class, named Virtual, is currently part of the JDK build in the
434+
<code>test/jtreg_test_thread_factory/</code> directory. This class gets
435+
compiled during the test image build. The implementation of the Virtual
436+
class creates a new virtual thread for executing each test class.</p>
429437
<h4 id="test_mode">TEST_MODE</h4>
430438
<p>The test mode (<code>agentvm</code> or <code>othervm</code>).</p>
431439
<p>Defaults to <code>agentvm</code>.</p>

doc/testing.md

+9
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,15 @@ Defaults to 4.
378378
Sets the argument `-timeoutHandlerTimeout` for JTReg. The default value is 0.
379379
This is only valid if the failure handler is built.
380380

381+
#### JTREG_TEST_THREAD_FACTORY
382+
383+
Sets the `-testThreadFactory` for JTReg. It should be the fully qualified classname
384+
of a class which implements `java.util.concurrent.ThreadFactory`.
385+
One such implementation class, named Virtual, is currently part of the JDK build
386+
in the `test/jtreg_test_thread_factory/` directory. This class gets compiled during
387+
the test image build. The implementation of the Virtual class creates a new virtual
388+
thread for executing each test class.
389+
381390
#### TEST_MODE
382391

383392
The test mode (`agentvm` or `othervm`).

make/Main.gmk

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -747,6 +747,22 @@ ifeq ($(BUILD_FAILURE_HANDLER), true)
747747
))
748748
endif
749749

750+
ifeq ($(BUILD_JTREG_TEST_THREAD_FACTORY), true)
751+
# Builds the test thread factory jtreg extension
752+
$(eval $(call SetupTarget, build-test-test-thread-factory, \
753+
MAKEFILE := test/BuildJtregTestThreadFactory, \
754+
TARGET := build, \
755+
DEPS := interim-langtools exploded-image, \
756+
))
757+
758+
# Copies the jtreg test thread factory into the test image
759+
$(eval $(call SetupTarget, test-image-test-thread-factory, \
760+
MAKEFILE := test/BuildJtregTestThreadFactory, \
761+
TARGET := images, \
762+
DEPS := build-test-test-thread-factory, \
763+
))
764+
endif
765+
750766
$(eval $(call SetupTarget, build-microbenchmark, \
751767
MAKEFILE := test/BuildMicrobenchmark, \
752768
DEPS := interim-langtools exploded-image, \
@@ -1227,6 +1243,10 @@ ifeq ($(BUILD_FAILURE_HANDLER), true)
12271243
test-image: test-image-failure-handler
12281244
endif
12291245

1246+
ifeq ($(BUILD_JTREG_TEST_THREAD_FACTORY), true)
1247+
test-image: test-image-test-thread-factory
1248+
endif
1249+
12301250
ifneq ($(JMH_CORE_JAR), )
12311251
test-image: build-microbenchmark
12321252
endif

make/RunTests.gmk

+13-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ endif
9393
JTREG_FAILURE_HANDLER_DIR := $(TEST_IMAGE_DIR)/failure_handler
9494
JTREG_FAILURE_HANDLER := $(JTREG_FAILURE_HANDLER_DIR)/jtregFailureHandler.jar
9595

96+
JTREG_TEST_THREAD_FACTORY_DIR := $(TEST_IMAGE_DIR)/jtreg_test_thread_factory
97+
JTREG_TEST_THREAD_FACTORY_JAR := $(JTREG_TEST_THREAD_FACTORY_DIR)/jtregTestThreadFactory.jar
98+
9699
JTREG_FAILURE_HANDLER_TIMEOUT ?= 0
97100

98101
ifneq ($(wildcard $(JTREG_FAILURE_HANDLER)), )
@@ -200,7 +203,7 @@ $(eval $(call SetTestOpt,REPORT,JTREG))
200203

201204
$(eval $(call ParseKeywordVariable, JTREG, \
202205
SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR FAILURE_HANDLER_TIMEOUT \
203-
TEST_MODE ASSERT VERBOSE RETAIN MAX_MEM RUN_PROBLEM_LISTS \
206+
TEST_MODE ASSERT VERBOSE RETAIN TEST_THREAD_FACTORY MAX_MEM RUN_PROBLEM_LISTS \
204207
RETRY_COUNT REPEAT_COUNT MAX_OUTPUT REPORT $(CUSTOM_JTREG_SINGLE_KEYWORDS), \
205208
STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS KEYWORDS \
206209
EXTRA_PROBLEM_LISTS LAUNCHER_OPTIONS \
@@ -752,6 +755,7 @@ define SetupRunJtregTestBody
752755

753756
JTREG_VERBOSE ?= fail,error,summary
754757
JTREG_RETAIN ?= fail,error
758+
JTREG_TEST_THREAD_FACTORY ?=
755759
JTREG_RUN_PROBLEM_LISTS ?= false
756760
JTREG_RETRY_COUNT ?= 0
757761
JTREG_REPEAT_COUNT ?= 0
@@ -765,6 +769,14 @@ define SetupRunJtregTestBody
765769
endif
766770
endif
767771

772+
ifneq ($$(JTREG_TEST_THREAD_FACTORY), )
773+
$1_JTREG_BASIC_OPTIONS += -testThreadFactoryPath:$$(JTREG_TEST_THREAD_FACTORY_JAR)
774+
$1_JTREG_BASIC_OPTIONS += -testThreadFactory:$$(JTREG_TEST_THREAD_FACTORY)
775+
$1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
776+
$$(addprefix $$($1_TEST_ROOT)/, ProblemList-$$(JTREG_TEST_THREAD_FACTORY).txt) \
777+
))
778+
endif
779+
768780
ifneq ($$(JTREG_LAUNCHER_OPTIONS), )
769781
$1_JTREG_LAUNCHER_OPTIONS += $$(JTREG_LAUNCHER_OPTIONS)
770782
endif

make/autoconf/configure.ac

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ HOTSPOT_SETUP_MISC
249249
###############################################################################
250250

251251
LIB_TESTS_ENABLE_DISABLE_FAILURE_HANDLER
252+
LIB_TESTS_ENABLE_DISABLE_JTREG_TEST_THREAD_FACTORY
252253

253254
JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST
254255
JDKOPT_EXCLUDE_TRANSLATIONS

make/autoconf/lib-tests.m4

+19
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,22 @@ AC_DEFUN_ONCE([LIB_TESTS_ENABLE_DISABLE_FAILURE_HANDLER],
301301
])
302302
AC_SUBST(BUILD_FAILURE_HANDLER)
303303
])
304+
305+
AC_DEFUN_ONCE([LIB_TESTS_ENABLE_DISABLE_JTREG_TEST_THREAD_FACTORY],
306+
[
307+
UTIL_ARG_ENABLE(NAME: jtreg-test-thread-factory, DEFAULT: auto,
308+
RESULT: BUILD_JTREG_TEST_THREAD_FACTORY,
309+
DESC: [enable building of the jtreg test thread factory],
310+
DEFAULT_DESC: [enabled if jtreg is present],
311+
CHECKING_MSG: [if the jtreg test thread factory should be built],
312+
CHECK_AVAILABLE: [
313+
AC_MSG_CHECKING([if the jtreg test thread factory is available])
314+
if test "x$JT_HOME" != "x"; then
315+
AC_MSG_RESULT([yes])
316+
else
317+
AVAILABLE=false
318+
AC_MSG_RESULT([no (jtreg not present)])
319+
fi
320+
])
321+
AC_SUBST(BUILD_JTREG_TEST_THREAD_FACTORY)
322+
])

make/autoconf/spec.gmk.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -358,6 +358,8 @@ BUILDJDK_OUTPUTDIR=$(OUTPUTDIR)/buildjdk
358358

359359
BUILD_FAILURE_HANDLER := @BUILD_FAILURE_HANDLER@
360360

361+
BUILD_JTREG_TEST_THREAD_FACTORY := @BUILD_JTREG_TEST_THREAD_FACTORY@
362+
361363
ENABLE_GENERATE_CLASSLIST := @ENABLE_GENERATE_CLASSLIST@
362364

363365
EXCLUDE_TRANSLATIONS := @EXCLUDE_TRANSLATIONS@
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
3+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
#
5+
# This code is free software; you can redistribute it and/or modify it
6+
# under the terms of the GNU General Public License version 2 only, as
7+
# published by the Free Software Foundation. Oracle designates this
8+
# particular file as subject to the "Classpath" exception as provided
9+
# by Oracle in the LICENSE file that accompanied this code.
10+
#
11+
# This code is distributed in the hope that it will be useful, but WITHOUT
12+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
# version 2 for more details (a copy is included in the LICENSE file that
15+
# accompanied this code).
16+
#
17+
# You should have received a copy of the GNU General Public License version
18+
# 2 along with this work; if not, write to the Free Software Foundation,
19+
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
#
21+
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
# or visit www.oracle.com if you need additional information or have any
23+
# questions.
24+
#
25+
26+
default: build
27+
28+
include $(SPEC)
29+
include MakeBase.gmk
30+
include JavaCompilation.gmk
31+
32+
TARGETS :=
33+
34+
################################################################################
35+
36+
TTF_BASEDIR := $(TOPDIR)/test/jtreg_test_thread_factory
37+
TTF_SUPPORT := $(SUPPORT_OUTPUTDIR)/test/jtreg_test_thread_factory
38+
TTF_JAR := $(TTF_SUPPORT)/jtregTestThreadFactory.jar
39+
40+
$(eval $(call SetupJavaCompilation, BUILD_JTREG_TEST_THREAD_FACTORY, \
41+
TARGET_RELEASE := $(TARGET_RELEASE_NEWJDK_UPGRADED), \
42+
SRC := $(TTF_BASEDIR)/src/share/classes, \
43+
BIN := $(TTF_SUPPORT)/classes, \
44+
JAR := $(TTF_JAR), \
45+
))
46+
47+
TARGETS += $(BUILD_JTREG_TEST_THREAD_FACTORY)
48+
49+
################################################################################
50+
# Targets for building test-image.
51+
################################################################################
52+
53+
# Copy to hotspot jtreg test image
54+
$(eval $(call SetupCopyFiles, COPY_TTF, \
55+
SRC := $(TTF_SUPPORT), \
56+
DEST := $(TEST_IMAGE_DIR)/jtreg_test_thread_factory, \
57+
FILES := $(TTF_JAR), \
58+
))
59+
60+
IMAGES_TARGETS += $(COPY_TTF)
61+
62+
build: $(TARGETS)
63+
images: $(IMAGES_TARGETS)
64+
65+
.PHONY: all images
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.util.concurrent.ThreadFactory;
25+
26+
public class Virtual implements ThreadFactory {
27+
28+
static {
29+
// This property is used by ProcessTools and some tests
30+
try {
31+
System.setProperty("main.wrapper", "Virtual");
32+
} catch (Throwable t) {
33+
// might be thrown by security manager
34+
}
35+
}
36+
37+
static final ThreadFactory VIRTUAL_TF = Thread.ofVirtual().factory();
38+
39+
@Override
40+
public Thread newThread(Runnable task) {
41+
return VIRTUAL_TF.newThread(task);
42+
}
43+
}

0 commit comments

Comments
 (0)