RFR: 8360515: PROPERFMTARGS should always use size_t template specialization for unit [v2]

David Holmes dholmes at openjdk.org
Thu Jun 26 02:38:29 UTC 2025


On Wed, 25 Jun 2025 11:19:47 GMT, Joel Sikström <jsikstro at openjdk.org> wrote:

>> Hello,
>> 
>> PROPERFMT is defined as the format string "%zu%s", which expects a size_t as input argument. When used in combination with PROPERFMTARGS, which uses the templated byte_size_in_proper_units, the byte size may not be size_t if the input is some other type.
>> 
>> To minimize confusion, PROPERFMTARGS should always use the size_t template specilization of byte_size_in_proper_units, to match PROPERFMT. Places that use byte_size_in_proper_units with other types can still use it, but should use their own format strings instead of PROPERFMT.
>> 
>> ProcSmapsSummary::print_on in memMapPrinter_macosx is the only place that uses PROPERFMTARGS with a type that is not size_t. I have changed those places to use the expanded version of the macro, which uses the templated version of byte_size_in_proper_unit instead.
>> 
>> Testing:
>> * Currently running Oracle's tier1-2
>
> Joel Sikström has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
> 
>  - Merge branch 'master' into JDK-8360515_properfmtargs
>  - 8360515: PROPERFMTARGS should always use size_t template specialization for unit

src/hotspot/os/bsd/memMapPrinter_macosx.cpp line 239:

> 237:       st->print_cr("               rss: %llu (%llu%s)", vm_info.resident_size, byte_size_in_proper_unit(vm_info.resident_size), proper_unit_for_byte_size(vm_info.resident_size));
> 238:       st->print_cr("          peak rss: %llu (%llu%s)", vm_info.resident_size_peak, byte_size_in_proper_unit(vm_info.resident_size_peak), proper_unit_for_byte_size(vm_info.resident_size_peak));
> 239:       st->print_cr("         page size: %d (" PROPERFMT ")", vm_info.page_size, PROPERFMTARGS((size_t)vm_info.page_size));

Just to clarify something for the reader here, as it tripped me up, the `vm_info` fields are declared as `mach_vm_size_t`, which one might expect is some kind of `size_t` but alas no [1]:

typedef uint64_t mach_vm_size_t;

But given you cast `page_size` to size_t (it is `int32_t`) why not cast the others too and use `PROPERFMT`?

[1] https://developer.apple.com/documentation/kernel/mach_vm_size_t

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25975#discussion_r2167979715


More information about the hotspot-dev mailing list