Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/ciReplay/SABase.java
41149 views
1
/*
2
* Copyright (c) 2016, 2021, 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.ciReplay;
25
26
import java.nio.file.Files;
27
import java.nio.file.Paths;
28
import java.io.BufferedReader;
29
import java.io.FileReader;
30
import java.io.IOException;
31
import java.io.File;
32
import java.io.FileInputStream;
33
import java.io.OutputStream;
34
import java.util.Arrays;
35
import jdk.test.lib.Platform;
36
import jdk.test.lib.Asserts;
37
import jdk.test.lib.JDKToolFinder;
38
import jdk.test.lib.process.OutputAnalyzer;
39
import jdk.test.lib.process.ProcessTools;
40
41
public class SABase extends CiReplayBase {
42
private static final String REPLAY_FILE_COPY = "replay_vm.txt";
43
44
public static void main(String args[]) throws Exception {
45
checkSetLimits();
46
SABase base = new SABase(args);
47
boolean c2 = base.runServer.orElseThrow(() -> new Error("runServer must be set"));
48
String[] extra = {};
49
if (Platform.isTieredSupported()) {
50
if (c2) {
51
// Replay produced on first compilation. We want that
52
// compilation delayed so profile data is produced.
53
extra = new String[] {"-XX:-TieredCompilation"};
54
} else {
55
extra = new String[] {"-XX:TieredStopAtLevel=1"};
56
}
57
}
58
base.runTest(/* needCoreDump = */ true, extra);
59
}
60
61
public SABase(String[] args) {
62
super(args);
63
}
64
65
@Override
66
public void testAction() {
67
try {
68
Files.move(Paths.get(REPLAY_FILE_NAME), Paths.get(REPLAY_FILE_COPY));
69
} catch (IOException ioe) {
70
throw new Error("Can't move files: " + ioe, ioe);
71
}
72
ProcessBuilder pb;
73
try {
74
pb = ProcessTools.createTestJvm("--add-modules", "jdk.hotspot.agent",
75
"--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
76
"sun.jvm.hotspot.CLHSDB", JDKToolFinder.getTestJDKTool("java"),
77
TEST_CORE_FILE_NAME);
78
} catch (Exception e) {
79
throw new Error("Can't create process builder: " + e, e);
80
}
81
Process p;
82
try {
83
p = pb.start();
84
} catch (IOException ioe) {
85
throw new Error("Can't start child process: " + ioe, ioe);
86
}
87
OutputStream input = p.getOutputStream();
88
String str = "dumpreplaydata -a > " + REPLAY_FILE_NAME + "\nquit\n";
89
try {
90
input.write(str.getBytes());
91
input.flush();
92
} catch (IOException ioe) {
93
throw new Error("Problem writing process input: " + str, ioe);
94
}
95
try {
96
p.waitFor();
97
} catch (InterruptedException ie) {
98
throw new Error("Problem waitinig child process: " + ie, ie);
99
}
100
int exitValue = p.exitValue();
101
if (exitValue != 0) {
102
String output;
103
try {
104
output = new OutputAnalyzer(p).getOutput();
105
} catch (IOException ioe) {
106
throw new Error("Can't get failed CLHSDB process output: " + ioe, ioe);
107
}
108
throw new AssertionError("CLHSDB wasn't run successfully: " + output);
109
}
110
File replay = new File(REPLAY_FILE_NAME);
111
Asserts.assertTrue(replay.exists() && replay.isFile() && replay.length() > 0,
112
"Replay data wasn't generated by SA");
113
// other than comment lines, content of 2 files should be identical
114
try {
115
BufferedReader rep = new BufferedReader(new FileReader(replay));
116
BufferedReader repCopy = new BufferedReader(new FileReader(REPLAY_FILE_COPY));
117
boolean failure = false;
118
while (true) {
119
String l1;
120
while ((l1 = rep.readLine()) != null) {
121
if (!l1.startsWith("#")) {
122
break;
123
}
124
}
125
String l2;
126
while ((l2 = repCopy.readLine()) != null) {
127
if (!l2.startsWith("#")) {
128
break;
129
}
130
}
131
if (l1 == null || l2 == null) {
132
if (l1 != null || l2 != null) {
133
System.out.println("Warning: replay files are not equal");
134
System.out.println("1: " + l1);
135
System.out.println("2: " + l2);
136
failure = true;
137
}
138
break;
139
}
140
if (!l1.equals(l2)) {
141
System.out.println("Warning: replay files are not equal");
142
System.out.println("1: " + l1);
143
System.out.println("2: " + l2);
144
failure = true;
145
}
146
}
147
if (failure) {
148
throw new RuntimeException("Warning: replay files are not equal");
149
}
150
} catch (IOException ioe) {
151
throw new Error("Can't read replay files: " + ioe, ioe);
152
}
153
commonTests();
154
runVmTests();
155
}
156
157
public static void checkSetLimits() {
158
if (!Platform.isWindows()) {
159
OutputAnalyzer oa;
160
try {
161
// first check if setting limit is possible
162
oa = ProcessTools.executeProcess("sh", "-c", RUN_SHELL_NO_LIMIT + "ulimit -c");
163
} catch (Throwable t) {
164
throw new Error("Can't set limits: " + t, t);
165
}
166
oa.shouldHaveExitValue(0);
167
168
String out = oa.getOutput().trim(); // cut win/*nix newlines
169
if (!out.equals("unlimited") && !out.equals("-1")) {
170
throw new Error("Unable to set limits");
171
}
172
}
173
}
174
}
175
176
177