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 package org.apache.harmony.jpda.tests.jdwp.ThreadReference; 20 21 import org.apache.harmony.jpda.tests.framework.DebuggeeSynchronizer; 22 import org.apache.harmony.jpda.tests.framework.LogWriter; 23 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer; 24 import org.apache.harmony.jpda.tests.share.SyncDebuggee; 25 26 27 /** 28 * The class specifies debuggee for <code>org.apache.harmony.jpda.tests.jdwp.ThreadReference.OwnedMonitorsStackDepthInfoTest</code>. 29 * This debuggee starts the tested thread <code>TESTED_THREAD</code> which 30 * synchronized with test via the <code>SGNL_READY</code> and 31 * <code>SGNL_CONTINUE</code> signals. 32 */ 33 public class OwnedMonitorsStackDepthInfoDebuggee extends SyncDebuggee { 34 35 public static final String TESTED_THREAD = "TestedThread"; 36 37 // These two objects are used 38 static Object waitForStart = new Object(); 39 static Object waitForFinish = new Object(); 40 41 @Override 42 public void run() { 43 DebuggeeThread thrd = new DebuggeeThread(TESTED_THREAD, 44 logWriter, synchronizer); 45 46 synchronized(waitForStart){ 47 thrd.start(); 48 try { 49 waitForStart.wait(); 50 } catch (InterruptedException e) { 51 52 } 53 } 54 55 synchronized(waitForFinish){ 56 logWriter.println("thread is finished"); 57 } 58 } 59 60 static class DebuggeeThread extends Thread { 61 62 LogWriter logWriter; 63 DebuggeeSynchronizer synchronizer; 64 65 public DebuggeeThread(String name, LogWriter logWriter, 66 DebuggeeSynchronizer synchronizer) { 67 super(name); 68 this.logWriter = logWriter; 69 this.synchronizer = synchronizer; 70 } 71 72 // Deliberately make several stack frames with known monitor states. 73 74 // 1. No monitors held in the outermost frame. 75 @Override 76 public void run() { 77 run1(); 78 } 79 80 // 2. One monitor ("this") held in the next frame. 81 private synchronized void run1() { 82 run2(); 83 } 84 85 // 3. No monitors held in the next frame. 86 private void run2() { 87 run3(); 88 } 89 90 // 4. Two monitors held in the frame after that. 91 private void run3() { 92 synchronized(OwnedMonitorsStackDepthInfoDebuggee.waitForFinish){ 93 94 synchronized(OwnedMonitorsStackDepthInfoDebuggee.waitForStart){ 95 96 OwnedMonitorsStackDepthInfoDebuggee.waitForStart.notifyAll(); 97 98 logWriter.println(getName() + ": started"); 99 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 100 101 logWriter.println(getName() + ": wait for SGNL_CONTINUE"); 102 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 103 logWriter.println(getName() + ": finished"); 104 } 105 } 106 } 107 } 108 109 public static void main(String [] args) { 110 runDebuggee(OwnedMonitorsStackDepthInfoDebuggee.class); 111 } 112 } 113