Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/AfterThreadDeathTest.java
38855 views
/*1* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 436467126* @summary Creating a StepRequest on a nonexistant thread fails27*28* @author jjh29*30* @run build TestScaffold VMConnection TargetListener TargetAdapter31* @run compile -g AfterThreadDeathTest.java32* @run main AfterThreadDeathTest33*/34import com.sun.jdi.*;35import com.sun.jdi.event.*;36import com.sun.jdi.request.*;3738import java.util.*;3940/********** target program **********/4142class AfterDeathTarg {43public static void main(String[] args){44System.out.println("Howdy!");45System.out.println("Goodbye from AfterDeathTarg!");46}47}4849/********** test program **********/5051public class AfterThreadDeathTest extends TestScaffold {52ReferenceType targetClass;53ThreadReference mainThread;54StepRequest stepRequest = null;55EventRequestManager erm;56boolean mainIsDead;5758AfterThreadDeathTest (String args[]) {59super(args);60}6162public static void main(String[] args) throws Exception {63new AfterThreadDeathTest(args).startTests();64}6566/********** event handlers **********/6768public void threadStarted(ThreadStartEvent event) {69println("Got ThreadStartEvent: " + event);7071if (stepRequest != null) {72erm.deleteEventRequest(stepRequest);73stepRequest = null;74println("Deleted stepRequest");75}7677if (mainIsDead) {78// Here is the odd thing about this test; whatever thread this event79// is for, we do a step on the mainThread. If the mainThread is80// already dead, we should get the exception. Note that we don't81// come here for the start of the main thread.82stepRequest = erm.createStepRequest(mainThread,83StepRequest.STEP_LINE,84StepRequest.STEP_OVER);85stepRequest.addCountFilter(1);86stepRequest.setSuspendPolicy (EventRequest.SUSPEND_ALL);87try {88stepRequest.enable();89} catch (IllegalThreadStateException ee) {90println("Ok; got expected IllegalThreadStateException");91return;92} catch (Exception ee) {93failure("FAILED: Did not get expected"94+ " IllegalThreadStateException"95+ " on a StepRequest.enable(). \n"96+ " Got this exception instead: " + ee);97return;98}99failure("FAILED: Did not get expected IllegalThreadStateException"100+ " on a StepRequest.enable()");101}102}103104public void threadDied(ThreadDeathEvent event) {105println("Got ThreadDeathEvent: " + event);106if (! mainIsDead) {107if (mainThread.equals(event.thread())) {108mainIsDead = true;109}110}111}112113public void vmDied(VMDeathEvent event) {114println("Got VMDeathEvent");115}116117public void vmDisconnected(VMDisconnectEvent event) {118println("Got VMDisconnectEvent");119}120121/********** test core **********/122123protected void runTests() throws Exception {124/*125* Get to the top of main()126* to determine targetClass and mainThread127*/128BreakpointEvent bpe = startToMain("AfterDeathTarg");129targetClass = bpe.location().declaringType();130mainThread = bpe.thread();131erm = vm().eventRequestManager();132133/*134* Set event requests135*/136ThreadStartRequest request = erm.createThreadStartRequest();137request.setSuspendPolicy(EventRequest.SUSPEND_ALL);138request.enable();139140ThreadDeathRequest request1 = erm.createThreadDeathRequest();141request1.setSuspendPolicy(EventRequest.SUSPEND_NONE);142request1.enable();143144/*145* resume the target listening for events146*/147listenUntilVMDisconnect();148149/*150* deal with results of test151* if anything has called failure("foo") testFailed will be true152*/153if (!testFailed) {154println("AfterThreadDeathTest: passed");155} else {156throw new Exception("AfterThreadDeathTest: failed");157}158}159}160161162