< prev index next >

jdk/test/tools/launcher/TooSmallStackSize.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 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  * @test
  26  * @bug 6762191
  27  * @summary Setting stack size to 16K causes segmentation fault
  28  * @compile TooSmallStackSize.java
  29  * @run main TooSmallStackSize
  30  */
  31 
  32 /*
  33  * The primary purpose of this test is to make sure we can run with a 16k stack
  34  * size without crashing. Also this test will determine the minimum allowed
  35  * stack size for the platform (as provided by the JVM error message when a very
  36  * small stack is used), and then verify that the JVM can be launched with that stack
  37  * size without a crash or any error messages.




  38  */
  39 
  40 public class TooSmallStackSize extends TestHelper {
  41     /* for debugging. Normally false. */
  42     static final boolean verbose = false;
  43 
  44     static void printTestOutput(TestResult tr) {
  45         System.out.println("*** exitValue = " + tr.exitValue);
  46         for (String x : tr.testOutput) {
  47             System.out.println(x);
  48         }
  49     }
  50 
  51     /*
  52      * Returns the minimum stack size this platform will allowed based on the
  53      * contents of the error message the JVM outputs when too small of a
  54      * -Xss size was used.
  55      *
  56      * The TestResult argument must contain the result of having already run
  57      * the JVM with too small of a stack size.
  58      */
  59     static String getMinStackAllowed(TestResult tr) {
  60         /*
  61          * The JVM output will contain in one of the lines:
  62          *   "The stack size specified is too small, Specify at least 100k"
  63          * Although the actual size will vary. We need to extract this size
  64          * string from the output and return it.
  65          */
  66         String matchStr = "Specify at least ";
  67         for (String x : tr.testOutput) {
  68             int match_idx = x.indexOf(matchStr);
  69             if (match_idx >= 0) {
  70                 int size_start_idx = match_idx + matchStr.length();
  71                 int k_start_idx = x.indexOf("k", size_start_idx);
  72                 return x.substring(size_start_idx, k_start_idx + 1); // include the "k"
  73             }
  74         }
  75 
  76         System.out.println("FAILED: Could not get the stack size from the output");
  77         throw new RuntimeException("test fails");
  78     }
  79 
  80     /*
  81      * Run the JVM with the specified stack size.
  82      *
  83      * Returns the minimum allowed stack size gleaned from the error message,
  84      * if there is an error message. Otherwise returns the stack size passed in.
  85      */
  86     static String checkStack(String stackSize) {
  87         String min_stack_allowed;
  88 
  89         if (verbose)
  90             System.out.println("*** Testing " + stackSize);
  91         TestResult tr = doExec(javaCmd, "-Xss" + stackSize, "-version");
  92         if (verbose)
  93             printTestOutput(tr);
  94 
  95         if (tr.isOK()) {
  96             System.out.println("PASSED: got no error message with stack size of " + stackSize);
  97             min_stack_allowed = stackSize;
  98         } else {
  99             if (tr.contains("The stack size specified is too small")) {
 100                 System.out.println("PASSED: got expected error message with stack size of " + stackSize);
 101                 min_stack_allowed = getMinStackAllowed(tr);
 102             } else {
 103                 // Likely a crash
 104                 System.out.println("FAILED: Did not get expected error message with stack size of " + stackSize);
 105                 throw new RuntimeException("test fails");
 106             }
 107         }
 108 
 109         return min_stack_allowed;
 110     }
 111 
 112     /*
 113      * Run the JVM with the minimum allowed stack size. This should always succeed.
 114      */
 115     static void checkMinStackAllowed(String stackSize) {
 116         if (verbose)
 117             System.out.println("*** Testing " + stackSize);
 118         TestResult tr = doExec(javaCmd, "-Xss" + stackSize, "-version");
 119         if (verbose)


   1 /*
   2  * Copyright (c) 2014, 2016, 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  * @test
  26  * @bug 6762191
  27  * @summary Setting stack size to 16K causes segmentation fault
  28  * @compile TooSmallStackSize.java
  29  * @run main TooSmallStackSize
  30  */
  31 
  32 /*
  33  * The primary purpose of this test is to make sure we can run with a 16k stack
  34  * size without crashing. Also this test will determine the minimum allowed
  35  * stack size for the platform (as provided by the JVM error message when a very
  36  * small stack is used), and then verify that the JVM can be launched with that stack
  37  * size without a crash or any error messages.
  38  *
  39  * Note: This repo's version of the test uses the '-Xss' option. The
  40  * hotspot repo's version of the test uses the '-XX:ThreadStackSize=n'
  41  * VM option.
  42  */
  43 
  44 public class TooSmallStackSize extends TestHelper {
  45     /* for debugging. Normally false. */
  46     static final boolean verbose = false;
  47 
  48     static void printTestOutput(TestResult tr) {
  49         System.out.println("*** exitValue = " + tr.exitValue);
  50         for (String x : tr.testOutput) {
  51             System.out.println(x);
  52         }
  53     }
  54 
  55     /*
  56      * Returns the minimum stack size this platform will allowed based on the
  57      * contents of the error message the JVM outputs when too small of a
  58      * -Xss size was used.
  59      *
  60      * The TestResult argument must contain the result of having already run
  61      * the JVM with too small of a stack size.
  62      */
  63     static String getMinStackAllowed(TestResult tr) {
  64         /*
  65          * The JVM output will contain in one of the lines:
  66          *   "The Java thread stack size specified is too small. Specify at least 100k"
  67          * Although the actual size will vary. We need to extract this size
  68          * string from the output and return it.
  69          */
  70         String matchStr = "Specify at least ";
  71         for (String x : tr.testOutput) {
  72             int match_idx = x.indexOf(matchStr);
  73             if (match_idx >= 0) {
  74                 int size_start_idx = match_idx + matchStr.length();
  75                 int k_start_idx = x.indexOf("k", size_start_idx);
  76                 return x.substring(size_start_idx, k_start_idx + 1); // include the "k"
  77             }
  78         }
  79 
  80         System.out.println("FAILED: Could not get the stack size from the output");
  81         throw new RuntimeException("test fails");
  82     }
  83 
  84     /*
  85      * Run the JVM with the specified stack size.
  86      *
  87      * Returns the minimum allowed stack size gleaned from the error message,
  88      * if there is an error message. Otherwise returns the stack size passed in.
  89      */
  90     static String checkStack(String stackSize) {
  91         String min_stack_allowed;
  92 
  93         if (verbose)
  94             System.out.println("*** Testing " + stackSize);
  95         TestResult tr = doExec(javaCmd, "-Xss" + stackSize, "-version");
  96         if (verbose)
  97             printTestOutput(tr);
  98 
  99         if (tr.isOK()) {
 100             System.out.println("PASSED: got no error message with stack size of " + stackSize);
 101             min_stack_allowed = stackSize;
 102         } else {
 103             if (tr.contains("The Java thread stack size specified is too small")) {
 104                 System.out.println("PASSED: got expected error message with stack size of " + stackSize);
 105                 min_stack_allowed = getMinStackAllowed(tr);
 106             } else {
 107                 // Likely a crash
 108                 System.out.println("FAILED: Did not get expected error message with stack size of " + stackSize);
 109                 throw new RuntimeException("test fails");
 110             }
 111         }
 112 
 113         return min_stack_allowed;
 114     }
 115 
 116     /*
 117      * Run the JVM with the minimum allowed stack size. This should always succeed.
 118      */
 119     static void checkMinStackAllowed(String stackSize) {
 120         if (verbose)
 121             System.out.println("*** Testing " + stackSize);
 122         TestResult tr = doExec(javaCmd, "-Xss" + stackSize, "-version");
 123         if (verbose)


< prev index next >