test/hotspot/jtreg/runtime/appcds/jigsaw/classpathtests/DummyClassesInBootClassPath.java
changeset 48832 f1e8ddd6fdc4
parent 48791 6e079ff6c83c
child 48979 514c73a1955b
equal deleted inserted replaced
48831:05894c073b7e 48832:f1e8ddd6fdc4
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    43 import jdk.test.lib.process.OutputAnalyzer;
    43 import jdk.test.lib.process.OutputAnalyzer;
    44 
    44 
    45 public class DummyClassesInBootClassPath {
    45 public class DummyClassesInBootClassPath {
    46     private static final String METHOD_NAME = "thisClassIsDummy()";
    46     private static final String METHOD_NAME = "thisClassIsDummy()";
    47 
    47 
       
    48     static void checkOutput(OutputAnalyzer output, String[] classNames) throws Exception {
       
    49         for (int i = 0; i < classNames.length; i++) {
       
    50             String cn = classNames[i].replace('/', '.');
       
    51             TestCommon.checkExec(output,
       
    52                 "java.lang.NoSuchMethodException: " + cn + "." +
       
    53                 METHOD_NAME);
       
    54             output.shouldNotContain(cn + ".class should be in shared space.");
       
    55         }
       
    56     }
       
    57 
    48     public static void main(String[] args) throws Exception {
    58     public static void main(String[] args) throws Exception {
    49         String classNames[] = { "java/net/HttpCookie",
    59         String classNames[] = { "java/net/HttpCookie",
    50                                 "javax/activation/MimeType"};
    60                                 "javax/activation/MimeType"};
    51         JarBuilder.build("dummyClasses", classNames[0], classNames[1]);
    61         JarBuilder.build("dummyClasses", classNames[0], classNames[1]);
    52 
    62 
    53         String appJar = TestCommon.getTestJar("dummyClasses.jar");
    63         String appJar = TestCommon.getTestJar("dummyClasses.jar");
    54         OutputAnalyzer dumpOutput = TestCommon.dump(
    64         OutputAnalyzer dumpOutput = TestCommon.dump(
    55             appJar, classNames, "-Xbootclasspath/a:" + appJar);
    65             appJar, classNames, "-Xbootclasspath/a:" + appJar,
    56 
    66             "--add-modules", "java.activation");
    57         List<String> argsList = new ArrayList<String>();
    67         List<String> argsList = new ArrayList<String>();
    58         for (int i = 0; i < classNames.length; i++) {
    68         for (int i = 0; i < classNames.length; i++) {
    59             argsList.add(classNames[i].replace('/', '.'));
    69             argsList.add(classNames[i].replace('/', '.'));
    60         }
    70         }
    61         String[] arguments = new String[argsList.size()];
    71         String[] arguments = new String[argsList.size()];
    62         arguments = argsList.toArray(arguments);
    72         arguments = argsList.toArray(arguments);
    63         OutputAnalyzer execOutput = TestCommon.execCommon(
    73         OutputAnalyzer execOutput = TestCommon.execCommon(
    64             "-cp", TestCommon.getTestDir("."), "-verbose:class",
    74             "--add-modules", "java.activation", "-Xbootclasspath/a:" + appJar,
    65             "--add-modules", "java.activation",
    75             "DummyClassHelper", arguments[0], arguments[1]);
    66             "-Xbootclasspath/a:" + appJar, "DummyClassHelper",
    76         checkOutput(execOutput, classNames);
    67             arguments[0], arguments[1]);
       
    68         for (int i = 0; i < arguments.length; i++) {
       
    69             TestCommon.checkExec(execOutput,
       
    70                 "java.lang.NoSuchMethodException: " + arguments[i] + "." +
       
    71                 METHOD_NAME);
       
    72         }
       
    73 
    77 
    74         JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
    78         JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
    75         String whiteBoxJar = TestCommon.getTestJar("WhiteBox.jar");
    79         String whiteBoxJar = TestCommon.getTestJar("WhiteBox.jar");
    76         String bootClassPath = "-Xbootclasspath/a:" + appJar +
    80         String bootClassPath = "-Xbootclasspath/a:" + appJar +
    77             File.pathSeparator + whiteBoxJar;
    81             File.pathSeparator + whiteBoxJar;
       
    82         dumpOutput = TestCommon.dump(
       
    83             appJar, classNames, bootClassPath, "--add-modules", "java.activation");
    78         argsList.add("testWithWhiteBox");
    84         argsList.add("testWithWhiteBox");
    79         arguments = new String[argsList.size()];
    85         arguments = new String[argsList.size()];
    80         arguments = argsList.toArray(arguments);
    86         arguments = argsList.toArray(arguments);
    81         String[] opts = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
    87         String[] opts = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
    82             bootClassPath, "-XX:+TraceClassPaths", "DummyClassHelper",
    88             "--add-modules", "java.activation", bootClassPath, "-Xlog:class+path=trace",
    83             arguments[0], arguments[1], arguments[2]};
    89             "DummyClassHelper", arguments[0], arguments[1], arguments[2]};
    84         OutputAnalyzer output = TestCommon.execCommon(opts);
    90         execOutput = TestCommon.execCommon(opts);
       
    91         checkOutput(execOutput, classNames);
    85     }
    92     }
    86 }
    93 }
    87 
    94