2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
2
|
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 |
*
|
5506
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
2
|
22 |
*/
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @test
|
|
26 |
* @bug 6485605
|
|
27 |
* @summary com.sun.jdi.InternalException: Inconsistent suspend policy in internal event handler
|
|
28 |
*
|
|
29 |
* @author jjh
|
|
30 |
*
|
|
31 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter
|
|
32 |
* @run compile -g SuspendThreadTest.java
|
|
33 |
* @run main SuspendThreadTest
|
|
34 |
*/
|
|
35 |
import com.sun.jdi.*;
|
|
36 |
import com.sun.jdi.event.*;
|
|
37 |
import com.sun.jdi.request.*;
|
|
38 |
|
|
39 |
import java.util.*;
|
|
40 |
|
|
41 |
/********** target program **********/
|
|
42 |
|
|
43 |
class SuspendThreadTarg {
|
|
44 |
public static long count;
|
|
45 |
|
|
46 |
public static void bkpt() {
|
|
47 |
count++;
|
|
48 |
}
|
|
49 |
|
|
50 |
public static void main(String[] args){
|
|
51 |
System.out.println("Howdy!");
|
|
52 |
|
|
53 |
// We need this to be running so the bkpt
|
|
54 |
// can be hit immediately when it is enabled
|
|
55 |
// in the back-end.
|
|
56 |
while(count >= 0) {
|
|
57 |
bkpt();
|
|
58 |
}
|
|
59 |
System.out.println("Goodbye from SuspendThreadTarg, count = " + count);
|
|
60 |
}
|
|
61 |
}
|
|
62 |
|
|
63 |
/********** test program **********/
|
|
64 |
|
|
65 |
public class SuspendThreadTest extends TestScaffold {
|
|
66 |
ClassType targetClass;
|
|
67 |
ThreadReference mainThread;
|
|
68 |
|
|
69 |
SuspendThreadTest (String args[]) {
|
|
70 |
super(args);
|
|
71 |
}
|
|
72 |
|
|
73 |
public static void main(String[] args) throws Exception {
|
|
74 |
new SuspendThreadTest(args).startTests();
|
|
75 |
}
|
|
76 |
|
|
77 |
/********** event handlers **********/
|
|
78 |
|
|
79 |
// 1000 makes the test take over 2 mins on win32
|
|
80 |
static int maxBkpts = 200;
|
|
81 |
int bkptCount;
|
|
82 |
BreakpointRequest bkptRequest;
|
|
83 |
Field debuggeeCountField;
|
|
84 |
|
|
85 |
// When we get a bkpt we want to disable the request,
|
|
86 |
// resume the debuggee, and then re-enable the request
|
|
87 |
public void breakpointReached(BreakpointEvent event) {
|
|
88 |
System.out.println("Got BreakpointEvent: " + bkptCount +
|
|
89 |
", debuggeeCount = " +
|
|
90 |
((LongValue)targetClass.
|
|
91 |
getValue(debuggeeCountField)).value()
|
|
92 |
);
|
|
93 |
bkptRequest.disable();
|
|
94 |
}
|
|
95 |
|
|
96 |
public void eventSetComplete(EventSet set) {
|
|
97 |
set.resume();
|
|
98 |
|
|
99 |
// The main thread watchs the bkptCount to
|
|
100 |
// see if bkpts stop coming in. The
|
|
101 |
// test _should_ fail well before maxBkpts bkpts.
|
|
102 |
if (bkptCount++ < maxBkpts) {
|
|
103 |
bkptRequest.enable();
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
public void vmDisconnected(VMDisconnectEvent event) {
|
|
108 |
println("Got VMDisconnectEvent");
|
|
109 |
}
|
|
110 |
|
|
111 |
/********** test core **********/
|
|
112 |
|
|
113 |
protected void runTests() throws Exception {
|
|
114 |
/*
|
|
115 |
* Get to the top of main()
|
|
116 |
* to determine targetClass and mainThread
|
|
117 |
*/
|
|
118 |
BreakpointEvent bpe = startToMain("SuspendThreadTarg");
|
|
119 |
targetClass = (ClassType)bpe.location().declaringType();
|
|
120 |
mainThread = bpe.thread();
|
|
121 |
EventRequestManager erm = vm().eventRequestManager();
|
|
122 |
|
|
123 |
Location loc1 = findMethod(targetClass, "bkpt", "()V").location();
|
|
124 |
|
|
125 |
bkptRequest = erm.createBreakpointRequest(loc1);
|
|
126 |
|
|
127 |
// Without this, it is a SUSPEND_ALL bkpt and the test will pass
|
|
128 |
bkptRequest.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD);
|
|
129 |
bkptRequest.enable();
|
|
130 |
|
|
131 |
debuggeeCountField = targetClass.fieldByName("count");
|
|
132 |
try {
|
|
133 |
|
|
134 |
addListener (this);
|
|
135 |
} catch (Exception ex){
|
|
136 |
ex.printStackTrace();
|
|
137 |
failure("failure: Could not add listener");
|
|
138 |
throw new Exception("SuspendThreadTest: failed");
|
|
139 |
}
|
|
140 |
|
|
141 |
int prevBkptCount;
|
|
142 |
vm().resume();
|
|
143 |
while (bkptCount < maxBkpts) {
|
|
144 |
prevBkptCount = bkptCount;
|
|
145 |
// If we don't get a bkpt within 5 secs,
|
|
146 |
// the test fails
|
|
147 |
try {
|
|
148 |
Thread.sleep(5000);
|
|
149 |
} catch (InterruptedException ee) {
|
|
150 |
}
|
|
151 |
if (prevBkptCount == bkptCount) {
|
|
152 |
failure("failure: test hung");
|
|
153 |
break;
|
|
154 |
}
|
|
155 |
prevBkptCount = bkptCount;
|
|
156 |
}
|
|
157 |
println("done with loop");
|
|
158 |
bkptRequest.disable();
|
|
159 |
removeListener(this);
|
|
160 |
|
|
161 |
|
|
162 |
/*
|
|
163 |
* deal with results of test
|
|
164 |
* if anything has called failure("foo") testFailed will be true
|
|
165 |
*/
|
|
166 |
if (!testFailed) {
|
|
167 |
println("SuspendThreadTest: passed");
|
|
168 |
} else {
|
|
169 |
throw new Exception("SuspendThreadTest: failed");
|
|
170 |
}
|
|
171 |
}
|
|
172 |
}
|