Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/jdk/jfr/startupargs/TestRetransformUsingLog.java
41893 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 jdk.jfr.startupargs;
25
26
import java.util.ArrayList;
27
import java.util.List;
28
import java.util.function.Consumer;
29
30
import jdk.test.lib.jfr.EventNames;
31
import jdk.test.lib.jfr.SimpleEvent;
32
import jdk.test.lib.process.OutputAnalyzer;
33
import jdk.test.lib.process.ProcessTools;
34
35
/**
36
* @test
37
* @key jfr
38
* @requires vm.hasJFR
39
* @library /test/lib
40
* @run main/othervm jdk.jfr.startupargs.TestRetransformUsingLog
41
*/
42
public class TestRetransformUsingLog {
43
44
private static final String FILE_READ_FORCED_CLASS_LOAD = "Adding forced instrumentation for event type " + EventNames.FileRead + " during initial class load";
45
private static final String SIMPLE_EVENT_FORCED_CLASS_LOAD = "Adding forced instrumentation for event type jdk.test.lib.jfr.SimpleEvent during initial class load";
46
private static final String SIMPLE_EVENT_UNFORCED_CLASS_LOAD = "Adding instrumentation for event type jdk.test.lib.jfr.SimpleEvent during initial class load";
47
48
public static class TestApp {
49
public static void main(String[] args) throws Exception {
50
SimpleEvent event = new SimpleEvent();
51
event.commit();
52
}
53
}
54
55
public static void main(String[] args) throws Exception {
56
testRecordingRetransFormFalse();
57
testRecordingRetransFormTrue();
58
testNoRecordingRetransFormFalse();
59
testNoRecordingRetransFormTrue();
60
}
61
62
private static void testRecordingRetransFormFalse() throws Exception {
63
startApp(true, false, out -> {
64
out.shouldContain(FILE_READ_FORCED_CLASS_LOAD);
65
out.shouldContain(SIMPLE_EVENT_FORCED_CLASS_LOAD);
66
});
67
}
68
69
private static void testRecordingRetransFormTrue() throws Exception {
70
startApp(true, true, out -> {
71
out.shouldContain(FILE_READ_FORCED_CLASS_LOAD);
72
out.shouldContain(SIMPLE_EVENT_UNFORCED_CLASS_LOAD);
73
});
74
}
75
76
private static void testNoRecordingRetransFormFalse() throws Exception {
77
startApp(false, false, out -> {
78
out.shouldNotContain(FILE_READ_FORCED_CLASS_LOAD);
79
out.shouldContain(SIMPLE_EVENT_FORCED_CLASS_LOAD);
80
});
81
}
82
83
private static void testNoRecordingRetransFormTrue() throws Exception {
84
startApp(false, true, out -> {
85
out.shouldNotContain(FILE_READ_FORCED_CLASS_LOAD);
86
out.shouldNotContain(SIMPLE_EVENT_FORCED_CLASS_LOAD);
87
out.shouldNotContain(SIMPLE_EVENT_UNFORCED_CLASS_LOAD);
88
});
89
}
90
91
private static void startApp(boolean recording, boolean retransform, Consumer<OutputAnalyzer> verifier) throws Exception {
92
List<String> args = new ArrayList<>();
93
args.add("-Xlog:jfr+system");
94
args.add("-XX:FlightRecorderOptions:retransform=" + retransform);
95
if (recording) {
96
args.add("-XX:StartFlightRecording");
97
}
98
args.add(TestApp.class.getName());
99
System.out.println();
100
System.out.println("Starting test app:");
101
System.out.print("java ");
102
for (String arg : args) {
103
System.out.print(arg + " ");
104
}
105
System.out.println();
106
System.out.println();
107
ProcessBuilder pb = ProcessTools.createTestJvm(args);
108
OutputAnalyzer out = ProcessTools.executeProcess(pb);
109
System.out.println(out.getOutput());
110
verifier.accept(out);
111
}
112
}
113
114