__tsan_java_finalize bug

Dmitry Vyukov dvyukov at google.com
Wed May 27 19:36:26 UTC 2020


On Wed, May 27, 2020 at 9:03 PM Man Cao <manc at google.com> wrote:
>
> __tsan_java_finalize() is used in Java finalizer:
> https://github.com/openjdk/tsan/blob/7f1f31a18bafd9df728b03c63953f4e3fe20abdb/src/java.base/share/classes/java/lang/ref/Finalizer.java#L90
> tsanFinalize() calls __tsan_java_finalize().
>
> finalize() is deprecated since Java 9. Perhaps the Cleaner mechanism does not need __tsan_java_finalize()?

I can't tell right away. This area proved to be tricky :)

>From quick skimming I don't see any synchronization/visibility
guarantees for Cleaner. If there are none (everything is supposed to
be synchronized by user code explicitly), then we done!

But FWIW the tsan issue with GlobalAcquire was fixed upstream.



> On Sat, May 23, 2020 at 5:57 AM Dmitry Vyukov <dvyukov at google.com> wrote:
>>
>> Hi,
>>
>> FYI there is a bug reported in tsan's AcquireGlobal:
>> https://github.com/golang/go/issues/39186
>> It's for Go, but I think it equally affects __tsan_java_finalize(). Is
>> it used in the current implementation for Java finalizers?
>>
>> Brief summary: it requires a very special program pattern and a very
>> narrow inconsistency window (4 threads participating in a very special
>> and tricky interleaving), but if all of that is satisfied it can lead
>> to arbitrary unexplainable false positives.


More information about the tsan-dev mailing list