test/hotspot/jtreg/runtime/cds/appcds/javaldr/AnonVmClassesDuringDump.java
changeset 59129 d8eddc0ba770
parent 57705 7cf02b2c1455
equal deleted inserted replaced
59128:ac11b83e0f38 59129:d8eddc0ba770
    30  *          such as classes that are generated for Lambda expressions.
    30  *          such as classes that are generated for Lambda expressions.
    31  *          See https://blogs.oracle.com/jrose/anonymous-classes-in-the-vm.
    31  *          See https://blogs.oracle.com/jrose/anonymous-classes-in-the-vm.
    32  * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
    32  * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
    33  * @requires vm.cds
    33  * @requires vm.cds
    34  * @requires vm.flavor != "minimal"
    34  * @requires vm.flavor != "minimal"
    35  * @build AnonVmClassesDuringDumpTransformer Hello
    35  * @run driver AnonVmClassesDuringDump
    36  * @run main/othervm AnonVmClassesDuringDump
       
    37  */
    36  */
    38 
    37 
    39 public class AnonVmClassesDuringDump {
    38 public class AnonVmClassesDuringDump {
    40     public static String appClasses[] = {
    39     public static String appClasses[] = {
    41         "Hello",
    40         Hello.class.getName(),
    42     };
    41     };
    43     public static String agentClasses[] = {
    42     public static String agentClasses[] = {
    44         "AnonVmClassesDuringDumpTransformer",
    43         AnonVmClassesDuringDumpTransformer.class.getName(),
    45     };
    44     };
    46 
    45 
    47     public static String cdsDiagnosticOption = "-XX:+AllowArchivingWithJavaAgent";
    46     public static String cdsDiagnosticOption = "-XX:+AllowArchivingWithJavaAgent";
    48 
    47 
    49     public static void main(String[] args) throws Throwable {
    48     public static void main(String[] args) throws Throwable {
    53                                         agentClasses);
    52                                         agentClasses);
    54 
    53 
    55         String appJar =
    54         String appJar =
    56             ClassFileInstaller.writeJar("AnonVmClassesDuringDumpApp.jar", appClasses);
    55             ClassFileInstaller.writeJar("AnonVmClassesDuringDumpApp.jar", appClasses);
    57 
    56 
    58         TestCommon.testDump(appJar, TestCommon.list("Hello"),
    57         TestCommon.testDump(appJar, TestCommon.list(Hello.class.getName()),
    59                             "-javaagent:" + agentJar,
    58                             "-javaagent:" + agentJar,
    60                             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
    59                             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
    61                             // Set the following property to see logs for dynamically generated classes
    60                             // Set the following property to see logs for dynamically generated classes
    62                             // in STDOUT
    61                             // in STDOUT
    63                             "-Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true");
    62                             "-Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true");
    69         String class_pattern = ".*Lambda([a-z0-9$]+)/([0-9]+).*";
    68         String class_pattern = ".*Lambda([a-z0-9$]+)/([0-9]+).*";
    70         String suffix = ".*source: shared objects file.*";
    69         String suffix = ".*source: shared objects file.*";
    71         String pattern = prefix + class_pattern + suffix;
    70         String pattern = prefix + class_pattern + suffix;
    72         // during run time, anonymous classes shouldn't be loaded from the archive
    71         // during run time, anonymous classes shouldn't be loaded from the archive
    73         TestCommon.run("-cp", appJar,
    72         TestCommon.run("-cp", appJar,
    74             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption, "Hello")
    73             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption, Hello.class.getName())
    75             .assertNormalExit(output -> output.shouldNotMatch(pattern));
    74             .assertNormalExit(output -> output.shouldNotMatch(pattern));
    76 
    75 
    77         // inspect the archive and make sure no anonymous class is in there
    76         // inspect the archive and make sure no anonymous class is in there
    78         TestCommon.run("-cp", appJar,
    77         TestCommon.run("-cp", appJar,
    79             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
    78             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
    80             "-XX:+PrintSharedArchiveAndExit", "-XX:+PrintSharedDictionary", "Hello")
    79             "-XX:+PrintSharedArchiveAndExit", "-XX:+PrintSharedDictionary", Hello.class.getName())
    81             .assertNormalExit(output -> output.shouldNotMatch(class_pattern));
    80             .assertNormalExit(output -> output.shouldNotMatch(class_pattern));
    82     }
    81     }
    83 }
    82 }
    84 
    83