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  *
23  */
24 /*
25  * @test
26  * @bug 8261090
27  * @summary CDS support of old classes with major version < JDK_6 (50) for static archive.
28  *          Test with old super interface.
29  * @requires vm.cds
30  * @library /test/lib
31  * @compile test-classes/OldInf.jasm
32  * @compile test-classes/ChildOldInf.java
33  * @compile test-classes/GChild2.java
34  * @compile test-classes/OldSuperInfApp.java
35  * @run driver OldSuperInf
36  */
37 
38 import jdk.test.lib.cds.CDSTestUtils;
39 import jdk.test.lib.process.OutputAnalyzer;
40 
41 public class OldSuperInf {
42 
43     public static void main(String[] args) throws Exception {
44         String mainClass = "OldSuperInfApp";
45         String namePrefix = "oldsuperinf";
46         String appClasses[] = TestCommon.list("OldInf", "ChildOldInf", "GChild2", mainClass);
47         JarBuilder.build(namePrefix, appClasses);
48 
49         String appJar = TestCommon.getTestJar(namePrefix + ".jar");
50         String archiveName = namePrefix + ".jsa";
51 
52         boolean dynamicMode = CDSTestUtils.DYNAMIC_DUMP;
53 
54         // create archive with class list
55         OutputAnalyzer output = TestCommon.dump(appJar, appClasses, "-Xlog:class+load,cds=debug,verification=trace");
56         TestCommon.checkExecReturn(output, 0,
57                                    dynamicMode ? true : false,
58                                    "Skipping OldInf: Old class has been linked",
59                                    "Skipping ChildOldInf: Old class has been linked",
60                                    "Skipping GChild2: Old class has been linked");
61 
62         // run with archive
63         TestCommon.run(
64             "-cp", appJar,
65             "-Xlog:class+load,cds=debug,verification=trace",
66             mainClass)
67           .assertNormalExit(out -> {
68               out.shouldContain("Verifying class OldInf with old format")
69                  .shouldContain("Verifying class ChildOldInf with new format")
70                  .shouldContain("Verifying class GChild2 with new format");
71               if (!dynamicMode) {
72                   out.shouldContain("OldInf source: shared objects file")
73                      .shouldContain("ChildOldInf source: shared objects file")
74                      .shouldContain("GChild2 source: shared objects file");
75               } else {
76                   // Old classes were already linked before dynamic dump happened,
77                   // so they couldn't be archived.
78                   out.shouldMatch(".class.load.*OldInf source:.*oldsuperinf.jar")
79                      .shouldMatch(".class.load.*ChildOldInf source:.*oldsuperinf.jar")
80                      .shouldMatch(".class.load.*GChild2 source:.*oldsuperinf.jar");
81               }
82           });
83     }
84 }