1 /*
   2  * Copyright (c) 2020, 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 MethodHandlesCastFailureTest.java test in dynamic 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
  35  *          /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes
  36  * @compile ../../../../../../../jdk/java/lang/invoke/MethodHandlesTest.java
  37  *        ../../../../../../../lib/jdk/test/lib/Utils.java
  38  *        ../../../../../../../jdk/java/lang/invoke/MethodHandlesCastFailureTest.java
  39  *        ../../../../../../../jdk/java/lang/invoke/remote/RemoteExample.java
  40  *        ../../../../../../../jdk/java/lang/invoke/common/test/java/lang/invoke/lib/CodeCacheOverflowProcessor.java
  41  *        ../test-classes/TestMHApp.java
  42  * @build sun.hotspot.WhiteBox
  43  * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  44  * @run junit/othervm/timeout=240 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. MethodHandlesCastFailureTest
  45  */
  46 
  47 import org.junit.Test;
  48 
  49 import java.io.File;
  50 
  51 import jtreg.SkippedException;
  52 
  53 import sun.hotspot.gc.GC;
  54 
  55 public class MethodHandlesCastFailureTest extends DynamicArchiveTestBase {
  56     @Test
  57     public void test() throws Exception {
  58         runTest(MethodHandlesCastFailureTest::testImpl);
  59     }
  60 
  61     private static final String classDir = System.getProperty("test.classes");
  62     private static final String mainClass = "TestMHApp";
  63     private static final String javaClassPath = System.getProperty("java.class.path");
  64     private static final String ps = System.getProperty("path.separator");
  65     private static final String testPackageName = "test.java.lang.invoke";
  66     private static final String testClassName = "MethodHandlesCastFailureTest";
  67     private static final String skippedException = "jtreg.SkippedException: Unable to map shared archive: test did not complete";
  68 
  69     static void testImpl() throws Exception {
  70         String topArchiveName = getNewArchiveName();
  71         JarBuilder.build("MH", new File(classDir), null);
  72         String appJar = classDir + File.separator + "MH.jar";
  73 
  74         String[] classPaths = javaClassPath.split(File.pathSeparator);
  75         String junitJar = null;
  76         for (String path : classPaths) {
  77             if (path.endsWith("junit.jar")) {
  78                 junitJar = path;
  79                 break;
  80             }
  81         }
  82 
  83         dumpAndRun(topArchiveName, "-Xlog:cds,cds+dynamic=debug,class+load=trace",
  84             "-cp", appJar + ps + junitJar,
  85             mainClass, testPackageName + "." + testClassName);
  86     }
  87 }