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 8266330
27  * @summary CDS support of old classes with major version < JDK_6 (50) for static archive.
28  *          Test a scenario that a class implements an old interface but the
29  *          implementation is in another class.
30  * @requires vm.cds
31  * @library /test/lib
32  * @compile test-classes/OldInf.jasm
33  * @compile test-classes/InfMethod.java
34  * @compile test-classes/IndirectImpInf.java
35  * @compile test-classes/IndirectImpInfApp.java
36  * @run driver OldSuperInfIndirect
37  */
38 
39 import jdk.test.lib.cds.CDSTestUtils;
40 import jdk.test.lib.process.OutputAnalyzer;
41 
42 public class OldSuperInfIndirect {
43 
44     public static void main(String[] args) throws Exception {
45         String mainClass = "IndirectImpInfApp";
46         String namePrefix = "indirectimpinfapp";
47         String appClasses[] = TestCommon.list("OldInf", "InfMethod", "IndirectImpInf", mainClass);
48         JarBuilder.build(namePrefix, appClasses);
49 
50         String appJar = TestCommon.getTestJar(namePrefix + ".jar");
51         String archiveName = namePrefix + ".jsa";
52 
53         boolean dynamicMode = CDSTestUtils.DYNAMIC_DUMP;
54 
55         // create archive with class list
56         OutputAnalyzer output = TestCommon.dump(appJar, appClasses, "-Xlog:class+load,cds=debug,verification=trace",
57                                                 "-XX:-PreloadSharedClasses");
58         TestCommon.checkExecReturn(output, 0,
59                                    dynamicMode ? true : false,
60                                    "Skipping OldInf: Old class has been linked",
61                                    "Skipping IndirectImpInf: Old class has been linked");
62 
63         // run with archive
64         TestCommon.run(
65             "-cp", appJar,
66             "-Xlog:class+load,cds=debug,verification=trace",
67             mainClass)
68           .assertNormalExit(out -> {
69               out.shouldContain("Verifying class OldInf with old format")
70                  .shouldContain("Verifying class IndirectImpInf with new format");
71               if (!dynamicMode) {
72                   out.shouldContain("OldInf source: shared objects file")
73                      .shouldContain("InfMethod source: shared objects file")
74                      .shouldContain("IndirectImpInf 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:.*indirectimpinfapp.jar")
79                      .shouldMatch(".class.load.*IndirectImpInf source:.*indirectimpinfapp.jar")
80                      .shouldContain("InfMethod source: shared objects file (top)");
81               }
82           });
83     }
84 }