Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdline_options_testresources/src/VMBench/GPTests/GPTest.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2020 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
package VMBench.GPTests;
24
25
import VMBench.GPTests.GPTest;
26
27
public class GPTest implements Runnable {
28
static { System.loadLibrary("gptest"); }
29
String arg;
30
31
public static int globalInt;
32
/**
33
*
34
* @param arg java.lang.String
35
*/
36
public GPTest(String arg) {
37
this.arg = arg;
38
}
39
40
public native void gpFloat();
41
public native void gpIll();
42
public native void gpRead();
43
public native void gpWrite();
44
public native void gpSoftwareFloat();
45
public native void gpHardwareFloat();
46
public native void gpSoftwareRead();
47
public native void gpHardwareRead();
48
public native void gpAbort();
49
50
public native void callBackIn();
51
public native void callInAndTriggerGPReadThenResumeAndCallInAgain();
52
public native void callInAndTriggerGPReadThenResumeAndReturnToJava(int count);
53
54
/**
55
* Starts the application.
56
* @param args an array of command-line arguments
57
*/
58
public static void main(java.lang.String[] args) {
59
boolean thread = false;
60
61
if (args.length != 1) {
62
if (args.length == 2 && args[0].equalsIgnoreCase("thread")) {
63
thread = true;
64
} else {
65
System.err.println("Incorrect args.");
66
System.err.println("Args: [thread] [float|ill|read|write|callin]");
67
System.err.println("If 'thread' is set the GP test runs in a child thread,");
68
System.err.println("otherwise it runs in the main thread.");
69
System.exit(1);
70
}
71
}
72
73
GPTest test = new GPTest(args[args.length - 1]);
74
if (thread) {
75
new Thread(test).start();
76
} else {
77
test.run();
78
}
79
}
80
public void run() {
81
82
if (arg.equalsIgnoreCase("softwareFloat")) {
83
this.gpSoftwareFloat();
84
System.err.println("Survived software-triggered SIGFPE!");
85
System.exit(3);
86
}
87
88
if (arg.equalsIgnoreCase("hardwareFloat")) {
89
this.gpHardwareFloat();
90
System.err.println("Survived hardware-triggered SIGFPE!");
91
System.exit(3);
92
}
93
94
if (arg.equalsIgnoreCase("softwareRead")) {
95
this.gpSoftwareRead();
96
System.err.println("Survived software-triggered SIGSEGV!");
97
System.exit(3);
98
}
99
100
if (arg.equalsIgnoreCase("hardwareRead")) {
101
this.gpHardwareRead();
102
System.err.println("Survived hardware-triggered SIGSEGV!");
103
System.exit(3);
104
}
105
106
if (arg.equalsIgnoreCase("abort")) {
107
System.out.println("Invoking abort!");
108
this.gpAbort();
109
System.err.println("Survived abort!");
110
System.exit(3);
111
}
112
113
if (arg.equalsIgnoreCase("float")) {
114
115
/* Call this multiple times for-XCEEHDLR to exercise running Java code following
116
* the conversion from LE Condition to Java ConditionException
117
*
118
* Calling it multiple times will not affect the non -XCEEHDLR case, as a crash is expected the first time 'round */
119
for (int i = 0; i < 50 ; i++) {
120
try {
121
this.gpFloat();
122
} catch (com.ibm.le.conditionhandling.ConditionException ce) {
123
byte []feedbackToken;
124
java.util.Locale locale = null;
125
126
System.err.println("");
127
System.err.println("");
128
System.err.println(ce.toString());
129
System.err.println("\t" + ce.getRoutine() + ": " + ce.getOffsetInRoutine());
130
System.err.println("\tfacilityID: " + ce.getFacilityID());
131
System.err.println("\tseverity: " + ce.getSeverity());
132
System.err.println("\tmessageNumber: " + ce.getMessageNumber());
133
feedbackToken = ce.getToken();
134
System.err.print("\t feedback token: ");
135
for (int j = 0 ; j< feedbackToken.length ; j++) {
136
System.err.printf(locale, "%#x ", feedbackToken[j]);
137
}
138
System.err.println("\nSuccesfully threw exception " + (i + 1) + " times");
139
ce.printStackTrace();
140
}
141
}
142
System.err.println("Survived float gp!");
143
System.exit(2);
144
}
145
146
if (arg.equalsIgnoreCase("ill")) {
147
this.gpIll();
148
System.err.println("Survived illegal instruction gp!");
149
System.exit(3);
150
}
151
152
if (arg.equalsIgnoreCase("read")) {
153
this.gpRead();
154
System.err.println("Survived read gp!");
155
System.exit(4);
156
}
157
158
if (arg.equalsIgnoreCase("write")) {
159
this.gpWrite();
160
System.err.println("Survived write gp!");
161
System.exit(5);
162
}
163
164
if (arg.equalsIgnoreCase("callin")) {
165
this.callBackIn();
166
}
167
168
if (arg.equalsIgnoreCase("callIn")) {
169
this.callBackIn();
170
}
171
172
if (arg.equalsIgnoreCase("callInAndTriggerGPReadThenResumeAndCallInAgain")) {
173
this.callInAndTriggerGPReadThenResumeAndCallInAgain();
174
}
175
176
if (arg.equalsIgnoreCase("callInAndTriggerGPReadThenResumeAndReturnToJava")) {
177
this.callInAndTriggerGPReadThenResumeAndReturnToJava(10);
178
}
179
180
if (arg.equalsIgnoreCase("callInAndTriggerGPReadThenResumeAndReturnToJIT")) {
181
this.callInAndTriggerGPReadThenResumeAndReturnToJava_wrapper_wrapper();
182
}
183
184
System.err.println("Unrecognized argument: " + arg);
185
System.exit(1);
186
187
}
188
189
public void callOut() {
190
this.gpRead();
191
System.err.println("Survived read gp!");
192
System.exit(4);
193
}
194
195
public void callInAndTriggerGPReadThenResumeAndReturnToJava_wrapper_wrapper() {
196
197
for (int i = 0 ; i < 100 ; i++) {
198
this.callInAndTriggerGPReadThenResumeAndReturnToJava_wrapper(i);
199
}
200
}
201
202
public void callInAndTriggerGPReadThenResumeAndReturnToJava_wrapper(int count) {
203
204
for (int i =0; i <100 ; i ++) {
205
globalInt = count;
206
}
207
208
this.callInAndTriggerGPReadThenResumeAndReturnToJava(globalInt);
209
210
}
211
212
public void callOutAndTriggerGPRead() {
213
this.gpRead();
214
System.err.println("Survived read gp!");
215
System.exit(4);
216
}
217
218
219
}
220
221