Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
19 changes: 12 additions & 7 deletions src/hotspot/share/memory/heapInspection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2026, 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 @@ -600,12 +600,17 @@ void PrintClassLayout::print_class_layout(outputStream* st, char* class_name) {
return;
}

Thread* THREAD = Thread::current();

Symbol* classname = SymbolTable::probe(class_name, (int)strlen(class_name));
ResourceMark rm;
char* normalized_name = NEW_RESOURCE_ARRAY(char, strlen(class_name) + 1);
strcpy(normalized_name, class_name);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to make a copy here rather than modifying in place? The user-supplied string is already in a mutable C-heap allocated buffer, as processed by the DCmd framework. If we think it inappropriate to modify at this level perhaps we can push the conversion up into the DCmd framework itself?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a Symbol::as_klass_external_name(char* buf, int size) method to do the '/'s into '.'s conversion. Should this code be moved to a new Symbol::as_klass_internal_name(char* buf, int size) method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept it in the same location as of now, but removed the extra allocation. I don't think putting it in Symbol is the right place, because here we are just modifying a mutable char*. So the operation is not really on a symbol. But it could perhaps be moved to where we parse the DCmd instead, if you feel like it doesn't belong here.

for (char* p = normalized_name; *p != '\0'; p++) {
if (*p == '.') {
*p = '/';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use JVM_SIGNATURE_DOT and JVM_SIGNATURE_SLASH - though it makes me cringe that we have to do this ad-hoc conversion.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know these existed, but I swapped to use these now.

}
}
Symbol* classname = SymbolTable::probe(normalized_name, (int)strlen(normalized_name));

GrowableArray<Klass*>* klasses = new (mtServiceability) GrowableArray<Klass*>(100, mtServiceability);

FindClassByNameClosure fbnc(klasses, classname);
cit.iterate(&fbnc);

Expand All @@ -614,9 +619,9 @@ void PrintClassLayout::print_class_layout(outputStream* st, char* class_name) {
if (!klass->is_instance_klass()) continue; // Skip
InstanceKlass* ik = InstanceKlass::cast(klass);
int tab = 1;
st->print_cr("Class %s [@%s]:", klass->name()->as_C_string(),
klass->class_loader_data()->loader_name());
ResourceMark rm;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may still need this to limit the ResourceArea usage, otherwise you will be keeping all allocations from the complete loop alive.

st->print_cr("Class %s [@%s]:", klass->external_name(),
klass->class_loader_data()->loader_name());
Comment thread
caspernorrbin marked this conversation as resolved.
Outdated
GrowableArray<FieldDesc>* fields = new (mtServiceability) GrowableArray<FieldDesc>(100, mtServiceability);
for (AllFieldStream fd(ik); !fd.done(); fd.next()) {
if (!fd.access_flags().is_static()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ static void testCmd(String arg, int expectExitCode, String... expectStrings) thr
}

public static void main(String args[]) throws Exception {
testCmd("foo/bar", 0, "");
testCmd("foo.bar", 0, "");
testCmd("", 1, "IllegalArgumentException", "mandatory");
testCmd("java/lang/Object", 0, "java/lang/Object", "@bootstrap");
testCmd("java/lang/Class", 0, "java/lang/Class", "@bootstrap");
testCmd("runtime/valhalla/inlinetypes/ClassPrintLayoutDcmd$Line", 0, "@app", "p1", "p2");
testCmd("java.lang.Object", 0, "java.lang.Object", "@bootstrap");
testCmd("java.lang.Class", 0, "java.lang.Class", "@bootstrap");
testCmd("runtime.valhalla.inlinetypes.ClassPrintLayoutDcmd$Line", 0, "@app", "p1", "p2");
}
}