annotate agent/test/jdi/multivm.java @ 18408:2c3666f44855

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