Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/LoadClass/LongBCP.java
40942 views
1
/*
2
* Copyright (c) 2017, 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
/*
25
* @test
26
* @summary JVM should be able to handle full path (directory path plus
27
* class name) or directory path longer than MAX_PATH specified
28
* in -Xbootclasspath/a on windows.
29
* @library /test/lib
30
* @modules java.base/jdk.internal.misc
31
* java.management
32
* jdk.jartool/sun.tools.jar
33
* @run driver LongBCP
34
*/
35
36
import java.io.File;
37
import java.nio.file.Files;
38
import java.nio.file.FileStore;
39
import java.nio.file.Path;
40
import java.nio.file.Paths;
41
import java.util.Arrays;
42
import java.util.spi.ToolProvider;
43
import jdk.test.lib.compiler.CompilerUtils;
44
import jdk.test.lib.process.ProcessTools;
45
import jdk.test.lib.process.OutputAnalyzer;
46
47
public class LongBCP {
48
49
private static final int MAX_PATH = 260;
50
51
private static final ToolProvider JAR = ToolProvider.findFirst("jar")
52
.orElseThrow(() -> new RuntimeException("ToolProvider for jar not found"));
53
54
public static void main(String args[]) throws Exception {
55
Path sourceDir = Paths.get(System.getProperty("test.src"), "test-classes");
56
Path classDir = Paths.get(System.getProperty("test.classes"));
57
Path destDir = classDir;
58
59
// create a sub-path so that the destDir length is almost MAX_PATH
60
// so that the full path (with the class name) will exceed MAX_PATH
61
int subDirLen = MAX_PATH - classDir.toString().length() - 2;
62
if (subDirLen > 0) {
63
char[] chars = new char[subDirLen];
64
Arrays.fill(chars, 'x');
65
String subPath = new String(chars);
66
destDir = Paths.get(System.getProperty("test.classes"), subPath);
67
}
68
69
CompilerUtils.compile(sourceDir, destDir);
70
71
String bootCP = "-Xbootclasspath/a:" + destDir.toString();
72
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
73
bootCP, "Hello");
74
75
OutputAnalyzer output = new OutputAnalyzer(pb.start());
76
output.shouldContain("Hello World")
77
.shouldHaveExitValue(0);
78
79
// increase the length of destDir to slightly over MAX_PATH
80
destDir = Paths.get(destDir.toString(), "xxxxx");
81
CompilerUtils.compile(sourceDir, destDir);
82
83
bootCP = "-Xbootclasspath/a:" + destDir.toString();
84
pb = ProcessTools.createJavaProcessBuilder(
85
bootCP, "Hello");
86
87
output = new OutputAnalyzer(pb.start());
88
output.shouldContain("Hello World")
89
.shouldHaveExitValue(0);
90
91
// create a hello.jar
92
String helloJar = destDir.toString() + File.separator + "hello.jar";
93
if (JAR.run(System.out, System.err, "-cf", helloJar, "-C", destDir.toString(), "Hello.class") != 0) {
94
throw new RuntimeException("jar operation for hello.jar failed");
95
}
96
97
// run with long bootclasspath to hello.jar
98
bootCP = "-Xbootclasspath/a:" + helloJar;
99
pb = ProcessTools.createJavaProcessBuilder(
100
bootCP, "Hello");
101
102
output = new OutputAnalyzer(pb.start());
103
output.shouldContain("Hello World")
104
.shouldHaveExitValue(0);
105
106
// relative path tests
107
//
108
// relative path length within the file system limit
109
int fn_max_length = 255;
110
// In AUFS file system, the maximal file name length is 242
111
FileStore store = Files.getFileStore(new File(".").toPath());
112
String fs_type = store.type();
113
if ("aufs".equals(fs_type)) {
114
fn_max_length = 242;
115
}
116
char[] chars = new char[fn_max_length];
117
Arrays.fill(chars, 'y');
118
String subPath = new String(chars);
119
destDir = Paths.get(".", subPath);
120
121
CompilerUtils.compile(sourceDir, destDir);
122
123
bootCP = "-Xbootclasspath/a:" + destDir.toString();
124
pb = ProcessTools.createJavaProcessBuilder(
125
bootCP, "Hello");
126
127
output = new OutputAnalyzer(pb.start());
128
output.shouldContain("Hello World")
129
.shouldHaveExitValue(0);
130
131
// Test a relative path for a jar file < MAX_PATH, but where the
132
// absolute path is > MAX_PATH.
133
Path jarDir = Paths.get(".");
134
for (int i = 0; i < 21; ++i) {
135
jarDir = jarDir.resolve("0123456789");
136
}
137
Files.createDirectories(jarDir);
138
Path jarPath = jarDir.resolve("hello.jar");
139
Files.copy(Paths.get(helloJar), jarPath);
140
bootCP = "-Xbootclasspath/a:" + jarPath.toString();
141
pb = ProcessTools.createJavaProcessBuilder(bootCP, "Hello");
142
143
output = new OutputAnalyzer(pb.start());
144
output.shouldContain("Hello World")
145
.shouldHaveExitValue(0);
146
147
// total relative path length exceeds MAX_PATH
148
destDir = Paths.get(destDir.toString(), "yyyyyyyy");
149
150
CompilerUtils.compile(sourceDir, destDir);
151
152
bootCP = "-Xbootclasspath/a:" + destDir.toString();
153
pb = ProcessTools.createJavaProcessBuilder(
154
bootCP, "Hello");
155
156
output = new OutputAnalyzer(pb.start());
157
output.shouldContain("Hello World")
158
.shouldHaveExitValue(0);
159
}
160
}
161
162