Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/services/diagnosticCommand.cpp
41144 views
1
/*
2
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
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
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "jvm.h"
27
#include "classfile/classLoaderHierarchyDCmd.hpp"
28
#include "classfile/classLoaderStats.hpp"
29
#include "classfile/javaClasses.hpp"
30
#include "classfile/systemDictionary.hpp"
31
#include "classfile/vmClasses.hpp"
32
#include "code/codeCache.hpp"
33
#include "compiler/compileBroker.hpp"
34
#include "compiler/directivesParser.hpp"
35
#include "gc/shared/gcVMOperations.hpp"
36
#include "memory/metaspace/metaspaceDCmd.hpp"
37
#include "memory/resourceArea.hpp"
38
#include "memory/universe.hpp"
39
#include "oops/objArrayOop.inline.hpp"
40
#include "oops/oop.inline.hpp"
41
#include "oops/typeArrayOop.inline.hpp"
42
#include "runtime/fieldDescriptor.inline.hpp"
43
#include "runtime/flags/jvmFlag.hpp"
44
#include "runtime/handles.inline.hpp"
45
#include "runtime/interfaceSupport.inline.hpp"
46
#include "runtime/javaCalls.hpp"
47
#include "runtime/jniHandles.hpp"
48
#include "runtime/os.hpp"
49
#include "runtime/vmOperations.hpp"
50
#include "runtime/vm_version.hpp"
51
#include "services/diagnosticArgument.hpp"
52
#include "services/diagnosticCommand.hpp"
53
#include "services/diagnosticFramework.hpp"
54
#include "services/heapDumper.hpp"
55
#include "services/management.hpp"
56
#include "services/writeableFlags.hpp"
57
#include "utilities/debug.hpp"
58
#include "utilities/events.hpp"
59
#include "utilities/formatBuffer.hpp"
60
#include "utilities/macros.hpp"
61
62
63
static void loadAgentModule(TRAPS) {
64
ResourceMark rm(THREAD);
65
HandleMark hm(THREAD);
66
67
JavaValue result(T_OBJECT);
68
Handle h_module_name = java_lang_String::create_from_str("jdk.management.agent", CHECK);
69
JavaCalls::call_static(&result,
70
vmClasses::module_Modules_klass(),
71
vmSymbols::loadModule_name(),
72
vmSymbols::loadModule_signature(),
73
h_module_name,
74
THREAD);
75
}
76
77
void DCmdRegistrant::register_dcmds(){
78
// Registration of the diagnostic commands
79
// First argument specifies which interfaces will export the command
80
// Second argument specifies if the command is enabled
81
// Third argument specifies if the command is hidden
82
uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI
83
| DCmd_Source_MBean;
84
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HelpDCmd>(full_export, true, false));
85
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VersionDCmd>(full_export, true, false));
86
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CommandLineDCmd>(full_export, true, false));
87
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintSystemPropertiesDCmd>(full_export, true, false));
88
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PrintVMFlagsDCmd>(full_export, true, false));
89
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SetVMFlagDCmd>(full_export, true, false));
90
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMDynamicLibrariesDCmd>(full_export, true, false));
91
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMUptimeDCmd>(full_export, true, false));
92
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<VMInfoDCmd>(full_export, true, false));
93
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemGCDCmd>(full_export, true, false));
94
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<RunFinalizationDCmd>(full_export, true, false));
95
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapInfoDCmd>(full_export, true, false));
96
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<FinalizerInfoDCmd>(full_export, true, false));
97
#if INCLUDE_SERVICES
98
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<HeapDumpDCmd>(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false));
99
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHistogramDCmd>(full_export, true, false));
100
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SystemDictionaryDCmd>(full_export, true, false));
101
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassHierarchyDCmd>(full_export, true, false));
102
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<SymboltableDCmd>(full_export, true, false));
103
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<StringtableDCmd>(full_export, true, false));
104
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<metaspace::MetaspaceDCmd>(full_export, true, false));
105
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<EventLogDCmd>(full_export, true, false));
106
#if INCLUDE_JVMTI // Both JVMTI and SERVICES have to be enabled to have this dcmd
107
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIAgentLoadDCmd>(full_export, true, false));
108
#endif // INCLUDE_JVMTI
109
#endif // INCLUDE_SERVICES
110
#if INCLUDE_JVMTI
111
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JVMTIDataDumpDCmd>(full_export, true, false));
112
#endif // INCLUDE_JVMTI
113
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ThreadDumpDCmd>(full_export, true, false));
114
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderStatsDCmd>(full_export, true, false));
115
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<ClassLoaderHierarchyDCmd>(full_export, true, false));
116
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompileQueueDCmd>(full_export, true, false));
117
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeListDCmd>(full_export, true, false));
118
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeCacheDCmd>(full_export, true, false));
119
#ifdef LINUX
120
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PerfMapDCmd>(full_export, true, false));
121
#endif // LINUX
122
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TouchedMethodsDCmd>(full_export, true, false));
123
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeHeapAnalyticsDCmd>(full_export, true, false));
124
125
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesPrintDCmd>(full_export, true, false));
126
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesAddDCmd>(full_export, true, false));
127
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesRemoveDCmd>(full_export, true, false));
128
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesClearDCmd>(full_export, true, false));
129
130
// Enhanced JMX Agent Support
131
// These commands won't be exported via the DiagnosticCommandMBean until an
132
// appropriate permission is created for them
133
uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
134
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
135
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
136
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
137
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStatusDCmd>(jmx_agent_export_flags, true,false));
138
139
// Debug on cmd (only makes sense with JVMTI since the agentlib needs it).
140
#if INCLUDE_JVMTI
141
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<DebugOnCmdStartDCmd>(full_export, true, true));
142
#endif // INCLUDE_JVMTI
143
144
#if INCLUDE_CDS
145
DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<DumpSharedArchiveDCmd>(full_export, true, false));
146
#endif // INCLUDE_CDS
147
}
148
149
#ifndef HAVE_EXTRA_DCMD
150
void DCmdRegistrant::register_dcmds_ext(){
151
// Do nothing here
152
}
153
#endif
154
155
156
HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),
157
_all("-all", "Show help for all commands", "BOOLEAN", false, "false"),
158
_cmd("command name", "The name of the command for which we want help",
159
"STRING", false) {
160
_dcmdparser.add_dcmd_option(&_all);
161
_dcmdparser.add_dcmd_argument(&_cmd);
162
};
163
164
165
static int compare_strings(const char** s1, const char** s2) {
166
return ::strcmp(*s1, *s2);
167
}
168
169
void HelpDCmd::execute(DCmdSource source, TRAPS) {
170
if (_all.value()) {
171
GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(source);
172
cmd_list->sort(compare_strings);
173
for (int i = 0; i < cmd_list->length(); i++) {
174
DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
175
strlen(cmd_list->at(i)));
176
output()->print_cr("%s%s", factory->name(),
177
factory->is_enabled() ? "" : " [disabled]");
178
output()->print_cr("\t%s", factory->description());
179
output()->cr();
180
factory = factory->next();
181
}
182
} else if (_cmd.has_value()) {
183
DCmd* cmd = NULL;
184
DCmdFactory* factory = DCmdFactory::factory(source, _cmd.value(),
185
strlen(_cmd.value()));
186
if (factory != NULL) {
187
output()->print_cr("%s%s", factory->name(),
188
factory->is_enabled() ? "" : " [disabled]");
189
output()->print_cr("%s", factory->description());
190
output()->print_cr("\nImpact: %s", factory->impact());
191
JavaPermission p = factory->permission();
192
if(p._class != NULL) {
193
if(p._action != NULL) {
194
output()->print_cr("\nPermission: %s(%s, %s)",
195
p._class, p._name == NULL ? "null" : p._name, p._action);
196
} else {
197
output()->print_cr("\nPermission: %s(%s)",
198
p._class, p._name == NULL ? "null" : p._name);
199
}
200
}
201
output()->cr();
202
cmd = factory->create_resource_instance(output());
203
if (cmd != NULL) {
204
DCmdMark mark(cmd);
205
cmd->print_help(factory->name());
206
}
207
} else {
208
output()->print_cr("Help unavailable : '%s' : No such command", _cmd.value());
209
}
210
} else {
211
output()->print_cr("The following commands are available:");
212
GrowableArray<const char *>* cmd_list = DCmdFactory::DCmd_list(source);
213
cmd_list->sort(compare_strings);
214
for (int i = 0; i < cmd_list->length(); i++) {
215
DCmdFactory* factory = DCmdFactory::factory(source, cmd_list->at(i),
216
strlen(cmd_list->at(i)));
217
output()->print_cr("%s%s", factory->name(),
218
factory->is_enabled() ? "" : " [disabled]");
219
factory = factory->_next;
220
}
221
output()->print_cr("\nFor more information about a specific command use 'help <command>'.");
222
}
223
}
224
225
void VersionDCmd::execute(DCmdSource source, TRAPS) {
226
output()->print_cr("%s version %s", VM_Version::vm_name(),
227
VM_Version::vm_release());
228
JDK_Version jdk_version = JDK_Version::current();
229
if (jdk_version.patch_version() > 0) {
230
output()->print_cr("JDK %d.%d.%d.%d", jdk_version.major_version(),
231
jdk_version.minor_version(), jdk_version.security_version(),
232
jdk_version.patch_version());
233
} else {
234
output()->print_cr("JDK %d.%d.%d", jdk_version.major_version(),
235
jdk_version.minor_version(), jdk_version.security_version());
236
}
237
}
238
239
PrintVMFlagsDCmd::PrintVMFlagsDCmd(outputStream* output, bool heap) :
240
DCmdWithParser(output, heap),
241
_all("-all", "Print all flags supported by the VM", "BOOLEAN", false, "false") {
242
_dcmdparser.add_dcmd_option(&_all);
243
}
244
245
void PrintVMFlagsDCmd::execute(DCmdSource source, TRAPS) {
246
if (_all.value()) {
247
JVMFlag::printFlags(output(), true);
248
} else {
249
JVMFlag::printSetFlags(output());
250
}
251
}
252
253
SetVMFlagDCmd::SetVMFlagDCmd(outputStream* output, bool heap) :
254
DCmdWithParser(output, heap),
255
_flag("flag name", "The name of the flag we want to set",
256
"STRING", true),
257
_value("string value", "The value we want to set", "STRING", false) {
258
_dcmdparser.add_dcmd_argument(&_flag);
259
_dcmdparser.add_dcmd_argument(&_value);
260
}
261
262
void SetVMFlagDCmd::execute(DCmdSource source, TRAPS) {
263
const char* val = NULL;
264
if (_value.value() != NULL) {
265
val = _value.value();
266
}
267
268
FormatBuffer<80> err_msg("%s", "");
269
int ret = WriteableFlags::set_flag(_flag.value(), val, JVMFlagOrigin::MANAGEMENT, err_msg);
270
271
if (ret != JVMFlag::SUCCESS) {
272
output()->print_cr("%s", err_msg.buffer());
273
}
274
}
275
276
void JVMTIDataDumpDCmd::execute(DCmdSource source, TRAPS) {
277
if (JvmtiExport::should_post_data_dump()) {
278
JvmtiExport::post_data_dump();
279
}
280
}
281
282
#if INCLUDE_SERVICES
283
#if INCLUDE_JVMTI
284
JVMTIAgentLoadDCmd::JVMTIAgentLoadDCmd(outputStream* output, bool heap) :
285
DCmdWithParser(output, heap),
286
_libpath("library path", "Absolute path of the JVMTI agent to load.",
287
"STRING", true),
288
_option("agent option", "Option string to pass the agent.", "STRING", false) {
289
_dcmdparser.add_dcmd_argument(&_libpath);
290
_dcmdparser.add_dcmd_argument(&_option);
291
}
292
293
void JVMTIAgentLoadDCmd::execute(DCmdSource source, TRAPS) {
294
295
if (_libpath.value() == NULL) {
296
output()->print_cr("JVMTI.agent_load dcmd needs library path.");
297
return;
298
}
299
300
char *suffix = strrchr(_libpath.value(), '.');
301
bool is_java_agent = (suffix != NULL) && (strncmp(".jar", suffix, 4) == 0);
302
303
if (is_java_agent) {
304
if (_option.value() == NULL) {
305
JvmtiExport::load_agent_library("instrument", "false",
306
_libpath.value(), output());
307
} else {
308
size_t opt_len = strlen(_libpath.value()) + strlen(_option.value()) + 2;
309
if (opt_len > 4096) {
310
output()->print_cr("JVMTI agent attach failed: Options is too long.");
311
return;
312
}
313
314
char *opt = (char *)os::malloc(opt_len, mtInternal);
315
if (opt == NULL) {
316
output()->print_cr("JVMTI agent attach failed: "
317
"Could not allocate " SIZE_FORMAT " bytes for argument.",
318
opt_len);
319
return;
320
}
321
322
jio_snprintf(opt, opt_len, "%s=%s", _libpath.value(), _option.value());
323
JvmtiExport::load_agent_library("instrument", "false", opt, output());
324
325
os::free(opt);
326
}
327
} else {
328
JvmtiExport::load_agent_library(_libpath.value(), "true",
329
_option.value(), output());
330
}
331
}
332
333
#endif // INCLUDE_JVMTI
334
#endif // INCLUDE_SERVICES
335
336
void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
337
// load VMSupport
338
Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
339
Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
340
InstanceKlass* ik = InstanceKlass::cast(k);
341
if (ik->should_be_initialized()) {
342
ik->initialize(THREAD);
343
}
344
if (HAS_PENDING_EXCEPTION) {
345
java_lang_Throwable::print(PENDING_EXCEPTION, output());
346
output()->cr();
347
CLEAR_PENDING_EXCEPTION;
348
return;
349
}
350
351
// invoke the serializePropertiesToByteArray method
352
JavaValue result(T_OBJECT);
353
JavaCallArguments args;
354
355
Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
356
JavaCalls::call_static(&result,
357
ik,
358
vmSymbols::serializePropertiesToByteArray_name(),
359
signature,
360
&args,
361
THREAD);
362
if (HAS_PENDING_EXCEPTION) {
363
java_lang_Throwable::print(PENDING_EXCEPTION, output());
364
output()->cr();
365
CLEAR_PENDING_EXCEPTION;
366
return;
367
}
368
369
// The result should be a [B
370
oop res = result.get_oop();
371
assert(res->is_typeArray(), "just checking");
372
assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
373
374
// copy the bytes to the output stream
375
typeArrayOop ba = typeArrayOop(res);
376
jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
377
output()->print_raw((const char*)addr, ba->length());
378
}
379
380
VMUptimeDCmd::VMUptimeDCmd(outputStream* output, bool heap) :
381
DCmdWithParser(output, heap),
382
_date("-date", "Add a prefix with current date", "BOOLEAN", false, "false") {
383
_dcmdparser.add_dcmd_option(&_date);
384
}
385
386
void VMUptimeDCmd::execute(DCmdSource source, TRAPS) {
387
if (_date.value()) {
388
output()->date_stamp(true, "", ": ");
389
}
390
output()->time_stamp().update_to(tty->time_stamp().ticks());
391
output()->stamp();
392
output()->print_cr(" s");
393
}
394
395
void VMInfoDCmd::execute(DCmdSource source, TRAPS) {
396
VMError::print_vm_info(_output);
397
}
398
399
void SystemGCDCmd::execute(DCmdSource source, TRAPS) {
400
Universe::heap()->collect(GCCause::_dcmd_gc_run);
401
}
402
403
void RunFinalizationDCmd::execute(DCmdSource source, TRAPS) {
404
Klass* k = vmClasses::System_klass();
405
JavaValue result(T_VOID);
406
JavaCalls::call_static(&result, k,
407
vmSymbols::run_finalization_name(),
408
vmSymbols::void_method_signature(), CHECK);
409
}
410
411
void HeapInfoDCmd::execute(DCmdSource source, TRAPS) {
412
MutexLocker hl(THREAD, Heap_lock);
413
Universe::heap()->print_on(output());
414
}
415
416
void FinalizerInfoDCmd::execute(DCmdSource source, TRAPS) {
417
ResourceMark rm(THREAD);
418
419
Klass* k = SystemDictionary::resolve_or_fail(
420
vmSymbols::finalizer_histogram_klass(), true, CHECK);
421
422
JavaValue result(T_ARRAY);
423
424
// We are calling lang.ref.FinalizerHistogram.getFinalizerHistogram() method
425
// and expect it to return array of FinalizerHistogramEntry as Object[]
426
427
JavaCalls::call_static(&result, k,
428
vmSymbols::get_finalizer_histogram_name(),
429
vmSymbols::void_finalizer_histogram_entry_array_signature(), CHECK);
430
431
objArrayOop result_oop = (objArrayOop) result.get_oop();
432
if (result_oop->length() == 0) {
433
output()->print_cr("No instances waiting for finalization found");
434
return;
435
}
436
437
oop foop = result_oop->obj_at(0);
438
InstanceKlass* ik = InstanceKlass::cast(foop->klass());
439
440
fieldDescriptor count_fd, name_fd;
441
442
Klass* count_res = ik->find_field(
443
vmSymbols::finalizer_histogram_entry_count_field(), vmSymbols::int_signature(), &count_fd);
444
445
Klass* name_res = ik->find_field(
446
vmSymbols::finalizer_histogram_entry_name_field(), vmSymbols::string_signature(), &name_fd);
447
448
assert(count_res != NULL && name_res != NULL, "Unexpected layout of FinalizerHistogramEntry");
449
450
output()->print_cr("Unreachable instances waiting for finalization");
451
output()->print_cr("#instances class name");
452
output()->print_cr("-----------------------");
453
454
for (int i = 0; i < result_oop->length(); ++i) {
455
oop element_oop = result_oop->obj_at(i);
456
oop str_oop = element_oop->obj_field(name_fd.offset());
457
char *name = java_lang_String::as_utf8_string(str_oop);
458
int count = element_oop->int_field(count_fd.offset());
459
output()->print_cr("%10d %s", count, name);
460
}
461
}
462
463
#if INCLUDE_SERVICES // Heap dumping/inspection supported
464
HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
465
DCmdWithParser(output, heap),
466
_filename("filename","Name of the dump file", "STRING",true),
467
_all("-all", "Dump all objects, including unreachable objects",
468
"BOOLEAN", false, "false"),
469
_gzip("-gz", "If specified, the heap dump is written in gzipped format "
470
"using the given compression level. 1 (recommended) is the fastest, "
471
"9 the strongest compression.", "INT", false, "1") {
472
_dcmdparser.add_dcmd_option(&_all);
473
_dcmdparser.add_dcmd_argument(&_filename);
474
_dcmdparser.add_dcmd_option(&_gzip);
475
}
476
477
void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
478
jlong level = -1; // -1 means no compression.
479
480
if (_gzip.is_set()) {
481
level = _gzip.value();
482
483
if (level < 1 || level > 9) {
484
output()->print_cr("Compression level out of range (1-9): " JLONG_FORMAT, level);
485
return;
486
}
487
}
488
489
// Request a full GC before heap dump if _all is false
490
// This helps reduces the amount of unreachable objects in the dump
491
// and makes it easier to browse.
492
HeapDumper dumper(!_all.value() /* request GC if _all is false*/);
493
dumper.dump(_filename.value(), output(), (int) level);
494
}
495
496
ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
497
DCmdWithParser(output, heap),
498
_all("-all", "Inspect all objects, including unreachable objects",
499
"BOOLEAN", false, "false"),
500
_parallel_thread_num("-parallel",
501
"Number of parallel threads to use for heap inspection. "
502
"0 (the default) means let the VM determine the number of threads to use. "
503
"1 means use one thread (disable parallelism). "
504
"For any other value the VM will try to use the specified number of "
505
"threads, but might use fewer.",
506
"INT", false, "0") {
507
_dcmdparser.add_dcmd_option(&_all);
508
_dcmdparser.add_dcmd_option(&_parallel_thread_num);
509
}
510
511
void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
512
jlong num = _parallel_thread_num.value();
513
if (num < 0) {
514
output()->print_cr("Parallel thread number out of range (>=0): " JLONG_FORMAT, num);
515
return;
516
}
517
uint parallel_thread_num = num == 0
518
? MAX2<uint>(1, (uint)os::initial_active_processor_count() * 3 / 8)
519
: num;
520
VM_GC_HeapInspection heapop(output(),
521
!_all.value(), /* request full gc if false */
522
parallel_thread_num);
523
VMThread::execute(&heapop);
524
}
525
526
#endif // INCLUDE_SERVICES
527
528
ThreadDumpDCmd::ThreadDumpDCmd(outputStream* output, bool heap) :
529
DCmdWithParser(output, heap),
530
_locks("-l", "print java.util.concurrent locks", "BOOLEAN", false, "false"),
531
_extended("-e", "print extended thread information", "BOOLEAN", false, "false") {
532
_dcmdparser.add_dcmd_option(&_locks);
533
_dcmdparser.add_dcmd_option(&_extended);
534
}
535
536
void ThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
537
// thread stacks
538
VM_PrintThreads op1(output(), _locks.value(), _extended.value());
539
VMThread::execute(&op1);
540
541
// JNI global handles
542
VM_PrintJNI op2(output());
543
VMThread::execute(&op2);
544
545
// Deadlock detection
546
VM_FindDeadlocks op3(output());
547
VMThread::execute(&op3);
548
}
549
550
// Enhanced JMX Agent support
551
552
JMXStartRemoteDCmd::JMXStartRemoteDCmd(outputStream *output, bool heap_allocated) :
553
554
DCmdWithParser(output, heap_allocated),
555
556
_config_file
557
("config.file",
558
"set com.sun.management.config.file", "STRING", false),
559
560
_jmxremote_host
561
("jmxremote.host",
562
"set com.sun.management.jmxremote.host", "STRING", false),
563
564
_jmxremote_port
565
("jmxremote.port",
566
"set com.sun.management.jmxremote.port", "STRING", false),
567
568
_jmxremote_rmi_port
569
("jmxremote.rmi.port",
570
"set com.sun.management.jmxremote.rmi.port", "STRING", false),
571
572
_jmxremote_ssl
573
("jmxremote.ssl",
574
"set com.sun.management.jmxremote.ssl", "STRING", false),
575
576
_jmxremote_registry_ssl
577
("jmxremote.registry.ssl",
578
"set com.sun.management.jmxremote.registry.ssl", "STRING", false),
579
580
_jmxremote_authenticate
581
("jmxremote.authenticate",
582
"set com.sun.management.jmxremote.authenticate", "STRING", false),
583
584
_jmxremote_password_file
585
("jmxremote.password.file",
586
"set com.sun.management.jmxremote.password.file", "STRING", false),
587
588
_jmxremote_access_file
589
("jmxremote.access.file",
590
"set com.sun.management.jmxremote.access.file", "STRING", false),
591
592
_jmxremote_login_config
593
("jmxremote.login.config",
594
"set com.sun.management.jmxremote.login.config", "STRING", false),
595
596
_jmxremote_ssl_enabled_cipher_suites
597
("jmxremote.ssl.enabled.cipher.suites",
598
"set com.sun.management.jmxremote.ssl.enabled.cipher.suite", "STRING", false),
599
600
_jmxremote_ssl_enabled_protocols
601
("jmxremote.ssl.enabled.protocols",
602
"set com.sun.management.jmxremote.ssl.enabled.protocols", "STRING", false),
603
604
_jmxremote_ssl_need_client_auth
605
("jmxremote.ssl.need.client.auth",
606
"set com.sun.management.jmxremote.need.client.auth", "STRING", false),
607
608
_jmxremote_ssl_config_file
609
("jmxremote.ssl.config.file",
610
"set com.sun.management.jmxremote.ssl.config.file", "STRING", false),
611
612
// JDP Protocol support
613
_jmxremote_autodiscovery
614
("jmxremote.autodiscovery",
615
"set com.sun.management.jmxremote.autodiscovery", "STRING", false),
616
617
_jdp_port
618
("jdp.port",
619
"set com.sun.management.jdp.port", "INT", false),
620
621
_jdp_address
622
("jdp.address",
623
"set com.sun.management.jdp.address", "STRING", false),
624
625
_jdp_source_addr
626
("jdp.source_addr",
627
"set com.sun.management.jdp.source_addr", "STRING", false),
628
629
_jdp_ttl
630
("jdp.ttl",
631
"set com.sun.management.jdp.ttl", "INT", false),
632
633
_jdp_pause
634
("jdp.pause",
635
"set com.sun.management.jdp.pause", "INT", false),
636
637
_jdp_name
638
("jdp.name",
639
"set com.sun.management.jdp.name", "STRING", false)
640
641
{
642
_dcmdparser.add_dcmd_option(&_config_file);
643
_dcmdparser.add_dcmd_option(&_jmxremote_host);
644
_dcmdparser.add_dcmd_option(&_jmxremote_port);
645
_dcmdparser.add_dcmd_option(&_jmxremote_rmi_port);
646
_dcmdparser.add_dcmd_option(&_jmxremote_ssl);
647
_dcmdparser.add_dcmd_option(&_jmxremote_registry_ssl);
648
_dcmdparser.add_dcmd_option(&_jmxremote_authenticate);
649
_dcmdparser.add_dcmd_option(&_jmxremote_password_file);
650
_dcmdparser.add_dcmd_option(&_jmxremote_access_file);
651
_dcmdparser.add_dcmd_option(&_jmxremote_login_config);
652
_dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_cipher_suites);
653
_dcmdparser.add_dcmd_option(&_jmxremote_ssl_enabled_protocols);
654
_dcmdparser.add_dcmd_option(&_jmxremote_ssl_need_client_auth);
655
_dcmdparser.add_dcmd_option(&_jmxremote_ssl_config_file);
656
_dcmdparser.add_dcmd_option(&_jmxremote_autodiscovery);
657
_dcmdparser.add_dcmd_option(&_jdp_port);
658
_dcmdparser.add_dcmd_option(&_jdp_address);
659
_dcmdparser.add_dcmd_option(&_jdp_source_addr);
660
_dcmdparser.add_dcmd_option(&_jdp_ttl);
661
_dcmdparser.add_dcmd_option(&_jdp_pause);
662
_dcmdparser.add_dcmd_option(&_jdp_name);
663
}
664
665
void JMXStartRemoteDCmd::execute(DCmdSource source, TRAPS) {
666
ResourceMark rm(THREAD);
667
HandleMark hm(THREAD);
668
669
// Load and initialize the jdk.internal.agent.Agent class
670
// invoke startRemoteManagementAgent(string) method to start
671
// the remote management server.
672
// throw java.lang.NoSuchMethodError if the method doesn't exist
673
674
loadAgentModule(CHECK);
675
Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
676
Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
677
678
JavaValue result(T_VOID);
679
680
// Pass all command line arguments to java as key=value,...
681
// All checks are done on java side
682
683
int len = 0;
684
stringStream options;
685
char comma[2] = {0,0};
686
687
// Leave default values on Agent.class side and pass only
688
// agruments explicitly set by user. All arguments passed
689
// to jcmd override properties with the same name set by
690
// command line with -D or by managmenent.properties
691
// file.
692
#define PUT_OPTION(a) \
693
do { \
694
if ( (a).is_set() ){ \
695
if ( *((a).type()) == 'I' ) { \
696
options.print("%scom.sun.management.%s=" JLONG_FORMAT, comma, (a).name(), (jlong)((a).value())); \
697
} else { \
698
options.print("%scom.sun.management.%s=%s", comma, (a).name(), (char*)((a).value())); \
699
} \
700
comma[0] = ','; \
701
}\
702
} while(0);
703
704
705
PUT_OPTION(_config_file);
706
PUT_OPTION(_jmxremote_host);
707
PUT_OPTION(_jmxremote_port);
708
PUT_OPTION(_jmxremote_rmi_port);
709
PUT_OPTION(_jmxremote_ssl);
710
PUT_OPTION(_jmxremote_registry_ssl);
711
PUT_OPTION(_jmxremote_authenticate);
712
PUT_OPTION(_jmxremote_password_file);
713
PUT_OPTION(_jmxremote_access_file);
714
PUT_OPTION(_jmxremote_login_config);
715
PUT_OPTION(_jmxremote_ssl_enabled_cipher_suites);
716
PUT_OPTION(_jmxremote_ssl_enabled_protocols);
717
PUT_OPTION(_jmxremote_ssl_need_client_auth);
718
PUT_OPTION(_jmxremote_ssl_config_file);
719
PUT_OPTION(_jmxremote_autodiscovery);
720
PUT_OPTION(_jdp_port);
721
PUT_OPTION(_jdp_address);
722
PUT_OPTION(_jdp_source_addr);
723
PUT_OPTION(_jdp_ttl);
724
PUT_OPTION(_jdp_pause);
725
PUT_OPTION(_jdp_name);
726
727
#undef PUT_OPTION
728
729
Handle str = java_lang_String::create_from_str(options.as_string(), CHECK);
730
JavaCalls::call_static(&result, k, vmSymbols::startRemoteAgent_name(), vmSymbols::string_void_signature(), str, CHECK);
731
}
732
733
JMXStartLocalDCmd::JMXStartLocalDCmd(outputStream *output, bool heap_allocated) :
734
DCmd(output, heap_allocated) {
735
// do nothing
736
}
737
738
void JMXStartLocalDCmd::execute(DCmdSource source, TRAPS) {
739
ResourceMark rm(THREAD);
740
HandleMark hm(THREAD);
741
742
// Load and initialize the jdk.internal.agent.Agent class
743
// invoke startLocalManagementAgent(void) method to start
744
// the local management server
745
// throw java.lang.NoSuchMethodError if method doesn't exist
746
747
loadAgentModule(CHECK);
748
Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
749
Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
750
751
JavaValue result(T_VOID);
752
JavaCalls::call_static(&result, k, vmSymbols::startLocalAgent_name(), vmSymbols::void_method_signature(), CHECK);
753
}
754
755
void JMXStopRemoteDCmd::execute(DCmdSource source, TRAPS) {
756
ResourceMark rm(THREAD);
757
HandleMark hm(THREAD);
758
759
// Load and initialize the jdk.internal.agent.Agent class
760
// invoke stopRemoteManagementAgent method to stop the
761
// management server
762
// throw java.lang.NoSuchMethodError if method doesn't exist
763
764
loadAgentModule(CHECK);
765
Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
766
Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
767
768
JavaValue result(T_VOID);
769
JavaCalls::call_static(&result, k, vmSymbols::stopRemoteAgent_name(), vmSymbols::void_method_signature(), CHECK);
770
}
771
772
JMXStatusDCmd::JMXStatusDCmd(outputStream *output, bool heap_allocated) :
773
DCmd(output, heap_allocated) {
774
// do nothing
775
}
776
777
void JMXStatusDCmd::execute(DCmdSource source, TRAPS) {
778
ResourceMark rm(THREAD);
779
HandleMark hm(THREAD);
780
781
// Load and initialize the jdk.internal.agent.Agent class
782
// invoke getManagementAgentStatus() method to generate the status info
783
// throw java.lang.NoSuchMethodError if method doesn't exist
784
785
loadAgentModule(CHECK);
786
Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
787
Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_internal_agent_Agent(), loader, Handle(), true, CHECK);
788
789
JavaValue result(T_OBJECT);
790
JavaCalls::call_static(&result, k, vmSymbols::getAgentStatus_name(), vmSymbols::void_string_signature(), CHECK);
791
792
jvalue* jv = (jvalue*) result.get_value_addr();
793
oop str = cast_to_oop(jv->l);
794
if (str != NULL) {
795
char* out = java_lang_String::as_utf8_string(str);
796
if (out) {
797
output()->print_cr("%s", out);
798
return;
799
}
800
}
801
output()->print_cr("Error obtaining management agent status");
802
}
803
804
VMDynamicLibrariesDCmd::VMDynamicLibrariesDCmd(outputStream *output, bool heap_allocated) :
805
DCmd(output, heap_allocated) {
806
// do nothing
807
}
808
809
void VMDynamicLibrariesDCmd::execute(DCmdSource source, TRAPS) {
810
os::print_dll_info(output());
811
output()->cr();
812
}
813
814
void CompileQueueDCmd::execute(DCmdSource source, TRAPS) {
815
VM_PrintCompileQueue printCompileQueueOp(output());
816
VMThread::execute(&printCompileQueueOp);
817
}
818
819
void CodeListDCmd::execute(DCmdSource source, TRAPS) {
820
CodeCache::print_codelist(output());
821
}
822
823
void CodeCacheDCmd::execute(DCmdSource source, TRAPS) {
824
CodeCache::print_layout(output());
825
}
826
827
#ifdef LINUX
828
void PerfMapDCmd::execute(DCmdSource source, TRAPS) {
829
CodeCache::write_perf_map();
830
}
831
#endif // LINUX
832
833
//---< BEGIN >--- CodeHeap State Analytics.
834
CodeHeapAnalyticsDCmd::CodeHeapAnalyticsDCmd(outputStream* output, bool heap) :
835
DCmdWithParser(output, heap),
836
_function("function", "Function to be performed (aggregate, UsedSpace, FreeSpace, MethodCount, MethodSpace, MethodAge, MethodNames, discard", "STRING", false, "all"),
837
_granularity("granularity", "Detail level - smaller value -> more detail", "INT", false, "4096") {
838
_dcmdparser.add_dcmd_argument(&_function);
839
_dcmdparser.add_dcmd_argument(&_granularity);
840
}
841
842
void CodeHeapAnalyticsDCmd::execute(DCmdSource source, TRAPS) {
843
jlong granularity = _granularity.value();
844
if (granularity < 1) {
845
Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(),
846
"Invalid granularity value " JLONG_FORMAT ". Should be positive.\n", granularity);
847
return;
848
}
849
850
CompileBroker::print_heapinfo(output(), _function.value(), granularity);
851
}
852
//---< END >--- CodeHeap State Analytics.
853
854
EventLogDCmd::EventLogDCmd(outputStream* output, bool heap) :
855
DCmdWithParser(output, heap),
856
_log("log", "Name of log to be printed. If omitted, all logs are printed.", "STRING", false, NULL),
857
_max("max", "Maximum number of events to be printed (newest first). If omitted, all events are printed.", "STRING", false, NULL)
858
{
859
_dcmdparser.add_dcmd_option(&_log);
860
_dcmdparser.add_dcmd_option(&_max);
861
}
862
863
void EventLogDCmd::execute(DCmdSource source, TRAPS) {
864
const char* max_value = _max.value();
865
long max = -1;
866
if (max_value != NULL) {
867
char* endptr = NULL;
868
max = ::strtol(max_value, &endptr, 10);
869
if (max == 0 && max_value == endptr) {
870
output()->print_cr("Invalid max option: \"%s\".", max_value);
871
return;
872
}
873
}
874
const char* log_name = _log.value();
875
if (log_name != NULL) {
876
Events::print_one(output(), log_name, max);
877
} else {
878
Events::print_all(output(), max);
879
}
880
}
881
882
void CompilerDirectivesPrintDCmd::execute(DCmdSource source, TRAPS) {
883
DirectivesStack::print(output());
884
}
885
886
CompilerDirectivesAddDCmd::CompilerDirectivesAddDCmd(outputStream* output, bool heap) :
887
DCmdWithParser(output, heap),
888
_filename("filename","Name of the directives file", "STRING",true) {
889
_dcmdparser.add_dcmd_argument(&_filename);
890
}
891
892
void CompilerDirectivesAddDCmd::execute(DCmdSource source, TRAPS) {
893
DirectivesParser::parse_from_file(_filename.value(), output());
894
}
895
896
void CompilerDirectivesRemoveDCmd::execute(DCmdSource source, TRAPS) {
897
DirectivesStack::pop(1);
898
}
899
900
void CompilerDirectivesClearDCmd::execute(DCmdSource source, TRAPS) {
901
DirectivesStack::clear();
902
}
903
#if INCLUDE_SERVICES
904
ClassHierarchyDCmd::ClassHierarchyDCmd(outputStream* output, bool heap) :
905
DCmdWithParser(output, heap),
906
_print_interfaces("-i", "Inherited interfaces should be printed.", "BOOLEAN", false, "false"),
907
_print_subclasses("-s", "If a classname is specified, print its subclasses. "
908
"Otherwise only its superclasses are printed.", "BOOLEAN", false, "false"),
909
_classname("classname", "Name of class whose hierarchy should be printed. "
910
"If not specified, all class hierarchies are printed.",
911
"STRING", false) {
912
_dcmdparser.add_dcmd_option(&_print_interfaces);
913
_dcmdparser.add_dcmd_option(&_print_subclasses);
914
_dcmdparser.add_dcmd_argument(&_classname);
915
}
916
917
void ClassHierarchyDCmd::execute(DCmdSource source, TRAPS) {
918
VM_PrintClassHierarchy printClassHierarchyOp(output(), _print_interfaces.value(),
919
_print_subclasses.value(), _classname.value());
920
VMThread::execute(&printClassHierarchyOp);
921
}
922
#endif
923
924
class VM_DumpTouchedMethods : public VM_Operation {
925
private:
926
outputStream* _out;
927
public:
928
VM_DumpTouchedMethods(outputStream* out) {
929
_out = out;
930
}
931
932
virtual VMOp_Type type() const { return VMOp_DumpTouchedMethods; }
933
934
virtual void doit() {
935
Method::print_touched_methods(_out);
936
}
937
};
938
939
void TouchedMethodsDCmd::execute(DCmdSource source, TRAPS) {
940
if (!LogTouchedMethods) {
941
output()->print_cr("VM.print_touched_methods command requires -XX:+LogTouchedMethods");
942
return;
943
}
944
VM_DumpTouchedMethods dumper(output());
945
VMThread::execute(&dumper);
946
}
947
948
#if INCLUDE_CDS
949
DumpSharedArchiveDCmd::DumpSharedArchiveDCmd(outputStream* output, bool heap) :
950
DCmdWithParser(output, heap),
951
_suboption("subcmd", "static_dump | dynamic_dump", "STRING", true),
952
_filename("filename", "Name of shared archive to be dumped", "STRING", false)
953
{
954
_dcmdparser.add_dcmd_argument(&_suboption);
955
_dcmdparser.add_dcmd_argument(&_filename);
956
}
957
958
void DumpSharedArchiveDCmd::execute(DCmdSource source, TRAPS) {
959
jboolean is_static;
960
const char* scmd = _suboption.value();
961
const char* file = _filename.value();
962
963
if (strcmp(scmd, "static_dump") == 0) {
964
is_static = JNI_TRUE;
965
output()->print_cr("Static dump:");
966
} else if (strcmp(scmd, "dynamic_dump") == 0) {
967
is_static = JNI_FALSE;
968
output()->print_cr("Dynamic dump:");
969
if (!UseSharedSpaces) {
970
output()->print_cr("Dynamic dump is unsupported when base CDS archive is not loaded");
971
return;
972
}
973
if (!RecordDynamicDumpInfo) {
974
output()->print_cr("Dump dynamic should run with -XX:+RecordDynamicDumpInfo");
975
return;
976
}
977
} else {
978
output()->print_cr("Invalid command for VM.cds, valid input is static_dump or dynamic_dump");
979
return;
980
}
981
982
// call CDS.dumpSharedArchive
983
Handle fileh;
984
if (file != NULL) {
985
fileh = java_lang_String::create_from_str(_filename.value(), CHECK);
986
}
987
Symbol* cds_name = vmSymbols::jdk_internal_misc_CDS();
988
Klass* cds_klass = SystemDictionary::resolve_or_fail(cds_name, true /*throw error*/, CHECK);
989
JavaValue result(T_VOID);
990
JavaCallArguments args;
991
args.push_int(is_static);
992
args.push_oop(fileh);
993
JavaCalls::call_static(&result,
994
cds_klass,
995
vmSymbols::dumpSharedArchive(),
996
vmSymbols::dumpSharedArchive_signature(),
997
&args, CHECK);
998
}
999
#endif // INCLUDE_CDS
1000
1001
#if INCLUDE_JVMTI
1002
extern "C" typedef char const* (JNICALL *debugInit_startDebuggingViaCommandPtr)(JNIEnv* env, jthread thread, char const** transport_name,
1003
char const** address, jboolean* first_start);
1004
static debugInit_startDebuggingViaCommandPtr dvc_start_ptr = NULL;
1005
1006
void DebugOnCmdStartDCmd::execute(DCmdSource source, TRAPS) {
1007
char const* transport = NULL;
1008
char const* addr = NULL;
1009
jboolean is_first_start = JNI_FALSE;
1010
JavaThread* thread = THREAD;
1011
jthread jt = JNIHandles::make_local(thread->threadObj());
1012
ThreadToNativeFromVM ttn(thread);
1013
const char *error = "Could not find jdwp agent.";
1014
1015
if (!dvc_start_ptr) {
1016
for (AgentLibrary* agent = Arguments::agents(); agent != NULL; agent = agent->next()) {
1017
if ((strcmp("jdwp", agent->name()) == 0) && (dvc_start_ptr == NULL)) {
1018
char const* func = "debugInit_startDebuggingViaCommand";
1019
dvc_start_ptr = (debugInit_startDebuggingViaCommandPtr) os::find_agent_function(agent, false, &func, 1);
1020
}
1021
}
1022
}
1023
1024
if (dvc_start_ptr) {
1025
error = dvc_start_ptr(thread->jni_environment(), jt, &transport, &addr, &is_first_start);
1026
}
1027
1028
if (error != NULL) {
1029
output()->print_cr("Debugging has not been started: %s", error);
1030
} else {
1031
output()->print_cr(is_first_start ? "Debugging has been started." : "Debugging is already active.");
1032
output()->print_cr("Transport : %s", transport ? transport : "#unknown");
1033
output()->print_cr("Address : %s", addr ? addr : "#unknown");
1034
}
1035
}
1036
#endif // INCLUDE_JVMTI
1037
1038