annotate agent/src/share/classes/sun/jvm/hotspot/DebugServer.java @ 20456:64156d22e49d

8032247: SA: Constantpool lookup for invokedynamic is not implemented Summary: implement constant pool lookup for invokedynamic Reviewed-by: sla, sspitsyn
author dsamersoff
date Thu, 11 Sep 2014 11:55:30 -0700
parents f6f3bb0ee072
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2011, 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 package sun.jvm.hotspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public class DebugServer {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 private void usage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 System.out.println("usage: java " + getClass().getName() + " <pid> [server id]");
a61af66fc99e Initial load
duke
parents:
diff changeset
34 System.out.println(" or: java " + getClass().getName() + " <executable> <core> [server id]");
a61af66fc99e Initial load
duke
parents:
diff changeset
35 System.out.println("\"pid\" must be the process ID of a HotSpot process.");
a61af66fc99e Initial load
duke
parents:
diff changeset
36 System.out.println("If reading a core file, \"executable\" must (currently) be the");
a61af66fc99e Initial load
duke
parents:
diff changeset
37 System.out.println("full path name to the precise java executable which generated");
a61af66fc99e Initial load
duke
parents:
diff changeset
38 System.out.println("the core file (not, on Solaris, the \"java\" wrapper script in");
a61af66fc99e Initial load
duke
parents:
diff changeset
39 System.out.println("the \"bin\" subdirectory of the JDK.)");
a61af66fc99e Initial load
duke
parents:
diff changeset
40 System.out.println("The \"server id\" is a unique name for a specific remote debuggee.");
a61af66fc99e Initial load
duke
parents:
diff changeset
41 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 }
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 new DebugServer().run(args);
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 void run(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if ((args.length < 1) || (args.length > 3)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // Attempt to handle "-h" or "-help"
a61af66fc99e Initial load
duke
parents:
diff changeset
54 if (args[0].startsWith("-")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 int pid = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 boolean usePid = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 String coreFileName = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // FIXME: would be nice to pick this up from the core file
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // somehow, but that doesn't look possible. Should at least figure
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // it out from a path to the JDK.
a61af66fc99e Initial load
duke
parents:
diff changeset
64 String javaExecutableName = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 String serverID = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 switch (args.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
69 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 pid = Integer.parseInt(args[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 usePid = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 } catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 usage();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // either we have pid and server id or exec file and core file
a61af66fc99e Initial load
duke
parents:
diff changeset
79 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 pid = Integer.parseInt(args[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 usePid = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 serverID = args[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
83 } catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 pid = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 usePid = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 javaExecutableName = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
87 coreFileName = args[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 case 3:
a61af66fc99e Initial load
duke
parents:
diff changeset
92 javaExecutableName = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
93 coreFileName = args[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
94 serverID = args[2];
a61af66fc99e Initial load
duke
parents:
diff changeset
95 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // should not happend, taken care already.
a61af66fc99e Initial load
duke
parents:
diff changeset
99 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 final HotSpotAgent agent = new HotSpotAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (usePid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 System.err.println("Attaching to process ID " + pid + " and starting RMI services, please wait...");
a61af66fc99e Initial load
duke
parents:
diff changeset
106 agent.startServer(pid, serverID);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 System.err.println("Attaching to core " + coreFileName +
a61af66fc99e Initial load
duke
parents:
diff changeset
109 " from executable " + javaExecutableName + " and starting RMI services, please wait...");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 agent.startServer(javaExecutableName, coreFileName, serverID);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (usePid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 System.err.print("Error attaching to process or starting server: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
116 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 System.err.print("Error attaching to core file or starting server: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 System.exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // shutdown hook to clean-up the server in case of forced exit.
a61af66fc99e Initial load
duke
parents:
diff changeset
124 Runtime.getRuntime().addShutdownHook(new java.lang.Thread(
a61af66fc99e Initial load
duke
parents:
diff changeset
125 new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 agent.shutdownServer();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }));
a61af66fc99e Initial load
duke
parents:
diff changeset
130 System.err.println("Debugger attached and RMI services started.");
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }