RFR: 8364434: Inconsistent BufferedContext state after GC
Alexey Ushakov
avu at openjdk.org
Tue Aug 5 13:48:07 UTC 2025
On Tue, 5 Aug 2025 13:25:19 GMT, Alexey Ushakov <avu at openjdk.org> wrote:
>> For "true" null objects, reset the ref itself to null. Non-null ref with null content means that the object was GC'ed. GC'ed state always behaves as not-equal to the new one, causing corresponding ops to be written into RQ.
>>
>> Although I could not find practical scenarios where refs other than `validPaintRef` could cause problems, this is generally fragile and potentially problematic for any state object kept in weak ref. Therefore I changed the usage of all weak refs in the same way.
>
> src/java.desktop/share/classes/sun/java2d/pipe/BufferedContext.java line 103:
>
>> 101: protected static BufferedContext currentContext;
>> 102:
>> 103: private Reference<AccelSurface> validSrcDataRef = null;
>
> I think that you can wrap these fields into Optional ones to simplify the state change verification.
For wrapping, you can use the following one-liner
`Optional.ofNullable(val).flatMap(e -> Optional.of(new WeakReference(val)));`
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26576#discussion_r2254404302
More information about the client-libs-dev
mailing list