Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/EventTestTemplates.java
41161 views
1
/*
2
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. 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 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.
22
*/
23
package nsk.share.jdi;
24
25
import com.sun.jdi.ObjectCollectedException;
26
import com.sun.jdi.event.Event;
27
import com.sun.jdi.event.MonitorContendedEnterEvent;
28
import com.sun.jdi.event.MonitorContendedEnteredEvent;
29
import com.sun.jdi.event.MonitorWaitEvent;
30
import com.sun.jdi.event.MonitorWaitedEvent;
31
32
/*
33
* Class contains debugger classes based on JDIEventsDebugger intended for JDI events testing
34
*/
35
public class EventTestTemplates {
36
37
// how many times rerun test in case when tested events aren't generated
38
static final int MAX_TEST_RUN_NUMBER = 10;
39
40
/*
41
* Method contains common code used by EventFilterTests and StressTestTemplate
42
*/
43
static void runTestWithRerunPossibilty(JDIEventsDebugger debugger, Runnable testRunner) {
44
for (int i = 0; i < MAX_TEST_RUN_NUMBER; i++) {
45
testRunner.run();
46
47
/*
48
* If events weren't generated at all but test accepts missing events
49
* try to rerun test (rerun test only if it didn't fail yet)
50
*/
51
if (debugger.eventsNotGenerated() && debugger.getSuccess()) {
52
if (i < MAX_TEST_RUN_NUMBER - 1) {
53
debugger.log.display("\nWARNING: tested events weren't generated at all, trying to rerun test (rerun attempt " + (i + 1) + ")\n");
54
} else {
55
debugger.setSuccess(false);
56
debugger.log.complain("Tested events weren't generated after " + MAX_TEST_RUN_NUMBER + " runs, test FAILED");
57
}
58
} else {
59
break;
60
}
61
}
62
}
63
64
static public boolean isEventFromNSK(Event event, Debugee debuggee) {
65
try {
66
if (event instanceof MonitorContendedEnterEvent) {
67
return ((MonitorContendedEnterEvent) event).location() != null && ((MonitorContendedEnterEvent) event).monitor().type().name().startsWith("nsk.");
68
}
69
if (event instanceof MonitorContendedEnteredEvent) {
70
return ((MonitorContendedEnteredEvent) event).location() != null && ((MonitorContendedEnteredEvent) event).monitor().type().name().startsWith("nsk.");
71
}
72
if (event instanceof MonitorWaitEvent) {
73
return ((MonitorWaitEvent) event).monitor().type().name().startsWith("nsk.");
74
}
75
if (event instanceof MonitorWaitedEvent) {
76
return ((MonitorWaitedEvent) event).monitor().type().name().startsWith("nsk.");
77
}
78
} catch (ObjectCollectedException ex) {
79
// The monitor object the event refers to might be already collected. Ignore this exception.
80
debuggee.getLog().display("Exception caught:" + ex);
81
return false;
82
}
83
// don't filter other events
84
return true;
85
}
86
87
}
88
89