1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2#include "java.h"
3
4jptr varaddr;
5jptr lockaddr;
6jptr varaddr2;
7jptr lockaddr2;
8
9void *Thread(void *p) {
10 barrier_wait(barrier: &barrier);
11 __tsan_java_mutex_lock(addr: lockaddr2);
12 *(int*)varaddr2 = 42;
13 __tsan_java_mutex_unlock(addr: lockaddr2);
14 return 0;
15}
16
17int main() {
18 barrier_init(barrier: &barrier, count: 2);
19 int const kHeapSize = 1024 * 1024;
20 jptr jheap = (jptr)malloc(size: kHeapSize + 8) + 8;
21 __tsan_java_init(heap_begin: jheap, heap_size: kHeapSize);
22 const int kBlockSize = 64;
23 int const kMove = 1024;
24 __tsan_java_alloc(ptr: jheap, size: kBlockSize);
25 varaddr = jheap;
26 lockaddr = jheap + 46;
27 varaddr2 = varaddr + kMove;
28 lockaddr2 = lockaddr + kMove;
29 pthread_t th;
30 pthread_create(newthread: &th, attr: 0, start_routine: Thread, arg: 0);
31 __tsan_java_mutex_lock(addr: lockaddr);
32 *(int*)varaddr = 43;
33 __tsan_java_mutex_unlock(addr: lockaddr);
34 __tsan_java_move(src: varaddr, dst: varaddr2, size: kBlockSize);
35 barrier_wait(barrier: &barrier);
36 pthread_join(th: th, thread_return: 0);
37 __tsan_java_free(ptr: varaddr2, size: kBlockSize);
38 fprintf(stderr, format: "DONE\n");
39 return __tsan_java_fini();
40}
41
42// CHECK-NOT: WARNING: ThreadSanitizer: data race
43// CHECK: DONE
44

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