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

Avoid use of Universe::heap() inside collectors

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 9
    • hotspot
    • gc
    • b64
    • generic
    • generic

        The following pattern is fairly common in the GC code:

        ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
        assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");

        Code for a specific collector should use its heap() function to avoid casting and asserting. The example above should be replaced by:

        ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();

        There are also other places where Universe::heap() is used, even when it's clear what we are inside, e.g. ParallelScavenge-related code. We should be using ParallelScavengeHeap::heap() here instead. Universe::heap() should (for clarity) only be used by code that doesn't know/care which collector we are currently using.

              pliden Per Liden (Inactive)
              pliden Per Liden (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: