Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/tools/jstat/JStatInterval.java
41152 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
/**
25
* @test
26
* @bug 8035668
27
* @library /test/lib
28
* @summary Test checks case when target application finishes execution and jstat didn't complete work.
29
jstat is started with interval = 100 (jstat -compiler 100) and monitored application finishes
30
after 500ms. This shouldn't cause crash or hang in target application or in jstat.
31
* @modules java.management
32
* @build JStatInterval
33
* @run main JStatInterval
34
*/
35
36
import jdk.test.lib.JDKToolLauncher;
37
import jdk.test.lib.Utils;
38
import jdk.test.lib.process.ProcessTools;
39
40
import java.util.concurrent.TimeUnit;
41
import java.util.concurrent.atomic.AtomicBoolean;
42
43
public class JStatInterval {
44
private static final String READY = "READY";
45
private static final String ERROR = "!ERROR";
46
47
public static class Application {
48
public static void main(String[] args) {
49
try {
50
System.out.println(READY);
51
System.out.flush();
52
int exitCode = System.in.read();
53
Thread.sleep(500);
54
System.exit(exitCode);
55
} catch (Exception e) {
56
System.out.println(ERROR);
57
System.out.flush();
58
throw new Error(e);
59
}
60
}
61
}
62
public static void main(String[] args) throws Exception {
63
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
64
"-cp",
65
System.getProperty("test.class.path"),
66
"-XX:+UsePerfData",
67
Application.class.getName()
68
);
69
AtomicBoolean error = new AtomicBoolean(false);
70
Process app = ProcessTools.startProcess(
71
"application",
72
pb,
73
line -> {
74
if (line.equals(READY)) {
75
return true;
76
} else if (line.equals(ERROR)) {
77
error.set(true);
78
return true;
79
}
80
return false;
81
},
82
10,
83
TimeUnit.SECONDS
84
);
85
if (error.get()) {
86
throw new Error("Unable to start the monitored application.");
87
}
88
89
String pidStr = String.valueOf(app.pid());
90
JDKToolLauncher l = JDKToolLauncher.createUsingTestJDK("jstat");
91
l.addVMArgs(Utils.getTestJavaOpts());
92
l.addToolArg("-compiler");
93
l.addToolArg(pidStr);
94
l.addToolArg("100");
95
96
ProcessBuilder jstatDef = new ProcessBuilder(l.getCommand());
97
Process jstat = ProcessTools.startProcess(
98
"jstat",
99
jstatDef,
100
line -> {
101
if (line.trim().toLowerCase().startsWith("compiled")) {
102
return true;
103
}
104
return false;
105
},
106
10,
107
TimeUnit.SECONDS
108
);
109
110
app.getOutputStream().write(0);
111
app.getOutputStream().flush();
112
113
if (app.waitFor() != 0) {
114
throw new Error("Error detected upon exiting the monitored application with active jstat");
115
}
116
if (jstat.waitFor() != 0) {
117
throw new Error("Error detected in jstat when monitored application has exited prematurely");
118
}
119
}
120
}
121
122