1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2#include "java.h"
3
4jptr varaddr;
5jptr varaddr2;
6
7void *Thread(void *p) {
8 barrier_wait(barrier: &barrier);
9 *(int*)varaddr2 = 42;
10 return 0;
11}
12
13int main() {
14 barrier_init(barrier: &barrier, count: 2);
15 int const kHeapSize = 1024 * 1024;
16 jptr jheap = (jptr)malloc(size: kHeapSize + 8) + 8;
17 __tsan_java_init(heap_begin: jheap, heap_size: kHeapSize);
18 const int kBlockSize = 64;
19 int const kMove = 1024;
20 __tsan_java_alloc(ptr: jheap, size: kBlockSize);
21 varaddr = jheap + 16;
22 varaddr2 = varaddr + kMove;
23 pthread_t th;
24 pthread_create(newthread: &th, attr: 0, start_routine: Thread, arg: 0);
25 *(int*)varaddr = 43;
26 __tsan_java_move(src: varaddr, dst: varaddr2, size: kBlockSize);
27 barrier_wait(barrier: &barrier);
28 pthread_join(th: th, thread_return: 0);
29 __tsan_java_free(ptr: varaddr2, size: kBlockSize);
30 fprintf(stderr, format: "DONE\n");
31 return __tsan_java_fini();
32}
33
34// Note: there is a race on the moved object (which we used to detect),
35// but now __tsan_java_move resets the object shadow, so we don't detect it anymore.
36// CHECK-NOT: WARNING: ThreadSanitizer: data race
37// CHECK: DONE
38

source code of compiler-rt/test/tsan/java_race_move.cpp