788N/A/*
1472N/A * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
788N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
788N/A *
788N/A * This code is free software; you can redistribute it and/or modify it
788N/A * under the terms of the GNU General Public License version 2 only, as
788N/A * published by the Free Software Foundation. Oracle designates this
788N/A * particular file as subject to the "Classpath" exception as provided
788N/A * by Oracle in the LICENSE file that accompanied this code.
788N/A *
788N/A * This code is distributed in the hope that it will be useful, but WITHOUT
788N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
788N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
788N/A * version 2 for more details (a copy is included in the LICENSE file that
788N/A * accompanied this code).
788N/A *
788N/A * You should have received a copy of the GNU General Public License version
788N/A * 2 along with this work; if not, write to the Free Software Foundation,
1472N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1472N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
788N/A * or visit www.oracle.com if you need additional information or have any
788N/A * questions.
788N/A */
788N/A
788N/Apackage com.sun.tools.jdi;
788N/A
788N/Aimport com.sun.jdi.*;
788N/Aimport com.sun.jdi.event.*;
788N/Aimport java.util.*;
788N/A
788N/Apublic class InternalEventHandler implements Runnable
788N/A{
788N/A EventQueueImpl queue;
788N/A VirtualMachineImpl vm;
788N/A
788N/A InternalEventHandler(VirtualMachineImpl vm, EventQueueImpl queue)
788N/A {
788N/A this.vm = vm;
788N/A this.queue = queue;
788N/A Thread thread = new Thread(vm.threadGroupForJDI(), this,
788N/A "JDI Internal Event Handler");
788N/A thread.setDaemon(true);
788N/A thread.start();
788N/A }
788N/A
788N/A public void run() {
788N/A if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {
788N/A vm.printTrace("Internal event handler running");
788N/A }
788N/A try {
788N/A while (true) {
788N/A try {
788N/A EventSet eventSet = queue.removeInternal();
788N/A EventIterator it = eventSet.eventIterator();
788N/A while (it.hasNext()) {
788N/A Event event = it.nextEvent();
788N/A if (event instanceof ClassUnloadEvent) {
788N/A ClassUnloadEvent cuEvent = (ClassUnloadEvent)event;
788N/A vm.removeReferenceType(cuEvent.classSignature());
788N/A
788N/A if ((vm.traceFlags & vm.TRACE_EVENTS) != 0) {
788N/A vm.printTrace("Handled Unload Event for " +
788N/A cuEvent.classSignature());
788N/A }
788N/A } else if (event instanceof ClassPrepareEvent) {
788N/A ClassPrepareEvent cpEvent = (ClassPrepareEvent)event;
788N/A ((ReferenceTypeImpl)cpEvent.referenceType())
788N/A .markPrepared();
788N/A
788N/A if ((vm.traceFlags & vm.TRACE_EVENTS) != 0) {
788N/A vm.printTrace("Handled Prepare Event for " +
788N/A cpEvent.referenceType().name());
788N/A }
788N/A }
788N/A
788N/A }
788N/A
788N/A /*
788N/A * Handle exceptions that can occur in normal operation
788N/A * but which can't be accounted for by event builder
788N/A * methods. The thread should not be terminated if they
788N/A * occur.
788N/A *
788N/A * TO DO: We need a better way to log these conditions.
788N/A */
788N/A } catch (VMOutOfMemoryException vmme) {
788N/A vmme.printStackTrace();
788N/A } catch (InconsistentDebugInfoException idie) {
788N/A idie.printStackTrace();
788N/A
788N/A /*
788N/A * If any of these exceptions below occurs, there is some
788N/A * sort of programming error that should be addressed in
788N/A * the JDI implemementation. However, it would cripple
788N/A * the implementation if we let this thread die due to
788N/A * one of them. So, a notification of the exception is
788N/A * given and we attempt to continue.
788N/A */
788N/A } catch (ObjectCollectedException oce) {
788N/A oce.printStackTrace();
788N/A } catch (ClassNotPreparedException cnpe) {
788N/A cnpe.printStackTrace();
788N/A }
788N/A }
788N/A } catch (InterruptedException e) { // should we really die here
788N/A } catch (VMDisconnectedException e) { // time to die
788N/A }
788N/A if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {
788N/A vm.printTrace("Internal event handler exiting");
788N/A }
788N/A }
788N/A}
788N/A