1 /*
   2  * Copyright (c) 2011, 2013, 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 /*
  27  * @test JsrRewriting
  28  * @summary JSR (jump local subroutine)
  29  *      rewriting can overflow memory address size variables
  30  * @bug 7020373
  31  * @bug 7055247
  32  * @bug 7053586
  33  * @bug 7185550
  34  * @bug 7149464
  35  * @key cte_test
  36  * @library /testlibrary
  37  * @run main JsrRewriting
  38  */
  39 
  40 import com.oracle.java.testlibrary.*;
  41 import java.io.File;
  42 
  43 public class JsrRewriting {
  44 
  45     public static void main(String[] args) throws Exception {
  46 
  47         // ======= Configure the test
  48         String jarFile = System.getProperty("test.src") +
  49             File.separator + "JsrRewritingTestCase.jar";
  50         String className = "OOMCrashClass4000_1";
  51 
  52         // limit is 768MB in native words
  53         int mallocMaxTestWords = (1024 * 1024 * 768 / 4);
  54         if (Platform.is64bit())
  55             mallocMaxTestWords = (mallocMaxTestWords / 2);
  56 
  57         // ======= extract the test class
  58         ProcessBuilder pb = new ProcessBuilder(new String[] {
  59             JDKToolFinder.getJDKTool("jar"),
  60             "xvf", jarFile } );
  61         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  62         output.shouldHaveExitValue(0);
  63 
  64         // ======= execute the test
  65         pb = ProcessTools.createJavaProcessBuilder(
  66             "-cp", ".",
  67             "-XX:+UnlockDiagnosticVMOptions",
  68             "-XX:MallocMaxTestWords=" + mallocMaxTestWords,
  69             className);
  70 
  71         output = new OutputAnalyzer(pb.start());
  72         String[] expectedMsgs = {
  73             "java.lang.LinkageError",
  74             "java.lang.NoSuchMethodError",
  75             "Main method not found in class " + className,
  76             "insufficient memory"
  77         };
  78 
  79         MultipleOrMatch(output, expectedMsgs);
  80     }
  81 
  82     private static void
  83         MultipleOrMatch(OutputAnalyzer analyzer, String[] whatToMatch) {
  84             String output = analyzer.getOutput();
  85 
  86             for (String expected : whatToMatch)
  87                 if (output.contains(expected))
  88                     return;
  89 
  90             String err =
  91                 " stdout: [" + analyzer.getOutput() + "];\n" +
  92                 " exitValue = " + analyzer.getExitValue() + "\n";
  93             System.err.println(err);
  94 
  95             StringBuilder msg = new StringBuilder("Output did not contain " +
  96                 "any of the following expected messages: \n");
  97             for (String expected : whatToMatch)
  98                 msg.append(expected).append(System.lineSeparator());
  99             throw new RuntimeException(msg.toString());
 100     }
 101 }
 102