author | fparain |
Wed, 14 Dec 2011 04:30:57 -0800 | |
changeset 11209 | 110525ac80b0 |
parent 8921 | 14bfe81f2a9d |
child 11441 | a89f443814cd |
permissions | -rw-r--r-- |
1 | 1 |
/* |
8921
14bfe81f2a9d
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
8076
diff
changeset
|
2 |
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4571
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/javaClasses.hpp" |
|
27 |
#include "classfile/systemDictionary.hpp" |
|
28 |
#include "gc_implementation/shared/vmGCOperations.hpp" |
|
29 |
#include "memory/resourceArea.hpp" |
|
30 |
#include "prims/jvmtiExport.hpp" |
|
31 |
#include "runtime/arguments.hpp" |
|
32 |
#include "runtime/globals.hpp" |
|
33 |
#include "runtime/java.hpp" |
|
34 |
#include "runtime/javaCalls.hpp" |
|
35 |
#include "runtime/os.hpp" |
|
36 |
#include "services/attachListener.hpp" |
|
11209 | 37 |
#include "services/diagnosticCommand.hpp" |
7397 | 38 |
#include "services/heapDumper.hpp" |
1 | 39 |
|
40 |
volatile bool AttachListener::_initialized; |
|
41 |
||
42 |
// Implementation of "properties" command. |
|
43 |
// |
|
44 |
// Invokes sun.misc.VMSupport.serializePropertiesToByteArray to serialize |
|
45 |
// the system properties into a byte array. |
|
46 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
47 |
static klassOop load_and_initialize_klass(Symbol* sh, TRAPS) { |
1 | 48 |
klassOop k = SystemDictionary::resolve_or_fail(sh, true, CHECK_NULL); |
49 |
instanceKlassHandle ik (THREAD, k); |
|
50 |
if (ik->should_be_initialized()) { |
|
51 |
ik->initialize(CHECK_NULL); |
|
52 |
} |
|
53 |
return ik(); |
|
54 |
} |
|
55 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
56 |
static jint get_properties(AttachOperation* op, outputStream* out, Symbol* serializePropertiesMethod) { |
1 | 57 |
Thread* THREAD = Thread::current(); |
58 |
HandleMark hm; |
|
59 |
||
60 |
// load sun.misc.VMSupport |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
61 |
Symbol* klass = vmSymbols::sun_misc_VMSupport(); |
1 | 62 |
klassOop k = load_and_initialize_klass(klass, THREAD); |
63 |
if (HAS_PENDING_EXCEPTION) { |
|
64 |
java_lang_Throwable::print(PENDING_EXCEPTION, out); |
|
65 |
CLEAR_PENDING_EXCEPTION; |
|
66 |
return JNI_ERR; |
|
67 |
} |
|
68 |
instanceKlassHandle ik(THREAD, k); |
|
69 |
||
70 |
// invoke the serializePropertiesToByteArray method |
|
71 |
JavaValue result(T_OBJECT); |
|
72 |
JavaCallArguments args; |
|
73 |
||
74 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
75 |
Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature(); |
1 | 76 |
JavaCalls::call_static(&result, |
77 |
ik, |
|
78 |
serializePropertiesMethod, |
|
79 |
signature, |
|
80 |
&args, |
|
81 |
THREAD); |
|
82 |
if (HAS_PENDING_EXCEPTION) { |
|
83 |
java_lang_Throwable::print(PENDING_EXCEPTION, out); |
|
84 |
CLEAR_PENDING_EXCEPTION; |
|
85 |
return JNI_ERR; |
|
86 |
} |
|
87 |
||
88 |
// The result should be a [B |
|
89 |
oop res = (oop)result.get_jobject(); |
|
90 |
assert(res->is_typeArray(), "just checking"); |
|
91 |
assert(typeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking"); |
|
92 |
||
93 |
// copy the bytes to the output stream |
|
94 |
typeArrayOop ba = typeArrayOop(res); |
|
95 |
jbyte* addr = typeArrayOop(res)->byte_at_addr(0); |
|
96 |
out->print_raw((const char*)addr, ba->length()); |
|
97 |
||
98 |
return JNI_OK; |
|
99 |
} |
|
100 |
||
101 |
// Implementation of "properties" command. |
|
102 |
static jint get_system_properties(AttachOperation* op, outputStream* out) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
103 |
return get_properties(op, out, vmSymbols::serializePropertiesToByteArray_name()); |
1 | 104 |
} |
105 |
||
106 |
// Implementation of "agent_properties" command. |
|
107 |
static jint get_agent_properties(AttachOperation* op, outputStream* out) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
108 |
return get_properties(op, out, vmSymbols::serializeAgentPropertiesToByteArray_name()); |
1 | 109 |
} |
110 |
||
111 |
// Implementation of "datadump" command. |
|
112 |
// |
|
113 |
// Raises a SIGBREAK signal so that VM dump threads, does deadlock detection, |
|
114 |
// etc. In theory this command should only post a DataDumpRequest to any |
|
115 |
// JVMTI environment that has enabled this event. However it's useful to |
|
116 |
// trigger the SIGBREAK handler. |
|
117 |
||
118 |
static jint data_dump(AttachOperation* op, outputStream* out) { |
|
119 |
if (!ReduceSignalUsage) { |
|
120 |
AttachListener::pd_data_dump(); |
|
121 |
} else { |
|
122 |
if (JvmtiExport::should_post_data_dump()) { |
|
123 |
JvmtiExport::post_data_dump(); |
|
124 |
} |
|
125 |
} |
|
126 |
return JNI_OK; |
|
127 |
} |
|
128 |
||
129 |
// Implementation of "threaddump" command - essentially a remote ctrl-break |
|
130 |
// |
|
131 |
static jint thread_dump(AttachOperation* op, outputStream* out) { |
|
132 |
bool print_concurrent_locks = false; |
|
133 |
if (op->arg(0) != NULL && strcmp(op->arg(0), "-l") == 0) { |
|
134 |
print_concurrent_locks = true; |
|
135 |
} |
|
136 |
||
137 |
// thread stacks |
|
138 |
VM_PrintThreads op1(out, print_concurrent_locks); |
|
139 |
VMThread::execute(&op1); |
|
140 |
||
141 |
// JNI global handles |
|
142 |
VM_PrintJNI op2(out); |
|
143 |
VMThread::execute(&op2); |
|
144 |
||
145 |
// Deadlock detection |
|
146 |
VM_FindDeadlocks op3(out); |
|
147 |
VMThread::execute(&op3); |
|
148 |
||
149 |
return JNI_OK; |
|
150 |
} |
|
151 |
||
11209 | 152 |
// A jcmd attach operation request was received, which will now |
153 |
// dispatch to the diagnostic commands used for serviceability functions. |
|
154 |
static jint jcmd(AttachOperation* op, outputStream* out) { |
|
155 |
Thread* THREAD = Thread::current(); |
|
156 |
// All the supplied jcmd arguments are stored as a single |
|
157 |
// string (op->arg(0)). This is parsed by the Dcmd framework. |
|
158 |
DCmd::parse_and_execute(out, op->arg(0), ' ', THREAD); |
|
159 |
if (HAS_PENDING_EXCEPTION) { |
|
160 |
java_lang_Throwable::print(PENDING_EXCEPTION, out); |
|
161 |
CLEAR_PENDING_EXCEPTION; |
|
162 |
// The exception has been printed on the output stream |
|
163 |
// If the JVM returns JNI_ERR, the attachAPI throws a generic I/O |
|
164 |
// exception and the content of the output stream is not processed. |
|
165 |
// By returning JNI_OK, the exception will be displayed on the client side |
|
166 |
} |
|
167 |
return JNI_OK; |
|
168 |
} |
|
169 |
||
1 | 170 |
#ifndef SERVICES_KERNEL // Heap dumping not supported |
171 |
// Implementation of "dumpheap" command. |
|
172 |
// |
|
173 |
// Input arguments :- |
|
174 |
// arg0: Name of the dump file |
|
175 |
// arg1: "-live" or "-all" |
|
176 |
jint dump_heap(AttachOperation* op, outputStream* out) { |
|
177 |
const char* path = op->arg(0); |
|
178 |
if (path == NULL || path[0] == '\0') { |
|
179 |
out->print_cr("No dump file specified"); |
|
180 |
} else { |
|
181 |
bool live_objects_only = true; // default is true to retain the behavior before this change is made |
|
182 |
const char* arg1 = op->arg(1); |
|
183 |
if (arg1 != NULL && (strlen(arg1) > 0)) { |
|
184 |
if (strcmp(arg1, "-all") != 0 && strcmp(arg1, "-live") != 0) { |
|
185 |
out->print_cr("Invalid argument to dumpheap operation: %s", arg1); |
|
186 |
return JNI_ERR; |
|
187 |
} |
|
188 |
live_objects_only = strcmp(arg1, "-live") == 0; |
|
189 |
} |
|
190 |
||
191 |
// Request a full GC before heap dump if live_objects_only = true |
|
192 |
// This helps reduces the amount of unreachable objects in the dump |
|
193 |
// and makes it easier to browse. |
|
194 |
HeapDumper dumper(live_objects_only /* request GC */); |
|
195 |
int res = dumper.dump(op->arg(0)); |
|
196 |
if (res == 0) { |
|
197 |
out->print_cr("Heap dump file created"); |
|
198 |
} else { |
|
199 |
// heap dump failed |
|
200 |
ResourceMark rm; |
|
201 |
char* error = dumper.error_as_C_string(); |
|
202 |
if (error == NULL) { |
|
203 |
out->print_cr("Dump failed - reason unknown"); |
|
204 |
} else { |
|
205 |
out->print_cr("%s", error); |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
return JNI_OK; |
|
210 |
} |
|
211 |
#endif // SERVICES_KERNEL |
|
212 |
||
213 |
// Implementation of "inspectheap" command |
|
214 |
// |
|
215 |
// Input arguments :- |
|
216 |
// arg0: "-live" or "-all" |
|
217 |
static jint heap_inspection(AttachOperation* op, outputStream* out) { |
|
218 |
bool live_objects_only = true; // default is true to retain the behavior before this change is made |
|
219 |
const char* arg0 = op->arg(0); |
|
220 |
if (arg0 != NULL && (strlen(arg0) > 0)) { |
|
221 |
if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) { |
|
222 |
out->print_cr("Invalid argument to inspectheap operation: %s", arg0); |
|
223 |
return JNI_ERR; |
|
224 |
} |
|
225 |
live_objects_only = strcmp(arg0, "-live") == 0; |
|
226 |
} |
|
2141
e9a644aaff87
6797870: Add -XX:+{HeapDump,PrintClassHistogram}{Before,After}FullGC
ysr
parents:
1
diff
changeset
|
227 |
VM_GC_HeapInspection heapop(out, live_objects_only /* request full gc */, true /* need_prologue */); |
1 | 228 |
VMThread::execute(&heapop); |
229 |
return JNI_OK; |
|
230 |
} |
|
231 |
||
232 |
// set a boolean global flag using value from AttachOperation |
|
233 |
static jint set_bool_flag(const char* name, AttachOperation* op, outputStream* out) { |
|
234 |
bool value = true; |
|
235 |
const char* arg1; |
|
236 |
if ((arg1 = op->arg(1)) != NULL) { |
|
237 |
int tmp; |
|
238 |
int n = sscanf(arg1, "%d", &tmp); |
|
239 |
if (n != 1) { |
|
4437
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
240 |
out->print_cr("flag value must be a boolean (1 or 0)"); |
1 | 241 |
return JNI_ERR; |
242 |
} |
|
243 |
value = (tmp != 0); |
|
244 |
} |
|
245 |
bool res = CommandLineFlags::boolAtPut((char*)name, &value, ATTACH_ON_DEMAND); |
|
246 |
if (! res) { |
|
247 |
out->print_cr("setting flag %s failed", name); |
|
248 |
} |
|
249 |
return res? JNI_OK : JNI_ERR; |
|
250 |
} |
|
251 |
||
252 |
// set a intx global flag using value from AttachOperation |
|
253 |
static jint set_intx_flag(const char* name, AttachOperation* op, outputStream* out) { |
|
254 |
intx value; |
|
255 |
const char* arg1; |
|
256 |
if ((arg1 = op->arg(1)) != NULL) { |
|
257 |
int n = sscanf(arg1, INTX_FORMAT, &value); |
|
258 |
if (n != 1) { |
|
4437
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
259 |
out->print_cr("flag value must be an integer"); |
1 | 260 |
return JNI_ERR; |
261 |
} |
|
262 |
} |
|
4437
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
263 |
bool res = CommandLineFlags::intxAtPut((char*)name, &value, ATTACH_ON_DEMAND); |
1 | 264 |
if (! res) { |
265 |
out->print_cr("setting flag %s failed", name); |
|
266 |
} |
|
267 |
||
268 |
return res? JNI_OK : JNI_ERR; |
|
269 |
} |
|
270 |
||
271 |
// set a uintx global flag using value from AttachOperation |
|
272 |
static jint set_uintx_flag(const char* name, AttachOperation* op, outputStream* out) { |
|
273 |
uintx value; |
|
274 |
const char* arg1; |
|
275 |
if ((arg1 = op->arg(1)) != NULL) { |
|
276 |
int n = sscanf(arg1, UINTX_FORMAT, &value); |
|
277 |
if (n != 1) { |
|
4437
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
278 |
out->print_cr("flag value must be an unsigned integer"); |
1 | 279 |
return JNI_ERR; |
280 |
} |
|
281 |
} |
|
4437
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
282 |
bool res = CommandLineFlags::uintxAtPut((char*)name, &value, ATTACH_ON_DEMAND); |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
283 |
if (! res) { |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
284 |
out->print_cr("setting flag %s failed", name); |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
285 |
} |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
286 |
|
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
287 |
return res? JNI_OK : JNI_ERR; |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
288 |
} |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
289 |
|
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
290 |
// set a uint64_t global flag using value from AttachOperation |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
291 |
static jint set_uint64_t_flag(const char* name, AttachOperation* op, outputStream* out) { |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
292 |
uint64_t value; |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
293 |
const char* arg1; |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
294 |
if ((arg1 = op->arg(1)) != NULL) { |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
295 |
int n = sscanf(arg1, UINT64_FORMAT, &value); |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
296 |
if (n != 1) { |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
297 |
out->print_cr("flag value must be an unsigned 64-bit integer"); |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
298 |
return JNI_ERR; |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
299 |
} |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
300 |
} |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
301 |
bool res = CommandLineFlags::uint64_tAtPut((char*)name, &value, ATTACH_ON_DEMAND); |
1 | 302 |
if (! res) { |
303 |
out->print_cr("setting flag %s failed", name); |
|
304 |
} |
|
305 |
||
306 |
return res? JNI_OK : JNI_ERR; |
|
307 |
} |
|
308 |
||
309 |
// set a string global flag using value from AttachOperation |
|
310 |
static jint set_ccstr_flag(const char* name, AttachOperation* op, outputStream* out) { |
|
311 |
const char* value; |
|
312 |
if ((value = op->arg(1)) == NULL) { |
|
4437
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
313 |
out->print_cr("flag value must be a string"); |
1 | 314 |
return JNI_ERR; |
315 |
} |
|
4437
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
316 |
bool res = CommandLineFlags::ccstrAtPut((char*)name, &value, ATTACH_ON_DEMAND); |
1 | 317 |
if (res) { |
318 |
FREE_C_HEAP_ARRAY(char, value); |
|
319 |
} else { |
|
320 |
out->print_cr("setting flag %s failed", name); |
|
321 |
} |
|
322 |
||
323 |
return res? JNI_OK : JNI_ERR; |
|
324 |
} |
|
325 |
||
326 |
// Implementation of "setflag" command |
|
327 |
static jint set_flag(AttachOperation* op, outputStream* out) { |
|
328 |
||
329 |
const char* name = NULL; |
|
330 |
if ((name = op->arg(0)) == NULL) { |
|
331 |
out->print_cr("flag name is missing"); |
|
332 |
return JNI_ERR; |
|
333 |
} |
|
334 |
||
335 |
Flag* f = Flag::find_flag((char*)name, strlen(name)); |
|
336 |
if (f && f->is_external() && f->is_writeable()) { |
|
337 |
if (f->is_bool()) { |
|
338 |
return set_bool_flag(name, op, out); |
|
339 |
} else if (f->is_intx()) { |
|
340 |
return set_intx_flag(name, op, out); |
|
341 |
} else if (f->is_uintx()) { |
|
342 |
return set_uintx_flag(name, op, out); |
|
4437
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
343 |
} else if (f->is_uint64_t()) { |
d1abc17afffb
6898160: Need serviceability support for new vm argument type 'uint64_t'
phh
parents:
2141
diff
changeset
|
344 |
return set_uint64_t_flag(name, op, out); |
1 | 345 |
} else if (f->is_ccstr()) { |
346 |
return set_ccstr_flag(name, op, out); |
|
347 |
} else { |
|
348 |
ShouldNotReachHere(); |
|
349 |
return JNI_ERR; |
|
350 |
} |
|
351 |
} else { |
|
352 |
return AttachListener::pd_set_flag(op, out); |
|
353 |
} |
|
354 |
} |
|
355 |
||
356 |
// Implementation of "printflag" command |
|
357 |
static jint print_flag(AttachOperation* op, outputStream* out) { |
|
358 |
const char* name = NULL; |
|
359 |
if ((name = op->arg(0)) == NULL) { |
|
360 |
out->print_cr("flag name is missing"); |
|
361 |
return JNI_ERR; |
|
362 |
} |
|
363 |
Flag* f = Flag::find_flag((char*)name, strlen(name)); |
|
364 |
if (f) { |
|
365 |
f->print_as_flag(out); |
|
366 |
out->print_cr(""); |
|
367 |
} else { |
|
368 |
out->print_cr("no such flag '%s'", name); |
|
369 |
} |
|
370 |
return JNI_OK; |
|
371 |
} |
|
372 |
||
373 |
// Table to map operation names to functions. |
|
374 |
||
375 |
// names must be of length <= AttachOperation::name_length_max |
|
376 |
static AttachOperationFunctionInfo funcs[] = { |
|
377 |
{ "agentProperties", get_agent_properties }, |
|
378 |
{ "datadump", data_dump }, |
|
379 |
#ifndef SERVICES_KERNEL |
|
380 |
{ "dumpheap", dump_heap }, |
|
381 |
#endif // SERVICES_KERNEL |
|
382 |
{ "load", JvmtiExport::load_agent_library }, |
|
383 |
{ "properties", get_system_properties }, |
|
384 |
{ "threaddump", thread_dump }, |
|
385 |
{ "inspectheap", heap_inspection }, |
|
386 |
{ "setflag", set_flag }, |
|
387 |
{ "printflag", print_flag }, |
|
11209 | 388 |
{ "jcmd", jcmd }, |
1 | 389 |
{ NULL, NULL } |
390 |
}; |
|
391 |
||
392 |
||
393 |
||
394 |
// The Attach Listener threads services a queue. It dequeues an operation |
|
395 |
// from the queue, examines the operation name (command), and dispatches |
|
396 |
// to the corresponding function to perform the operation. |
|
397 |
||
398 |
static void attach_listener_thread_entry(JavaThread* thread, TRAPS) { |
|
399 |
os::set_priority(thread, NearMaxPriority); |
|
400 |
||
401 |
if (AttachListener::pd_init() != 0) { |
|
402 |
return; |
|
403 |
} |
|
404 |
AttachListener::set_initialized(); |
|
405 |
||
406 |
for (;;) { |
|
407 |
AttachOperation* op = AttachListener::dequeue(); |
|
408 |
if (op == NULL) { |
|
409 |
return; // dequeue failed or shutdown |
|
410 |
} |
|
411 |
||
412 |
ResourceMark rm; |
|
413 |
bufferedStream st; |
|
414 |
jint res = JNI_OK; |
|
415 |
||
416 |
// handle special detachall operation |
|
417 |
if (strcmp(op->name(), AttachOperation::detachall_operation_name()) == 0) { |
|
418 |
AttachListener::detachall(); |
|
419 |
} else { |
|
420 |
// find the function to dispatch too |
|
421 |
AttachOperationFunctionInfo* info = NULL; |
|
422 |
for (int i=0; funcs[i].name != NULL; i++) { |
|
423 |
const char* name = funcs[i].name; |
|
424 |
assert(strlen(name) <= AttachOperation::name_length_max, "operation <= name_length_max"); |
|
425 |
if (strcmp(op->name(), name) == 0) { |
|
426 |
info = &(funcs[i]); |
|
427 |
break; |
|
428 |
} |
|
429 |
} |
|
430 |
||
431 |
// check for platform dependent attach operation |
|
432 |
if (info == NULL) { |
|
433 |
info = AttachListener::pd_find_operation(op->name()); |
|
434 |
} |
|
435 |
||
436 |
if (info != NULL) { |
|
437 |
// dispatch to the function that implements this operation |
|
438 |
res = (info->func)(op, &st); |
|
439 |
} else { |
|
440 |
st.print("Operation %s not recognized!", op->name()); |
|
441 |
res = JNI_ERR; |
|
442 |
} |
|
443 |
} |
|
444 |
||
445 |
// operation complete - send result and output to client |
|
446 |
op->complete(res, &st); |
|
447 |
} |
|
448 |
} |
|
449 |
||
450 |
// Starts the Attach Listener thread |
|
451 |
void AttachListener::init() { |
|
452 |
EXCEPTION_MARK; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
453 |
klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK); |
1 | 454 |
instanceKlassHandle klass (THREAD, k); |
455 |
instanceHandle thread_oop = klass->allocate_instance_handle(CHECK); |
|
456 |
||
457 |
const char thread_name[] = "Attach Listener"; |
|
458 |
Handle string = java_lang_String::create_from_str(thread_name, CHECK); |
|
459 |
||
460 |
// Initialize thread_oop to put it into the system threadGroup |
|
461 |
Handle thread_group (THREAD, Universe::system_thread_group()); |
|
462 |
JavaValue result(T_VOID); |
|
463 |
JavaCalls::call_special(&result, thread_oop, |
|
464 |
klass, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
465 |
vmSymbols::object_initializer_name(), |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
466 |
vmSymbols::threadgroup_string_void_signature(), |
1 | 467 |
thread_group, |
468 |
string, |
|
469 |
CHECK); |
|
470 |
||
4571 | 471 |
KlassHandle group(THREAD, SystemDictionary::ThreadGroup_klass()); |
1 | 472 |
JavaCalls::call_special(&result, |
473 |
thread_group, |
|
474 |
group, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
475 |
vmSymbols::add_method_name(), |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
476 |
vmSymbols::thread_void_signature(), |
1 | 477 |
thread_oop, // ARG 1 |
478 |
CHECK); |
|
479 |
||
480 |
{ MutexLocker mu(Threads_lock); |
|
481 |
JavaThread* listener_thread = new JavaThread(&attach_listener_thread_entry); |
|
482 |
||
483 |
// Check that thread and osthread were created |
|
484 |
if (listener_thread == NULL || listener_thread->osthread() == NULL) { |
|
485 |
vm_exit_during_initialization("java.lang.OutOfMemoryError", |
|
486 |
"unable to create new native thread"); |
|
487 |
} |
|
488 |
||
489 |
java_lang_Thread::set_thread(thread_oop(), listener_thread); |
|
490 |
java_lang_Thread::set_daemon(thread_oop()); |
|
491 |
||
492 |
listener_thread->set_threadObj(thread_oop()); |
|
493 |
Threads::add(listener_thread); |
|
494 |
Thread::start(listener_thread); |
|
495 |
} |
|
496 |
} |
|
497 |
||
498 |
// Performs clean-up tasks on platforms where we can detect that the last |
|
499 |
// client has detached |
|
500 |
void AttachListener::detachall() { |
|
501 |
// call the platform dependent clean-up |
|
502 |
pd_detachall(); |
|
503 |
} |