1 /*
  2  * Copyright (c) 2020, 2023, 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 // this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
 25 
 26 /*
 27  * @test
 28  * @summary Run the MethodHandlesAsCollectorTest.java test in static CDS archive mode.
 29  * @requires vm.cds & vm.compMode != "Xcomp"
 30  * @comment Some of the tests run excessively slowly with -Xcomp. The original
 31  *          tests aren't executed with -Xcomp in the CI pipeline, so let's exclude
 32  *          the generated tests from -Xcomp execution as well.
 33  * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
 34  *          /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
 35  * @compile ../../../../../../jdk/java/lang/invoke/MethodHandlesTest.java
 36  *        ../../../../../../lib/jdk/test/lib/Utils.java
 37  *        ../../../../../../jdk/java/lang/invoke/MethodHandlesAsCollectorTest.java
 38  *        ../../../../../../jdk/java/lang/invoke/remote/RemoteExample.java
 39  *        ../../../../../../jdk/java/lang/invoke/common/test/java/lang/invoke/lib/CodeCacheOverflowProcessor.java
 40  *        ../dynamicArchive/test-classes/TestMHApp.java
 41  * @build jdk.test.whitebox.WhiteBox
 42  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 43  * @run junit/othervm/timeout=480 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. MethodHandlesAsCollectorTest
 44  */
 45 
 46 import org.junit.Test;
 47 
 48 import java.io.File;
 49 import java.nio.file.Path;
 50 
 51 import jdk.test.lib.cds.CDSOptions;
 52 import jdk.test.lib.cds.CDSTestUtils;
 53 import jdk.test.lib.process.OutputAnalyzer;
 54 import jdk.test.lib.Platform;
 55 
 56 public class MethodHandlesAsCollectorTest {
 57     @Test
 58     public void test() throws Exception {
 59         testImpl();
 60     }
 61 
 62     private static final String classDir = System.getProperty("test.classes");
 63     private static final String mainClass = "TestMHApp";
 64     private static final String javaClassPath = System.getProperty("java.class.path");
 65     private static final String ps = System.getProperty("path.separator");
 66     private static final String testPackageName = "test.java.lang.invoke";
 67     private static final String testClassName = "MethodHandlesAsCollectorTest";
 68 
 69     static void testImpl() throws Exception {
 70         String appJar = JarBuilder.build("MH", new File(classDir), null);
 71         String classList = testClassName + ".list";
 72         String archiveName = testClassName + ".jsa";
 73         // Disable VerifyDpendencies when running with debug build because
 74         // the test requires a lot more time to execute with the option enabled.
 75         String verifyOpt =
 76             Platform.isDebugBuild() ? "-XX:-VerifyDependencies" : "-showversion";
 77 
 78         String junitJar = Path.of(Test.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
 79 
 80         String jars = appJar + ps + junitJar;
 81 
 82         // dump class list
 83         CDSTestUtils.dumpClassList(classList, "-cp", jars, verifyOpt, mainClass,
 84                                    testPackageName + "." + testClassName);
 85 
 86         // create archive with the class list
 87         CDSOptions opts = (new CDSOptions())
 88             .addPrefix("-XX:ExtraSharedClassListFile=" + classList,
 89                        "-cp", jars,
 90                        "-Xlog:class+load,cds")
 91             .setArchiveName(archiveName);
 92         CDSTestUtils.createArchiveAndCheck(opts);
 93 
 94         // run with archive
 95         CDSOptions runOpts = (new CDSOptions())
 96             .addPrefix("-cp", jars, "-Xlog:class+load,cds=debug", verifyOpt)
 97             .setArchiveName(archiveName)
 98             .setUseVersion(false)
 99             .addSuffix(mainClass, testPackageName + "." + testClassName);
100         OutputAnalyzer output = CDSTestUtils.runWithArchive(runOpts);
101         // FIXME:leyden-premain : we disabled archived Lambda proxy classes due to JDK-8307468
102         // output.shouldMatch(".class.load. test.java.lang.invoke.MethodHandlesAsCollectorTest[$][$]Lambda.*/0x.*source:.*shared.*objects.*file")
103         //      .shouldHaveExitValue(0);
104     }
105 }