< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/cacheObject/ArchiveHeapTestClass.java

Print this page
*** 25,27 ***
  /*
   * @test
   * @bug 8214781 8293187
   * @summary Test for the -XX:ArchiveHeapTestClass flag
   * @requires vm.debug == true & vm.cds.write.archived.java.heap
!  * @modules java.base/sun.invoke.util java.logging
   * @library /test/jdk/lib/testlibrary /test/lib
   *          /test/hotspot/jtreg/runtime/cds/appcds
   *          /test/hotspot/jtreg/runtime/cds/appcds/test-classes
   * @build ArchiveHeapTestClass Hello pkg.ClassInPackage
   * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar boot.jar
   *             CDSTestClassA CDSTestClassA$XX CDSTestClassA$YY
   *             CDSTestClassB CDSTestClassC CDSTestClassD
!  *             CDSTestClassE CDSTestClassF CDSTestClassG
   *             pkg.ClassInPackage
   * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar Hello
   * @run driver ArchiveHeapTestClass
   */
  
  import jdk.test.lib.Platform;
  import jdk.test.lib.helpers.ClassFileInstaller;
  import jdk.test.lib.process.OutputAnalyzer;
  
  public class ArchiveHeapTestClass {
      static final String bootJar = ClassFileInstaller.getJarPath("boot.jar");
      static final String appJar = ClassFileInstaller.getJarPath("app.jar");
      static final String[] appClassList = {"Hello"};
--- 25,28 ---
  /*
   * @test
   * @bug 8214781 8293187
   * @summary Test for the -XX:ArchiveHeapTestClass flag
   * @requires vm.debug == true & vm.cds.write.archived.java.heap
!  * @modules java.base/sun.invoke.util java.base/jdk.internal.misc java.logging
   * @library /test/jdk/lib/testlibrary /test/lib
   *          /test/hotspot/jtreg/runtime/cds/appcds
   *          /test/hotspot/jtreg/runtime/cds/appcds/test-classes
   * @build ArchiveHeapTestClass Hello pkg.ClassInPackage
   * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar boot.jar
   *             CDSTestClassA CDSTestClassA$XX CDSTestClassA$YY
   *             CDSTestClassB CDSTestClassC CDSTestClassD
!  *             CDSTestClassE CDSTestClassF CDSTestClassG CDSTestClassG$MyEnum
   *             pkg.ClassInPackage
   * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar Hello
   * @run driver ArchiveHeapTestClass
   */
  
  import jdk.test.lib.Platform;
  import jdk.test.lib.helpers.ClassFileInstaller;
  import jdk.test.lib.process.OutputAnalyzer;
+ import jdk.internal.misc.CDS;
  
  public class ArchiveHeapTestClass {
      static final String bootJar = ClassFileInstaller.getJarPath("boot.jar");
      static final String appJar = ClassFileInstaller.getJarPath("app.jar");
      static final String[] appClassList = {"Hello"};

*** 100,10 ***
--- 101,21 ---
      }
  
      static void testDebugBuild() throws Exception {
          OutputAnalyzer output;
  
+         testCase("sun.invoke.util.Wrapper");
+         output = dumpBootAndHello(CDSTestClassG_name);
+         mustSucceed(output);
+ 
+         TestCommon.run("-Xbootclasspath/a:" + bootJar, "-cp", appJar, "-Xlog:cds+heap",
+                        "--add-exports", "java.base/sun.invoke.util=ALL-UNNAMED",
+                        "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED",
+                        CDSTestClassG_name)
+             .assertNormalExit("resolve subgraph " + CDSTestClassG_name,
+                               "Initialized from CDS");
+ 
          testCase("Simple positive case");
          output = dumpBootAndHello(CDSTestClassA_name);
          mustSucceed(output, CDSTestClassA.getOutput()); // make sure <clinit> is executed
          output.shouldMatch("warning.*cds.*Loading ArchiveHeapTestClass " + CDSTestClassA_name);
          output.shouldMatch("warning.*cds.*Initializing ArchiveHeapTestClass " + CDSTestClassA_name);

*** 267,10 ***
  }
  
  class CDSTestClassG {
      static Object[] archivedObjects;
      static {
!         // Not in java.base
!         archivedObjects = new Object[1];
!         archivedObjects[0] = sun.invoke.util.Wrapper.BOOLEAN;
      }
  }
--- 279,88 ---
  }
  
  class CDSTestClassG {
      static Object[] archivedObjects;
      static {
!         CDS.initializeFromArchive(CDSTestClassG.class);
!         if (archivedObjects == null) {
!             archivedObjects = new Object[4];
+             archivedObjects[0] = sun.invoke.util.Wrapper.BOOLEAN;
+             archivedObjects[1] = sun.invoke.util.Wrapper.INT.zero();
+             archivedObjects[2] = sun.invoke.util.Wrapper.DOUBLE.zero();
+             archivedObjects[3] = MyEnum.DUMMY1;
+         } else {
+             System.out.println("Initialized from CDS");
+         }
+     }
+ 
+     public static void main(String args[]) {
+         if (archivedObjects[0] != sun.invoke.util.Wrapper.BOOLEAN) {
+             throw new RuntimeException("Huh 1");
+         }
+ 
+         if (archivedObjects[1] != sun.invoke.util.Wrapper.INT.zero()) {
+             throw new RuntimeException("Huh 2");
+         }
+ 
+         Object MY_INT_ZERO = (Integer)(int)0;
+         if (archivedObjects[1] != MY_INT_ZERO) {
+             throw new RuntimeException("Huh 3");
+         }
+ 
+         if (archivedObjects[2] != sun.invoke.util.Wrapper.DOUBLE.zero()) {
+             throw new RuntimeException("Huh 4");
+         }
+ 
+         if (false) {
+             Object MY_DOUBLE_ZERO = (Double)(double)0;
+             if (archivedObjects[1] != MY_DOUBLE_ZERO) {
+                 throw new RuntimeException("Huh 5");
+             }
+         }
+ 
+         if (MyEnum.BOOLEAN != true) {
+             throw new RuntimeException("Huh 10.1");
+         }
+         if (MyEnum.BYTE != -128) {
+             throw new RuntimeException("Huh 10.2");
+         }
+         if (MyEnum.CHAR != 'c') {
+             throw new RuntimeException("Huh 10.3");
+         }
+         if (MyEnum.SHORT != -12345) {
+             throw new RuntimeException("Huh 10.4");
+         }
+         if (MyEnum.INT != -123456) {
+             throw new RuntimeException("Huh 10.5");
+         }
+         if (MyEnum.LONG != 0x1234567890L) {
+             throw new RuntimeException("Huh 10.6");
+         }
+         if (MyEnum.LONG2 != -0x1234567890L) {
+             throw new RuntimeException("Huh 10.7");
+         }
+         if (MyEnum.FLOAT != 567891.0f) {
+             throw new RuntimeException("Huh 10.8");
+         }
+         if (MyEnum.DOUBLE != 12345678905678.890) {
+             throw new RuntimeException("Huh 10.9");
+         }
+ 
+         System.out.println("Success!");
+     }
+ 
+     enum MyEnum {
+         DUMMY1,
+         DUMMY2;
+ 
+         static final boolean BOOLEAN = true;
+         static final byte    BYTE    = -128;
+         static final short   SHORT   = -12345;
+         static final char    CHAR    = 'c';
+         static final int     INT     = -123456;
+         static final long    LONG    =  0x1234567890L;
+         static final long    LONG2   = -0x1234567890L;
+         static final float   FLOAT   = 567891.0f;
+         static final double  DOUBLE  = 12345678905678.890;
      }
  }
< prev index next >