|
| 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 | + * @bug 8355627 |
| 28 | + * @summary Test that events are listed in the hs_err_pid file |
| 29 | + * @library /test/lib |
| 30 | + * @requires vm.flagless |
| 31 | + * @requires vm.debug == true & (os.family == "linux" | os.family == "windows") |
| 32 | + * @modules java.base/jdk.internal.misc |
| 33 | + * @run driver ShowEventsOnCrashTest |
| 34 | + */ |
| 35 | + |
| 36 | +// Note: this test can only run on debug since it relies on VMError::controlled_crash() which |
| 37 | +// only exists in debug builds. |
| 38 | +import java.io.File; |
| 39 | +import java.util.regex.Pattern; |
| 40 | + |
| 41 | +import jdk.test.lib.process.OutputAnalyzer; |
| 42 | +import jdk.test.lib.process.ProcessTools; |
| 43 | + |
| 44 | +public class ShowEventsOnCrashTest { |
| 45 | + |
| 46 | + public static void main(String[] args) throws Exception { |
| 47 | + |
| 48 | + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder( |
| 49 | + "-XX:+UnlockDiagnosticVMOptions", "-Xmx100M", "-XX:-CreateCoredumpOnCrash", |
| 50 | + "-XX:ErrorHandlerTest=2", |
| 51 | + "-version"); |
| 52 | + |
| 53 | + OutputAnalyzer output_detail = new OutputAnalyzer(pb.start()); |
| 54 | + |
| 55 | + // we should have crashed with an internal error. We should definitely NOT have crashed with a segfault |
| 56 | + // (which would be a sign that the assert poison page mechanism does not work). |
| 57 | + output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*"); |
| 58 | + output_detail.shouldMatch("# +Internal Error.*"); |
| 59 | + File hs_err_file = HsErrFileUtils.openHsErrFileFromOutput(output_detail); |
| 60 | + // Pattern match the hs_err_pid file. |
| 61 | + Pattern[] patterns = new Pattern[] { |
| 62 | + Pattern.compile("Compilation events \\([0-9]* events\\):"), |
| 63 | + Pattern.compile("GC Heap History \\([0-9]* events\\):"), |
| 64 | + Pattern.compile("Dll operation events \\([0-9]* events\\):"), |
| 65 | + Pattern.compile("Deoptimization events \\([0-9]* events\\):"), |
| 66 | + Pattern.compile("Classes loaded \\([0-9]* events\\):"), |
| 67 | + Pattern.compile("Classes unloaded \\([0-9]* events\\):"), |
| 68 | + Pattern.compile("Classes redefined \\([0-9]* events\\):"), |
| 69 | + Pattern.compile("Internal exceptions \\([0-9]* events\\):"), |
| 70 | + Pattern.compile("VM Operations \\([0-9]* events\\):"), |
| 71 | + Pattern.compile("Memory protections \\([0-9]* events\\):") |
| 72 | + }; |
| 73 | + |
| 74 | + HsErrFileUtils.checkHsErrFileContent(hs_err_file, patterns, false); |
| 75 | + |
| 76 | + } |
| 77 | +} |
| 78 | + |
0 commit comments