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.EventModifiers;
20 
21 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
22 import org.apache.harmony.jpda.tests.share.SyncDebuggee;
23 
24 /**
25  * Debuggee for InstanceOnlyModifierTest.
26  */
27 public class InstanceOnlyModifierDebuggee extends SyncDebuggee {
28     static class TestException extends Exception {
29     }
30 
31     static class TestClass {
32         int watchedField = 0;
33 
eventTestMethod()34         public void eventTestMethod() {
35             System.out.println(
36                     "InstanceOnlyModifierDebuggee.TestClass.eventTestMethod()");
37         }
38 
throwAndCatchException()39         public void throwAndCatchException() {
40             try {
41                 throwException();
42             } catch (TestException e) {
43                 System.out.println("Catch TestException");
44             }
45         }
46 
readAndWriteField()47         public void readAndWriteField() {
48             System.out.println(
49                     "InstanceOnlyModifierDebuggee.TestClass.readAndWriteField()");
50             watchedField = watchedField + 1;
51         }
52 
throwException()53         private void throwException() throws TestException {
54             System.out.println(
55                     "InstanceOnlyModifierDebuggee.TestClass.throwException()");
56             throw new TestException();
57         }
58     }
59 
60     static TestClass INSTANCE_ONLY;
61 
62     @Override
run()63     public void run() {
64         new TestException();  // force class loading.
65 
66         logWriter.println("Create instances");
67         final TestClass[] instances = new TestClass[10];
68         for (int i = 0; i < instances.length; ++i) {
69             instances[i] = new TestClass();
70         }
71 
72         System.out.println("Set INSTANCE_ONLY to the last instance");
73         INSTANCE_ONLY = instances[instances.length - 1];
74         System.out.println("Set INSTANCE_ONLY to the last instance");
75 
76         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
77 
78         logWriter.println("InstanceOnlyModifierDebuggee started");
79 
80         // Wait for test setup.
81         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
82 
83         System.out.println("Fire breakpoint, method entry/exit events");
84         for (int i = 0; i < instances.length; ++i) {
85             instances[i].eventTestMethod();
86         }
87 
88         System.out.println("Fire caught exception events");
89         for (int i = 0; i < instances.length; ++i) {
90             instances[i].throwAndCatchException();
91         }
92 
93         System.out.println("Fire field access/modification events");
94         for (int i = 0; i < instances.length; ++i) {
95             instances[i].readAndWriteField();
96         }
97 
98         logWriter.println("InstanceOnlyModifierDebuggee finished");
99     }
100 
main(String[] args)101     public static void main(String[] args) {
102         runDebuggee(InstanceOnlyModifierDebuggee.class);
103     }
104 
105 }
106