author | clanger |
Thu, 17 Oct 2019 22:41:36 +0200 | |
changeset 58681 | 5f14a659a8cb |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58681
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2005, 2019, 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 |
/** |
|
44423 | 25 |
* @test |
26 |
* @bug 6230699 |
|
27 |
* @summary Test ThreadReference.ownedMonitorsAndFrames() |
|
28 |
* @bug 6701700 |
|
29 |
* @summary MonitorInfo objects aren't invalidated when the owning thread is resumed |
|
30 |
* @author Swamy Venkataramanappa |
|
2 | 31 |
* |
44423 | 32 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter |
33 |
* @run compile -g MonitorFrameInfo.java |
|
34 |
* @run driver MonitorFrameInfo |
|
2 | 35 |
*/ |
58681
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
36 |
import java.util.List; |
2 | 37 |
|
58681
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
38 |
import com.sun.jdi.InvalidStackFrameException; |
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
39 |
import com.sun.jdi.MonitorInfo; |
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
40 |
import com.sun.jdi.ReferenceType; |
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
41 |
import com.sun.jdi.ThreadReference; |
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
42 |
import com.sun.jdi.event.BreakpointEvent; |
2 | 43 |
|
44 |
/********** target program **********/ |
|
45 |
||
58681
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
46 |
class MonitorFrameInfoTarg { |
2 | 47 |
static void foo3() { |
48 |
System.out.println("executing foo3"); |
|
49 |
||
50 |
} |
|
51 |
static void foo2() { |
|
52 |
Object l1 = new Object(); |
|
53 |
synchronized(l1) { |
|
899
40d3416d937a
6730587: TEST: com/sun/jdi/MonitorFrameInfoTest.java fails with -server -Xcomp
jjh
parents:
836
diff
changeset
|
54 |
System.out.println("executing foo2 " + l1); |
2 | 55 |
foo3(); |
56 |
} |
|
57 |
} |
|
58 |
static void foo1() { |
|
59 |
foo2(); |
|
60 |
} |
|
61 |
public static void main(String[] args){ |
|
62 |
System.out.println("Howdy!"); |
|
63 |
Object l1 = new Object(); |
|
64 |
synchronized(l1) { |
|
899
40d3416d937a
6730587: TEST: com/sun/jdi/MonitorFrameInfoTest.java fails with -server -Xcomp
jjh
parents:
836
diff
changeset
|
65 |
System.out.println("executing main" + l1); |
2 | 66 |
foo1(); |
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
/********** test program **********/ |
|
72 |
||
73 |
public class MonitorFrameInfo extends TestScaffold { |
|
74 |
ReferenceType targetClass; |
|
75 |
ThreadReference mainThread; |
|
58681
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
76 |
List<MonitorInfo> monitors; |
2 | 77 |
|
78 |
static int expectedCount = 2; |
|
79 |
static int[] expectedDepth = { 1, 3 }; |
|
80 |
||
81 |
static String[] expectedNames = {"foo3", "foo2", "foo1", "main"}; |
|
82 |
||
83 |
MonitorFrameInfo (String args[]) { |
|
84 |
super(args); |
|
85 |
} |
|
86 |
||
87 |
public static void main(String[] args) throws Exception { |
|
88 |
new MonitorFrameInfo(args).startTests(); |
|
89 |
} |
|
90 |
||
91 |
/********** test core **********/ |
|
92 |
||
93 |
protected void runTests() throws Exception { |
|
94 |
/* |
|
95 |
* Get to the top of main() |
|
96 |
* to determine targetClass and mainThread |
|
97 |
*/ |
|
58681
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
98 |
BreakpointEvent bpe = startToMain("MonitorFrameInfoTarg"); |
2 | 99 |
targetClass = bpe.location().declaringType(); |
100 |
mainThread = bpe.thread(); |
|
101 |
||
102 |
int initialSize = mainThread.frames().size(); |
|
103 |
||
58681
5f14a659a8cb
8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents:
47216
diff
changeset
|
104 |
resumeTo("MonitorFrameInfoTarg", "foo3", "()V"); |
2 | 105 |
|
106 |
if (!mainThread.frame(0).location().method().name() |
|
107 |
.equals("foo3")) { |
|
836
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
108 |
failure("FAILED: frame failed"); |
2 | 109 |
} |
110 |
||
111 |
if (mainThread.frames().size() != (initialSize + 3)) { |
|
836
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
112 |
failure("FAILED: frames size failed"); |
2 | 113 |
} |
114 |
||
115 |
if (mainThread.frames().size() != mainThread.frameCount()) { |
|
836
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
116 |
failure("FAILED: frames size not equal to frameCount"); |
2 | 117 |
} |
118 |
||
119 |
/* Test monitor frame info. |
|
120 |
*/ |
|
121 |
if (vm().canGetMonitorFrameInfo()) { |
|
122 |
System.out.println("Get monitors"); |
|
123 |
monitors = mainThread.ownedMonitorsAndFrames(); |
|
124 |
if (monitors.size() != expectedCount) { |
|
125 |
failure("monitors count is not equal to expected count"); |
|
126 |
} |
|
836
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
127 |
MonitorInfo mon = null; |
2 | 128 |
for (int j=0; j < monitors.size(); j++) { |
836
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
129 |
mon = (MonitorInfo)monitors.get(j); |
2 | 130 |
System.out.println("Monitor obj " + mon.monitor() + "depth =" +mon.stackDepth()); |
131 |
if (mon.stackDepth() != expectedDepth[j]) { |
|
836
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
132 |
failure("FAILED: monitor stack depth is not equal to expected depth"); |
2 | 133 |
} |
134 |
} |
|
836
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
135 |
|
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
136 |
// The last gotten monInfo is in mon. When we resume the thread, |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
137 |
// it should become invalid. We will step out of the top frame |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
138 |
// so that the frame depth in this mon object will no longer be correct. |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
139 |
// That is why the monInfo's have to become invalid when the thread is |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
140 |
// resumed. |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
141 |
stepOut(mainThread); |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
142 |
boolean ok = false; |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
143 |
try { |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
144 |
System.out.println("*** Saved Monitor obj " + mon.monitor() + "depth =" +mon.stackDepth()); |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
145 |
} catch(InvalidStackFrameException ee) { |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
146 |
// ok |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
147 |
ok = true; |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
148 |
System.out.println("Got expected InvalidStackFrameException after a resume"); |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
149 |
} |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
150 |
if (!ok) { |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
151 |
failure("FAILED: MonitorInfo object was not invalidated by a resume"); |
d81b1f62fb82
6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents:
2
diff
changeset
|
152 |
} |
2 | 153 |
} else { |
154 |
System.out.println("can not get monitors frame info"); |
|
155 |
} |
|
156 |
||
157 |
||
158 |
/* |
|
159 |
* resume until end |
|
160 |
*/ |
|
161 |
listenUntilVMDisconnect(); |
|
162 |
||
163 |
/* |
|
164 |
* deal with results of test |
|
165 |
* if anything has called failure("foo") testFailed will be true |
|
166 |
*/ |
|
167 |
if (!testFailed) { |
|
168 |
println("MonitorFrameInfo: passed"); |
|
169 |
} else { |
|
170 |
throw new Exception("MonitorFrameInfo: failed"); |
|
171 |
} |
|
172 |
} |
|
173 |
} |