Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Shenandoah GC in JDK 14, Part 2: Concurrent roots and class unloading

March 9, 2020
Roman Kennke
Related topics:
Java

    The first part of this miniseries about Shenandoah GC in JDK 14 covered self-fixing barriers. This article discusses concurrent roots processing and concurrent class unloading, both of which aim to reduce GC pause time by moving GC work from the pause to a concurrent phase.

    Concurrent roots processing

    Once concurrent marking is done, Shenandoah needs to complete the marking and prepare for evacuation. While these are two logically independent operations, they are performed under a single pause that is confusingly named "Final Mark."

    While evacuation itself is concurrent in Shenandoah, there are still a few things that need to be done at pause. These include:

    • Pre-evacuating and updating non-weak roots (for example, thread stacks and strong JNI handles).
    • Pre-evacuating and cleaning up weak roots (for example, string tables and weak JNI handles).
    • Unloading classes.

    Since this work is done during the pause, it affects pause times. To minimize these pause times, we want to perform most of these tasks concurrently. This approach is particularly important for any GC roots that are unbounded in size.

    The reason we need to pre-evacuate and update all GC roots during the pause is to ensure the strong invariant. Any object that is read from or stored to must be in to-space.

    Here is the important caveat: Loading the objects out of GC roots does not employ load reference barriers. So, the application has to see the correct copy of the object, and we have to perform the evacs and updates before unblocking from the pause. In this problem statement lies a relatively simple solution: Ensure that loads from relevant GC roots are guarded by a Load Reference Barrier (LRB) that we call "native LRB," and move the actual updating of those roots to the concurrent phase.

    The so-called "weak" roots are special, though. During marking, we might determine that certain GC roots are no longer reachable. An example of this issue is weak JNI handles. Once the weak JNI handle is declared dead (during final mark), it should not be accidentally resurrected—for example, by inserting the reference to its presumed-dead object back into the heap.

    Therefore, not only do we have to pre-evacuate and update the weak roots that are reachable (like all other roots), we also need to clean up the weak roots that are not reachable so the application cannot possibly touch and resurrect them.

    Moving this cleanup to the concurrent phase requires extra work for the native LRB, which checks whether a weak root is reachable (as told by the marking bitmap). If the weak root is not reachable, the native LRB simply returns NULL, thus pretending to the rest of the JVM that the handle is already cleaned. This process ensures that we do not accidentally make an already-unreachable object reachable again.

    In pseudocode, the native LRB looks like this:

    T native_LRB(T* addr) {
      T obj = *addr; // Load from GC root
      if (is_reachable(obj)) {
        return LRB(obj);
      } else {
        return NULL;
      }
    }
    

    Concurrent class unloading

    Another large item during the final mark pause used to be class unloading, which is important for applications that make heavy use of class loaders. This situation is usually the case for application servers and other large-ish applications (e.g., IDEs). However, class unloading is also relevant when using anonymous classes (each of which has its own class loader) and lambdas (similar to anonymous classes).

    Class unloading is a complex procedure. It requires the code to determine whether or not classes (or rather, class loaders) are reachable. This check already happens during concurrent marking. When reachability of all objects (including class-loaders) is established, all unreachable class loaders and their classes and auxiliary data structures need to be unlinked and cleaned. Compiled code that belongs to those classes needs to get cleaned.

    For the most part, Shenandoah's implementation builds on the work done by ZGC developers in JDK 13. This implementation does require the native barriers described above. In addition to that, it also requires so-called "nmethod entry barriers."

    Usually, during the pause, we need to pre-evacuate and update all references that are embedded in all compiled methods. Ideally, we would only pre-evacuate/update references in methods that are currently executed (i.e., reachable by frames on the stacks), and handle other methods concurrently. In order for this approach to work, we need to handle the scenario where a thread starts executing a method.

    The idea behind nmethod barriers is that they are executed whenever a method is called. Before execution is handed over to the method, the GC barrier is called to do certain things. In Shenandoah, this means to scan the method's code for embedded objects (constants) and evacuate-and-update them, in order to ensure the strong invariant above. Live nmethods are armed at the final mark pause and disarmed by either GC threads during a concurrent phase or by Java threads when the nmethods are about to be executed.

    The net advantage of concurrent roots processing and concurrent class unloading is that the final mark pause is shorter, and thus global latency is improved, even when the application makes heavy use of class loaders or JNI handles.

    Last updated: June 29, 2020

    Recent Posts

    • Federated identity across the hybrid cloud using zero trust workload identity manager

    • Confidential virtual machine storage attack scenarios

    • Introducing virtualization platform autopilot

    • Integrate zero trust workload identity manager with Red Hat OpenShift GitOps

    • Best Practice Configuration and Tuning for Linux and Windows VMs

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.