8339638: Update vmTestbase/nsk/jvmti/*Field*Watch tests to use virtual thread factory
Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
parent
6fd043f1e4
commit
9785e19f3f
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2024, 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
|
||||
@ -23,6 +23,8 @@
|
||||
|
||||
package nsk.jvmti.ClearFieldAccessWatch;
|
||||
|
||||
import jdk.test.lib.thread.TestThreadFactory;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class clrfldw001 {
|
||||
@ -58,7 +60,7 @@ public class clrfldw001 {
|
||||
public static int run(String argv[], PrintStream ref) {
|
||||
clrfldw001 t = new clrfldw001();
|
||||
clrfldw001a t_a = new clrfldw001a();
|
||||
clrfldw001b t_b = new clrfldw001b();
|
||||
Thread t_b = TestThreadFactory.newThread(new clrfldw001b());
|
||||
for (int i = 0; i < 5; i++) {
|
||||
setWatch(i);
|
||||
}
|
||||
@ -91,7 +93,7 @@ class clrfldw001a {
|
||||
int fld = 2;
|
||||
}
|
||||
|
||||
class clrfldw001b extends Thread {
|
||||
class clrfldw001b implements Runnable {
|
||||
float fld4 = 6.0f;
|
||||
public void run() {
|
||||
clrfldw001.clearWatch(4);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2024, 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
|
||||
@ -23,6 +23,8 @@
|
||||
|
||||
package nsk.jvmti.ClearFieldModificationWatch;
|
||||
|
||||
import jdk.test.lib.thread.TestThreadFactory;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class clrfmodw001 {
|
||||
@ -58,7 +60,7 @@ public class clrfmodw001 {
|
||||
public static int run(String argv[], PrintStream ref) {
|
||||
clrfmodw001 t = new clrfmodw001();
|
||||
clrfmodw001a t_a = new clrfmodw001a();
|
||||
clrfmodw001b t_b = new clrfmodw001b();
|
||||
Thread t_b = TestThreadFactory.newThread(new clrfmodw001b());
|
||||
for (int i = 0; i < 5; i++) {
|
||||
setWatch(i);
|
||||
}
|
||||
@ -91,7 +93,7 @@ class clrfmodw001a {
|
||||
int fld = 2;
|
||||
}
|
||||
|
||||
class clrfmodw001b extends Thread {
|
||||
class clrfmodw001b implements Runnable {
|
||||
float fld4;
|
||||
public void run() {
|
||||
clrfmodw001.clearWatch(4);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2024, 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
|
||||
@ -23,6 +23,8 @@
|
||||
|
||||
package nsk.jvmti.SetFieldAccessWatch;
|
||||
|
||||
import jdk.test.lib.thread.TestThreadFactory;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class setfldw001 {
|
||||
@ -62,7 +64,7 @@ public class setfldw001 {
|
||||
public static int run(String argv[], PrintStream ref) {
|
||||
setfldw001 t = new setfldw001();
|
||||
setfldw001a t_a = new setfldw001a();
|
||||
setfldw001b t_b = new setfldw001b();
|
||||
Thread t_b = TestThreadFactory.newThread(new setfldw001b());
|
||||
t_b.start();
|
||||
synchronized (lock) {
|
||||
fld = fld1 + 1;
|
||||
@ -111,7 +113,7 @@ class setfldw001a {
|
||||
int fld = 2;
|
||||
}
|
||||
|
||||
class setfldw001b extends Thread {
|
||||
class setfldw001b implements Runnable {
|
||||
float fld4 = 6.0f;
|
||||
public void run() {
|
||||
synchronized (setfldw001.lock) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2024, 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
|
||||
@ -23,6 +23,8 @@
|
||||
|
||||
package nsk.jvmti.SetFieldModificationWatch;
|
||||
|
||||
import jdk.test.lib.thread.TestThreadFactory;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class setfmodw001 {
|
||||
@ -62,7 +64,7 @@ public class setfmodw001 {
|
||||
public static int run(String argv[], PrintStream ref) {
|
||||
setfmodw001 t = new setfmodw001();
|
||||
setfmodw001a t_a = new setfmodw001a();
|
||||
setfmodw001b t_b = new setfmodw001b();
|
||||
Thread t_b = TestThreadFactory.newThread(new setfmodw001b());
|
||||
t_b.start();
|
||||
synchronized (lock) {
|
||||
fld1 = fld1 + 1;
|
||||
@ -111,7 +113,7 @@ class setfmodw001a {
|
||||
int fld = 2;
|
||||
}
|
||||
|
||||
class setfmodw001b extends Thread {
|
||||
class setfmodw001b implements Runnable {
|
||||
float fld4;
|
||||
public void run() {
|
||||
synchronized (setfmodw001.lock) {
|
||||
|
55
test/lib/jdk/test/lib/thread/TestThreadFactory.java
Normal file
55
test/lib/jdk/test/lib/thread/TestThreadFactory.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 2024, 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.
|
||||
*/
|
||||
|
||||
package jdk.test.lib.thread;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
/*
|
||||
This factory is used to start new threads in tests.
|
||||
It supports creation of virtual threads when jtreg test.thread.factory plugin is enabled.
|
||||
*/
|
||||
|
||||
public class TestThreadFactory {
|
||||
|
||||
private static ThreadFactory threadFactory = "Virtual".equals(System.getProperty("test.thread.factory"))
|
||||
? virtualThreadFactory() : platformThreadFactory();
|
||||
|
||||
public static Thread newThread(Runnable task) {
|
||||
return threadFactory.newThread(task);
|
||||
}
|
||||
|
||||
public static Thread newThread(Runnable task, String name) {
|
||||
Thread t = threadFactory.newThread(task);
|
||||
t.setName(name);
|
||||
return t;
|
||||
}
|
||||
|
||||
private static ThreadFactory platformThreadFactory() {
|
||||
return Thread.ofPlatform().factory();
|
||||
}
|
||||
|
||||
private static ThreadFactory virtualThreadFactory() {
|
||||
return Thread.ofVirtual().factory();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user