11/*
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.
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
@@ -51,9 +51,9 @@ public static void main(String[] args){
5151public class AfterThreadDeathTest extends TestScaffold {
5252 ReferenceType targetClass ;
5353 ThreadReference mainThread ;
54- StepRequest stepRequest = null ;
5554 EventRequestManager erm ;
56- boolean mainIsDead ;
55+ volatile boolean mainIsDead = false ;
56+ volatile boolean gotExpectedThreadStart = false ;
5757
5858 AfterThreadDeathTest (String args []) {
5959 super (args );
@@ -68,20 +68,23 @@ public static void main(String[] args) throws Exception {
6868 public void threadStarted (ThreadStartEvent event ) {
6969 println ("Got ThreadStartEvent: " + event );
7070
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 ;
7575 }
76+ gotExpectedThreadStart = true ;
7677
77- if (mainIsDead ) {
78+ if (!mainIsDead ) {
79+ failure ("FAILED: Got expected ThreadStartEvent before \" main\" ThreadDeathEvent" );
80+ } else {
7881 // Here is the odd thing about this test; whatever thread this event
7982 // is for, we do a step on the mainThread. If the mainThread is
8083 // already dead, we should get the exception. Note that we don't
8184 // 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 );
8588 stepRequest .addCountFilter (1 );
8689 stepRequest .setSuspendPolicy (EventRequest .SUSPEND_ALL );
8790 try {
@@ -146,6 +149,13 @@ protected void runTests() throws Exception {
146149 */
147150 listenUntilVMDisconnect ();
148151
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+
149159 /*
150160 * deal with results of test
151161 * if anything has called failure("foo") testFailed will be true
0 commit comments