Wed, 02 Apr 2008 12:09:59 -0700
6667042: PrintAssembly option does not work without special plugin
Summary: remove old private plugin interface, simplify, rework old plugin to use unchanged Gnu sources
Reviewed-by: kvn, rasbold
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | import com.sun.jdi.*; |
duke@435 | 26 | import com.sun.jdi.connect.*; |
duke@435 | 27 | |
duke@435 | 28 | import java.util.Map; |
duke@435 | 29 | import java.util.List; |
duke@435 | 30 | import java.util.Iterator; |
duke@435 | 31 | import java.io.IOException; |
duke@435 | 32 | |
duke@435 | 33 | /* This class is used to test multi VM connectivity feature of |
duke@435 | 34 | * SA/JDI. Accepts two PIDs as arguments. Connects to first VM |
duke@435 | 35 | *, Connects to second VM and disposes them in that order. |
duke@435 | 36 | */ |
duke@435 | 37 | |
duke@435 | 38 | public class multivm { |
duke@435 | 39 | static AttachingConnector myPIDConn; |
duke@435 | 40 | static VirtualMachine vm1; |
duke@435 | 41 | static VirtualMachine vm2; |
duke@435 | 42 | static VirtualMachineManager vmmgr; |
duke@435 | 43 | |
duke@435 | 44 | public static void println(String msg) { |
duke@435 | 45 | System.out.println(msg); |
duke@435 | 46 | } |
duke@435 | 47 | |
duke@435 | 48 | private static void usage() { |
duke@435 | 49 | System.err.println("Usage: java multivm <pid1> <pid2>"); |
duke@435 | 50 | System.exit(1); |
duke@435 | 51 | } |
duke@435 | 52 | |
duke@435 | 53 | public static void main(String args[]) { |
duke@435 | 54 | vmmgr = Bootstrap.virtualMachineManager(); |
duke@435 | 55 | List attachingConnectors = vmmgr.attachingConnectors(); |
duke@435 | 56 | if (attachingConnectors.isEmpty()) { |
duke@435 | 57 | System.err.println( "ERROR: No attaching connectors"); |
duke@435 | 58 | return; |
duke@435 | 59 | } |
duke@435 | 60 | Iterator myIt = attachingConnectors.iterator(); |
duke@435 | 61 | while (myIt.hasNext()) { |
duke@435 | 62 | AttachingConnector tmpCon = (AttachingConnector)myIt.next(); |
duke@435 | 63 | if (tmpCon.name().equals( |
duke@435 | 64 | "sun.jvm.hotspot.jdi.SAPIDAttachingConnector")) { |
duke@435 | 65 | myPIDConn = tmpCon; |
duke@435 | 66 | break; |
duke@435 | 67 | } |
duke@435 | 68 | } |
duke@435 | 69 | |
duke@435 | 70 | int pid1 = 0, pid2 = 0; |
duke@435 | 71 | String pidText = null; |
duke@435 | 72 | switch (args.length) { |
duke@435 | 73 | case (2): |
duke@435 | 74 | try { |
duke@435 | 75 | pidText = args[0]; |
duke@435 | 76 | pid1 = Integer.parseInt(pidText); |
duke@435 | 77 | System.out.println( "pid1: " + pid1); |
duke@435 | 78 | vm1 = attachPID(pid1); |
duke@435 | 79 | pidText = args[1]; |
duke@435 | 80 | pid2 = Integer.parseInt(pidText); |
duke@435 | 81 | System.out.println( "pid2: " + pid2); |
duke@435 | 82 | vm2 = attachPID(pid2); |
duke@435 | 83 | } catch (NumberFormatException e) { |
duke@435 | 84 | println(e.getMessage()); |
duke@435 | 85 | usage(); |
duke@435 | 86 | } |
duke@435 | 87 | break; |
duke@435 | 88 | default: |
duke@435 | 89 | usage(); |
duke@435 | 90 | } |
duke@435 | 91 | |
duke@435 | 92 | if (vm1 != null) { |
duke@435 | 93 | System.out.println("vm1: attached ok!"); |
duke@435 | 94 | System.out.println(vm1.version()); |
duke@435 | 95 | sagdoit mine = new sagdoit(vm1); |
duke@435 | 96 | mine.doAll(); |
duke@435 | 97 | } |
duke@435 | 98 | |
duke@435 | 99 | if (vm2 != null) { |
duke@435 | 100 | System.out.println("vm2: attached ok!"); |
duke@435 | 101 | System.out.println(vm2.version()); |
duke@435 | 102 | sagdoit mine = new sagdoit(vm2); |
duke@435 | 103 | mine.doAll(); |
duke@435 | 104 | } |
duke@435 | 105 | |
duke@435 | 106 | if (vm1 != null) { |
duke@435 | 107 | vm1.dispose(); |
duke@435 | 108 | } |
duke@435 | 109 | |
duke@435 | 110 | if (vm2 != null) { |
duke@435 | 111 | vm2.dispose(); |
duke@435 | 112 | } |
duke@435 | 113 | } |
duke@435 | 114 | |
duke@435 | 115 | private static VirtualMachine attachPID(int pid) { |
duke@435 | 116 | Map connArgs = myPIDConn.defaultArguments(); |
duke@435 | 117 | System.out.println("connArgs = " + connArgs); |
duke@435 | 118 | VirtualMachine vm; |
duke@435 | 119 | Connector.StringArgument connArg = (Connector.StringArgument)connArgs.get("pid"); |
duke@435 | 120 | connArg.setValue(Integer.toString(pid)); |
duke@435 | 121 | |
duke@435 | 122 | try { |
duke@435 | 123 | vm = myPIDConn.attach(connArgs); |
duke@435 | 124 | } catch (IOException ee) { |
duke@435 | 125 | System.err.println("ERROR: myPIDConn.attach got IO Exception:" + ee); |
duke@435 | 126 | vm = null; |
duke@435 | 127 | } catch (IllegalConnectorArgumentsException ee) { |
duke@435 | 128 | System.err.println("ERROR: myPIDConn.attach got illegal args exception:" + ee); |
duke@435 | 129 | vm = null; |
duke@435 | 130 | } |
duke@435 | 131 | return vm; |
duke@435 | 132 | } |
duke@435 | 133 | } |