RFR: 8321940: Improve CDSHeapVerifier in handling of interned strings

Ioi Lam iklam at openjdk.org
Thu Dec 14 22:52:37 UTC 2023


On Thu, 14 Dec 2023 21:55:01 GMT, Calvin Cheung <ccheung at openjdk.org> wrote:

> With your new changes, item C in the comment can be removed.
> 
> ```
>  80 // [C] A non-final static string that is assigned a string literal during class
>  81 //     initialization; this string is never changed during -Xshare:dump.
> ```

Hi Calvin:

Thanks for the review. [C] can still be useful for checking problematic code like this (a variation of the example in cdsHeapVerifier.cpp)

We want cdsHeapVerifier to flag such patterns. However, if we know that `someCondition()` always returns the same condition, then we can add an exclusion of type [C] so cdsHeapVerifier won't complain about it.


class Foo {
    final Foo archivedFoo; // this field is archived by CDS
    String bar;
    static {
        CDS.initializeFromArchive(Foo.class);
        if (archivedFoo == null) {
            archivedFoo = new Foo();
            archivedFoo.bar = Bar.bar;
        }
    }
    static Foo get() { return archivedFoo; }
    boolean test() {
        return bar == Bar.bar;
    }
}

class Bar {
    // this field is initialized in both CDS dump time and runtime.
    // It may hold a different value depending on someCondition()
    static String bar = (someCondition()) ? "xxx" : "yyy";
}

-------------

PR Comment: https://git.openjdk.org/jdk/pull/17102#issuecomment-1856861138


More information about the hotspot-runtime-dev mailing list