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

G1CollectedHeap::expand_and_allocate() may fail to allocate even after heap expansion succeeds

XMLWordPrintable

    • gc
    • 20
    • master

      This problem was discovered during the work for SoftMaxHeapSize (JDK-8236073) (and our internal ProposedHeapSize). In G1CollectedHeap::expand_and_allocate(), it does:

      if (expand(expand_bytes, _workers)) {
          ...
          return attempt_allocation_at_safepoint(word_size, false);
      }

      We found that when expand() returns true, attempt_allocation_at_safepoint() could immediately return nullptr. This is counter-intuitive, because allocation immediately after a heap expansion should normally succeed. One possible cause is another thread immediately uses up the newly created region, because expand() and attempt_allocation_at_safepoint() are not atomic.

      This mostly affects use cases for SoftMaxHeapSize, where setting a small SoftMaxHeapSize could cause OutOfMemoryError. To work around it, we internally revived the removed attempt_allocation_force() method (deleted by JDK-8331562), and use it when this problem happens.

            iwalulya Ivan Walulya
            manc Man Cao
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: