Skip to content

8360515: PROPERFMTARGS should always use size_t template specialization for unit #25975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/hotspot/os/bsd/memMapPrinter_macosx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ class ProcSmapsSummary {
mach_msg_type_number_t num_out = TASK_VM_INFO_COUNT;
kern_return_t err = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t)(&vm_info), &num_out);
if (err == KERN_SUCCESS) {
st->print_cr(" vsize: %llu (%llu%s)", vm_info.virtual_size, PROPERFMTARGS(vm_info.virtual_size));
st->print_cr(" rss: %llu (%llu%s)", vm_info.resident_size, PROPERFMTARGS(vm_info.resident_size));
st->print_cr(" peak rss: %llu (%llu%s)", vm_info.resident_size_peak, PROPERFMTARGS(vm_info.resident_size_peak));
st->print_cr(" page size: %d (%ld%s)", vm_info.page_size, PROPERFMTARGS((size_t)vm_info.page_size));
st->print_cr(" vsize: %llu (%llu%s)", vm_info.virtual_size, byte_size_in_proper_unit(vm_info.virtual_size), proper_unit_for_byte_size(vm_info.virtual_size));
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));
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));
st->print_cr(" page size: %d (" PROPERFMT ")", vm_info.page_size, PROPERFMTARGS((size_t)vm_info.page_size));
Comment on lines +236 to +239
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally wanted this patch to be minimally invasive and just fix the mismatch between PROPERFMT and PROPERFMTARGS. The cast to size_t wasn't added by me, I just changed the format specifier to match the type in PROPERFMTARGS. I agree that it looks a bit weird to have both the expanded macro and PROPERFMTARGS next to each other, and I'm not 100% sure why vm_info.page_size is casted to size_t.

I'm fine with making the usage consistent in this patch, making all the prints use PROPERFMT+PROPERFMTARGS with casts to size_t, or the other way around using the expanded macro.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for mis-attributing the cast to your change. This could go either way with no way clearly better than the other. Lets see if another reviewer has a strong opinion.

} else {
st->print_cr("error getting vm_info %d", err);
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/utilities/globalDefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ inline T byte_size_in_proper_unit(T s) {
}

#define PROPERFMT "%zu%s"
#define PROPERFMTARGS(s) byte_size_in_proper_unit(s), proper_unit_for_byte_size(s)
#define PROPERFMTARGS(s) byte_size_in_proper_unit<size_t>(s), proper_unit_for_byte_size(s)

// Printing a range, with start and bytes given
#define RANGEFMT "[" PTR_FORMAT " - " PTR_FORMAT "), (%zu bytes)"
Expand Down