📄 virtualmachinecommandset.java
字号:
/* VirtualMachineCommandSet.java -- class to implement the VirtualMachine Command Set Copyright (C) 2005 Free Software Foundation This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package gnu.classpath.jdwp.processor;import gnu.classpath.jdwp.JdwpConstants;import gnu.classpath.jdwp.VMVirtualMachine;import gnu.classpath.jdwp.exception.JdwpException;import gnu.classpath.jdwp.exception.JdwpInternalErrorException;import gnu.classpath.jdwp.exception.NotImplementedException;import gnu.classpath.jdwp.id.ObjectId;import gnu.classpath.jdwp.id.ReferenceTypeId;import gnu.classpath.jdwp.util.JdwpString;import gnu.classpath.jdwp.util.Signature;import java.io.DataOutputStream;import java.io.IOException;import java.nio.ByteBuffer;import java.util.ArrayList;import java.util.Iterator;import java.util.Properties;/** * A class representing the VirtualMachine Command Set. * * @author Aaron Luchko <aluchko@redhat.com> */public class VirtualMachineCommandSet extends CommandSet{ public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command) throws JdwpException { boolean shutdown = false; try { switch (command) { case JdwpConstants.CommandSet.VirtualMachine.VERSION: executeVersion(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.CLASSES_BY_SIGNATURE: executeClassesBySignature(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.ALL_CLASSES: executeAllClasses(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.ALL_THREADS: executeAllThreads(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.TOP_LEVEL_THREAD_GROUPS: executeTopLevelThreadGroups(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.IDSIZES: executeIDsizes(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.DISPOSE: shutdown = true; executeDispose(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.SUSPEND: executeSuspend(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.RESUME: executeResume(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.EXIT: shutdown = true; executeExit(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.CREATE_STRING: executeCreateString(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.CAPABILITIES: executeCapabilities(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.CLASS_PATHS: executeClassPaths(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.DISPOSE_OBJECTS: executeDisposeObjects(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.HOLD_EVENTS: executeHoldEvents(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.RELEASE_EVENTS: executeReleaseEvents(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.CAPABILITIES_NEW: executeCapabilitiesNew(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.REDEFINE_CLASSES: executeRedefineClasses(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.SET_DEFAULT_STRATUM: executeSetDefaultStratum(bb, os); break; case JdwpConstants.CommandSet.VirtualMachine.ALL_CLASSES_WITH_GENERIC: executeAllClassesWithGeneric(bb, os); break; default: throw new NotImplementedException("Command " + command + " not found in VirtualMachine Command Set."); } } catch (IOException ex) { // The DataOutputStream we're using isn't talking to a socket at all // So if we throw an IOException we're in serious trouble throw new JdwpInternalErrorException(ex); } return shutdown; } private void executeVersion(ByteBuffer bb, DataOutputStream os) throws JdwpException, IOException { Properties props = System.getProperties(); int jdwpMajor = JdwpConstants.Version.MAJOR; int jdwpMinor = JdwpConstants.Version.MINOR; // The description field is pretty loosely defined String description = "JDWP version " + jdwpMajor + "." + jdwpMinor + ", JVM version " + props.getProperty("java.vm.name") + " " + props.getProperty("java.vm.version") + " " + props.getProperty("java.version"); String vmVersion = props.getProperty("java.version"); String vmName = props.getProperty("java.vm.name"); JdwpString.writeString(os, description); os.writeInt(jdwpMajor); os.writeInt(jdwpMinor); JdwpString.writeString(os, vmName); JdwpString.writeString(os, vmVersion); } private void executeClassesBySignature(ByteBuffer bb, DataOutputStream os) throws JdwpException, IOException { String sig = JdwpString.readString(bb); ArrayList allMatchingClasses = new ArrayList(); // This will be an Iterator over all loaded Classes Iterator iter = VMVirtualMachine.getAllLoadedClasses(); while (iter.hasNext()) { Class clazz = (Class) iter.next(); String clazzSig = Signature.computeClassSignature(clazz); if (clazzSig.equals(sig)) allMatchingClasses.add(clazz); } os.writeInt(allMatchingClasses.size()); for (int i = 0; i < allMatchingClasses.size(); i++) { Class clazz = (Class) allMatchingClasses.get(i); ReferenceTypeId id = idMan.getReferenceTypeId(clazz); id.writeTagged(os); int status = VMVirtualMachine.getClassStatus(clazz); os.writeInt(status); } } private void executeAllClasses(ByteBuffer bb, DataOutputStream os) throws JdwpException, IOException { // Disable garbage collection while we're collecting the info on loaded // classes so we some classes don't get collected between the time we get // the count and the time we get the list //VMVirtualMachine.disableGarbageCollection(); int classCount = VMVirtualMachine.getAllLoadedClassesCount(); os.writeInt(classCount); // This will be an Iterator over all loaded Classes Iterator iter = VMVirtualMachine.getAllLoadedClasses(); //VMVirtualMachine.enableGarbageCollection(); int count = 0; // Note it's possible classes were created since out classCount so make // sure we don't write more classes than we told the debugger while (iter.hasNext() && count++ < classCount) { Class clazz = (Class) iter.next(); ReferenceTypeId id = idMan.getReferenceTypeId(clazz); id.writeTagged(os); String sig = Signature.computeClassSignature(clazz); JdwpString.writeString(os, sig); int status = VMVirtualMachine.getClassStatus(clazz); os.writeInt(status); } } private void executeAllThreads(ByteBuffer bb, DataOutputStream os) throws JdwpException, IOException
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -