|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 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 Out of memory When dumping the CDS archive |
| 28 | + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes |
| 29 | + * @requires vm.cds.archived.java.heap |
| 30 | + * @requires vm.jvmti |
| 31 | + * @run driver ExceptionDuringDumpAtObjectsInitPhase |
| 32 | + */ |
| 33 | + |
| 34 | +import jdk.test.lib.cds.CDSOptions; |
| 35 | +import jdk.test.lib.process.OutputAnalyzer; |
| 36 | +import jdk.test.lib.process.ProcessTools; |
| 37 | + |
| 38 | +public class ExceptionDuringDumpAtObjectsInitPhase { |
| 39 | + public static String appClasses[] = { |
| 40 | + Hello.class.getName(), |
| 41 | + }; |
| 42 | + public static String agentClasses[] = { |
| 43 | + GCDuringDumpTransformer.class.getName(), |
| 44 | + GCDuringDumpTransformer.MyCleaner.class.getName(), |
| 45 | + }; |
| 46 | + |
| 47 | + public static void main(String[] args) throws Throwable { |
| 48 | + String agentJar = |
| 49 | + ClassFileInstaller.writeJar("GCDuringDumpTransformer.jar", |
| 50 | + ClassFileInstaller.Manifest.fromSourceFile("GCDuringDumpTransformer.mf"), |
| 51 | + agentClasses); |
| 52 | + |
| 53 | + String appJar = |
| 54 | + ClassFileInstaller.writeJar("GCDuringDumpApp.jar", appClasses); |
| 55 | + |
| 56 | + String gcLog = Boolean.getBoolean("test.cds.verbose.gc") ? |
| 57 | + "-Xlog:gc*=info,gc+region=trace,gc+alloc+region=debug" : "-showversion"; |
| 58 | + |
| 59 | + // 1. Test with exception |
| 60 | + System.out.println("1. Exception during dump"); |
| 61 | + TestCommon.dump(appJar, |
| 62 | + TestCommon.list(Hello.class.getName()), |
| 63 | + "-XX:+UnlockDiagnosticVMOptions", |
| 64 | + "-XX:+AllowArchivingWithJavaAgent", |
| 65 | + "-javaagent:" + agentJar, |
| 66 | + "-Xlog:cds,class+load", |
| 67 | + "-Xmx32m", |
| 68 | + "-Dtest.with.exception=true", |
| 69 | + gcLog).shouldNotHaveExitValue(0) |
| 70 | + .shouldContain("Preload Error: Failed to load jdk/internal/math/FDBigInteger") |
| 71 | + .shouldContain("VM exits due to exception, use -Xlog:cds,exceptions=trace for detail"); |
| 72 | + |
| 73 | + // 2. Test with OOM |
| 74 | + System.out.println("2. OOM during dump"); |
| 75 | + TestCommon.dump(appJar, |
| 76 | + TestCommon.list(Hello.class.getName()), |
| 77 | + "-XX:+UnlockDiagnosticVMOptions", |
| 78 | + "-XX:+AllowArchivingWithJavaAgent", |
| 79 | + "-javaagent:" + agentJar, |
| 80 | + "-Dtest.with.oom=true", |
| 81 | + "-Xlog:cds,class+load", |
| 82 | + "-Xmx12M", |
| 83 | + gcLog).shouldNotHaveExitValue(0) |
| 84 | + .shouldContain("Out of memory. Please run with a larger Java heap, current MaxHeapSize"); |
| 85 | + } |
| 86 | +} |
0 commit comments