/* * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * @test * @bug 4409241 4432820 * @summary Test the bug fix for: MethodExitEvents disappear when Object-Methods are called from main * @author Tim Bell * * @run build TestScaffold VMConnection TargetListener TargetAdapter * @run compile -g MethodEntryExitEvents.java * @run driver MethodEntryExitEvents SUSPEND_EVENT_THREAD MethodEntryExitEventsDebugee * @run driver MethodEntryExitEvents SUSPEND_NONE MethodEntryExitEventsDebugee * @run driver MethodEntryExitEvents SUSPEND_ALL MethodEntryExitEventsDebugee
*/ import com.sun.jdi.*; import com.sun.jdi.event.*; import com.sun.jdi.request.*; import java.util.*;
class t2 { publicstaticvoid sayHello1(int i, int j) {
sayHello2(i, j);
} publicstaticvoid sayHello2(int i, int j) {
sayHello3(i, j);
} publicstaticvoid sayHello3(int i, int j) {
sayHello4(i, j);
} publicstaticvoid sayHello4(int i, int j) {
sayHello5(i, j);
} publicstaticvoid sayHello5(int i, int j) { if (i < 2) {
sayHello1(++i, j);
} else {
System.out.print ("MethodEntryExitEventsDebugee: ");
System.out.print (" -->> Hello. j is: ");
System.out.print (j);
System.out.println(" <<--");
}
}
}
class MethodEntryExitEventsDebugee { publicstaticvoid loopComplete () { /* * The implementation here is deliberately inefficient * because the debugger is still watching this method.
*/
StringBuffer sb = new StringBuffer();
sb.append ("MethodEntryExitEventsDebugee: ");
sb.append ("Executing loopComplete method for a graceful shutdown...");
String s = sb.toString(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i);
System.out.print(c);
}
System.out.println();
} publicstaticvoid main(String[] args) {
t2 test = new t2(); for (int j = 0; j < 3; j++) {
test.sayHello1(0, j);
}
loopComplete();
}
}
publicclass MethodEntryExitEvents extends TestScaffold { int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
StepRequest stepReq = null; //Only one step request allowed per thread boolean finishedCounting = false;
/* * Enter main() , then t2.<init>, then sayHello[1,2,3,4,5] 15 times 3 loops, * then loopComplete()
*/ finalint expectedEntryCount = 1 + 1 + (15 * 3) + 1; int methodEntryCount = 0;
/* * Exit t2.<init>, then sayHello[1,2,3,4,5] 15 times 3 loopa * (event monitoring is cancelled before we exit loopComplete() or main())
*/ finalint expectedExitCount = 1 + (15 * 3); int methodExitCount = 0;
// Classes which we are interested in private List includes = Arrays.asList(new String[] { "MethodEntryExitEventsDebugee", "t2"
});
// Step to the catch if (stepReq == null) {
stepReq =
eventRequestManager().createStepRequest(event.thread(),
StepRequest.STEP_MIN,
StepRequest.STEP_INTO);
stepReq.addCountFilter(1); // next step only
stepReq.setSuspendPolicy(EventRequest.SUSPEND_ALL);
}
stepReq.enable();
} publicvoid stepCompleted(StepEvent event) {
System.out.println("stepCompleted: line#=" +
event.location().lineNumber() + " event=" + event); // disable the step and then run to completion //eventRequestManager().deleteEventRequest(event.request());
StepRequest str= (StepRequest)event.request();
str.disable();
} publicvoid methodEntered(MethodEntryEvent event) { if (!includes.contains(event.method().declaringType().name())) { return;
}
if (! finishedCounting) { // We have to count the entry to loopComplete, but // not the exit
methodEntryCount++;
System.out.print (" Method entry number: ");
System.out.print (methodEntryCount);
System.out.print (" : ");
System.out.println(event); if ("loopComplete".equals(event.method().name())) {
finishedCounting = true;
}
}
}
publicvoid methodExited(MethodExitEvent event) { if (!includes.contains(event.method().declaringType().name())) { return;
}
/* * We are now set up to receive the notifications we want. * Here we go. This adds 'this' as a listener so * that our handlers above will be called.
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.