1
1
/*
2
- * Copyright (c) 2001, 2015 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2001, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -51,9 +51,9 @@ public static void main(String[] args){
51
51
public class AfterThreadDeathTest extends TestScaffold {
52
52
ReferenceType targetClass ;
53
53
ThreadReference mainThread ;
54
- StepRequest stepRequest = null ;
55
54
EventRequestManager erm ;
56
- boolean mainIsDead ;
55
+ volatile boolean mainIsDead = false ;
56
+ volatile boolean gotExpectedThreadStart = false ;
57
57
58
58
AfterThreadDeathTest (String args []) {
59
59
super (args );
@@ -68,20 +68,23 @@ public static void main(String[] args) throws Exception {
68
68
public void threadStarted (ThreadStartEvent event ) {
69
69
println ("Got ThreadStartEvent: " + event );
70
70
71
- if ( stepRequest != null ) {
72
- erm . deleteEventRequest ( stepRequest );
73
- stepRequest = null ;
74
- println ( "Deleted stepRequest" ) ;
71
+ // We don't want to attempt the StepRequest.enable() until we recieve
72
+ // the ThreadStartEvent for the "DestroyJavaVM" thread. See JDK-8232839.
73
+ if (! event . thread (). name (). equals ( "DestroyJavaVM" )) {
74
+ return ;
75
75
}
76
+ gotExpectedThreadStart = true ;
76
77
77
- if (mainIsDead ) {
78
+ if (!mainIsDead ) {
79
+ failure ("FAILED: Got expected ThreadStartEvent before \" main\" ThreadDeathEvent" );
80
+ } else {
78
81
// Here is the odd thing about this test; whatever thread this event
79
82
// is for, we do a step on the mainThread. If the mainThread is
80
83
// already dead, we should get the exception. Note that we don't
81
84
// come here for the start of the main thread.
82
- stepRequest = erm .createStepRequest (mainThread ,
83
- StepRequest .STEP_LINE ,
84
- StepRequest .STEP_OVER );
85
+ StepRequest stepRequest = erm .createStepRequest (mainThread ,
86
+ StepRequest .STEP_LINE ,
87
+ StepRequest .STEP_OVER );
85
88
stepRequest .addCountFilter (1 );
86
89
stepRequest .setSuspendPolicy (EventRequest .SUSPEND_ALL );
87
90
try {
@@ -146,6 +149,13 @@ protected void runTests() throws Exception {
146
149
*/
147
150
listenUntilVMDisconnect ();
148
151
152
+ if (!gotExpectedThreadStart ) {
153
+ failure ("FAILED: never got expected ThreadStartEvent" );
154
+ }
155
+ if (!mainIsDead ) {
156
+ failure ("FAILED: never got ThreadDeathEvent for \" main\" thread" );
157
+ }
158
+
149
159
/*
150
160
* deal with results of test
151
161
* if anything has called failure("foo") testFailed will be true
0 commit comments