Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codecache/stress/Helper.java
41153 views
1
/*
2
* Copyright (c) 2014, 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
24
package compiler.codecache.stress;
25
26
import jdk.test.lib.Asserts;
27
import jdk.test.lib.ByteCodeLoader;
28
import jdk.test.lib.InfiniteLoop;
29
import sun.hotspot.WhiteBox;
30
31
import java.io.BufferedInputStream;
32
import java.io.ByteArrayOutputStream;
33
import java.io.IOException;
34
import java.util.concurrent.Callable;
35
36
public final class Helper {
37
public static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
38
39
private static final long THRESHOLD = WHITE_BOX.getIntxVMFlag("CompileThreshold");
40
private static final String TEST_CASE_IMPL_CLASS_NAME = TestCaseImpl.class.getName();
41
private static byte[] CLASS_DATA;
42
static {
43
try {
44
CLASS_DATA = loadClassData(TEST_CASE_IMPL_CLASS_NAME);
45
} catch (IOException e) {
46
throw new Error("TESTBUG: cannot load class byte code " + TEST_CASE_IMPL_CLASS_NAME, e);
47
}
48
}
49
50
private Helper() {
51
}
52
53
public static void startInfiniteLoopThread(Runnable action) {
54
startInfiniteLoopThread(action, 0L);
55
}
56
57
public static void startInfiniteLoopThread(Runnable action, long millis) {
58
Thread t = new Thread(new InfiniteLoop(action, millis));
59
t.setDaemon(true);
60
t.start();
61
}
62
63
public static int callMethod(Callable<Integer> callable, int expected) {
64
int result = 0;
65
for (int i = 0; i < THRESHOLD; ++i) {
66
try {
67
result = callable.call();
68
} catch (Exception e) {
69
throw new AssertionError(
70
"Exception occurred during test method execution", e);
71
}
72
Asserts.assertEQ(result, expected, "Method returns unexpected value");
73
}
74
return result;
75
}
76
77
private static byte[] loadClassData(String name) throws IOException {
78
try (BufferedInputStream in = new BufferedInputStream(
79
ClassLoader.getSystemResourceAsStream(name.replace(".", "/")
80
+ ".class"))) {
81
ByteArrayOutputStream result = new ByteArrayOutputStream();
82
byte[] buffer = new byte[1024];
83
int read;
84
while ((read = in.read(buffer)) != -1) {
85
result.write(buffer, 0, read);
86
}
87
return result.toByteArray();
88
}
89
}
90
91
public interface TestCase {
92
93
public static TestCase get() {
94
try {
95
Class clazz = ByteCodeLoader.load(
96
TEST_CASE_IMPL_CLASS_NAME, CLASS_DATA);
97
return (TestCase) clazz.newInstance();
98
} catch (ReflectiveOperationException e) {
99
throw new Error(String.format(
100
"TESTBUG: error while creating %s instance from reloaded class",
101
TEST_CASE_IMPL_CLASS_NAME), e);
102
}
103
}
104
105
Callable<Integer> getCallable();
106
int method();
107
int expectedValue();
108
}
109
}
110
111