Home | History | Annotate | Download | only in VirtualMachine
      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.VirtualMachine;
     20 
     21 import org.apache.harmony.jpda.tests.framework.TestErrorException;
     22 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
     23 import org.apache.harmony.jpda.tests.share.SyncDebuggee;
     24 
     25 /**
     26  * Debuggee for {@link DisposeDuringInvokeTest}.
     27  */
     28 public class DisposeDuringInvokeDebuggee extends SyncDebuggee {
     29     public static final String INVOKED_METHOD_NAME = "invokeMethodWithSynchronization";
     30     public static final String BREAKPOINT_METHOD_NAME = "breakpointMethod";
     31     public static final String THIS_FIELD_NAME = "thisObject";
     32 
     33     // This field holds the receiver to invoke the invokeMethodWithSynchronization method.
     34     public static DisposeDuringInvokeDebuggee thisObject;
     35 
     36     private class DebuggeeThread extends Thread {
     37         public DebuggeeThread() {
     38             super("DebuggeeThread");
     39         }
     40 
     41         @Override
     42         public void run() {
     43             breakpointMethod();
     44         }
     45     }
     46 
     47     /**
     48      * The method used to suspend the DebuggeeThread on a breakpoint.
     49      */
     50     private void breakpointMethod() {
     51     }
     52 
     53     /**
     54      * The method called by the DebuggeeThread through JDWP.
     55      */
     56     @SuppressWarnings("unused")
     57     private void invokeMethodWithSynchronization() {
     58         logWriter.println("#START invokeMethodWithSynchronization");
     59 
     60         // Tell the test we are invoking the requested method.
     61         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     62 
     63         // Wait for the test to send a VirtualMachine.Dispose command and resume us.
     64         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     65 
     66         logWriter.println("#END invokeMethodWithSynchronization");
     67     }
     68 
     69     @Override
     70     public void run() {
     71         thisObject = this;
     72 
     73         DebuggeeThread thrd = new DebuggeeThread();
     74         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     75 
     76         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     77 
     78         logWriter.println("Start DebuggeeThread");
     79         thrd.start();
     80 
     81         logWriter.println("Main thread waits for DebuggeeThread ...");
     82         try {
     83             thrd.join();
     84         } catch (InterruptedException e) {
     85            throw new TestErrorException(e);
     86         }
     87         logWriter.println("DebuggeeThread is finished");
     88 
     89         // Tell the test we successfully waited for the end of DebuggeeThread.
     90         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
     91 
     92         // Wait for the test to resume us.
     93         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
     94     }
     95 
     96     public static void main(String [] args) {
     97         runDebuggee(DisposeDuringInvokeDebuggee.class);
     98     }
     99 }
    100