RFR(L): 8029075 - String deduplication in G1

John Rose john.r.rose at oracle.com
Fri Mar 7 00:40:00 UTC 2014

On Mar 6, 2014, at 1:04 PM, Christian Thalinger <christian.thalinger at oracle.com> wrote:

> Another way would be to use some kind of annotation to mark references and teach the GCs about that.

Here's how the story looks to me:

Define a new annotation @WeakReferenceField.

Take Alexey's code for @Contended and duplicate with adjustments for @WeakReferenceField.  Define another field bit and store it in metadata.

Looks for the bit in the JVM wherever it currently asks about java_lang_ref_Reference::referent_offset.
(This is the hard part, especially for G1, but it is traded against adding more GC-sensitive C++ code into the JVM, for a benefit of narrow scope.)

Don't bother about queueing; it's optional for WeakReference.

The goal is that the following classes work about the same, except for heap pressure:

> class A1 {
>   private WeakReference<String> ref1 = new WeakReference<>(something);
>   private WeakReference<String> ref2 = new WeakReference<>(somethingElse);
> }
> class A2 {
>  private @WeakReferenceField String ref1 = something;
>  private @WeakReferenceField String ref2 = somethingElse;
> }

Put the annotation in sun.misc or some other internal place.  Use it only for private JVM-coupled things like string dedup (no JCK or general testing).

Put whatever practical limits you want on the implementation.  Let the next user (there will be a next user) refine it further.

Enjoy coding and debugging multi-thread GC-safe code in Java.

I hope this helps!

— John

P.S. Connection with value types:  Eventually, we could add value types like java.lang.ref.WeakReferenceValue which would provide a standard form for this.  Or we could standardize the annotation, perhaps.

P.P.S. For a little more on value types, see https://blogs.oracle.com/jrose/entry/value_types_and_struct_tearing

More information about the hotspot-dev mailing list