1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * @author Vitaly A. Provodin 21 */ 22 23 /** 24 * Created on 19.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.VirtualMachine; 27 28 import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer; 29 import org.apache.harmony.jpda.tests.framework.LogWriter; 30 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 31 import org.apache.harmony.jpda.tests.share.SyncDebuggee; 32 33 34 /** 35 * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.VirtualMachine.AllThreadsTest</code>. 36 * This debuggee starts the tested thread <code>TESTED_THREAD</code> and for 37 * different goals of tests, the debuggee sends the <code>SGNL_READY</code> 38 * signal to and waits for the <code>SGNL_CONTINUE</code> signal from debugger 39 * in two places: 40 * <ul> 41 * <li>right away when the tested thread has been started 42 * <li>when the tested thread has been finished 43 * </ul> 44 */ 45 public class AllThreadsDebuggee extends SyncDebuggee { 46 47 static Object waitTimeObject = new Object(); waitMlsecsTime(long mlsecsTime)48 static void waitMlsecsTime(long mlsecsTime) { 49 synchronized(waitTimeObject) { 50 try { 51 waitTimeObject.wait(mlsecsTime); 52 } catch (Throwable throwable) { 53 // ignore 54 } 55 } 56 } 57 58 public static final String TESTED_THREAD = "TestedThread"; 59 60 static Object waitForStart = new Object(); 61 run()62 public void run() { 63 DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD, 64 logWriter, synchronizer); 65 66 synchronized(waitForStart){ 67 thrd.start(); 68 try { 69 waitForStart.wait(); 70 } catch (InterruptedException e) { 71 72 } 73 } 74 75 logWriter.println("Wait for thread to finish..."); 76 while ( thrd.isAlive() ) { 77 waitMlsecsTime(1000); 78 } 79 logWriter.println("thread finished"); 80 logWriter.println("send SGNL_READY"); 81 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 82 83 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 84 } 85 86 class DebuggeeThread extends Thread { 87 88 LogWriter logWriter; 89 DebuggeeSynchronizer synchronizer; 90 DebuggeeThread(String name, LogWriter logWriter, DebuggeeSynchronizer synchronizer)91 public DebuggeeThread(String name, LogWriter logWriter, 92 DebuggeeSynchronizer synchronizer) { 93 super(name); 94 this.logWriter = logWriter; 95 this.synchronizer = synchronizer; 96 } 97 run()98 public void run() { 99 100 logWriter.println(getName() + ": started..."); 101 synchronized(AllThreadsDebuggee.waitForStart){ 102 103 AllThreadsDebuggee.waitForStart.notifyAll(); 104 } 105 106 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 107 logWriter.println(getName() + ": wait for SGNL_CONTINUE"); 108 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 109 logWriter.println(getName() + ": is finishing..."); 110 } 111 } 112 main(String [] args)113 public static void main(String [] args) { 114 runDebuggee(AllThreadsDebuggee.class); 115 } 116 } 117