Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8339872

Exit JVM when -XX:+UseCompressedOops is supplied with incompatible heap size

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • hotspot

      Compressed oops are remarkably important for lots of services. Unfortunately, there is no clear way to enforce their use, especially on heaps closer to 32GB. The exact boundary depends on a few factors, notably the choice of GC.

      Counter-intuitively, even when users supply -XX:+UseCompressedOops explicitly, VM configured with incompatible heap size just silently disables UseCompressedOops and continues:
      https://github.com/openjdk/jdk/blob/c8e64cb7a578f1a32b48f76649fe19900ba6d040/src/hotspot/share/runtime/arguments.cpp#L1415-L1418.

      I think we can improve UX on that part: if user supplied -XX:+UseCompressedOops, and JVM cannot do it, exit right away with the error message. Something like this:

      ```
      diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp
      index 0d0b58412ae..37463407c8a 100644
      --- a/src/hotspot/share/runtime/arguments.cpp
      +++ b/src/hotspot/share/runtime/arguments.cpp
      @@ -1407,14 +1407,16 @@ void Arguments::set_use_compressed_oops() {
         // to use UseCompressedOops are InitialHeapSize and MinHeapSize.
         size_t max_heap_size = MAX3(MaxHeapSize, InitialHeapSize, MinHeapSize);
       
      - if (max_heap_size <= max_heap_for_compressed_oops()) {
      + size_t max_heap_size_coops = max_heap_for_compressed_oops();
      + if (max_heap_size <= max_heap_size_coops) {
           if (FLAG_IS_DEFAULT(UseCompressedOops)) {
             FLAG_SET_ERGO(UseCompressedOops, true);
           }
         } else {
           if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
      - warning("Max heap size too large for Compressed Oops");
      - FLAG_SET_DEFAULT(UseCompressedOops, false);
      + vm_exit_during_initialization(err_msg("Compressed oops are requested, but configured max heap size ("
      + PROPERFMT ") is larger than max heap size for compressed oops (" PROPERFMT ")",
      + PROPERFMTARGS(max_heap_size), PROPERFMTARGS(max_heap_size_coops)));
           }
         }
       #endif // _LP64
      ```

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: