1 /*
2  * Copyright (c) 2001, 2018, 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 package nsk.jdi.VirtualMachine.resume;
24 
25 import nsk.share.jdi.*;
26 
27 //    THIS TEST IS LINE NUMBER SENSITIVE
28 
29 /*
30  * Debuggee part of test (debuggee starts several test threads which should
31  * be suspended at breakpoint)
32  *
33  * WARNING: edit this file carefully, breakpoint line number is hardcoded
34  */
35 public class resume001a extends AbstractJDIDebuggee {
36 
37     static final String COMMAND_STOP_ALL_THREADS_AT_BREAKPOINT = "COMMAND_START_TEST_THREADS";
38 
39     static final String COMMAND_JOIN_TEST_THREADS = "COMMAND_JOIN_TEST_THREADS";
40 
41     static int counter;
42 
43     static final String COUNTER_FIELD_NAME = "counter";
44 
incCounter()45     synchronized static void incCounter() {
46         counter++;
47     }
48 
49     class TestThread extends Thread {
50 
run()51         public void run() {
52             log.display(getName() + " started");
53 
54             stopAtBreakpoint();
55 
56             log.display(getName() + " finished");
57         }
58     }
59 
60     static final int BREAKPOINT_LINE_NUMBER = 63;
61 
stopAtBreakpoint()62     static void stopAtBreakpoint() {
63         int i = 0; // BREAKPOINT_LINE_NUMBER
64 
65         incCounter();
66     }
67 
68     static final int TEST_THREAD_NUMBER = 10;
69 
70     private TestThread[] testThreads = new TestThread[TEST_THREAD_NUMBER];
71 
resume001a()72     public resume001a() {
73         for (int i = 0; i < testThreads.length; i++) {
74             testThreads[i] = new TestThread();
75         }
76     }
77 
parseCommand(String command)78     public boolean parseCommand(String command) {
79         if (super.parseCommand(command))
80             return true;
81 
82         if (command.equals(COMMAND_STOP_ALL_THREADS_AT_BREAKPOINT)) {
83             /*
84              * All TestThreads execute method stopAtBreakpoint()
85              */
86             for (TestThread testThread : testThreads) {
87                 testThread.start();
88             }
89 
90             // debuggee main thread also stops at breakpoint
91             stopAtBreakpoint();
92 
93             return true;
94         } else if (command.equals(COMMAND_JOIN_TEST_THREADS)) {
95             for (TestThread testThread : testThreads) {
96                 try {
97                     testThread.join();
98                 } catch (InterruptedException e) {
99                     unexpectedException(e);
100                 }
101             }
102             return true;
103         }
104 
105         return false;
106     }
107 
main(String args[])108     public static void main(String args[]) {
109         new resume001a().doTest(args);
110     }
111 
112 }
113