diff options
Diffstat (limited to 'compiler-rt/test/tsan/java_finalizer.cc')
-rw-r--r-- | compiler-rt/test/tsan/java_finalizer.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/compiler-rt/test/tsan/java_finalizer.cc b/compiler-rt/test/tsan/java_finalizer.cc new file mode 100644 index 00000000000..706b946be61 --- /dev/null +++ b/compiler-rt/test/tsan/java_finalizer.cc @@ -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 |