Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
8282384: [LOOM] Need test for ThreadReference.interrupt() on a vthread
Browse files Browse the repository at this point in the history
Reviewed-by: lmesnik, sspitsyn
  • Loading branch information
plummercj committed May 1, 2023
1 parent c7e1df8 commit ae5f678
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
Expand Down Expand Up @@ -47,11 +47,9 @@
* The test is passed if both 'interrupted status" are equal, <BR>
* otherwise the test failed. <BR>
* <BR>
* The test consists of two cases as follows: <BR>
* The test consists of one test case as follows: <BR>
* - both debuggee's threads are locked up at synchronized block and <BR>
* are not suspended; <BR>
* - both debuggee's threads are locked up at synchronized block and <BR>
* are suspended by java.lang.Thread.suspend() method; <BR>
*/

public class interrupt001 {
Expand Down Expand Up @@ -211,7 +209,9 @@ private void executeCase(int testCase, String threadName2) {
throw new TestBug("ERROR: Not found ThreadReference for name :" + threadName2);
}

log2("......interrupting the thread2");
log2("......thread2 is " + (thread2.isVirtual() ? "" : "not ") + "a virtual thread");

log2("......interrupting thread2");
thread2.interrupt();

log2("......instructing main thread to check up threads' interrupted statuses");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
Expand Down Expand Up @@ -65,9 +65,9 @@ private static void logErr(String message) {
// scaffold objects
private static volatile ArgumentHandler argumentHandler = null;

private static interrupt001aThread thread2 = null;
private static Thread thread2 = null;

private static interrupt001aThread thread3 = null;
private static Thread thread3 = null;

private static IOPipe pipe;

Expand Down Expand Up @@ -102,7 +102,7 @@ public static void main(String argv[]) {

} else if (instruction.equals("newcheck")) {

synchronized (interrupt001aThread.lockingObject) {
synchronized (interrupt001aTask.lockingObject) {
thread2 = threadStart("Thread02");
thread3 = threadStart("Thread03");

Expand Down Expand Up @@ -142,14 +142,15 @@ public static void main(String argv[]) {
System.exit(exitCode + PASS_BASE);
}

private static interrupt001aThread threadStart(String threadName) {
interrupt001aThread resultThread = new interrupt001aThread(threadName);
synchronized (resultThread.waitnotifyObj) {
private static Thread threadStart(String threadName) {
interrupt001aTask resultRunnable = new interrupt001aTask(threadName);
Thread resultThread = JDIThreadFactory.newThread(resultRunnable, threadName);
synchronized (resultRunnable.waitnotifyObj) {
resultThread.start();
try {
log1(" before: waitnotifyObj.wait();");
while (!resultThread.ready)
resultThread.waitnotifyObj.wait();
while (!resultRunnable.ready)
resultRunnable.waitnotifyObj.wait();
log1(" after: waitnotifyObj.wait();");
} catch (InterruptedException e) {
logErr("Unexpected InterruptedException while waiting for start of : " + threadName);
Expand Down Expand Up @@ -205,10 +206,10 @@ private static int checkInterruptStatus() {
}
}

class interrupt001aThread extends Thread {
class interrupt001aTask extends NamedTask {

public interrupt001aThread(String threadName) {
super(threadName);
public interrupt001aTask(String taskName) {
super(taskName);
}

public boolean ready;
Expand All @@ -235,6 +236,6 @@ public void run() {
}

void log(String str) {
interrupt001a.log2(Thread.currentThread().getName() + " : " + str);
interrupt001a.log2(getName() + " : " + str);
}
}

0 comments on commit ae5f678

Please sign in to comment.