2362N/A * Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Framework used by all JDI regression tests 0N/A * We create a VMDeathRequest, SUSPEND_ALL, to sync the BE and FE. 0N/A * We create an ExceptionRequest, SUSPEND_NONE so that we can 0N/A * catch it and output a msg if an exception occurs in the 0N/A * If we do catch an uncaught exception, we set this true 0N/A * so the testcase can find out if it wants to. 0N/A * An easy way to sleep for awhile 0N/A * Return true if eventSet contains the VMDeathEvent for the request in 0N/A * the ourVMDeathRequest ivar. 0N/A // We assume that an EventSet contains only VMDeathEvents 0N/A // or no VMDeathEvents. 0N/A /************************************************************************ 0N/A * The following methods override those in our base class, TargetAdapter. 0N/A *************************************************************************/ 0N/A * Events handled directly by scaffold always resume (well, almost always) 0N/A // The listener in connect(..) resumes after receiving our 0N/A // special VMDeathEvent. We can't also do the resume 0N/A // here or we will probably get a VMDisconnectedException 0N/A * This method sets up default requests. 0N/A * Testcases can override this to change default behavior. 0N/A * We want the BE to stop when it issues a VMDeathEvent in order to 0N/A * give the FE time to complete handling events that occured before 0N/A * the VMDeath. When we get the VMDeathEvent for this request in 0N/A * the listener in connect(), we will do a resume. 0N/A * If a testcase wants to do something special with VMDeathEvent's, 0N/A * then it should override this method with an empty method or 0N/A * whatever in order to suppress the automatic resume. The testcase 0N/A * will then be responsible for the handling of VMDeathEvents. It 0N/A * has to be sure that it does a resume if it gets a VMDeathEvent 0N/A * with SUSPEND_ALL, and it has to be sure that it doesn't do a 0N/A * resume after getting a VMDeath with SUSPEND_NONE (the automatically 0N/A * generated VMDeathEvent.) 0N/A * This will allow us to print a warning if a debuggee gets an 0N/A * unexpected exception. The unexpected exception will be handled in 0N/A * the exceptionThrown method in the listener created in the connect() 0N/A * If a testcase does not want an uncaught exception to cause a 0N/A * msg, it must override this method. 0N/A // We can't afford to make this be other than SUSPEND_NONE. Otherwise, 0N/A // it would have to be resumed. If our connect() listener resumes it, 0N/A // what about the case where the EventSet contains other events with 0N/A // SUSPEND_ALL and there are other listeners who expect the BE to still 0N/A // be suspended when their handlers get called? 0N/A traceln(
"TS: eventHandler: suspend = SUSPEND_NONE");
0N/A traceln(
"TS: eventHandler: suspend = SUSPEND_ALL");
0N/A traceln(
"TS: eventHandler: suspend = SUSPEND_EVENT_THREAD");
0N/A traceln(
"TS: eventHandler: end of listeners loop");
0N/A traceln(
"TS: eventHandler: InterruptedException");
0N/A failure(
"FAILED: Exception occured in eventHandler: " + e);
0N/A // This will make the waiters such as waitForVMDisconnect 0N/A // exit their wait loops. 0N/A * Helper for the redefine method. Build the map 0N/A * needed for a redefine. 0N/A * Redefine a class - HotSwap it 0N/A * Test cases should implement tests in runTests and should 0N/A * initiate testing by calling run(). 0N/A * classpath can span two arguments so we need to handle 0N/A * This is called to connect to a debuggee VM. It starts the VM and 0N/A * installs a listener to catch VMStartEvent, our default events, and 0N/A * VMDisconnectedEvent. When these events appear, that is remembered 0N/A * and waiters are notified. 0N/A * This is normally called in the main thread of the test case. 0N/A * It starts up an EventHandler thread that gets events coming in 0N/A * from the debuggee and distributes them to listeners. That thread 0N/A * keeps running until a VMDisconnectedEvent occurs or some exception 0N/A * occurs during its processing. 0N/A * The 'listenUntilVMDisconnect' method adds 'this' as a listener. 0N/A * This means that 'this's vmDied method will get called. This has a 0N/A * waitForRequestedEvent also adds an adaptor listener that listens 0N/A * for the particular event it is supposed to wait for (and it also 0N/A * catches VMDisconnectEvents.) This listener is removed once 0N/A * its eventReceived method is called. 0N/A * waitForRequestedEvent is called by most of the methods to do bkpts, 0N/A // Note that we want to do the above resume before 0N/A // waking up any sleepers. 0N/A * By default, we catch uncaught exceptions and print a msg. 0N/A * The testcase must override the createDefaultExceptionRequest 0N/A * method if it doesn't want this behavior. 0N/A * intermittent ObjectCollectedException 0N/A * Since this request was SUSPEND_NONE, the debuggee 0N/A * could keep running and the calls below back into 0N/A * the debuggee might not work. That is why we 0N/A * This code is commented out because it needs a thread 0N/A * in which to do the invokeMethod and we don't have 0N/A * one. To enable this code change the request 0N/A * to be SUSPEND_ALL in createDefaultExceptionRequest, 0N/A * and then put this line 0N/A * mainThread = bpe.thread(); 0N/A * in the testcase after the line 0N/A * BreakpointEvent bpe = startToMain("...."); 0N/A println(
"TestScaffold Exception while handling debuggee Exception: " 0N/A // Allow application to complete and shut down 0N/A traceln(
"TS: waitForRequestedEvent: vm.resume called");
0N/A traceln(
"TS: resumeToVMDisconnect: vm.resume called");
0N/A // Shutting down after the VM has gone away. This is 0N/A // not an error, and we just ignore it.