Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/tools/jdi/InternalEventHandler.java
38920 views
/*1* Copyright (c) 1998, 2011, 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.*;28import com.sun.jdi.event.*;29import java.util.*;3031public class InternalEventHandler implements Runnable32{33EventQueueImpl queue;34VirtualMachineImpl vm;3536InternalEventHandler(VirtualMachineImpl vm, EventQueueImpl queue)37{38this.vm = vm;39this.queue = queue;40Thread thread = new Thread(vm.threadGroupForJDI(), this,41"JDI Internal Event Handler");42thread.setDaemon(true);43thread.start();44}4546public void run() {47if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {48vm.printTrace("Internal event handler running");49}50try {51while (true) {52try {53EventSet eventSet = queue.removeInternal();54EventIterator it = eventSet.eventIterator();55while (it.hasNext()) {56Event event = it.nextEvent();57if (event instanceof ClassUnloadEvent) {58ClassUnloadEvent cuEvent = (ClassUnloadEvent)event;59vm.removeReferenceType(cuEvent.classSignature());6061if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {62vm.printTrace("Handled Unload Event for " +63cuEvent.classSignature());64}65} else if (event instanceof ClassPrepareEvent) {66ClassPrepareEvent cpEvent = (ClassPrepareEvent)event;67((ReferenceTypeImpl)cpEvent.referenceType())68.markPrepared();6970if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {71vm.printTrace("Handled Prepare Event for " +72cpEvent.referenceType().name());73}74}7576}7778/*79* Handle exceptions that can occur in normal operation80* but which can't be accounted for by event builder81* methods. The thread should not be terminated if they82* occur.83*84* TO DO: We need a better way to log these conditions.85*/86} catch (VMOutOfMemoryException vmme) {87vmme.printStackTrace();88} catch (InconsistentDebugInfoException idie) {89idie.printStackTrace();9091/*92* If any of these exceptions below occurs, there is some93* sort of programming error that should be addressed in94* the JDI implemementation. However, it would cripple95* the implementation if we let this thread die due to96* one of them. So, a notification of the exception is97* given and we attempt to continue.98*/99} catch (ObjectCollectedException oce) {100oce.printStackTrace();101} catch (ClassNotPreparedException cnpe) {102cnpe.printStackTrace();103}104}105} catch (InterruptedException e) { // should we really die here106} catch (VMDisconnectedException e) { // time to die107}108if ((vm.traceFlags & VirtualMachine.TRACE_EVENTS) != 0) {109vm.printTrace("Internal event handler exiting");110}111}112}113114115