2

I have seen other questions on here like: How is the default max Java heap size determined? and Understanding java heap

I run the command to see my heap size java -XX:+PrintFlagsFinal -version and I get the output for MaxHeapSize:

uintx MaxHeapSize := 0 {product}

What does this mean?

kalelien
  • 422
  • 2
  • 9
  • 1
    This means, you run 64-bit JDK 8 (or earlier) on Windows, and the maximum heap size (-Xmx) is the exact multiple of 4 GiB. – apangin Aug 07 '20 at 00:41
  • I just verified this by running `java -Xmx4g -XX:+PrintFlagsFinal -version` and could reproduce `MaxHeapSize := 0`. Can you elaborate on why this is the case? – kalelien Aug 07 '20 at 05:41

1 Answers1

5

This is a bug in JDK 8.

MaxHeapSize is defined in HotSpot sources as uintx, which stands for 64-bit unsigned integer.

In JDK 8, the format for printing uintx flag values is "%-16lu", which treats input as unsigned long.

However, the size of C++ unsigned long differs on Windows and Unix:

  • Most Unix-like systems are LP64, where the size of unsigned long is 64 bit.
  • Visual C++ on Windows is LLP64, where the size of unsigned long is 32 bit.

So, JDK 8 on Windows prints only low 32 bits of uintx flags. That's why if MaxHeapSize is an exact multiple of 4 GiB, you'll see uintx MaxHeapSize := 0. This is just the printing error; the actual max heap size is correct.

The bug was fixed in JDK 9 as a part of JDK-8042893 change:

     } else if (is_uintx()) {
-      st->print("%-16lu", get_uintx());
+      st->print(UINTX_FORMAT_W(-16), get_uintx());
apangin
  • 79,047
  • 9
  • 168
  • 200