Path: blob/master/test/hotspot/jtreg/runtime/ErrorHandling/SafeFetchInErrorHandlingTest.java
40942 views
/*1* Copyright (c) 2015, 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*/2223import java.io.BufferedReader;24import java.io.File;25import java.io.FileInputStream;26import java.io.InputStreamReader;27import java.util.regex.Pattern;2829import jdk.test.lib.process.OutputAnalyzer;30import jdk.test.lib.process.ProcessTools;3132/*33* @test34* @bug 807455235* @summary SafeFetch32 and SafeFetchN do not work in error handling36* @modules java.base/jdk.internal.misc37* @library /test/lib38* @requires vm.debug39* @requires vm.flavor != "zero"40* @author Thomas Stuefe (SAP)41* @run driver SafeFetchInErrorHandlingTest42*/4344public class SafeFetchInErrorHandlingTest {4546public static void main(String[] args) throws Exception {47ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(48"-XX:+UnlockDiagnosticVMOptions",49"-Xmx100M",50"-XX:ErrorHandlerTest=14",51"-XX:+TestSafeFetchInErrorHandler",52"-XX:-CreateCoredumpOnCrash",53"-version");5455OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());5657// we should have crashed with a SIGSEGV58output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");59output_detail.shouldMatch("# +(?:SIGSEGV|SIGBUS|EXCEPTION_ACCESS_VIOLATION).*");6061// extract hs-err file62String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1);63if (hs_err_file == null) {64throw new RuntimeException("Did not find hs-err file in output.\n");65}6667File f = new File(hs_err_file);68if (!f.exists()) {69throw new RuntimeException("hs-err file missing at "70+ f.getAbsolutePath() + ".\n");71}7273System.out.println("Found hs_err file. Scanning...");7475FileInputStream fis = new FileInputStream(f);76BufferedReader br = new BufferedReader(new InputStreamReader(fis));77String line = null;7879Pattern [] pattern = new Pattern[] {80Pattern.compile("Will test SafeFetch..."),81Pattern.compile("SafeFetch OK."),82};83int currentPattern = 0;8485String lastLine = null;86while ((line = br.readLine()) != null) {87if (currentPattern < pattern.length) {88if (pattern[currentPattern].matcher(line).matches()) {89System.out.println("Found: " + line + ".");90currentPattern ++;91}92}93lastLine = line;94}95br.close();9697if (currentPattern < pattern.length) {98throw new RuntimeException("hs-err file incomplete (first missing pattern: " + currentPattern + ")");99}100101if (!lastLine.equals("END.")) {102throw new RuntimeException("hs-err file incomplete (missing END marker.)");103} else {104System.out.println("End marker found.");105}106107System.out.println("OK.");108109}110111}112113114115