RFR: 8281213: Unsafe uses of long and size_t in MemReporterBase::diff_in_current_scale

Thomas Stuefe stuefe at openjdk.org
Fri Dec 9 13:35:15 UTC 2022


On Fri, 9 Dec 2022 12:27:00 GMT, Afshin Zafari <duke at openjdk.org> wrote:

> So, I will do these: the return value is of type int64_t; Then, there is no need to change the printing format for the returned value in places where this function is called. Correct? What other changes need to be done?

See this PR: https://github.com/openjdk/jdk/pull/11568 - solves the same issue as yours, but for the counters. The only difference to your patch is that with counters, I can use `ssize_t`, since I know that on 32-bit these counters cannot overflow SSIZE_MAX (2g, -2g). But with memory sizes this can happen (think: a 32-bit VM mallocing 2.1GB, then freeing it again), therefore we need to use `int64_t`.

You need to change the print formats too. Currently, the printout uses `%+ld`, which on Windows and on 32-bit platforms in general would print with 32-bit. You need to use INT64_FORMAT, but since the printout wants to have a leading '+' for positive numbers, you need something like INT64_PLUS_FORMAT. 

INT64_PLUS_FORMAT does not exist yet, you need to add it. Just do this:


--- a/src/hotspot/share/utilities/globalDefinitions.hpp
+++ b/src/hotspot/share/utilities/globalDefinitions.hpp
@@ -120,6 +120,7 @@ class oopDesc;
 
 // Format 64-bit quantities.
 #define INT64_FORMAT             "%"          PRId64
+#define INT64_PLUS_FORMAT        "%+"         PRId64
 #define INT64_FORMAT_X           "0x%"        PRIx64
 #define INT64_FORMAT_X_0         "0x%016"     PRIx64
 #define INT64_FORMAT_W(width)    "%"   #width PRId64


Cheers, Thomas

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

PR: https://git.openjdk.org/jdk/pull/11514


More information about the hotspot-runtime-dev mailing list