Path: blob/master/src/jdk.jdi/share/classes/com/sun/tools/jdi/InternalEventHandler.java
41161 views
/*1* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.jdi;2627import com.sun.jdi.ClassNotPreparedException;28import com.sun.jdi.InconsistentDebugInfoException;29import com.sun.jdi.ObjectCollectedException;30import com.sun.jdi.VMDisconnectedException;31import com.sun.jdi.VMOutOfMemoryException;32import com.sun.jdi.VirtualMachine;33import com.sun.jdi.event.ClassPrepareEvent;34import com.sun.jdi.event.ClassUnloadEvent;35import com.sun.jdi.event.Event;36import com.sun.jdi.event.EventIterator;37import com.sun.jdi.event.EventSet;3839public class InternalEventHandler implements Runnable40{41EventQueueImpl queue;42VirtualMachineImpl vm;4344InternalEventHandler(VirtualMachineImpl vm, EventQueueImpl queue) {45this.vm = vm;46this.queue = queue;47Thread thread = new Thread(vm.threadGroupForJDI(), this,48"JDI Internal Event Handler");49thread.setDaemon(true);50thread.start();51}5253public void run() {54if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {55vm.printTrace("Internal event handler running");56}57try {58while (true) {59try {60EventSet eventSet = queue.removeInternal();61EventIterator it = eventSet.eventIterator();62while (it.hasNext()) {63Event event = it.nextEvent();64if (event instanceof ClassUnloadEvent) {65ClassUnloadEvent cuEvent = (ClassUnloadEvent)event;66vm.removeReferenceType(cuEvent.classSignature());6768if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {69vm.printTrace("Handled Unload Event for " +70cuEvent.classSignature());71}72} else if (event instanceof ClassPrepareEvent) {73ClassPrepareEvent cpEvent = (ClassPrepareEvent)event;74((ReferenceTypeImpl)cpEvent.referenceType())75.markPrepared();7677if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {78vm.printTrace("Handled Prepare Event for " +79cpEvent.referenceType().name());80}81}82}8384/*85* Handle exceptions that can occur in normal operation86* but which can't be accounted for by event builder87* methods. The thread should not be terminated if they88* occur.89*90* TO DO: We need a better way to log these conditions.91*/92} catch (VMOutOfMemoryException vmme) {93vmme.printStackTrace();94} catch (InconsistentDebugInfoException idie) {95idie.printStackTrace();9697/*98* If any of these exceptions below occurs, there is some99* sort of programming error that should be addressed in100* the JDI implemementation. However, it would cripple101* the implementation if we let this thread die due to102* one of them. So, a notification of the exception is103* given and we attempt to continue.104*/105} catch (ObjectCollectedException oce) {106oce.printStackTrace();107} catch (ClassNotPreparedException cnpe) {108cnpe.printStackTrace();109}110}111} catch (InterruptedException e) { // should we really die here112} catch (VMDisconnectedException e) { // time to die113}114if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {115vm.printTrace("Internal event handler exiting");116}117}118}119120121