1 /* 2 * Copyright (c) 2017, 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 * @summary Test user threads with various stack sizes. 27 * @run main/othervm TestThreadStackSizes 28 */ 29 30 public class TestThreadStackSizes extends Thread { 31 static final int K = 1024; 32 TestThreadStackSizes(long stackSize)33 public TestThreadStackSizes(long stackSize) { 34 super(null, null, "TestThreadStackSizes" + stackSize, stackSize); 35 } 36 37 @Override run()38 public void run() { 39 } 40 createThread(long stackSize)41 public static void createThread(long stackSize) { 42 System.out.println("StackSize: " + stackSize); 43 try { 44 TestThreadStackSizes testThreadStackSize = new TestThreadStackSizes(stackSize); 45 testThreadStackSize.start(); 46 try { 47 testThreadStackSize.join(); 48 } catch (InterruptedException e) { 49 throw new Error("InterruptedException in main thread", e); 50 } 51 } catch (Error e) { // we sometimes get OutOfMemoryError for very large stacks 52 System.out.println("Got exception for stack size " + stackSize + ": " + e); 53 } 54 } 55 main(String[] args)56 public static void main(String[] args) throws Error { 57 // Try every stack size from 0k to 320k. 58 for (int i = 0; i <= 320; i++) { 59 createThread(i * K); 60 } 61 // Try a few other potentially problematic stack sizes. 62 createThread(500*K); 63 createThread(501*K); 64 createThread(-1); 65 createThread(500*K*K); 66 createThread(9223372036854774784L); 67 } 68 } 69