Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/sde/SDEDebuggee.java
41162 views
1
/*
2
* Copyright (c) 2007, 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.sde;
24
25
import java.lang.reflect.Method;
26
import nsk.share.TestBug;
27
import nsk.share.jdi.*;
28
29
public class SDEDebuggee extends AbstractJDIDebuggee {
30
public static String mainThreadName = "SDEDebuggee_mainThread";
31
32
// command:class_name
33
public static String COMMAND_EXECUTE_TEST_METHODS = "executeTestMethods";
34
35
public static void main(String args[]) {
36
new SDEDebuggee().doTest(args);
37
}
38
39
protected String[] doInit(String[] args) {
40
args = super.doInit(args);
41
42
if (classpath == null)
43
throw new TestBug("Debuggee requires '-testClassPath' parameter");
44
45
Thread.currentThread().setName(mainThreadName);
46
47
return args;
48
}
49
50
public boolean parseCommand(String command) {
51
if (super.parseCommand(command))
52
return true;
53
54
if (command.startsWith(COMMAND_EXECUTE_TEST_METHODS)) {
55
// extract class name
56
String split[] = command.split(":");
57
58
if ((split.length != 2) || (split[1].length() == 0))
59
throw new TestBug("");
60
61
executeTestMethods(split[1]);
62
breakpointMethod();
63
64
return true;
65
}
66
67
return false;
68
}
69
70
// Keep class loader alive to avoid ObjectCollectedException
71
// on the debugger side, in case the GC unloads the class and
72
// invalidates code locations.
73
private TestClassLoader classLoader;
74
75
// create instance of given class and execute all methods which names start
76
// with 'sde_testMethod'
77
private void executeTestMethods(String className) {
78
classLoader = new TestClassLoader();
79
classLoader.setClassPath(classpath);
80
81
try {
82
Class<?> klass = classLoader.loadClass(className);
83
Object testObject = klass.newInstance();
84
85
for (Method method : klass.getDeclaredMethods()) {
86
if (method.getName().startsWith("sde_testMethod"))
87
method.invoke(testObject, new Object[] {});
88
}
89
} catch (Exception e) {
90
setSuccess(false);
91
log.complain("Unexpected exception: " + e);
92
e.printStackTrace(log.getOutStream());
93
94
throw new TestBug("Unexpected exception: " + e);
95
}
96
}
97
98
}
99
100