< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/stepRequests/stepreq001t.java

Print this page

  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 package nsk.jdi.EventRequestManager.stepRequests;
 25 

 26 import nsk.share.jpda.*;
 27 import nsk.share.jdi.*;
 28 
 29 
 30 /**
 31  * This is a debuggee class creating several dummy user and
 32  * daemon threads with own names.
 33  */
 34 public class stepreq001t {
 35     private static ArgumentHandler argHandler;
 36 
 37     public static void main(String args[]) {
 38         System.exit(new stepreq001t().runThis(args));
 39     }
 40 
 41     private int runThis(String args[]) {
 42         argHandler = new ArgumentHandler(args);
 43         IOPipe pipe = argHandler.createDebugeeIOPipe();
 44         Thread  thrs[] = new Thread[stepreq001.THRDS_NUM];
 45         Object lockObj = new Object();
 46         Object readyObj = new Object();
 47         String cmd;
 48 
 49 // Create several dummy threads and give them new names
 50         thrs[0] = Thread.currentThread();
 51         try {
 52             thrs[0].setName(stepreq001.DEBUGGEE_THRDS[0]);
 53         } catch (SecurityException e) {
 54             System.err.println("TEST FAILURE: setName: caught in debuggee "
 55                 + e);
 56             pipe.println("failed");
 57             return stepreq001.JCK_STATUS_BASE +
 58                 stepreq001.FAILED;
 59         }
 60 // Get a monitor in order to prevent the threads from exiting
 61         synchronized(lockObj) {
 62             for (int i=1; i<stepreq001.THRDS_NUM; i++) {
 63                 thrs[i] = JDIThreadFactory.newThread(new stepreq001a(readyObj, lockObj,
 64                     stepreq001.DEBUGGEE_THRDS[i]));
 65                 thrs[i].setDaemon(stepreq001.DAEMON_THRDS[i]);


 66                 if (argHandler.verbose())
 67                     System.out.println("Debuggee: starting thread #"
 68                         + i + " \"" + thrs[i].getName() + "\"");
 69                 synchronized(readyObj) {
 70                     thrs[i].start();
 71                     try {
 72                         readyObj.wait(); // wait for the thread's readiness
 73                     } catch (InterruptedException e) {
 74                         System.out.println("TEST FAILURE: Debuggee: waiting for the thread "
 75                             + thrs[i].toString() + ": caught " + e);
 76                         pipe.println("failed");
 77                         return stepreq001.JCK_STATUS_BASE +
 78                             stepreq001.FAILED;
 79                     }
 80                 }
 81                 if (argHandler.verbose())
 82                     System.out.println("Debuggee: the thread #"
 83                         + i + " \"" + thrs[i].getName() + "\" started");
 84             }
 85 // Now the debuggee is ready for testing

 92             try {
 93                 thrs[i].join(argHandler.getWaitTime()*60000);
 94                 if (argHandler.verbose())
 95                     System.out.println("Debuggee: thread #"
 96                         + i + " \"" + thrs[i].getName() + "\" done");
 97             } catch (InterruptedException e) {
 98                 System.err.println("Debuggee: joining the thread #"
 99                     + i + " \"" + thrs[i].getName() + "\": " + e);
100             }
101         }
102         if (!cmd.equals(stepreq001.COMMAND_QUIT)) {
103             System.err.println("TEST BUG: unknown debugger command: "
104                 + cmd);
105             return stepreq001.JCK_STATUS_BASE +
106                 stepreq001.FAILED;
107         }
108         return stepreq001.JCK_STATUS_BASE +
109             stepreq001.PASSED;
110     }
111 









112     class stepreq001a extends NamedTask {
113         private Object readyObj;
114         private Object lockObj;
115 
116         stepreq001a(Object readyObj, Object obj,
117                 String name) {
118             super(name);
119             this.readyObj = readyObj;
120             lockObj = obj;
121         }
122 
123         public void run() {
124             Thread thr = Thread.currentThread();
125 
126             synchronized(readyObj) {
127                 readyObj.notify(); // notify the main thread
128             }
129             if (argHandler.verbose())
130                 System.out.println("Debuggee's thread \""
131                     + thr.getName() + "\": going to be blocked");

  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 package nsk.jdi.EventRequestManager.stepRequests;
 25 
 26 import java.lang.reflect.Method;
 27 import nsk.share.jpda.*;
 28 import nsk.share.jdi.*;
 29 
 30 
 31 /**
 32  * This is a debuggee class creating several dummy user and
 33  * daemon threads with own names.
 34  */
 35 public class stepreq001t {
 36     private static ArgumentHandler argHandler;
 37 
 38     public static void main(String args[]) {
 39         System.exit(new stepreq001t().runThis(args));
 40     }
 41 
 42     private int runThis(String args[]) {
 43         argHandler = new ArgumentHandler(args);
 44         IOPipe pipe = argHandler.createDebugeeIOPipe();
 45         Thread  thrs[] = new Thread[stepreq001.THRDS_NUM];
 46         Object lockObj = new Object();
 47         Object readyObj = new Object();
 48         String cmd;
 49 
 50 // Create several dummy threads and give them new names
 51         thrs[0] = Thread.currentThread();
 52         try {
 53             thrs[0].setName(stepreq001.DEBUGGEE_THRDS[0]);
 54         } catch (SecurityException e) {
 55             System.err.println("TEST FAILURE: setName: caught in debuggee "
 56                 + e);
 57             pipe.println("failed");
 58             return stepreq001.JCK_STATUS_BASE +
 59                 stepreq001.FAILED;
 60         }
 61 // Get a monitor in order to prevent the threads from exiting
 62         synchronized(lockObj) {
 63             for (int i=1; i<stepreq001.THRDS_NUM; i++) {
 64                 thrs[i] = JDIThreadFactory.newThread(new stepreq001a(readyObj, lockObj,
 65                     stepreq001.DEBUGGEE_THRDS[i]));
 66                 if (!isVirtual(thrs[i])) {
 67                     thrs[i].setDaemon(stepreq001.DAEMON_THRDS[i]);
 68                 }
 69                 if (argHandler.verbose())
 70                     System.out.println("Debuggee: starting thread #"
 71                         + i + " \"" + thrs[i].getName() + "\"");
 72                 synchronized(readyObj) {
 73                     thrs[i].start();
 74                     try {
 75                         readyObj.wait(); // wait for the thread's readiness
 76                     } catch (InterruptedException e) {
 77                         System.out.println("TEST FAILURE: Debuggee: waiting for the thread "
 78                             + thrs[i].toString() + ": caught " + e);
 79                         pipe.println("failed");
 80                         return stepreq001.JCK_STATUS_BASE +
 81                             stepreq001.FAILED;
 82                     }
 83                 }
 84                 if (argHandler.verbose())
 85                     System.out.println("Debuggee: the thread #"
 86                         + i + " \"" + thrs[i].getName() + "\" started");
 87             }
 88 // Now the debuggee is ready for testing

 95             try {
 96                 thrs[i].join(argHandler.getWaitTime()*60000);
 97                 if (argHandler.verbose())
 98                     System.out.println("Debuggee: thread #"
 99                         + i + " \"" + thrs[i].getName() + "\" done");
100             } catch (InterruptedException e) {
101                 System.err.println("Debuggee: joining the thread #"
102                     + i + " \"" + thrs[i].getName() + "\": " + e);
103             }
104         }
105         if (!cmd.equals(stepreq001.COMMAND_QUIT)) {
106             System.err.println("TEST BUG: unknown debugger command: "
107                 + cmd);
108             return stepreq001.JCK_STATUS_BASE +
109                 stepreq001.FAILED;
110         }
111         return stepreq001.JCK_STATUS_BASE +
112             stepreq001.PASSED;
113     }
114 
115     private static boolean isVirtual(Thread thread) {
116         try {
117             Method isVirtual = Thread.class.getMethod("isVirtual");
118             return (boolean) isVirtual.invoke(thread);
119         } catch (Exception e) {
120             throw new RuntimeException(e);
121         }
122     }
123 
124     class stepreq001a extends NamedTask {
125         private Object readyObj;
126         private Object lockObj;
127 
128         stepreq001a(Object readyObj, Object obj,
129                 String name) {
130             super(name);
131             this.readyObj = readyObj;
132             lockObj = obj;
133         }
134 
135         public void run() {
136             Thread thr = Thread.currentThread();
137 
138             synchronized(readyObj) {
139                 readyObj.notify(); // notify the main thread
140             }
141             if (argHandler.verbose())
142                 System.out.println("Debuggee's thread \""
143                     + thr.getName() + "\": going to be blocked");
< prev index next >