hotspot/test/runtime/6819213/TestBootNativeLibraryPath.java
author adlertz
Fri, 24 Jan 2014 13:06:52 +0100
changeset 22804 401135897b65
parent 5547 f4b087cbb361
child 29678 dd2f3932c21e
permissions -rw-r--r--
8031498: Cleanup and re-factorize PhaseChaitin::build_ifg_physical Summary: Created sub-functions, added data structures, improved naming and removed unnecessary code Reviewed-by: kvn, roland, rbackman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2358
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
     2
 * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
2358
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
     4
 *
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
     8
 *
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    13
 * accompanied this code).
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    14
 *
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
2358
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    22
 */
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    23
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    24
/*
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    25
 * @test TestBootNativeLibraryPath.java
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    26
 * @bug 6819213
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    27
 * @compile -XDignore.symbol.file TestBootNativeLibraryPath.java
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    28
 * @summary verify sun.boot.native.library.path is expandable on 32 bit systems
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    29
 * @run main TestBootNativeLibraryPath
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    30
 * @author ksrini
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    31
*/
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    32
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    33
import java.io.BufferedReader;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    34
import java.io.File;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    35
import java.io.FileOutputStream;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    36
import java.io.IOException;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    37
import java.io.InputStreamReader;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    38
import java.io.PrintStream;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    39
import java.util.ArrayList;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    40
import java.util.List;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    41
import java.util.Map;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    42
import java.util.logging.Level;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    43
import java.util.logging.Logger;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    44
import javax.tools.JavaCompiler;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    45
import javax.tools.ToolProvider;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    46
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    47
public class TestBootNativeLibraryPath {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    48
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    49
    private static final String TESTFILE = "Test6";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    50
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    51
    static void createTestClass() throws IOException {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    52
        FileOutputStream fos = new FileOutputStream(TESTFILE + ".java");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    53
        PrintStream ps = new PrintStream(fos);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    54
        ps.println("public class " + TESTFILE + "{");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    55
        ps.println("public static void main(String[] args) {\n");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    56
        ps.println("System.out.println(System.getProperty(\"sun.boot.library.path\"));\n");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    57
        ps.println("}}\n");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    58
        ps.close();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    59
        fos.close();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    60
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    61
        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    62
        String javacOpts[] = {TESTFILE + ".java"};
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    63
        if (javac.run(null, null, null,  javacOpts) != 0) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    64
            throw new RuntimeException("compilation of " + TESTFILE + ".java Failed");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    65
        }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    66
    }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    67
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    68
    static List<String> doExec(String... args) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    69
        String javaCmd = System.getProperty("java.home") + "/bin/java";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    70
        if (!new File(javaCmd).exists()) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    71
            javaCmd = System.getProperty("java.home") + "/bin/java.exe";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    72
        }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    73
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    74
        ArrayList<String> cmds = new ArrayList<String>();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    75
        cmds.add(javaCmd);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    76
        for (String x : args) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    77
            cmds.add(x);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    78
        }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    79
        System.out.println("cmds=" + cmds);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    80
        ProcessBuilder pb = new ProcessBuilder(cmds);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    81
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    82
        Map<String, String> env = pb.environment();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    83
        pb.directory(new File("."));
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    84
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    85
        List<String> out = new ArrayList<String>();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    86
        try {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    87
            pb.redirectErrorStream(true);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    88
            Process p = pb.start();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    89
            BufferedReader rd = new BufferedReader(new InputStreamReader(p.getInputStream()),8192);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    90
            String in = rd.readLine();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    91
            while (in != null) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    92
                out.add(in);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    93
                System.out.println(in);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    94
                in = rd.readLine();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    95
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    96
            int retval = p.waitFor();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    97
            p.destroy();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    98
            if (retval != 0) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
    99
                throw new RuntimeException("Error: test returned non-zero value");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   100
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   101
            return out;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   102
        } catch (Exception ex) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   103
            ex.printStackTrace();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   104
            throw new RuntimeException(ex.getMessage());
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   105
        }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   106
    }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   107
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   108
    public static void main(String[] args) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   109
        try {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   110
            if (!System.getProperty("sun.arch.data.model").equals("32")) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   111
                System.out.println("Warning: test skipped for 64-bit systems\n");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   112
                return;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   113
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   114
            String osname = System.getProperty("os.name");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   115
            if (osname.startsWith("Windows")) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   116
                osname = "Windows";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   117
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   118
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   119
            createTestClass();
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   120
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   121
            // Test a simple path
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   122
            String libpath = File.pathSeparator + "tmp" + File.pathSeparator + "foobar";
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   123
            List<String> processOut = null;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   124
            String sunbootlibrarypath = "-Dsun.boot.library.path=" + libpath;
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   125
            processOut = doExec(sunbootlibrarypath, "-cp", ".", TESTFILE);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   126
            if (processOut == null || !processOut.get(0).endsWith(libpath)) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   127
                throw new RuntimeException("Error: did not get expected error string");
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   128
            }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   129
        } catch (IOException ex) {
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   130
            throw new RuntimeException("Unexpected error " + ex);
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   131
        }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   132
    }
7c8346929fc6 6819213: revive sun.boot.library.path
phh
parents:
diff changeset
   133
}