|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 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 | +/* |
| 26 | + * @test |
| 27 | + * @summary -XX:AOTMode=record should not interfere with app execution: (1) thread creation; (2) exit code |
| 28 | + * @bug 8351327 |
| 29 | + * @requires vm.cds.supports.aot.class.linking |
| 30 | + * @comment work around JDK-8345635 |
| 31 | + * @requires !vm.jvmci.enabled |
| 32 | + * @library /test/jdk/lib/testlibrary /test/lib |
| 33 | + * @build TrainingRun |
| 34 | + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar MyTestApp |
| 35 | + * @run driver TrainingRun AOT |
| 36 | + */ |
| 37 | + |
| 38 | +import jdk.test.lib.cds.CDSAppTester; |
| 39 | +import jdk.test.lib.helpers.ClassFileInstaller; |
| 40 | +import jdk.test.lib.process.OutputAnalyzer; |
| 41 | + |
| 42 | +public class TrainingRun { |
| 43 | + static final String appJar = ClassFileInstaller.getJarPath("app.jar"); |
| 44 | + static final String mainClass = "MyTestApp"; |
| 45 | + |
| 46 | + public static void main(String[] args) throws Exception { |
| 47 | + (new Tester()).run(args); |
| 48 | + } |
| 49 | + |
| 50 | + static class Tester extends CDSAppTester { |
| 51 | + public Tester() { |
| 52 | + super(mainClass); |
| 53 | + |
| 54 | + // CDSAppTester usually wants the app to return exit value 0, but this test |
| 55 | + // checks whether the training run can return 2. |
| 56 | + setCheckExitValue(false); |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public String classpath(RunMode runMode) { |
| 61 | + return appJar; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public String[] appCommandLine(RunMode runMode) { |
| 66 | + return new String[] { |
| 67 | + mainClass, |
| 68 | + }; |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public void checkExecution(OutputAnalyzer out, RunMode runMode) { |
| 73 | + if (runMode.isApplicationExecuted()) { |
| 74 | + out.shouldHaveExitValue(2); |
| 75 | + out.shouldContain("Hello: x is 1"); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +class MyTestApp { |
| 82 | + volatile static int x = 0; |
| 83 | + |
| 84 | + public static void main(String args[]) throws Exception { |
| 85 | + Thread t = new Thread(() -> { |
| 86 | + x = 1; |
| 87 | + }); |
| 88 | + t.start(); |
| 89 | + t.join(); |
| 90 | + |
| 91 | + if (x != 1) { |
| 92 | + throw new RuntimeException("x should be 1 but is " + x); |
| 93 | + } |
| 94 | + System.out.println("Hello: x is " + x); |
| 95 | + System.out.println("I am calling System.exit(2)"); |
| 96 | + System.exit(2); |
| 97 | + } |
| 98 | +} |
0 commit comments