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 4919105 27 * @summary Generified basic unit test of Thread.getAllStackTraces() 28 * @author Mandy Chung 29 */ 30 31 import java.util.*; 32 33 public class GenerifyStackTraces { 34 35 private static Object go = new Object(); 36 private static Object dumpObj = new Object(); 37 private static String[] methodNames = {"run", "A", "B", "C", "Done"}; 38 private static int DONE_DEPTH = 5; 39 private static boolean testFailed = false; 40 41 private static Thread one; 42 private static boolean trace = false; 43 public static void main(String[] args) throws Exception { 44 if (args.length > 0 && args[0].equals("trace")) { 45 trace = true; 46 } 47 48 one = new ThreadOne(); 49 one.start(); 50 51 Thread dt = new DumpThread(); 52 dt.setDaemon(true); 53 dt.start(); 54 55 if (testFailed) { 56 throw new RuntimeException("Test Failed."); 57 } 58 } 59 60 static class DumpThread extends Thread { 61 public void run() { 62 int depth = 2; 63 while (true) { 64 // At each iterator, wait until ThreadOne blocks 65 // to wait for thread dump. 66 // Then dump stack trace and notify ThreadOne to continue. 67 try { 68 sleep(2000); 69 dumpStacks(depth); 70 depth++; 71 finishDump(); 72 } catch (Exception e) { 73 e.printStackTrace(); 74 testFailed = true; 75 } 76 } 77 } 78 } 79 80 static class ThreadOne extends Thread { 81 public void run() { 82 A(); 83 } 84 private void A() { 85 waitForDump(); 86 B(); 87 } 88 private void B() { 89 waitForDump(); 90 C(); 91 } 92 private void C() { 93 waitForDump(); 94 Done(); 95 } 96 private void Done() { 97 waitForDump(); | 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 4919105 8004177 27 * @summary Generified basic unit test of Thread.getAllStackTraces() 28 * @author Mandy Chung 29 */ 30 31 import java.util.*; 32 33 public class GenerifyStackTraces { 34 35 private static Object go = new Object(); 36 private static String[] methodNames = {"run", "A", "B", "C", "Done"}; 37 private static int DONE_DEPTH = 5; 38 private static boolean testFailed = false; 39 40 private static Thread one; 41 private static boolean trace = false; 42 public static void main(String[] args) throws Exception { 43 if (args.length > 0 && args[0].equals("trace")) { 44 trace = true; 45 } 46 47 one = new ThreadOne(); 48 one.start(); 49 50 DumpThread dt = new DumpThread(); 51 dt.start(); 52 53 try { 54 one.join(); 55 }finally { 56 dt.shutdown(); 57 } 58 59 if (testFailed) { 60 throw new RuntimeException("Test Failed."); 61 } 62 } 63 64 static class DumpThread extends Thread { 65 private volatile boolean finished = false; 66 67 public void run() { 68 int depth = 2; 69 while (!finished) { 70 // At each iterator, wait until ThreadOne blocks 71 // to wait for thread dump. 72 // Then dump stack trace and notify ThreadOne to continue. 73 try { 74 sleep(2000); 75 dumpStacks(depth); 76 depth++; 77 finishDump(); 78 } catch (Exception e) { 79 e.printStackTrace(); 80 testFailed = true; 81 } 82 } 83 } 84 85 public void shutdown() throws InterruptedException { 86 finished = true; 87 this.join(); 88 } 89 } 90 91 static class ThreadOne extends Thread { 92 public void run() { 93 A(); 94 } 95 private void A() { 96 waitForDump(); 97 B(); 98 } 99 private void B() { 100 waitForDump(); 101 C(); 102 } 103 private void C() { 104 waitForDump(); 105 Done(); 106 } 107 private void Done() { 108 waitForDump(); |