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 CountModifierTest. 26 */ 27 public class CountModifierDebuggee extends SyncDebuggee { 28 static int locationEventCount = 0; 29 static int exceptionEventCount = 0; 30 static int fieldReadWriteCount = 0; 31 32 static int watchedField = 0; 33 34 static final int EVENT_COUNT = 5; 35 36 static class TestException extends Exception { 37 } 38 39 static class TestClass { eventTestMethod()40 public void eventTestMethod() { 41 System.out.println("TestClass.eventTestMethod: count=" + locationEventCount); 42 } 43 throwException()44 public void throwException() throws TestException { 45 System.out.println("TestClass.throwException: exceptionCount=" + exceptionEventCount); 46 throw new TestException(); 47 } 48 } 49 countAndCall(TestClass obj)50 private void countAndCall(TestClass obj) { 51 ++locationEventCount; 52 obj.eventTestMethod(); 53 } 54 catchException(TestClass obj)55 private static void catchException(TestClass obj) { 56 ++exceptionEventCount; 57 try { 58 obj.throwException(); 59 } catch (TestException e) { 60 // ignore. 61 } 62 } 63 readAndWriteField()64 void readAndWriteField() { 65 ++fieldReadWriteCount; 66 System.out.println("CountModifierDebuggee.readAndWriteField: fieldReadWriteCount=" + fieldReadWriteCount); 67 watchedField = watchedField + 1; 68 } 69 70 @Override run()71 public void run() { 72 TestClass obj = new TestClass(); 73 new TestException(); // force class loading. 74 75 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY); 76 77 logWriter.println("CountModifierDebuggee started"); 78 79 // Wait for test setup. 80 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 81 82 locationEventCount = 0; 83 for (int i = 0; i < EVENT_COUNT; ++i) { 84 countAndCall(obj); 85 } 86 87 exceptionEventCount = 0; 88 for (int i = 0; i < EVENT_COUNT; ++i) { 89 catchException(obj); 90 } 91 92 fieldReadWriteCount = 0; 93 for (int i = 0; i < EVENT_COUNT; ++i) { 94 readAndWriteField(); 95 } 96 97 logWriter.println("CountModifierDebuggee finished"); 98 } 99 main(String[] args)100 public static void main(String[] args) { 101 runDebuggee(CountModifierDebuggee.class); 102 } 103 104 } 105