< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/OldClassInBaseArchive.java

Print this page

  1 /*
  2  * Copyright (c) 2021, 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  *

 45 
 46 public class OldClassInBaseArchive extends DynamicArchiveTestBase {
 47     static final String classList = CDSTestUtils.getOutputFileName("classlist");
 48     static final String appClass = "OldSuperApp";
 49     static final String baseArchiveClass = "OldSuper";
 50 
 51     public static void main(String[] args) throws Exception {
 52         runTest(OldClassInBaseArchive::testCustomBase);
 53     }
 54 
 55     static void testCustomBase() throws Exception {
 56         String topArchiveName = getNewArchiveName("top");
 57         doTestCustomBase(topArchiveName);
 58     }
 59 
 60     private static void doTestCustomBase(String topArchiveName) throws Exception {
 61         String appJar = ClassFileInstaller.getJarPath("old-class-base-archive.jar");
 62 
 63         // create a custom base archive containing and old class
 64         OutputAnalyzer output = TestCommon.dump(appJar,
 65             TestCommon.list("OldSuper"), "-Xlog:class+load,cds+class=debug");

 66         TestCommon.checkDump(output);
 67         // Check the OldSuper is being dumped into the base archive.
 68         output.shouldMatch(".cds.class.*klass.*0x.*app.*OldSuper.*unlinked");
 69 
 70         String baseArchiveName = TestCommon.getCurrentArchiveName();
 71 
 72         // create a dynamic archive with the custom base archive.
 73         // The old class is in the base archive and will be
 74         // accessed from OldSuperApp.
 75         // The OldSuperApp, ChildOldSuper, and GChild classes will be archived
 76         // in the dynamic archive.
 77         dump2(baseArchiveName, topArchiveName,
 78               "-Xlog:cds,cds+dynamic,class+load,cds+class=debug",
 79               "-cp", appJar,

 80               appClass)
 81             .assertNormalExit(out -> {
 82                     out.shouldContain("OldSuper source: shared objects file")
 83                        // Check the following classes are being dumped into the dynamic archive.
 84                        .shouldMatch(".cds,class.*klass.*0x.*app.*OldSuperApp")
 85                        .shouldMatch(".cds,class.*klass.*0x.*app.*ChildOldSuper")
 86                        .shouldMatch(".cds,class.*klass.*0x.*app.*GChild");
 87                 });
 88 
 89         // Run with both base and dynamic archives. The OldSuper class
 90         // should be loaded from the base archive. The OldSuperApp
 91         // and related classes should be loaded from the dynamic archive.
 92         run2(baseArchiveName, topArchiveName,
 93               "-Xlog:cds,cds+dynamic,class+load",
 94               "-cp", appJar,
 95               appClass)
 96             .assertNormalExit(out -> {
 97                     out.shouldContain("OldSuper source: shared objects file")
 98                        .shouldContain("OldSuperApp source: shared objects file (top)")
 99                        .shouldContain("ChildOldSuper source: shared objects file (top)")

  1 /*
  2  * Copyright (c) 2021, 202, 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  *

 45 
 46 public class OldClassInBaseArchive extends DynamicArchiveTestBase {
 47     static final String classList = CDSTestUtils.getOutputFileName("classlist");
 48     static final String appClass = "OldSuperApp";
 49     static final String baseArchiveClass = "OldSuper";
 50 
 51     public static void main(String[] args) throws Exception {
 52         runTest(OldClassInBaseArchive::testCustomBase);
 53     }
 54 
 55     static void testCustomBase() throws Exception {
 56         String topArchiveName = getNewArchiveName("top");
 57         doTestCustomBase(topArchiveName);
 58     }
 59 
 60     private static void doTestCustomBase(String topArchiveName) throws Exception {
 61         String appJar = ClassFileInstaller.getJarPath("old-class-base-archive.jar");
 62 
 63         // create a custom base archive containing and old class
 64         OutputAnalyzer output = TestCommon.dump(appJar,
 65             TestCommon.list("OldSuper"), "-Xlog:class+load,cds+class=debug",
 66             "-XX:-PreloadSharedClasses");
 67         TestCommon.checkDump(output);
 68         // Check the OldSuper is being dumped into the base archive.
 69         output.shouldMatch(".cds.class.*klass.*0x.*app.*OldSuper.*unlinked");
 70 
 71         String baseArchiveName = TestCommon.getCurrentArchiveName();
 72 
 73         // create a dynamic archive with the custom base archive.
 74         // The old class is in the base archive and will be
 75         // accessed from OldSuperApp.
 76         // The OldSuperApp, ChildOldSuper, and GChild classes will be archived
 77         // in the dynamic archive.
 78         dump2(baseArchiveName, topArchiveName,
 79               "-Xlog:cds,cds+dynamic,class+load,cds+class=debug",
 80               "-cp", appJar,
 81               "-XX:-PreloadSharedClasses",
 82               appClass)
 83             .assertNormalExit(out -> {
 84                     out.shouldContain("OldSuper source: shared objects file")
 85                        // Check the following classes are being dumped into the dynamic archive.
 86                        .shouldMatch(".cds,class.*klass.*0x.*app.*OldSuperApp")
 87                        .shouldMatch(".cds,class.*klass.*0x.*app.*ChildOldSuper")
 88                        .shouldMatch(".cds,class.*klass.*0x.*app.*GChild");
 89                 });
 90 
 91         // Run with both base and dynamic archives. The OldSuper class
 92         // should be loaded from the base archive. The OldSuperApp
 93         // and related classes should be loaded from the dynamic archive.
 94         run2(baseArchiveName, topArchiveName,
 95               "-Xlog:cds,cds+dynamic,class+load",
 96               "-cp", appJar,
 97               appClass)
 98             .assertNormalExit(out -> {
 99                     out.shouldContain("OldSuper source: shared objects file")
100                        .shouldContain("OldSuperApp source: shared objects file (top)")
101                        .shouldContain("ChildOldSuper source: shared objects file (top)")
< prev index next >