Path: blob/master/test/hotspot/jtreg/runtime/ClassFile/JsrRewriting.java
40942 views
/*1* Copyright (c) 2011, 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*/22232425/*26* @test JsrRewriting27* @summary JSR (jump local subroutine)28* rewriting can overflow memory address size variables29* @bug 702037330* @bug 705524731* @bug 705358632* @bug 718555033* @bug 714946434* @library /test/lib35* @modules java.base/jdk.internal.misc36* java.desktop37* java.management38* @run driver JsrRewriting39*/4041import jdk.test.lib.JDKToolFinder;42import jdk.test.lib.Platform;43import jdk.test.lib.process.ProcessTools;44import jdk.test.lib.process.OutputAnalyzer;45import java.io.File;4647public class JsrRewriting {4849public static void main(String[] args) throws Exception {5051// ======= Configure the test52String jarFile = System.getProperty("test.src") +53File.separator + "JsrRewritingTestCase.jar";54String className = "OOMCrashClass4000_1";5556// limit is 768MB in native words57int mallocMaxTestWords = (1024 * 1024 * 768 / 4);58if (Platform.is64bit())59mallocMaxTestWords = (mallocMaxTestWords / 2);6061// ======= extract the test class62ProcessBuilder pb = new ProcessBuilder(new String[] {63JDKToolFinder.getJDKTool("jar"),64"xvf", jarFile } );65OutputAnalyzer output = new OutputAnalyzer(pb.start());66output.shouldHaveExitValue(0);6768// ======= execute the test69pb = ProcessTools.createJavaProcessBuilder(70"-cp", ".",71"-XX:+UnlockDiagnosticVMOptions",72"-XX:MallocMaxTestWords=" + mallocMaxTestWords,73className);7475output = new OutputAnalyzer(pb.start());76String[] expectedMsgs = {77"java.lang.LinkageError",78"java.lang.NoSuchMethodError",79"Main method not found in class " + className,80"insufficient memory"81};8283MultipleOrMatch(output, expectedMsgs);84}8586private static void87MultipleOrMatch(OutputAnalyzer analyzer, String[] whatToMatch) {88String output = analyzer.getOutput();8990for (String expected : whatToMatch)91if (output.contains(expected))92return;9394String err =95" stdout: [" + analyzer.getOutput() + "];\n" +96" exitValue = " + analyzer.getExitValue() + "\n";97System.err.println(err);9899StringBuilder msg = new StringBuilder("Output did not contain " +100"any of the following expected messages: \n");101for (String expected : whatToMatch)102msg.append(expected).append(System.lineSeparator());103throw new RuntimeException(msg.toString());104}105}106107108109