1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /*
  26  * @test
  27  * @summary Run the CustomFJPoolTest in dynamic CDSarchive mode.
  28  * @requires vm.cds
  29  * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
  30  *          /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
  31  * @compile ../../../../../../jdk/java/util/stream/CustomFJPoolTest.java
  32  *          test-classes/TestStreamApp.java
  33  * @build sun.hotspot.WhiteBox
  34  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  35  * @run testng/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. CDSStreamTestDriver
  36  */
  37 
  38 import org.testng.annotations.Test;
  39 
  40 import java.io.File;
  41 
  42 import jtreg.SkippedException;
  43 
  44 import sun.hotspot.gc.GC;
  45 
  46 @Test
  47 public class CDSStreamTestDriver extends DynamicArchiveTestBase {
  48     @Test
  49     public void testMain() throws Exception {
  50         runTest(CDSStreamTestDriver::doTest);
  51     }
  52 
  53     private static final String classDir = System.getProperty("test.classes");
  54     private static final String mainClass = "TestStreamApp";
  55     private static final String javaClassPath = System.getProperty("java.class.path");
  56     private static final String ps = System.getProperty("path.separator");
  57     private static final String skippedException = "jtreg.SkippedException: Unable to map shared archive: test did not complete";
  58 
  59     static void doTest() throws Exception {
  60         String topArchiveName = getNewArchiveName();
  61         JarBuilder.build("streamapp", new File(classDir), null);
  62         String appJar = classDir + File.separator + "streamapp.jar";
  63 
  64         String[] classPaths = javaClassPath.split(File.pathSeparator);
  65         String testngJar = null;
  66         for (String path : classPaths) {
  67             if (path.endsWith("testng.jar")) {
  68                 testngJar = path;
  69                 break;
  70             }
  71         }
  72 
  73         String[] testClassNames = { "CustomFJPoolTest" };
  74 
  75         for (String className : testClassNames) {
  76             try {
  77             dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
  78                 "-cp", appJar + ps + testngJar,
  79                 mainClass, className);
  80            } catch (SkippedException s) {
  81                if (GC.Z.isSelected() && s.toString().equals(skippedException)) {
  82                    System.out.println("Got " + s.toString() + " as expected.");
  83                    System.out.println("Because the test was run with ZGC with UseCompressedOops and UseCompressedClassPointers disabled,");
  84                    System.out.println("but the base archive was created with the options enabled");
  85               } else {
  86                    throw new RuntimeException("Archive mapping should always succeed after JDK-8231610 (did the machine run out of memory?)");
  87               }
  88            }
  89         }
  90     }
  91 }