On Wed, 29 Apr 2026 12:25:34 GMT, Casper Norrbin <[email protected]> wrote:

> Hi everyone, `PrintClassLayout::print_class_layout` expects internal class 
> names as its argument, but is called externally by users through `jcmd`. This 
> leads to inconsistencies with other functions. For example:
> 
> jcmd <pid> VM.class_hierarchy java.lang.String
> jcmd <pid> VM.class_print_layout java/lang/String
> 
> 
> In addition, its output is also in the internal format. This should be 
> changed to also use the external dotted class name instead. For this fix I 
> changed the `Closure` used for finding classes to instead use external names, 
> and also swapped the output print to use the external name.
> 
> Testing:
> - Tier 1
> - Manual inspection with `jcmd` 
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

src/hotspot/share/memory/heapInspection.cpp line 614:

> 612:     InstanceKlass* ik = InstanceKlass::cast(klass);
> 613:     int tab = 1;
> 614:     st->print_cr("Class %s [@%s]:", klass->external_name(),

Doesn't it suffice to just make this change? If we convert to Symbol it seems 
more efficient than using `strcmp` (though I confess I'm not clear what this 
closure is actually doing and what set of classes it potentially generates).

src/hotspot/share/memory/heapInspection.cpp line 619:

> 617:     st->print_cr("Class %s [@%s]:", klass->name()->as_C_string(),
> 618:         klass->class_loader_data()->loader_name());
> 619:     ResourceMark rm;

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

-------------

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2375#discussion_r3165166967
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2375#discussion_r3165149735

Reply via email to