Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/VM_Test/src/j9vm/runner/Runner.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
package j9vm.runner;
23
import java.io.*;
24
import java.util.Properties;
25
import java.util.Iterator;
26
import java.util.Map;
27
import java.lang.reflect.Method;
28
29
public class Runner {
30
31
protected enum OSName {
32
AIX,
33
LINUX,
34
WINDOWS,
35
ZOS,
36
MAC,
37
UNKNOWN
38
}
39
40
protected enum OSArch {
41
PPC,
42
S390X,
43
X86,
44
UNKNOWN
45
}
46
47
protected enum AddrMode {
48
BIT31,
49
BIT32,
50
BIT64,
51
UNKNOWN
52
}
53
54
public static final String systemPropertyPrefix = "j9vm.";
55
56
protected String className;
57
protected String exeName;
58
protected String bootClassPath;
59
protected String userClassPath;
60
protected String javaVersion;
61
protected OutputCollector inCollector;
62
protected OutputCollector errCollector;
63
protected OSName osName = OSName.UNKNOWN;
64
protected OSArch osArch = OSArch.UNKNOWN;
65
protected AddrMode addrMode = AddrMode.UNKNOWN;
66
67
private final String heapOptions = "-Xms64m -Xmx64m";
68
69
private void setPlatform() {
70
71
String OSSpec = System.getProperty("os.name").toLowerCase();
72
if (OSSpec != null) {
73
/* Get OS from the spec string */
74
if (OSSpec.contains("aix")) {
75
osName = OSName.AIX;
76
} else if (OSSpec.contains("linux")) {
77
osName = OSName.LINUX;
78
} else if (OSSpec.contains("windows")) {
79
osName = OSName.WINDOWS;
80
} else if (OSSpec.contains("z/os")) {
81
osName = OSName.ZOS;
82
} else if (OSSpec.contains("mac")) {
83
osName = OSName.MAC;
84
} else {
85
System.out.println("Runner couldn't determine underlying OS. Got OS Name:" + OSSpec);
86
osName = OSName.UNKNOWN;
87
}
88
}
89
String archSpec = System.getProperty("os.arch").toLowerCase();
90
if (archSpec != null) {
91
/* Get arch from spec string */
92
if (archSpec.contains("ppc")) {
93
osArch = OSArch.PPC;
94
} else if (archSpec.contains("s390")) {
95
osArch = OSArch.S390X;
96
} else if (archSpec.contains("amd64") || archSpec.contains("x86")) {
97
osArch = OSArch.X86;
98
} else {
99
System.out.println("Runner couldn't determine underlying architecture. Got OS Arch:" + archSpec);
100
osArch = OSArch.UNKNOWN;
101
}
102
}
103
104
String addressingMode = System.getProperty("sun.arch.data.model");
105
if (addressingMode != null) {
106
/* Get address mode. S390 31-Bit addressing mode should return 32. */
107
if ((osArch == OSArch.S390X) && (addressingMode.contains("32"))) {
108
addrMode = AddrMode.BIT31;
109
} else if (addressingMode.contains("32")) {
110
addrMode = AddrMode.BIT32;
111
} else if (addressingMode.contains("64")) {
112
addrMode = AddrMode.BIT64;
113
} else {
114
System.out.println("Runner couldn't determine underlying addressing mode. Got addressingMode:" + addressingMode);
115
addrMode = AddrMode.UNKNOWN;
116
}
117
}
118
}
119
120
public Runner(String className, String exeName, String bootClassPath, String userClassPath, String javaVersion) {
121
super();
122
this.className = className;
123
this.exeName = exeName;
124
this.bootClassPath = bootClassPath;
125
this.userClassPath = userClassPath;
126
this.javaVersion = javaVersion;
127
setPlatform();
128
}
129
130
public String getBootClassPathOption () {
131
if (bootClassPath == null) return "";
132
return "-Xbootclasspath:" + bootClassPath;
133
}
134
135
public String getUserClassPathOption () {
136
if (userClassPath == null) return "";
137
return "-classpath " + userClassPath;
138
}
139
140
public String getJ9VMSystemPropertiesString() {
141
String result = "";
142
Properties systemProperties = System.getProperties();
143
Iterator it = systemProperties.entrySet().iterator();
144
while(it.hasNext()) {
145
Map.Entry entry = (Map.Entry) it.next();
146
String key = (String) entry.getKey();
147
if(key.startsWith(systemPropertyPrefix)) {
148
String value = (String) entry.getValue();
149
result += "-D" + key + "=" + value + " ";
150
}
151
152
}
153
return result;
154
}
155
156
public String getCustomCommandLineOptions() {
157
/* For sub-classes to override, if desired. */
158
return "";
159
}
160
161
public String getCommandLine() {
162
return exeName + " " + heapOptions + " " + getCustomCommandLineOptions() + " "
163
+ getJ9VMSystemPropertiesString() + " " + getBootClassPathOption() + " "
164
+ getUserClassPathOption() + " ";
165
}
166
167
public String getTestClassArguments() {
168
/* For sub-classes to override, if desired. */
169
return "";
170
}
171
172
public int runCommandLine(String commandLine) {
173
System.out.println("command: " + commandLine);
174
System.out.println();
175
Process process;
176
try {
177
process = Runtime.getRuntime().exec(commandLine);
178
} catch (Throwable e) {
179
System.out.println("Exception starting process!");
180
System.out.println("(" + e.getMessage() + ")");
181
e.printStackTrace();
182
return 99999;
183
}
184
185
BufferedInputStream inStream = new BufferedInputStream(process.getInputStream());
186
BufferedInputStream errStream = new BufferedInputStream(process.getErrorStream());
187
inCollector = new OutputCollector(inStream);
188
errCollector = new OutputCollector(errStream);
189
inCollector.start();
190
errCollector.start();
191
try {
192
process.waitFor();
193
inCollector.join();
194
errCollector.join();
195
} catch (InterruptedException e) {
196
/* Nothing. */
197
}
198
/* Must release process resources here, or wimpy platforms
199
like Neutrino will run out of handles! */
200
int retval = process.exitValue();
201
process.destroy(); process = null;
202
System.gc();
203
return retval;
204
}
205
206
public boolean run() {
207
int retval = runCommandLine(getCommandLine() + " " + className + " " + getTestClassArguments());
208
if ( 0 != retval ) {
209
System.out.println("no-zero exit value: " + retval);
210
return false;
211
}
212
return true;
213
}
214
215
}
216
217