Path: blob/master/test/hotspot/jtreg/runtime/ErrorHandling/ShowRegistersOnAssertTest.java
64474 views
/*1* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/*25* @test26* @bug 819110127* @summary Show Registers on assert/guarantee28* @library /test/lib29* @requires (vm.debug == true) & (os.family == "linux")30* @author Thomas Stuefe (SAP)31* @modules java.base/jdk.internal.misc32* java.management33* @run driver ShowRegistersOnAssertTest34*/3536// Note: this test can only run on debug since it relies on VMError::controlled_crash() which37// only exists in debug builds.38import java.io.BufferedReader;39import java.io.File;40import java.io.FileInputStream;41import java.io.InputStreamReader;42import java.util.regex.Pattern;4344import jdk.test.lib.process.OutputAnalyzer;45import jdk.test.lib.Platform;46import jdk.test.lib.process.ProcessTools;4748public class ShowRegistersOnAssertTest {4950private static void do_test(boolean do_assert, // true - assert, false - guarantee51boolean suppress_assert,52boolean show_registers_on_assert) throws Exception53{54System.out.println("Testing " + (suppress_assert ? "suppressed" : "normal") + " " + (do_assert ? "assert" : "guarantee") +55" with " + (show_registers_on_assert ? "-XX:+ShowRegistersOnAssert" : "-XX:-ShowRegistersOnAssert") + "...");56ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(57"-XX:+UnlockDiagnosticVMOptions", "-Xmx100M", "-XX:-CreateCoredumpOnCrash",58"-XX:ErrorHandlerTest=" + (do_assert ? "1" : "2"),59(suppress_assert ? "-XX:SuppressErrorAt=/vmError.cpp" : ""),60(show_registers_on_assert ? "-XX:+ShowRegistersOnAssert" : "-XX:-ShowRegistersOnAssert"),61"-version");6263OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());6465if (suppress_assert) {66// we should have not have crashed. See VMError::controlled_crash().67output_detail.shouldMatch(".*survived intentional crash.*");68} else {69// we should have crashed with an internal error. We should definitly NOT have crashed with a segfault70// (which would be a sign that the assert poison page mechanism does not work).71output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");72output_detail.shouldMatch("# +Internal Error.*");73}74}7576public static void main(String[] args) throws Exception {77// Note: for now, this is only a regression test testing that the addition of ShowRegistersOnAssert does78// not break normal assert/guarantee handling. The feature is not implemented on all platforms and really testing79// it requires more effort.80do_test(false, false, false);81do_test(false, false, true);82do_test(false, true, false);83do_test(false, true, true);84do_test(true, false, false);85do_test(true, false, true);86do_test(true, true, false);87do_test(true, true, true);88}8990}91929394