2
|
1 |
/*
|
|
2 |
* Copyright 2005 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 6230699
|
|
27 |
* @summary Test ThreadReference.ownedMonitorsAndFrames()
|
|
28 |
*
|
|
29 |
* @author Swamy Venkataramanappa
|
|
30 |
*
|
|
31 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter
|
|
32 |
* @run compile -g MonitorFrameInfo.java
|
|
33 |
* @run main MonitorFrameInfo
|
|
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 MonitorTestTarg {
|
|
44 |
static void foo3() {
|
|
45 |
System.out.println("executing foo3");
|
|
46 |
|
|
47 |
}
|
|
48 |
static void foo2() {
|
|
49 |
Object l1 = new Object();
|
|
50 |
synchronized(l1) {
|
|
51 |
foo3();
|
|
52 |
}
|
|
53 |
}
|
|
54 |
static void foo1() {
|
|
55 |
foo2();
|
|
56 |
}
|
|
57 |
public static void main(String[] args){
|
|
58 |
System.out.println("Howdy!");
|
|
59 |
Object l1 = new Object();
|
|
60 |
synchronized(l1) {
|
|
61 |
foo1();
|
|
62 |
}
|
|
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
/********** test program **********/
|
|
67 |
|
|
68 |
public class MonitorFrameInfo extends TestScaffold {
|
|
69 |
ReferenceType targetClass;
|
|
70 |
ThreadReference mainThread;
|
|
71 |
List monitors;
|
|
72 |
|
|
73 |
static int expectedCount = 2;
|
|
74 |
static int[] expectedDepth = { 1, 3 };
|
|
75 |
|
|
76 |
static String[] expectedNames = {"foo3", "foo2", "foo1", "main"};
|
|
77 |
|
|
78 |
MonitorFrameInfo (String args[]) {
|
|
79 |
super(args);
|
|
80 |
}
|
|
81 |
|
|
82 |
public static void main(String[] args) throws Exception {
|
|
83 |
new MonitorFrameInfo(args).startTests();
|
|
84 |
}
|
|
85 |
|
|
86 |
/********** test core **********/
|
|
87 |
|
|
88 |
protected void runTests() throws Exception {
|
|
89 |
/*
|
|
90 |
* Get to the top of main()
|
|
91 |
* to determine targetClass and mainThread
|
|
92 |
*/
|
|
93 |
BreakpointEvent bpe = startToMain("MonitorTestTarg");
|
|
94 |
targetClass = bpe.location().declaringType();
|
|
95 |
mainThread = bpe.thread();
|
|
96 |
|
|
97 |
int initialSize = mainThread.frames().size();
|
|
98 |
|
|
99 |
resumeTo("MonitorTestTarg", "foo3", "()V");
|
|
100 |
|
|
101 |
if (!mainThread.frame(0).location().method().name()
|
|
102 |
.equals("foo3")) {
|
|
103 |
failure("frame failed");
|
|
104 |
}
|
|
105 |
|
|
106 |
if (mainThread.frames().size() != (initialSize + 3)) {
|
|
107 |
failure("frames size failed");
|
|
108 |
}
|
|
109 |
|
|
110 |
if (mainThread.frames().size() != mainThread.frameCount()) {
|
|
111 |
failure("frames size not equal to frameCount");
|
|
112 |
}
|
|
113 |
|
|
114 |
/* Test monitor frame info.
|
|
115 |
*/
|
|
116 |
if (vm().canGetMonitorFrameInfo()) {
|
|
117 |
System.out.println("Get monitors");
|
|
118 |
monitors = mainThread.ownedMonitorsAndFrames();
|
|
119 |
if (monitors.size() != expectedCount) {
|
|
120 |
failure("monitors count is not equal to expected count");
|
|
121 |
}
|
|
122 |
for (int j=0; j < monitors.size(); j++) {
|
|
123 |
MonitorInfo mon = (MonitorInfo)monitors.get(j);
|
|
124 |
System.out.println("Monitor obj " + mon.monitor() + "depth =" +mon.stackDepth());
|
|
125 |
if (mon.stackDepth() != expectedDepth[j]) {
|
|
126 |
failure("monitor stack depth is not equal to expected depth");
|
|
127 |
}
|
|
128 |
}
|
|
129 |
} else {
|
|
130 |
System.out.println("can not get monitors frame info");
|
|
131 |
}
|
|
132 |
|
|
133 |
|
|
134 |
/*
|
|
135 |
* resume until end
|
|
136 |
*/
|
|
137 |
listenUntilVMDisconnect();
|
|
138 |
|
|
139 |
/*
|
|
140 |
* deal with results of test
|
|
141 |
* if anything has called failure("foo") testFailed will be true
|
|
142 |
*/
|
|
143 |
if (!testFailed) {
|
|
144 |
println("MonitorFrameInfo: passed");
|
|
145 |
} else {
|
|
146 |
throw new Exception("MonitorFrameInfo: failed");
|
|
147 |
}
|
|
148 |
}
|
|
149 |
}
|