diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2012-12-20 10:21:30 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2012-12-20 10:21:30 +0000 |
commit | d088b3b21925f048fc3d07c9e1b68da651db1100 (patch) | |
tree | 7ffef99ef5bfd319efd65bd2b4271318834523eb /compiler-rt/lib/tsan/lit_tests/java_race.cc | |
parent | ab8d33184d06bc726058be393f81a25e42621168 (diff) | |
download | bcm5719-llvm-d088b3b21925f048fc3d07c9e1b68da651db1100.tar.gz bcm5719-llvm-d088b3b21925f048fc3d07c9e1b68da651db1100.zip |
tsan: add java interface implementation stub
llvm-svn: 170681
Diffstat (limited to 'compiler-rt/lib/tsan/lit_tests/java_race.cc')
-rw-r--r-- | compiler-rt/lib/tsan/lit_tests/java_race.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/compiler-rt/lib/tsan/lit_tests/java_race.cc b/compiler-rt/lib/tsan/lit_tests/java_race.cc new file mode 100644 index 00000000000..9e842243d2d --- /dev/null +++ b/compiler-rt/lib/tsan/lit_tests/java_race.cc @@ -0,0 +1,37 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s +#include <pthread.h> +#include <stdlib.h> + +extern "C" { +typedef unsigned long jptr; // NOLINT +void __tsan_java_init(jptr heap_begin, jptr heap_size); +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_mutex_lock(jptr addr); +void __tsan_java_mutex_unlock(jptr addr); +void __tsan_java_mutex_read_lock(jptr addr); +void __tsan_java_mutex_read_unlock(jptr addr); +} + +void *Thread(void *p) { + *(int*)p = 42; + return 0; +} + +int main() { + int const kHeapSize = 1024 * 1024; + void *jheap = malloc(kHeapSize); + __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); + return __tsan_java_fini(); +} + +// CHECK: WARNING: ThreadSanitizer: data race |