[compiler-rt] r211829 - tsan: add __tsan_java_finalize interface function
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Fri Jun 27 01:19:31 PDT 2014
I've disabled this test in r211882, as it is failing on both sanitizer bots.
Please fix and re-enable.
On Fri, Jun 27, 2014 at 4:47 AM, Dmitry Vyukov <dvyukov at google.com> wrote:
> Author: dvyukov
> Date: Thu Jun 26 19:47:38 2014
> New Revision: 211829
>
> URL: http://llvm.org/viewvc/llvm-project?rev=211829&view=rev
> Log:
> tsan: add __tsan_java_finalize interface function
> It is required to prevent false positives between object ctor and finalizer,
> as otherwise they look completely unsynchronized.
>
>
> Added:
> compiler-rt/trunk/test/tsan/java_finalizer.cc
> Modified:
> compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.cc
> compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.h
> compiler-rt/trunk/test/tsan/java.h
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.cc?rev=211829&r1=211828&r2=211829&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.cc Thu Jun 26 19:47:38 2014
> @@ -142,6 +142,12 @@ void __tsan_java_move(jptr src, jptr dst
> }
> }
>
> +void __tsan_java_finalize() {
> + SCOPED_JAVA_FUNC(__tsan_java_finalize);
> + DPrintf("#%d: java_mutex_finalize()\n", thr->tid);
> + AcquireGlobal(thr, 0);
> +}
> +
> void __tsan_java_mutex_lock(jptr addr) {
> SCOPED_JAVA_FUNC(__tsan_java_mutex_lock);
> DPrintf("#%d: java_mutex_lock(%p)\n", thr->tid, addr);
>
> Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.h?rev=211829&r1=211828&r2=211829&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.h (original)
> +++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface_java.h Thu Jun 26 19:47:38 2014
> @@ -52,6 +52,11 @@ void __tsan_java_free(jptr ptr, jptr siz
> // Can be aggregated for several objects (preferably).
> // The ranges must not overlap.
> void __tsan_java_move(jptr src, jptr dst, jptr size) INTERFACE_ATTRIBUTE;
> +// This function must be called on the finalizer thread
> +// before executing a batch of finalizers.
> +// It ensures necessary synchronization between
> +// java object creation and finalization.
> +void __tsan_java_finalize() INTERFACE_ATTRIBUTE;
>
> // Mutex lock.
> // Addr is any unique address associated with the mutex.
>
> Modified: compiler-rt/trunk/test/tsan/java.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java.h?rev=211829&r1=211828&r2=211829&view=diff
> ==============================================================================
> --- compiler-rt/trunk/test/tsan/java.h (original)
> +++ compiler-rt/trunk/test/tsan/java.h Thu Jun 26 19:47:38 2014
> @@ -11,6 +11,7 @@ int __tsan_java_fini();
> void __tsan_java_alloc(jptr ptr, jptr size);
> void __tsan_java_free(jptr ptr, jptr size);
> void __tsan_java_move(jptr src, jptr dst, jptr size);
> +void __tsan_java_finalize();
> void __tsan_java_mutex_lock(jptr addr);
> void __tsan_java_mutex_unlock(jptr addr);
> void __tsan_java_mutex_read_lock(jptr addr);
>
> Added: compiler-rt/trunk/test/tsan/java_finalizer.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/java_finalizer.cc?rev=211829&view=auto
> ==============================================================================
> --- compiler-rt/trunk/test/tsan/java_finalizer.cc (added)
> +++ compiler-rt/trunk/test/tsan/java_finalizer.cc Thu Jun 26 19:47:38 2014
> @@ -0,0 +1,27 @@
> +// RUN: %clangxx_tsan -O1 %s -o %t && %run %t | FileCheck %s
> +#include "java.h"
> +
> +void *Thread(void *p) {
> + sleep(1);
> + __tsan_java_finalize();
> + *(int*)p = 42;
> + return 0;
> +}
> +
> +int main() {
> + int const kHeapSize = 1024 * 1024;
> + void *jheap = (char*)malloc(kHeapSize + 8) + 8;
> + __tsan_java_init((jptr)jheap, kHeapSize);
> + const int kBlockSize = 16;
> + __tsan_java_alloc((jptr)jheap, kBlockSize);
> + pthread_t th;
> + pthread_create(&th, 0, Thread, jheap);
> + *(int*)jheap = 43;
> + pthread_join(th, 0);
> + __tsan_java_free((jptr)jheap, kBlockSize);
> + fprintf(stderr, "DONE\n");
> + return __tsan_java_fini();
> +}
> +
> +// CHECK-NOT: WARNING: ThreadSanitizer: data race
> +// CHECK: DONE
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list