test/hotspot/jtreg/runtime/LoadClass/LongBCP.java
author rschmelter
Tue, 01 Oct 2019 14:09:44 +0200
changeset 58426 ed5e399d967d
parent 51750 9151fde080e6
child 58878 452df727bebb
permissions -rw-r--r--
8191521: handle long relative path specified in -Xbootclasspath/a on windows Reviewed-by: ccheung, clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48016
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
     1
/*
58426
ed5e399d967d 8191521: handle long relative path specified in -Xbootclasspath/a on windows
rschmelter
parents: 51750
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
48016
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
     4
 *
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
     8
 *
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    13
 * accompanied this code).
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    14
 *
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    18
 *
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    21
 * questions.
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    22
 */
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    23
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    24
/*
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    25
 * @test
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    26
 * @summary JVM should be able to handle full path (directory path plus
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    27
 *          class name) or directory path longer than MAX_PATH specified
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    28
 *          in -Xbootclasspath/a on windows.
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    29
 * @library /test/lib
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    30
 * @modules java.base/jdk.internal.misc
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    31
 *          java.management
51750
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    32
 *          jdk.jartool/sun.tools.jar
48016
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    33
 * @run main LongBCP
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    34
 */
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    35
51312
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
    36
import java.io.File;
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
    37
import java.nio.file.Files;
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
    38
import java.nio.file.FileStore;
48016
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    39
import java.nio.file.Path;
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    40
import java.nio.file.Paths;
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    41
import java.util.Arrays;
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    42
import jdk.test.lib.compiler.CompilerUtils;
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    43
import jdk.test.lib.process.ProcessTools;
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    44
import jdk.test.lib.process.OutputAnalyzer;
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    45
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    46
public class LongBCP {
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    47
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    48
    private static final int MAX_PATH = 260;
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    49
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    50
    public static void main(String args[]) throws Exception {
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    51
        Path sourceDir = Paths.get(System.getProperty("test.src"), "test-classes");
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    52
        Path classDir = Paths.get(System.getProperty("test.classes"));
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    53
        Path destDir = classDir;
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    54
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    55
        // create a sub-path so that the destDir length is almost MAX_PATH
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    56
        // so that the full path (with the class name) will exceed MAX_PATH
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    57
        int subDirLen = MAX_PATH - classDir.toString().length() - 2;
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    58
        if (subDirLen > 0) {
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    59
            char[] chars = new char[subDirLen];
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    60
            Arrays.fill(chars, 'x');
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    61
            String subPath = new String(chars);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    62
            destDir = Paths.get(System.getProperty("test.classes"), subPath);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    63
        }
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    64
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    65
        CompilerUtils.compile(sourceDir, destDir);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    66
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    67
        String bootCP = "-Xbootclasspath/a:" + destDir.toString();
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    68
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    69
            bootCP, "Hello");
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    70
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    71
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    72
        output.shouldContain("Hello World")
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    73
              .shouldHaveExitValue(0);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    74
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    75
        // increase the length of destDir to slightly over MAX_PATH
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    76
        destDir = Paths.get(destDir.toString(), "xxxxx");
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    77
        CompilerUtils.compile(sourceDir, destDir);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    78
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    79
        bootCP = "-Xbootclasspath/a:" + destDir.toString();
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    80
        pb = ProcessTools.createJavaProcessBuilder(
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    81
            bootCP, "Hello");
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    82
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    83
        output = new OutputAnalyzer(pb.start());
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    84
        output.shouldContain("Hello World")
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    85
              .shouldHaveExitValue(0);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
    86
51750
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    87
        // create a hello.jar
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    88
        sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    89
        String helloJar = destDir.toString() + File.separator + "hello.jar";
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    90
        if (!jarTool.run(new String[]
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    91
            {"-cf", helloJar, "-C", destDir.toString(), "Hello.class"})) {
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    92
            throw new RuntimeException("Could not write the Hello jar file");
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    93
        }
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    94
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    95
        // run with long bootclasspath to hello.jar
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    96
        bootCP = "-Xbootclasspath/a:" + helloJar;
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    97
        pb = ProcessTools.createJavaProcessBuilder(
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    98
            bootCP, "Hello");
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
    99
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
   100
        output = new OutputAnalyzer(pb.start());
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
   101
        output.shouldContain("Hello World")
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
   102
              .shouldHaveExitValue(0);
9151fde080e6 8190737: use unicode version of the canonicalize() function to handle long path on windows
ccheung
parents: 51312
diff changeset
   103
48016
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   104
        // relative path tests
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   105
        // We currently cannot handle relative path specified in the
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   106
        // -Xbootclasspath/a on windows.
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   107
        //
51312
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
   108
        // relative path length within the file system limit
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
   109
        int fn_max_length = 255;
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
   110
        // In AUFS file system, the maximal file name length is 242
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
   111
        FileStore store = Files.getFileStore(new File(".").toPath());
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
   112
        String fs_type = store.type();
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
   113
        if ("aufs".equals(fs_type)) {
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
   114
            fn_max_length = 242;
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
   115
        }
c00451b67854 8208623: [TESTBUG] runtime/LoadClass/LongBCP.java fails in AUFS file system
dholmes
parents: 48016
diff changeset
   116
        char[] chars = new char[fn_max_length];
48016
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   117
        Arrays.fill(chars, 'y');
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   118
        String subPath = new String(chars);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   119
        destDir = Paths.get(".", subPath);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   120
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   121
        CompilerUtils.compile(sourceDir, destDir);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   122
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   123
        bootCP = "-Xbootclasspath/a:" + destDir.toString();
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   124
        pb = ProcessTools.createJavaProcessBuilder(
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   125
            bootCP, "Hello");
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   126
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   127
        output = new OutputAnalyzer(pb.start());
58426
ed5e399d967d 8191521: handle long relative path specified in -Xbootclasspath/a on windows
rschmelter
parents: 51750
diff changeset
   128
        output.shouldContain("Hello World")
ed5e399d967d 8191521: handle long relative path specified in -Xbootclasspath/a on windows
rschmelter
parents: 51750
diff changeset
   129
              .shouldHaveExitValue(0);
48016
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   130
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   131
        // total relative path length exceeds MAX_PATH
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   132
        destDir = Paths.get(destDir.toString(), "yyyyyyyy");
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   133
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   134
        CompilerUtils.compile(sourceDir, destDir);
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   135
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   136
        bootCP = "-Xbootclasspath/a:" + destDir.toString();
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   137
        pb = ProcessTools.createJavaProcessBuilder(
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   138
            bootCP, "Hello");
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   139
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   140
        output = new OutputAnalyzer(pb.start());
58426
ed5e399d967d 8191521: handle long relative path specified in -Xbootclasspath/a on windows
rschmelter
parents: 51750
diff changeset
   141
        output.shouldContain("Hello World")
ed5e399d967d 8191521: handle long relative path specified in -Xbootclasspath/a on windows
rschmelter
parents: 51750
diff changeset
   142
              .shouldHaveExitValue(0);
48016
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   143
    }
df39ee817323 8188122: Path length limits on Windows leads to obscure class loading failures
ccheung
parents:
diff changeset
   144
}