1 /* 2 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @bug 4453310 27 * @summary Test the deletion of event requests that are expired 28 * by virtue of addCountFilter. 29 * 30 * @author Robert Field 31 * 32 * @modules jdk.jdi 33 * @run build TestScaffold VMConnection TargetListener TargetAdapter 34 * @run compile -g ExpiredRequestDeletionTest.java 35 * @run driver ExpiredRequestDeletionTest 36 */ 37 import com.sun.jdi.*; 38 import com.sun.jdi.event.*; 39 import com.sun.jdi.request.*; 40 41 import java.util.*; 42 43 /********** target program **********/ 44 45 class ExpiredRequestDeletionTarg { 46 int foo = 9; 47 48 public static void main(String[] args){ 49 System.out.println("Why, hello there..."); 50 (new ExpiredRequestDeletionTarg()).bar(); 51 } 52 53 void bar() { 54 ++foo; 55 } 56 } 57 58 /********** test program **********/ 59 60 public class ExpiredRequestDeletionTest extends TestScaffold { 61 EventRequestManager erm; 62 ReferenceType targetClass; 63 ThreadReference mainThread; 64 Throwable throwable = null; 65 66 ExpiredRequestDeletionTest (String args[]) { 67 super(args); 68 } 69 70 public static void main(String[] args) throws Exception { 71 new ExpiredRequestDeletionTest(args).startTests(); 72 } 73 74 /********** event handlers **********/ 75 76 public void breakpointReached(BreakpointEvent event) { 77 try { 78 EventRequest req = event.request(); 79 if (req != null) { 80 println("Deleting BreakpointRequest"); 81 erm.deleteEventRequest(req); 82 } else { 83 println("Got BreakpointEvent with null request"); 84 } 85 } catch (Throwable exc) { 86 throwable = exc; 87 failure("Deleting BreakpointRequest threw - " + exc); 88 } 89 } 90 91 public void stepCompleted(StepEvent event) { 92 try { 93 EventRequest req = event.request(); 94 if (req != null) { 95 println("Deleting StepRequest"); 96 erm.deleteEventRequest(req); 97 } else { 98 println("Got StepEvent with null request"); 99 } 100 } catch (Throwable exc) { 101 throwable = exc; 102 failure("Deleting StepRequest threw - " + exc); 103 } 104 } 105 106 /********** test core **********/ 107 108 protected void runTests() throws Exception { 109 /* 110 * Get to the top of main() 111 * to determine targetClass and mainThread 112 */ 113 BreakpointEvent bpe = startToMain("ExpiredRequestDeletionTarg"); 114 targetClass = bpe.location().declaringType(); 115 mainThread = bpe.thread(); 116 erm = vm().eventRequestManager(); 117 118 List meths = targetClass.methodsByName("bar"); 119 if (meths.size() != 1) { 120 throw new Exception("test error: should be one bar()"); 121 } 122 Method barMethod = (Method)meths.get(0); 123 124 /* 125 * Set event requests 126 */ 127 StepRequest sr = erm.createStepRequest(mainThread, 128 StepRequest.STEP_LINE, 129 StepRequest.STEP_OVER); 130 sr.addCountFilter(1); 131 sr.enable(); 132 133 BreakpointRequest bpr = 134 erm.createBreakpointRequest(barMethod.location()); 135 bpr.addCountFilter(1); 136 bpr.enable(); 137 138 /* 139 * resume the target listening for events 140 */ 141 listenUntilVMDisconnect(); 142 143 /* 144 * deal with results of test 145 * if anything has called failure("foo") testFailed will be true 146 */ 147 if (!testFailed) { 148 println("ExpiredRequestDeletionTest: passed"); 149 } else { 150 throw new Exception("ExpiredRequestDeletionTest: failed", throwable); 151 } 152 } 153 }