annotate agent/src/os/solaris/dbx/svc_agent_dbx.hpp @ 210:05712c37c828

6676016: ParallelOldGC leaks memory Summary: ensure that GCTask threads release resource and handle memory Reviewed-by: jmasa, chrisphi
author jcoomes
date Wed, 18 Jun 2008 18:36:47 -0700
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2000-2001 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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 #include "shell_imp.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "IOBuf.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
27 #include <sys/time.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #include <thread_db.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 typedef td_err_e td_init_fn_t();
a61af66fc99e Initial load
duke
parents:
diff changeset
31 typedef td_err_e td_ta_new_fn_t(struct ps_prochandle *, td_thragent_t **);
a61af66fc99e Initial load
duke
parents:
diff changeset
32 typedef td_err_e td_ta_delete_fn_t(td_thragent_t *);
a61af66fc99e Initial load
duke
parents:
diff changeset
33 typedef td_err_e td_ta_map_id2thr_fn_t(const td_thragent_t *, thread_t, td_thrhandle_t *);
a61af66fc99e Initial load
duke
parents:
diff changeset
34 typedef td_err_e td_thr_getgregs_fn_t(const td_thrhandle_t *, prgregset_t);
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 class ServiceabilityAgentDbxModule {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 ServiceabilityAgentDbxModule(int major, int minor,
a61af66fc99e Initial load
duke
parents:
diff changeset
39 shell_imp_interp_t interp, int argc, char *argv[]);
a61af66fc99e Initial load
duke
parents:
diff changeset
40 ~ServiceabilityAgentDbxModule();
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 bool install();
a61af66fc99e Initial load
duke
parents:
diff changeset
43 bool uninstall();
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 /* This is invoked through the dbx command interpreter. It listens
a61af66fc99e Initial load
duke
parents:
diff changeset
46 on a socket for commands and does not return until it receives an
a61af66fc99e Initial load
duke
parents:
diff changeset
47 "exit" command. At that point control is returned to dbx's main
a61af66fc99e Initial load
duke
parents:
diff changeset
48 loop, at which point if the user sends an exit command to dbx's
a61af66fc99e Initial load
duke
parents:
diff changeset
49 shell the dbx process will exit. Returns true if completed
a61af66fc99e Initial load
duke
parents:
diff changeset
50 successfully, false if an error occurred while running (for
a61af66fc99e Initial load
duke
parents:
diff changeset
51 example, unable to bind listening socket). */
a61af66fc99e Initial load
duke
parents:
diff changeset
52 bool run();
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // This must be shared between the Java and C layers
a61af66fc99e Initial load
duke
parents:
diff changeset
57 static const int PORT = 21928;
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Command handlers
a61af66fc99e Initial load
duke
parents:
diff changeset
60 bool handleAddressSize(char* data);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 bool handlePeekFailFast(char* data);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 bool handlePeek(char* data);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 bool handlePoke(char* data);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 bool handleMapped(char* data);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 bool handleLookup(char* data);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 bool handleThrGRegs(char* data);
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // Input routines
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // May mutate addr argument even if result is false
a61af66fc99e Initial load
duke
parents:
diff changeset
71 bool scanAddress(char** data, psaddr_t* addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // May mutate num argument even if result is false
a61af66fc99e Initial load
duke
parents:
diff changeset
73 bool scanUnsignedInt(char** data, unsigned int* num);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // Returns NULL if error occurred while scanning. Otherwise, returns
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // newly-allocated character array which must be freed with delete[].
a61af66fc99e Initial load
duke
parents:
diff changeset
76 char* scanSymbol(char** data);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // Helper routine: converts ASCII to 4-bit integer. Returns true if
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // character is in range, false otherwise.
a61af66fc99e Initial load
duke
parents:
diff changeset
79 bool charToNibble(char ascii, int* value);
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Output routines
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // Writes an int with no leading or trailing spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
84 bool writeInt(int val, int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // Writes an address in hex format with no leading or trailing
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // spaces
a61af66fc99e Initial load
duke
parents:
diff changeset
87 bool writeAddress(psaddr_t addr, int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Writes a register in hex format with no leading or trailing
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // spaces (addresses and registers might be of different size)
a61af66fc99e Initial load
duke
parents:
diff changeset
90 bool writeRegister(prgreg_t reg, int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Writes a space to given file descriptor
a61af66fc99e Initial load
duke
parents:
diff changeset
92 bool writeSpace(int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Writes carriage return to given file descriptor
a61af66fc99e Initial load
duke
parents:
diff changeset
94 bool writeCR(int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Writes a bool as [0|1]
a61af66fc99e Initial load
duke
parents:
diff changeset
96 bool writeBoolAsInt(bool val, int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Helper routine: converts low 4 bits to ASCII [0..9][A..F]
a61af66fc99e Initial load
duke
parents:
diff changeset
98 char nibbleToChar(unsigned char nibble);
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // Base routine called by most of the above
a61af66fc99e Initial load
duke
parents:
diff changeset
101 bool writeString(const char* str, int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Writes a binary character
a61af66fc99e Initial load
duke
parents:
diff changeset
104 bool writeBinChar(char val, int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Writes a binary unsigned int in network (big-endian) byte order
a61af66fc99e Initial load
duke
parents:
diff changeset
106 bool writeBinUnsignedInt(unsigned int val, int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Writes a binary buffer
a61af66fc99e Initial load
duke
parents:
diff changeset
108 bool writeBinBuf(char* buf, int size, int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Routine to flush the socket
a61af66fc99e Initial load
duke
parents:
diff changeset
111 bool flush(int client_socket);
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 void cleanup(int client_socket);
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // The shell interpreter on which we can invoke commands (?)
a61af66fc99e Initial load
duke
parents:
diff changeset
116 shell_imp_interp_t _interp;
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // The "command line" arguments passed to us by dbx (?)
a61af66fc99e Initial load
duke
parents:
diff changeset
119 int _argc;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 char **_argv;
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // The installed command in the dbx shell
a61af66fc99e Initial load
duke
parents:
diff changeset
123 shell_imp_command_t _command;
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Access to libthread_db (dlsym'ed to be able to pick up the
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // version loaded by dbx)
a61af66fc99e Initial load
duke
parents:
diff changeset
127 td_init_fn_t* td_init_fn;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 td_ta_new_fn_t* td_ta_new_fn;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 td_ta_delete_fn_t* td_ta_delete_fn;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 td_ta_map_id2thr_fn_t* td_ta_map_id2thr_fn;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 td_thr_getgregs_fn_t* td_thr_getgregs_fn;
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // Our "thread agent" -- access to libthread_db
a61af66fc99e Initial load
duke
parents:
diff changeset
134 td_thragent_t* _tdb_agent;
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // Path to libthread.so in target process; free with delete[]
a61af66fc99e Initial load
duke
parents:
diff changeset
137 char* libThreadName;
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // Handle to dlopen'ed libthread_db.so
a61af66fc99e Initial load
duke
parents:
diff changeset
140 void* libThreadDB;
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // Helper callback for finding libthread_db.so
a61af66fc99e Initial load
duke
parents:
diff changeset
143 friend int findLibThreadCB(const rd_loadobj_t* lo, void* data);
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // Support for reading C strings out of the target process (so we
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // can find the correct libthread_db). Returns newly-allocated char*
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // which must be freed with delete[], or null if the read failed.
a61af66fc99e Initial load
duke
parents:
diff changeset
148 char* readCStringFromProcess(psaddr_t addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 IOBuf myComm;
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Output buffer support (used by writeString, writeChar, flush)
a61af66fc99e Initial load
duke
parents:
diff changeset
153 char* output_buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 int output_buffer_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 int output_buffer_pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // "Fail fast" flag
a61af66fc99e Initial load
duke
parents:
diff changeset
158 bool peek_fail_fast;
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Commands
a61af66fc99e Initial load
duke
parents:
diff changeset
161 static const char* CMD_ADDRESS_SIZE;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 static const char* CMD_PEEK_FAIL_FAST;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 static const char* CMD_PEEK;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 static const char* CMD_POKE;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 static const char* CMD_MAPPED;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 static const char* CMD_LOOKUP;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 static const char* CMD_THR_GREGS;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 static const char* CMD_EXIT;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 };
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 // For profiling. Times reported are in milliseconds.
a61af66fc99e Initial load
duke
parents:
diff changeset
172 class Timer {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
174 Timer();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 ~Timer();
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 void start();
a61af66fc99e Initial load
duke
parents:
diff changeset
178 void stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
179 long total();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 long average();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 void reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
184 struct timeval startTime;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 long long totalMicroseconds; // stored internally in microseconds
a61af66fc99e Initial load
duke
parents:
diff changeset
186 int counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 long long timevalDiff(struct timeval* startTime, struct timeval* endTime);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 };