Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/attach/ShMemLongName.java
41149 views
1
/*
2
* Copyright (c) 2018, 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 8049695
27
* @summary Ensure shmem transport works with long names
28
* @requires os.family == "windows"
29
* @library /test/lib
30
* @run main/othervm ShMemLongName
31
*/
32
33
import java.io.BufferedReader;
34
import java.io.IOException;
35
import java.io.InputStreamReader;
36
import java.io.InputStream;
37
import java.util.Collections;
38
import java.util.Map;
39
40
import com.sun.jdi.Bootstrap;
41
import com.sun.jdi.VirtualMachine;
42
import com.sun.jdi.connect.AttachingConnector;
43
import com.sun.jdi.connect.Connector;
44
import jdk.test.lib.process.ProcessTools;
45
46
47
public class ShMemLongName {
48
49
private static final int maxShMemLength = 49;
50
51
private static final String transport = "dt_shmem";
52
53
public static void main(String[] args) throws Exception {
54
// test with the maximum supported shmem name length
55
String shmemName = ("ShMemLongName" + ProcessHandle.current().pid()
56
+ String.join("", Collections.nCopies(maxShMemLength, "x"))
57
).substring(0, maxShMemLength);
58
Process target = getTarget(shmemName).start();
59
try {
60
waitForReady(target);
61
62
log("attaching to the VM...");
63
AttachingConnector ac = Bootstrap.virtualMachineManager().attachingConnectors()
64
.stream()
65
.filter(c -> transport.equals(c.transport().name()))
66
.findFirst()
67
.orElseThrow(() -> new RuntimeException("Failed to find transport " + transport));
68
Map<String, Connector.Argument> acArgs = ac.defaultArguments();
69
acArgs.get("name").setValue(shmemName);
70
71
VirtualMachine vm = ac.attach(acArgs);
72
73
log("attached. test(1) PASSED.");
74
75
vm.dispose();
76
} finally {
77
target.destroy();
78
target.waitFor();
79
}
80
81
// extra test: ensure using of too-long name fails gracefully
82
// (shmemName + "X") is expected to be "too long".
83
ProcessTools.executeProcess(getTarget(shmemName + "X"))
84
.shouldContain("address strings longer than")
85
.shouldHaveExitValue(2);
86
log("test(2) PASSED.");
87
}
88
89
private static void log(String s) {
90
System.out.println(s);
91
System.out.flush();
92
}
93
94
// creates target process builder for the specified shmem transport name
95
private static ProcessBuilder getTarget(String shmemName) throws IOException {
96
log("starting target with shmem name: '" + shmemName + "'...");
97
return ProcessTools.createJavaProcessBuilder(
98
"-Xdebug",
99
"-Xrunjdwp:transport=" + transport + ",server=y,suspend=n,address=" + shmemName,
100
"ShMemLongName$Target");
101
}
102
103
private static void waitForReady(Process target) throws Exception {
104
InputStream os = target.getInputStream();
105
try (BufferedReader reader = new BufferedReader(new InputStreamReader(os))) {
106
String line;
107
while ((line = reader.readLine()) != null) {
108
if (line.equals(Target.readyString)) {
109
return;
110
}
111
}
112
}
113
}
114
115
public static class Target {
116
public static final String readyString = "Ready";
117
public static void main(String[] args) throws Exception {
118
log(readyString);
119
while (true) {
120
Thread.sleep(1000);
121
}
122
}
123
}
124
}
125
126