Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/hotspot/share/runtime/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,13 +1344,11 @@ class PrintOnClosure : public ThreadClosure {
void Threads::print_on(outputStream* st, bool print_stacks,
bool internal_format, bool print_concurrent_locks,
bool print_extended_info) {
char buf[32];
st->print_raw_cr(os::local_time_string(buf, sizeof(buf)));

st->print_cr("Full thread dump %s (%s %s)",
VM_Version::vm_name(),
VM_Version::vm_release(),
VM_Version::vm_info_string());
char buf[32];
JDK_Version::current().to_string(buf, sizeof(buf));
const char* runtime_name = JDK_Version::runtime_name() != nullptr ?
JDK_Version::runtime_name() : "";
Expand Down
30 changes: 30 additions & 0 deletions src/hotspot/share/services/diagnosticCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ static int compare_strings(const char** s1, const char** s2) {
return ::strcmp(*s1, *s2);
}

static void print_local_time(outputStream* output) {
char buf[32];
output->print_cr("%s", os::local_time_string(buf, sizeof(buf)));
}


void HelpDCmd::execute(DCmdSource source, TRAPS) {
if (_all.value()) {
GrowableArray<const char*>* cmd_list = DCmdFactory::DCmd_list(source);
Expand Down Expand Up @@ -250,6 +256,7 @@ PrintVMFlagsDCmd::PrintVMFlagsDCmd(outputStream* output, bool heap) :
}

void PrintVMFlagsDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
if (_all.value()) {
JVMFlag::printFlags(output(), true);
} else {
Expand Down Expand Up @@ -398,6 +405,7 @@ void VMUptimeDCmd::execute(DCmdSource source, TRAPS) {
}

void VMInfoDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
VMError::print_vm_info(_output);
}

Expand All @@ -414,11 +422,13 @@ void RunFinalizationDCmd::execute(DCmdSource source, TRAPS) {
}

void HeapInfoDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
MutexLocker hl(THREAD, Heap_lock);
Universe::heap()->print_heap_on(output());
}

void FinalizerInfoDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
ResourceMark rm(THREAD);

if (!InstanceKlass::is_finalization_enabled()) {
Expand Down Expand Up @@ -492,6 +502,7 @@ HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) :
}

void HeapDumpDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
jlong level = -1; // -1 means no compression.
jlong parallel = HeapDumper::default_num_of_dump_threads();

Expand Down Expand Up @@ -539,6 +550,7 @@ ClassHistogramDCmd::ClassHistogramDCmd(outputStream* output, bool heap) :
}

void ClassHistogramDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
jlong num = _parallel_thread_num.value();
if (num < 0) {
output()->print_cr("Parallel thread number out of range (>=0): " JLONG_FORMAT, num);
Expand All @@ -564,6 +576,7 @@ ThreadDumpDCmd::ThreadDumpDCmd(outputStream* output, bool heap) :
}

void ThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
// thread stacks and JNI global handles
VM_PrintThreads op1(output(), _locks.value(), _extended.value(), true /* print JNI handle info */);
VMThread::execute(&op1);
Expand Down Expand Up @@ -801,6 +814,7 @@ JMXStatusDCmd::JMXStatusDCmd(outputStream *output, bool heap_allocated) :
}

void JMXStatusDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
ResourceMark rm(THREAD);
HandleMark hm(THREAD);

Expand Down Expand Up @@ -834,20 +848,24 @@ VMDynamicLibrariesDCmd::VMDynamicLibrariesDCmd(outputStream *output, bool heap_a
}

void VMDynamicLibrariesDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
os::print_dll_info(output());
output()->cr();
}

void CompileQueueDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
VM_PrintCompileQueue printCompileQueueOp(output());
VMThread::execute(&printCompileQueueOp);
}

void CodeListDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
CodeCache::print_codelist(output());
}

void CodeCacheDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
CodeCache::print_layout(output());
}

Expand All @@ -874,6 +892,7 @@ CodeHeapAnalyticsDCmd::CodeHeapAnalyticsDCmd(outputStream* output, bool heap) :
}

void CodeHeapAnalyticsDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
jlong granularity = _granularity.value();
if (granularity < 1) {
Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(),
Expand All @@ -895,6 +914,7 @@ EventLogDCmd::EventLogDCmd(outputStream* output, bool heap) :
}

void EventLogDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
int max = (int)_max.value();
if (max < 0) {
output()->print_cr("Invalid max option: \"%d\".", max);
Expand All @@ -909,6 +929,7 @@ void EventLogDCmd::execute(DCmdSource source, TRAPS) {
}

void CompilerDirectivesPrintDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
DirectivesStack::print(output());
}

Expand All @@ -929,6 +950,7 @@ void CompilerDirectivesRemoveDCmd::execute(DCmdSource source, TRAPS) {
void CompilerDirectivesClearDCmd::execute(DCmdSource source, TRAPS) {
DirectivesStack::clear();
}

#if INCLUDE_SERVICES
ClassHierarchyDCmd::ClassHierarchyDCmd(outputStream* output, bool heap) :
DCmdWithParser(output, heap),
Expand All @@ -945,6 +967,7 @@ ClassHierarchyDCmd::ClassHierarchyDCmd(outputStream* output, bool heap) :
}

void ClassHierarchyDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
VM_PrintClassHierarchy printClassHierarchyOp(output(), _print_interfaces.value(),
_print_subclasses.value(), _classname.value());
VMThread::execute(&printClassHierarchyOp);
Expand Down Expand Up @@ -982,6 +1005,7 @@ class VM_PrintClasses : public VM_Operation {
};

void ClassesDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
VM_PrintClasses vmop(output(), _verbose.value());
VMThread::execute(&vmop);
}
Expand All @@ -1000,6 +1024,7 @@ DumpSharedArchiveDCmd::DumpSharedArchiveDCmd(outputStream* output, bool heap) :
}

void DumpSharedArchiveDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
jboolean is_static;
const char* scmd = _suboption.value();

Expand Down Expand Up @@ -1140,10 +1165,12 @@ static void execute_vthread_command(Symbol* method_name, outputStream* output, T
}

void VThreadSchedulerDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
execute_vthread_command(vmSymbols::printScheduler_name(), output(), CHECK);
}

void VThreadPollersDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
execute_vthread_command(vmSymbols::printPollers_name(), output(), CHECK);
}

Expand All @@ -1158,6 +1185,7 @@ CompilationMemoryStatisticDCmd::CompilationMemoryStatisticDCmd(outputStream* out
}

void CompilationMemoryStatisticDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
const size_t minsize = _minsize.has_value() ? _minsize.value()._size : 0;
CompilationMemoryStatistic::print_jcmd_report(output(), _verbose.value(), _legend.value(), minsize);
}
Expand All @@ -1167,6 +1195,7 @@ void CompilationMemoryStatisticDCmd::execute(DCmdSource source, TRAPS) {
SystemMapDCmd::SystemMapDCmd(outputStream* output, bool heap) : DCmd(output, heap) {}

void SystemMapDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
MemMapPrinter::print_all_mappings(output());
}

Expand All @@ -1179,6 +1208,7 @@ SystemDumpMapDCmd::SystemDumpMapDCmd(outputStream* output, bool heap) :
}

void SystemDumpMapDCmd::execute(DCmdSource source, TRAPS) {
print_local_time(output());
const char* name = _filename.value();
if (name == nullptr || name[0] == 0) {
output()->print_cr("filename is empty or not specified. No file written");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -113,6 +113,7 @@ public void run(CommandExecutor executor) {
// Get output from dcmd (diagnostic command)
OutputAnalyzer output = executor.execute("Compiler.codecache");
Iterator<String> lines = output.asLines().iterator();
lines.next(); // skip timestamp

// Validate code cache segments
String line;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -54,15 +54,18 @@ public class ClassHierarchyTest {
// |--DcmdTestClass$$Lambda/4081552/0xa529fbb0

// > VM.class_hierarchy DcmdBaseClass
// 2025-01-01 10:59:59
// java.lang.Object/null
// |--DcmdBaseClass/0xa4abcd48

// > VM.class_hierarchy DcmdBaseClass -s
// 2025-01-01 10:59:59
// java.lang.Object/null
// |--DcmdBaseClass/0xa4abcd48
// | |--DcmdTestClass/0xa4abcd48

// > VM.class_hierarchy DcmdBaseClass -i -s
// 2025-01-01 10:59:59
// java.lang.Object/null
// |--DcmdBaseClass/0xa4abcd48
// | implements Intf2/0xa4abcd48 (declared intf)
Expand Down Expand Up @@ -111,13 +114,14 @@ public void run(CommandExecutor executor) throws ClassNotFoundException {
// Verify the output for the simple hierachry of just DcmdBaseClass.
output = executor.execute("VM.class_hierarchy DcmdBaseClass");
lines = output.asLines().iterator();
lines.next(); // skip timestamp
i = 0;
while (lines.hasNext()) {
String line = lines.next();
Matcher m = expected_lines[i].matcher(line);
i++;
if (!m.matches()) {
Assert.fail("Failed to match line #" + i + ": " + line);
Assert.fail("Failed. Expected line #%d \"%s\" to match \"%s\"".formatted(i, line, expected_lines[i].pattern()));
}
// Should only be two lines of output in this form.
if (i == 2) break;
Expand All @@ -130,13 +134,14 @@ public void run(CommandExecutor executor) throws ClassNotFoundException {
// Verify the output for the full hierarchy of DcmdBaseClass, but without interfaces.
output = executor.execute("VM.class_hierarchy DcmdBaseClass -s");
lines = output.asLines().iterator();
lines.next(); // skip timestamp
i = 0;
while (lines.hasNext()) {
String line = lines.next();
Matcher m = expected_lines[i].matcher(line);
i++;
if (!m.matches()) {
Assert.fail("Failed to match line #" + i + ": " + line);
Assert.fail("Failed. Expected line #%d \"%s\" to match \"%s\"".formatted(i, line, expected_lines[i].pattern()));
}
// "implements" lines should not be in this output.
if (i == 2 || i == 4) i += 2;
Expand All @@ -149,6 +154,7 @@ public void run(CommandExecutor executor) throws ClassNotFoundException {
// Verify the output for the full hierarchy of DcmdBaseClass, including interfaces.
output = executor.execute("VM.class_hierarchy DcmdBaseClass -i -s");
lines = output.asLines().iterator();
lines.next(); // skip timestamp
i = 0;
String classLoaderAddr = null;
while (lines.hasNext()) {
Expand Down