blob: 1467347c10a7fac6be0e70efafc0219b033b9004 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 4420844 4449394
27 * @summary Checks that no events are sent after VMDeath, and test vm.canBeModified
28 *
29 * @author Robert Field
30 *
31 * @run build TestScaffold VMConnection TargetListener TargetAdapter
32 * @run compile -g HelloWorld.java
33 * @run build VMDeathLastTest
34 * @run main VMDeathLastTest
35 */
36import com.sun.jdi.*;
37import com.sun.jdi.event.*;
38import com.sun.jdi.request.*;
39
40import java.util.*;
41
42 /********** test program **********/
43
44public class VMDeathLastTest extends TestScaffold {
45 Object syncer = new Object();
46 boolean vmDead = false;
47 boolean disconnected = false;
48
49 VMDeathLastTest (String args[]) {
50 super(args);
51 }
52
53 public static void main(String[] args) throws Exception {
54 new VMDeathLastTest(args).startTests();
55 }
56
57 /********** event handlers **********/
58
59 public void methodEntered(MethodEntryEvent event) {
60 if (vmDead) {
61 failure("Failure: Got MethodEntryEvent after VM Dead");
62 }
63 }
64
65 public void classPrepared(ClassPrepareEvent event) {
66 if (vmDead) {
67 failure("Failure: Got ClassPrepareEvent after VM Dead");
68 }
69 }
70
71 public void threadDied(ThreadDeathEvent event) {
72 if (vmDead) {
73 failure("Failure: Got ThreadDeathEvent after VM Dead");
74 }
75 }
76
77 public void vmDied(VMDeathEvent event) {
78 println("Got VMDeathEvent");
79 vmDead = true;
80 }
81
82 public void vmDisconnected(VMDisconnectEvent event) {
83 println("Got VMDisconnectEvent");
84 if (!vmDead) {
85 failure("Test failure: didn't get VMDeath");
86 }
87 disconnected = true;
88 synchronized (syncer) {
89 syncer.notifyAll();
90 }
91 }
92
93 /**
94 * Turn off default VMDeath handling.
95 */
96 protected void createDefaultVMDeathRequest() {
97 }
98
99 /********** test core **********/
100
101 protected void runTests() throws Exception {
102 /*
103 * Get to the top of main()
104 * to determine targetClass and mainThread
105 */
106 startToMain("HelloWorld");
107 if (!vm().canBeModified()) {
108 failure("VM says it is read-only");
109 }
110 EventRequestManager erm = vm().eventRequestManager();
111
112 /*
113 * Set event requests
114 */
115 erm.createMethodEntryRequest().enable();
116 erm.createClassPrepareRequest().enable();
117 erm.createThreadDeathRequest().enable();
118
119 /*
120 * resume the target listening for events
121 */
122 addListener(this);
123 synchronized (syncer) {
124 vm().resume();
125 while (!disconnected) {
126 try {
127 syncer.wait();
128 } catch (InterruptedException e) {
129 }
130 }
131 }
132
133 /*
134 * deal with results of test
135 */
136 if (!testFailed) {
137 println("VMDeathLastTest: passed");
138 } else {
139 throw new Exception("VMDeathLastTest: failed");
140 }
141 }
142}