< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/javaldr/AnonVmClassesDuringDump.java

Print this page
rev 59477 : [mq]: cds_lambda


  28  *          are handled properly. Note: these are not "anonymous inner classes" in the Java source code,
  29  *          but rather classes that are not recorded in any ClassLoaderData::dictionary(),
  30  *          such as classes that are generated for Lambda expressions.
  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
  33  * @requires vm.cds
  34  * @requires vm.flavor != "minimal"
  35  * @run driver AnonVmClassesDuringDump
  36  */
  37 
  38 public class AnonVmClassesDuringDump {
  39     public static String appClasses[] = {
  40         Hello.class.getName(),
  41     };
  42     public static String agentClasses[] = {
  43         AnonVmClassesDuringDumpTransformer.class.getName(),
  44     };
  45 
  46     public static String cdsDiagnosticOption = "-XX:+AllowArchivingWithJavaAgent";
  47 



  48     public static void main(String[] args) throws Throwable {
  49         String agentJar =
  50             ClassFileInstaller.writeJar("AnonVmClassesDuringDumpTransformer.jar",
  51                                         ClassFileInstaller.Manifest.fromSourceFile("AnonVmClassesDuringDumpTransformer.mf"),
  52                                         agentClasses);
  53 
  54         String appJar =
  55             ClassFileInstaller.writeJar("AnonVmClassesDuringDumpApp.jar", appClasses);
  56 
  57         TestCommon.testDump(appJar, TestCommon.list(Hello.class.getName()),
  58                             "-javaagent:" + agentJar,
  59                             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
  60                             // Set the following property to see logs for dynamically generated classes
  61                             // in STDOUT
  62                             "-Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true");
  63 
  64         String prefix = ".class.load. ";
  65         // class name pattern like the following:
  66         // jdk.internal.loader.BuiltinClassLoader$$Lambda$1/1816757085
  67         // java.lang.invoke.LambdaForm$MH/1585787493
  68         String class_pattern = ".*Lambda([a-z0-9$]+)/([0-9]+).*";
  69         String suffix = ".*source: shared objects file.*";
  70         String pattern = prefix + class_pattern + suffix;
  71         // during run time, anonymous classes shouldn't be loaded from the archive
  72         TestCommon.run("-cp", appJar,
  73             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption, Hello.class.getName())
  74             .assertNormalExit(output -> output.shouldNotMatch(pattern));


  75 
  76         // inspect the archive and make sure no anonymous class is in there
  77         TestCommon.run("-cp", appJar,
  78             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
  79             "-XX:+PrintSharedArchiveAndExit", "-XX:+PrintSharedDictionary", Hello.class.getName())
  80             .assertNormalExit(output -> output.shouldNotMatch(class_pattern));


  81     }
  82 }
  83 


  28  *          are handled properly. Note: these are not "anonymous inner classes" in the Java source code,
  29  *          but rather classes that are not recorded in any ClassLoaderData::dictionary(),
  30  *          such as classes that are generated for Lambda expressions.
  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
  33  * @requires vm.cds
  34  * @requires vm.flavor != "minimal"
  35  * @run driver AnonVmClassesDuringDump
  36  */
  37 
  38 public class AnonVmClassesDuringDump {
  39     public static String appClasses[] = {
  40         Hello.class.getName(),
  41     };
  42     public static String agentClasses[] = {
  43         AnonVmClassesDuringDumpTransformer.class.getName(),
  44     };
  45 
  46     public static String cdsDiagnosticOption = "-XX:+AllowArchivingWithJavaAgent";
  47 
  48     public static final boolean dynamicMode =
  49         Boolean.getBoolean(System.getProperty("test.dynamic.cds.archive", "false"));
  50 
  51     public static void main(String[] args) throws Throwable {
  52         String agentJar =
  53             ClassFileInstaller.writeJar("AnonVmClassesDuringDumpTransformer.jar",
  54                                         ClassFileInstaller.Manifest.fromSourceFile("AnonVmClassesDuringDumpTransformer.mf"),
  55                                         agentClasses);
  56 
  57         String appJar =
  58             ClassFileInstaller.writeJar("AnonVmClassesDuringDumpApp.jar", appClasses);
  59 
  60         TestCommon.testDump(appJar, TestCommon.list(Hello.class.getName()),
  61                             "-javaagent:" + agentJar,
  62                             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
  63                             // Set the following property to see logs for dynamically generated classes
  64                             // in STDOUT
  65                             "-Djava.lang.invoke.MethodHandle.DUMP_CLASS_FILES=true");
  66 
  67         String prefix = ".class.load. ";
  68         // class name pattern like the following:
  69         // jdk.internal.loader.BuiltinClassLoader$$Lambda$1/1816757085
  70         // java.lang.invoke.LambdaForm$MH/1585787493
  71         String class_pattern = ".*Lambda([a-z0-9$]+)/([0-9]+).*";
  72         String suffix = ".*source: shared objects file.*";
  73         String pattern = prefix + class_pattern + suffix;
  74         // during run time, anonymous classes shouldn't be loaded from the archive
  75         TestCommon.run("-cp", appJar,
  76             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption, Hello.class.getName())
  77             .assertNormalExit(dynamicMode ?
  78                 output -> output.shouldMatch(pattern) :
  79                 output -> output.shouldNotMatch(pattern));
  80 
  81         // inspect the archive and make sure no anonymous class is in there
  82         TestCommon.run("-cp", appJar,
  83             "-XX:+UnlockDiagnosticVMOptions", cdsDiagnosticOption,
  84             "-XX:+PrintSharedArchiveAndExit", "-XX:+PrintSharedDictionary", Hello.class.getName())
  85             .assertNormalExit(dynamicMode ?
  86                 output -> output.shouldMatch(pattern) :
  87                 output -> output.shouldNotMatch(pattern));
  88     }
  89 }
  90 
< prev index next >