4632N/A/*
4632N/A * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/A/**
4632N/A * @test
4632N/A * @bug 4420844 4449394
4632N/A * @summary Checks that no events are sent after VMDeath, and test vm.canBeModified
4632N/A *
4632N/A * @author Robert Field
4632N/A *
4632N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter
4632N/A * @run compile -g HelloWorld.java
4632N/A * @run build VMDeathLastTest
4632N/A * @run main VMDeathLastTest
4632N/A */
4632N/Aimport com.sun.jdi.*;
4632N/Aimport com.sun.jdi.event.*;
4632N/Aimport com.sun.jdi.request.*;
4632N/A
4632N/Aimport java.util.*;
4632N/A
4632N/A /********** test program **********/
4632N/A
4632N/Apublic class VMDeathLastTest extends TestScaffold {
4632N/A Object syncer = new Object();
4632N/A boolean vmDead = false;
4632N/A boolean disconnected = false;
4632N/A
4632N/A VMDeathLastTest (String args[]) {
4632N/A super(args);
4632N/A }
4632N/A
4632N/A public static void main(String[] args) throws Exception {
4632N/A new VMDeathLastTest(args).startTests();
4632N/A }
4632N/A
4632N/A /********** event handlers **********/
4632N/A
4632N/A public void methodEntered(MethodEntryEvent event) {
4632N/A if (vmDead) {
4632N/A failure("Failure: Got MethodEntryEvent after VM Dead");
4632N/A }
4632N/A }
4632N/A
4632N/A public void classPrepared(ClassPrepareEvent event) {
4632N/A if (vmDead) {
4632N/A failure("Failure: Got ClassPrepareEvent after VM Dead");
4632N/A }
4632N/A }
4632N/A
4632N/A public void threadDied(ThreadDeathEvent event) {
4632N/A if (vmDead) {
4632N/A failure("Failure: Got ThreadDeathEvent after VM Dead");
4632N/A }
4632N/A }
4632N/A
4632N/A public void vmDied(VMDeathEvent event) {
4632N/A println("Got VMDeathEvent");
4632N/A vmDead = true;
4632N/A }
4632N/A
4632N/A public void vmDisconnected(VMDisconnectEvent event) {
4632N/A println("Got VMDisconnectEvent");
4632N/A if (!vmDead) {
4632N/A failure("Test failure: didn't get VMDeath");
4632N/A }
4632N/A disconnected = true;
4632N/A synchronized (syncer) {
4632N/A syncer.notifyAll();
4632N/A }
4632N/A }
4632N/A
4632N/A /**
4632N/A * Turn off default VMDeath handling.
4632N/A */
4632N/A protected void createDefaultVMDeathRequest() {
4632N/A }
4632N/A
4632N/A /********** test core **********/
4632N/A
4632N/A protected void runTests() throws Exception {
4632N/A /*
4632N/A * Get to the top of main()
4632N/A * to determine targetClass and mainThread
4632N/A */
4632N/A startToMain("HelloWorld");
4632N/A if (!vm().canBeModified()) {
4632N/A failure("VM says it is read-only");
4632N/A }
4632N/A EventRequestManager erm = vm().eventRequestManager();
4632N/A
4632N/A /*
4632N/A * Set event requests
4632N/A */
4632N/A erm.createMethodEntryRequest().enable();
4632N/A erm.createClassPrepareRequest().enable();
4632N/A erm.createThreadDeathRequest().enable();
4632N/A
4632N/A /*
4632N/A * resume the target listening for events
4632N/A */
4632N/A addListener(this);
4632N/A synchronized (syncer) {
4632N/A vm().resume();
4632N/A while (!disconnected) {
4632N/A try {
4632N/A syncer.wait();
4632N/A } catch (InterruptedException e) {
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A /*
4632N/A * deal with results of test
4632N/A */
4632N/A if (!testFailed) {
4632N/A println("VMDeathLastTest: passed");
4632N/A } else {
4632N/A throw new Exception("VMDeathLastTest: failed");
4632N/A }
4632N/A }
4632N/A}
4632N/A