1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/runtime/7107135/TestMT.java Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,85 @@ 1.4 +/* 1.5 + * Copyright (c) 2002-2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2011 SAP AG. All Rights Reserved. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + */ 1.27 + 1.28 +class TestMT { 1.29 + 1.30 + static boolean loadLib(String libName) { 1.31 + try { 1.32 + System.loadLibrary(libName); 1.33 + System.out.println("Loaded library "+ libName + "."); 1.34 + return true; 1.35 + } catch (SecurityException e) { 1.36 + System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n"); 1.37 + } catch (UnsatisfiedLinkError e) { 1.38 + System.out.println("loadLibrary(\"" + libName + "\") throws: " + e + "\n"); 1.39 + } 1.40 + return false; 1.41 + } 1.42 + 1.43 + public static int counter = 1; 1.44 + static int Runner() { 1.45 + counter = counter * -1; 1.46 + int i = counter; 1.47 + if (counter < 2) counter += Runner(); 1.48 + return i; 1.49 + } 1.50 + 1.51 + public static int run(String msg) { 1.52 + try { 1.53 + Runner(); 1.54 + } catch (StackOverflowError e) { 1.55 + System.out.println(msg + " caught stack overflow error."); 1.56 + return 0; 1.57 + } catch (OutOfMemoryError e) { 1.58 + return 0; 1.59 + } 1.60 + return 2; 1.61 + } 1.62 + 1.63 + public static void main(String argv[]) { 1.64 + try { 1.65 + for (int i = 0; i < 20; i++) { 1.66 + Thread t = new DoStackOverflow("SpawnedThread " + i); 1.67 + t.start(); 1.68 + } 1.69 + run("Main thread"); 1.70 + loadLib("test-rwx"); 1.71 + run("Main thread"); 1.72 + } catch (Exception e) { 1.73 + System.out.println(e); 1.74 + } 1.75 + } 1.76 + 1.77 + static class DoStackOverflow extends Thread { 1.78 + public DoStackOverflow(String name) { 1.79 + super(name); 1.80 + } 1.81 + public void run() { 1.82 + for (int i = 0; i < 10; ++i) { 1.83 + TestMT.run(getName()); 1.84 + yield(); 1.85 + } 1.86 + } 1.87 + } 1.88 +}