Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach030/attach030Agent00.java
40951 views
1
/*
2
* Copyright (c) 2007, 2018, 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.jvmti.AttachOnDemand.attach030;
24
25
import nsk.share.TestBug;
26
import nsk.share.aod.AbstractJarAgent;
27
import java.lang.instrument.Instrumentation;
28
29
/*
30
* First agent tries to redefine class loaded by the target application, then agent itself loads
31
* class and redefines it
32
*/
33
public class attach030Agent00 extends AbstractJarAgent {
34
35
private static final String classToRedefine1 = "nsk.jvmti.AttachOnDemand.attach030.ClassToRedefine01";
36
37
private static final String classToRedefine2 = "nsk.jvmti.AttachOnDemand.attach030.ClassToRedefine02";
38
39
protected void init(String[] args) {
40
if (pathToNewByteCode() == null)
41
throw new TestBug("Path to new byte code wasn't specified (" + pathToNewByteCodeOption + "=...)");
42
}
43
44
protected void agentActions() throws Throwable {
45
boolean classWasFound = false;
46
47
for (Class<?> klass : inst.getAllLoadedClasses()) {
48
/*
49
* When agent is running class 'classToRedefine1' should be
50
* already loaded by the target application
51
*/
52
if (klass.getName().equals(classToRedefine1)) {
53
classWasFound = true;
54
display("Trying to redefine class '" + classToRedefine1 + "'");
55
redefineClass(klass);
56
display("Class was redefined");
57
break;
58
}
59
}
60
61
if (!classWasFound) {
62
setStatusFailed("Instrumentation.getAllLoadedClasses() didn't return class '" + classToRedefine1 + "'");
63
}
64
65
/*
66
* Try to load and redefine 'classToRedefine2'
67
*/
68
69
Class<?> klass = Class.forName(classToRedefine2);
70
display("Trying to redefine class '" + classToRedefine2 + "'");
71
redefineClass(klass);
72
display("Class was redefined");
73
74
final String expectedString = "ClassToRedefine02: Class is redefined";
75
ClassToRedefine02 instance = new ClassToRedefine02();
76
String string = instance.getString();
77
display("ClassToRedefine02.getString(): " + string);
78
if (!string.equals(expectedString)) {
79
setStatusFailed("ClassToRedefine02.getString() returned unexpected value , expected is '" + expectedString + "'");
80
}
81
}
82
83
public static void agentmain(String options, Instrumentation inst) {
84
new attach030Agent00().runJarAgent(options, inst);
85
}
86
}
87
88