Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002.java
40948 views
1
/*
2
* Copyright (c) 2003, 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
24
package nsk.jvmti.ClassFileLoadHook;
25
26
import java.io.*;
27
28
import jdk.test.lib.Utils;
29
import nsk.share.*;
30
import nsk.share.jvmti.*;
31
32
/**
33
* Debuggee class of JVMTI test.
34
*/
35
public class classfloadhk002 extends DebugeeClass {
36
37
/** Load native library if required. */
38
static {
39
System.loadLibrary("classfloadhk002");
40
}
41
42
/** Run test from command line. */
43
public static void main(String argv[]) {
44
argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
45
46
// JCK-compatible exit
47
System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
48
}
49
50
/** Run test from JCK-compatible environment. */
51
public static int run(String argv[], PrintStream out) {
52
return new classfloadhk002().runIt(argv, out);
53
}
54
55
/* =================================================================== */
56
57
/* constant names */
58
public static final String PACKAGE_NAME = "nsk.jvmti.ClassFileLoadHook";
59
public static final String TESTED_CLASS_NAME = PACKAGE_NAME + ".classfloadhk002r";
60
61
/* scaffold objects */
62
ArgumentHandler argHandler = null;
63
Log log = null;
64
long timeout = 0;
65
int status = Consts.TEST_PASSED;
66
67
/* original bytecode of tested class */
68
public static byte origClassBytes[] = null;
69
70
/** Run debuggee code. */
71
public int runIt(String argv[], PrintStream out) {
72
argHandler = new ArgumentHandler(argv);
73
log = new Log(out, argHandler);
74
timeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds
75
76
String args[] = argHandler.getArguments();
77
if (args.length <= 0) {
78
throw new Failure("Path for tested class file to load not specified");
79
}
80
81
log.display("Reading original bytecode of tested class: \n\t" + TESTED_CLASS_NAME);
82
try {
83
origClassBytes = readBytes(TESTED_CLASS_NAME);
84
} catch (IOException e) {
85
throw new Failure("IOException in reading bytecode of tested class file:\n\t" + e);
86
}
87
88
log.display("Sync: debugee ready to load tested class");
89
status = checkStatus(status);
90
91
try {
92
log.display("Loading tested class: " + TESTED_CLASS_NAME);
93
Class testedClass = Class.forName(TESTED_CLASS_NAME);
94
} catch (ClassNotFoundException e) {
95
throw new Failure("No tested class file found: \n\t" + e);
96
}
97
98
log.display("Sync: tested class loaded");
99
status = checkStatus(status);
100
101
return status;
102
}
103
104
/** Read classfile for class name. */
105
public static byte[] readBytes(String classname) throws IOException {
106
String filename = ClassFileFinder.findClassFile(classname, Utils.TEST_CLASS_PATH).toString();
107
FileInputStream in = new FileInputStream(filename);
108
byte[] bytes = new byte[in.available()];
109
in.read(bytes);
110
in.close();
111
return bytes;
112
}
113
}
114
115