RFR: 8047998: -XX:InitialHeapSize is unnecessarily set to MaxHeapSize

Guoxiong Li gli at openjdk.org
Wed May 10 12:35:24 UTC 2023


On Wed, 10 May 2023 12:06:29 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:

> Could you provide a concrete example (specific JVM flags and values) to illustrate the problem (unexpected behavior due to > inadequate/misleading/confusing doc)? I don't get what the problem is, even after reading the original ticket description and  > your revised solution.

The possible flags are `-XX:MaxHeapSize=256M -XX:NewSize=1M -XX:MaxNewSize=80M`.
The user wants the JVM to initialize the new generation as 1M and then expands to 80M gradually.

If the physical memory is very larger, the `InitialHeapSize` will be set to `MaxHeapSize` 
(which is `256M` according to the previous flags).
The related code in method `Arguments::set_heap_size` is shown below.


// method Arguments::set_heap_size
      julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100);
      reasonable_initial = limit_heap_by_allocatable_memory(reasonable_initial);

      reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)MinHeapSize);
      reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize); // <-- here


Then in method `GenArguments::initialize_size_info`, the `MaxNewSize` is set to `NewSize`
(which is `1M` according to the previous flags).
The related code in method `GenArguments::initialize_size_info` is shown below.


// method GenArguments::initialize_size_info
if (MaxHeapSize == InitialHeapSize) {
    // The maximum and initial heap sizes are the same so the generation's
    // initial size must be the same as it maximum size. Use NewSize as the
    // size if set on command line.
    max_young_size = FLAG_IS_CMDLINE(NewSize) ? NewSize : max_young_size; // <-- here
    initial_young_size = max_young_size;

    // Also update the minimum size if min == initial == max.
    if (MaxHeapSize == MinHeapSize) {
      MinNewSize = max_young_size;
    }
}


As you can see, the `MaxNewSize` and `NewSize` are always `1M` and the new generation never expands,
which is not the user's intention and may lead to unexpected result.

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

PR Comment: https://git.openjdk.org/jdk/pull/13876#issuecomment-1542121917


More information about the hotspot-gc-dev mailing list