Skip to content
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

8347566: Replace SSIZE_FORMAT with 'z' length modifier #23084

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 13 additions & 13 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -2312,14 +2312,14 @@ bool os::Linux::query_process_memory_info(os::Linux::meminfo_t* info) {
info->rssanon = info->rssfile = info->rssshmem = -1;
if (f != nullptr) {
while (::fgets(buf, sizeof(buf), f) != nullptr && num_found < num_values) {
if ( (info->vmsize == -1 && sscanf(buf, "VmSize: " SSIZE_FORMAT " kB", &info->vmsize) == 1) ||
(info->vmpeak == -1 && sscanf(buf, "VmPeak: " SSIZE_FORMAT " kB", &info->vmpeak) == 1) ||
(info->vmswap == -1 && sscanf(buf, "VmSwap: " SSIZE_FORMAT " kB", &info->vmswap) == 1) ||
(info->vmhwm == -1 && sscanf(buf, "VmHWM: " SSIZE_FORMAT " kB", &info->vmhwm) == 1) ||
(info->vmrss == -1 && sscanf(buf, "VmRSS: " SSIZE_FORMAT " kB", &info->vmrss) == 1) ||
(info->rssanon == -1 && sscanf(buf, "RssAnon: " SSIZE_FORMAT " kB", &info->rssanon) == 1) || // Needs Linux 4.5
(info->rssfile == -1 && sscanf(buf, "RssFile: " SSIZE_FORMAT " kB", &info->rssfile) == 1) || // Needs Linux 4.5
(info->rssshmem == -1 && sscanf(buf, "RssShmem: " SSIZE_FORMAT " kB", &info->rssshmem) == 1) // Needs Linux 4.5
if ( (info->vmsize == -1 && sscanf(buf, "VmSize: %zd kB", &info->vmsize) == 1) ||
(info->vmpeak == -1 && sscanf(buf, "VmPeak: %zd kB", &info->vmpeak) == 1) ||
(info->vmswap == -1 && sscanf(buf, "VmSwap: %zd kB", &info->vmswap) == 1) ||
(info->vmhwm == -1 && sscanf(buf, "VmHWM: %zd kB", &info->vmhwm) == 1) ||
(info->vmrss == -1 && sscanf(buf, "VmRSS: %zd kB", &info->vmrss) == 1) ||
(info->rssanon == -1 && sscanf(buf, "RssAnon: %zd kB", &info->rssanon) == 1) || // Needs Linux 4.5
(info->rssfile == -1 && sscanf(buf, "RssFile: %zd kB", &info->rssfile) == 1) || // Needs Linux 4.5
(info->rssshmem == -1 && sscanf(buf, "RssShmem: %zd kB", &info->rssshmem) == 1) // Needs Linux 4.5
)
{
num_found ++;
@@ -2367,15 +2367,15 @@ void os::Linux::print_process_memory_info(outputStream* st) {
// rss its components if the kernel is recent enough.
meminfo_t info;
if (query_process_memory_info(&info)) {
st->print_cr("Virtual Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", info.vmsize, info.vmpeak);
st->print("Resident Set Size: " SSIZE_FORMAT "K (peak: " SSIZE_FORMAT "K)", info.vmrss, info.vmhwm);
st->print_cr("Virtual Size: %zdK (peak: %zdK)", info.vmsize, info.vmpeak);
st->print("Resident Set Size: %zdK (peak: %zdK)", info.vmrss, info.vmhwm);
if (info.rssanon != -1) { // requires kernel >= 4.5
st->print(" (anon: " SSIZE_FORMAT "K, file: " SSIZE_FORMAT "K, shmem: " SSIZE_FORMAT "K)",
st->print(" (anon: %zdK, file: %zdK, shmem: %zdK)",
info.rssanon, info.rssfile, info.rssshmem);
}
st->cr();
if (info.vmswap != -1) { // requires kernel >= 2.6.34
st->print_cr("Swapped out: " SSIZE_FORMAT "K", info.vmswap);
st->print_cr("Swapped out: %zdK", info.vmswap);
}
} else {
st->print_cr("Could not open /proc/self/status to get process memory related information");
10 changes: 5 additions & 5 deletions src/hotspot/share/code/codeCache.cpp
Original file line number Diff line number Diff line change
@@ -565,7 +565,7 @@ CodeBlob* CodeCache::allocate(uint size, CodeBlobType code_blob_type, bool handl
} else {
tty->print("CodeCache");
}
tty->print_cr(" extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (" SSIZE_FORMAT " bytes)",
tty->print_cr(" extended to [" INTPTR_FORMAT ", " INTPTR_FORMAT "] (%zd bytes)",
(intptr_t)heap->low_boundary(), (intptr_t)heap->high(),
(address)heap->high() - (address)heap->low_boundary());
}
@@ -1491,10 +1491,10 @@ void CodeCache::print_memory_overhead() {
}
// Print bytes that are allocated in the freelist
ttyLocker ttl;
tty->print_cr("Number of elements in freelist: " SSIZE_FORMAT, freelists_length());
tty->print_cr("Allocated in freelist: " SSIZE_FORMAT "kB", bytes_allocated_in_freelists()/K);
tty->print_cr("Unused bytes in CodeBlobs: " SSIZE_FORMAT "kB", (wasted_bytes/K));
tty->print_cr("Segment map size: " SSIZE_FORMAT "kB", allocated_segments()/K); // 1 byte per segment
tty->print_cr("Number of elements in freelist: %zd", freelists_length());
tty->print_cr("Allocated in freelist: %zdkB", bytes_allocated_in_freelists()/K);
tty->print_cr("Unused bytes in CodeBlobs: %zdkB", (wasted_bytes/K));
tty->print_cr("Segment map size: %zdkB", allocated_segments()/K); // 1 byte per segment
}

//------------------------------------------------------------------------------------------------
83 changes: 42 additions & 41 deletions src/hotspot/share/gc/shenandoah/shenandoahFreeSet.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 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
@@ -95,7 +96,7 @@ size_t ShenandoahSimpleBitMap::count_trailing_ones(idx_t last_idx) const {

bool ShenandoahSimpleBitMap::is_forward_consecutive_ones(idx_t start_idx, idx_t count) const {
while (count > 0) {
assert((start_idx >= 0) && (start_idx < _num_bits), "precondition: start_idx: " SSIZE_FORMAT ", count: " SSIZE_FORMAT,
assert((start_idx >= 0) && (start_idx < _num_bits), "precondition: start_idx: %zd, count: %zd",
start_idx, count);
assert(start_idx + count <= (idx_t) _num_bits, "precondition");
size_t array_idx = start_idx >> LogBitsPerWord;
14 changes: 7 additions & 7 deletions src/hotspot/share/nmt/memReporter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@@ -554,7 +554,7 @@ void MemSummaryDiffReporter::print_malloc_diff(size_t current_amount, size_t cur
out->print(" #" SIZE_FORMAT "", current_count);
const ssize_t delta_count = counter_diff(current_count, early_count);
if (delta_count != 0) {
out->print(" " SSIZE_PLUS_FORMAT, delta_count);
out->print(" %+zd", delta_count);
}
}
}
@@ -572,7 +572,7 @@ void MemSummaryDiffReporter::print_arena_diff(size_t current_amount, size_t curr
out->print(" #" SIZE_FORMAT "", current_count);
const ssize_t delta_count = counter_diff(current_count, early_count);
if (delta_count != 0) {
out->print(" " SSIZE_PLUS_FORMAT, delta_count);
out->print(" %+zd", delta_count);
}
}

@@ -650,21 +650,21 @@ void MemSummaryDiffReporter::diff_summary_of_type(MemTag mem_tag,
const ssize_t class_count_diff =
counter_diff(_current_baseline.class_count(), _early_baseline.class_count());
if (class_count_diff != 0) {
out->print(" " SSIZE_PLUS_FORMAT, class_count_diff);
out->print(" %+zd", class_count_diff);
}
out->print_cr(")");

out->print("( instance classes #" SIZE_FORMAT, _current_baseline.instance_class_count());
const ssize_t instance_class_count_diff =
counter_diff(_current_baseline.instance_class_count(), _early_baseline.instance_class_count());
if (instance_class_count_diff != 0) {
out->print(" " SSIZE_PLUS_FORMAT, instance_class_count_diff);
out->print(" %+zd", instance_class_count_diff);
}
out->print(", array classes #" SIZE_FORMAT, _current_baseline.array_class_count());
const ssize_t array_class_count_diff =
counter_diff(_current_baseline.array_class_count(), _early_baseline.array_class_count());
if (array_class_count_diff != 0) {
out->print(" " SSIZE_PLUS_FORMAT, array_class_count_diff);
out->print(" %+zd", array_class_count_diff);
}
out->print_cr(")");

@@ -673,7 +673,7 @@ void MemSummaryDiffReporter::diff_summary_of_type(MemTag mem_tag,
out->print("(threads #" SIZE_FORMAT, _current_baseline.thread_count());
const ssize_t thread_count_diff = counter_diff(_current_baseline.thread_count(), _early_baseline.thread_count());
if (thread_count_diff != 0) {
out->print(" " SSIZE_PLUS_FORMAT, thread_count_diff);
out->print(" %+zd", thread_count_diff);
}
out->print_cr(")");

3 changes: 0 additions & 3 deletions src/hotspot/share/utilities/globalDefinitions.hpp
Original file line number Diff line number Diff line change
@@ -135,9 +135,6 @@ class oopDesc;
#define UINT64_FORMAT_0 "%016" PRIx64

// Format integers which change size between 32- and 64-bit.
#define SSIZE_FORMAT "%" PRIdPTR
#define SSIZE_PLUS_FORMAT "%+" PRIdPTR
#define SSIZE_FORMAT_W(width) "%" #width PRIdPTR
#define SIZE_FORMAT "%" PRIuPTR
#define SIZE_FORMAT_X "0x%" PRIxPTR
#ifdef _LP64
20 changes: 10 additions & 10 deletions test/hotspot/gtest/utilities/test_globalDefinitions.cpp
Original file line number Diff line number Diff line change
@@ -261,16 +261,16 @@ TEST(globalDefinitions, format_specifiers) {
check_format(UINT64_FORMAT_W(5), (uint64_t)123, " 123");
check_format(UINT64_FORMAT_W(-5), (uint64_t)123, "123 ");

check_format(SSIZE_FORMAT, (ssize_t)123, "123");
check_format(SSIZE_FORMAT, (ssize_t)-123, "-123");
check_format(SSIZE_FORMAT, (ssize_t)2147483647, "2147483647");
check_format(SSIZE_FORMAT, (ssize_t)-2147483647, "-2147483647");
check_format(SSIZE_PLUS_FORMAT, (ssize_t)123, "+123");
check_format(SSIZE_PLUS_FORMAT, (ssize_t)-123, "-123");
check_format(SSIZE_PLUS_FORMAT, (ssize_t)2147483647, "+2147483647");
check_format(SSIZE_PLUS_FORMAT, (ssize_t)-2147483647, "-2147483647");
check_format(SSIZE_FORMAT_W(5), (ssize_t)123, " 123");
check_format(SSIZE_FORMAT_W(-5), (ssize_t)123, "123 ");
check_format("%zd", (ssize_t)123, "123");
check_format("%zd", (ssize_t)-123, "-123");
check_format("%zd", (ssize_t)2147483647, "2147483647");
check_format("%zd", (ssize_t)-2147483647, "-2147483647");
check_format("%+zd", (ssize_t)123, "+123");
check_format("%+zd", (ssize_t)-123, "-123");
check_format("%+zd", (ssize_t)2147483647, "+2147483647");
check_format("%+zd", (ssize_t)-2147483647, "-2147483647");
check_format("%5zd", (ssize_t)123, " 123");
check_format("%-5zd", (ssize_t)123, "123 ");
check_format(SIZE_FORMAT, (size_t)123u, "123");
check_format(SIZE_FORMAT_X, (size_t)0x123u, "0x123");
check_format(SIZE_FORMAT_X_0, (size_t)0x123u, "0x" LP64_ONLY("00000000") "00000123");