Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate behaviour of Thread.stop() on suspended threads #17818

Closed
gacholio opened this issue Jul 19, 2023 · 4 comments
Closed

Investigate behaviour of Thread.stop() on suspended threads #17818

gacholio opened this issue Jul 19, 2023 · 4 comments
Assignees
Labels

Comments

@gacholio
Copy link
Contributor

In #17806 we changed the behaviour of JVMTI StopThread() to no longer resume a suspended thread. We need to see if a similar change should be made to the java Thread.stop() which is implemented seperately.

@gacholio gacholio self-assigned this Jul 19, 2023
@gacholio
Copy link
Contributor Author

gacholio commented Jul 19, 2023

public class StopTest {
	public static void main(String args[]) throws Throwable {
		Thread t = new Thread() {
			public void run() {
				try {
					System.out.println("suspending");
					Thread.currentThread().suspend();
					System.out.println("resumed");
				} catch(Throwable t) {
					t.printStackTrace();
				}
			}
		};
		System.out.println("starting");
		t.start();
		Thread.sleep(5000);
		System.out.println("stopping");
		t.stop();
		Thread.sleep(5000);
		System.out.println("resuming");
		t.resume();
		t.join();
	}
}

@gacholio
Copy link
Contributor Author

j9build@736bb006f300:DOCKER-IMAGE $ jdk1.8.0_381/bin/java StopTest
starting
suspending
stopping
java.lang.ThreadDeath
	at java.lang.Thread.stop(Thread.java:858)
	at StopTest.main(StopTest.java:18)
resumedresuming
j9build@736bb006f300:DOCKER-IMAGE $ jdk1.8.0_381/bin/java StopTest
starting
suspending
stopping
resumed
resuming
j9build@736bb006f300:DOCKER-IMAGE $ jdk1.8.0_381/bin/java StopTest
starting
suspending
stopping
resumedjava.lang.ThreadDeath
	at java.lang.Thread.stop(Thread.java:858)
	at StopTest.main(StopTest.java:18)

resuming

Oracle JDK8 does appear to resume the thread on stop(). The exception appears to be thrown at some random time after the resume.

@gacholio
Copy link
Contributor Author

j9build@736bb006f300:DOCKER-IMAGE $ /team/gac/80/bin/java -Xint StopTest
starting
suspending
stopping
java.lang.ThreadDeath
	at java.lang.Thread.stop(Thread.java:1028)
	at StopTest.main(StopTest.java:18)
resuming

On J9, we throw the exception immediately.

@gacholio
Copy link
Contributor Author

Given these findings and the fact that stop() has been removed since Java 11, no action needs to be taken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant