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