< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/share/jdi/OwnedMonitorsDebugger.java

Print this page

 79             return super.canRunTest();
 80     }
 81 
 82     protected String debuggeeClassName() {
 83         return OwnedMonitorsDebuggee.class.getName();
 84     }
 85 
 86     // read debuggee's array 'monitorsInfo' containing information about acquired monitors
 87     protected List<DebugMonitorInfo> getDebugMonitorsInfo() {
 88         List<DebugMonitorInfo> result = new ArrayList<DebugMonitorInfo>();
 89 
 90         ReferenceType referenceType = debuggee.classByName(debuggeeClassNameWithoutArgs());
 91         ArrayReference monitorsInfo = (ArrayReference) referenceType.getValue(referenceType.fieldByName("monitorsInfo"));
 92 
 93         for (int i = 0; i < monitorsInfo.length(); i++)
 94             result.add(new DebugMonitorInfo((ObjectReference) monitorsInfo.getValue(i)));
 95 
 96         return result;
 97     }
 98 



















 99     private boolean compare(MonitorInfo actual, DebugMonitorInfo expected) {
100         boolean success = true;
101 
102         if (actual.stackDepth() != expected.stackDepth) {








103             setSuccess(false);
104             success = false;
105             log.complain("Expected and actual monitor(" + actual.monitor() + ") stack depth differs, expected: " + expected.stackDepth + " actual: "
106                     + actual.stackDepth());








107         }
108 
109         if (!actual.thread().equals(expected.thread)) {
110             setSuccess(false);
111             success = false;
112             log.complain("Expected and actual monitor(" + actual.monitor() + " thread differs, expected: " + expected.thread + " actual: "
113                     + actual.thread());
114         }
115 
116         return success;
117     }
118 
119     protected void compare(List<MonitorInfo> actualData, List<DebugMonitorInfo> expectedData) {
120         boolean success = true;
121 
122         // compare total amount of monitors
123         if (actualData.size() != expectedData.size()) {
124             setSuccess(false);
125             success = false;
126             log.complain("Number of expected monitors and actual ones differs");

 79             return super.canRunTest();
 80     }
 81 
 82     protected String debuggeeClassName() {
 83         return OwnedMonitorsDebuggee.class.getName();
 84     }
 85 
 86     // read debuggee's array 'monitorsInfo' containing information about acquired monitors
 87     protected List<DebugMonitorInfo> getDebugMonitorsInfo() {
 88         List<DebugMonitorInfo> result = new ArrayList<DebugMonitorInfo>();
 89 
 90         ReferenceType referenceType = debuggee.classByName(debuggeeClassNameWithoutArgs());
 91         ArrayReference monitorsInfo = (ArrayReference) referenceType.getValue(referenceType.fieldByName("monitorsInfo"));
 92 
 93         for (int i = 0; i < monitorsInfo.length(); i++)
 94             result.add(new DebugMonitorInfo((ObjectReference) monitorsInfo.getValue(i)));
 95 
 96         return result;
 97     }
 98 
 99     int implStackDepth(ThreadReference threadReference, String className, String methodName) {
100         try {
101             int stackDepth = 0;
102             for (int i = 0; i < threadReference.frames().size(); i++) {
103                 StackFrame sf = threadReference.frames().get(i);
104                 if (!sf.location().declaringType().name().equals(className)) {
105                     return stackDepth;
106                 }
107                 if (sf.location().method().name().equals(methodName)) {
108                     stackDepth = i;
109                 }
110             }
111         }  catch (IncompatibleThreadStateException e) {
112             log.complain("Unexpected exception", e);
113             return 0;
114         }
115         return 0;
116     }
117 
118     private boolean compare(MonitorInfo actual, DebugMonitorInfo expected) {
119         boolean success = true;
120 
121         int depth = actual.stackDepth();
122         ThreadReference threadReference = actual.thread();
123         if (expected.stackDepth != - 1) {
124             // Exclude implementation of Thread.sleep()/Object.wait() from comparison
125             depth -= implStackDepth(threadReference, "java.lang.Thread", "sleep");
126             depth -= implStackDepth(threadReference, "java.lang.Object", "wait");
127         }
128 
129         if (depth != expected.stackDepth) {
130             setSuccess(false);
131             success = false;
132             log.complain("Expected and actual monitor(" + actual.monitor() + ") stack depth differs, expected: "
133                     + expected.stackDepth + " actual (excluding wait/sleep impl): " + depth);
134             log.complain("The stack:");
135             try {
136                 for (int idx = 0; idx < threadReference.frames().size(); idx++) {
137                     log.complain(idx + ": " + threadReference.frames().get(idx).toString());
138                 }
139             } catch (IncompatibleThreadStateException e) {
140                 e.printStackTrace();
141             }
142         }
143 
144         if (!actual.thread().equals(expected.thread)) {
145             setSuccess(false);
146             success = false;
147             log.complain("Expected and actual monitor(" + actual.monitor() + " thread differs, expected: " + expected.thread + " actual: "
148                     + actual.thread());
149         }
150 
151         return success;
152     }
153 
154     protected void compare(List<MonitorInfo> actualData, List<DebugMonitorInfo> expectedData) {
155         boolean success = true;
156 
157         // compare total amount of monitors
158         if (actualData.size() != expectedData.size()) {
159             setSuccess(false);
160             success = false;
161             log.complain("Number of expected monitors and actual ones differs");
< prev index next >