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

Native stack overflow when writing Java heap objects into AOT cache

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 25
    • 21, 24, repo-leyden
    • hotspot
    • master

      https://github.com/openjdk/jdk/blob/b6443f6ff96707f67552df41c01d18c193560223/src/hotspot/share/cds/heapShared.cpp#L1350C18-L1350C18

      The WalkOopAndArchiveClosure class makes a depth first search to dump all reachable heap objects into the AOT cache. The recursion is done on the native stack, so with a very long reference chain, we can overflow the native stack.

      The bug was discovered with JDK-8341587 when we enable AOT caching of WeakReferences. As a result, we can see long link lists of WeakReference objects.

      Impact:

      The JDK mainline does not support AOT caching of WeakReferences. The set of Java objects cached by the JDK mainline are very limited and do not seem to have such long reference chains. So this bug is unlikely to affect the JDK mainline.

      Proposed fix:

      Instead of recursing on the native thread stack, implement the recursion using a side data structure (e.g., GrowableArray with push/pop).

      We already do this when caching metaspace objects with MetaspaceClosure.

            iklam Ioi Lam
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: