1 // RUN: %clangxx_tsan -O1 %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s
3 // RUN: %run %t arg 2>&1 | FileCheck %s
15 void *Thread(void *p
) {
16 barrier_wait(&barrier
);
17 __tsan_java_mutex_lock(lockaddr1_new
);
18 *(char*)varaddr1_new
= 43;
19 __tsan_java_mutex_unlock(lockaddr1_new
);
20 __tsan_java_mutex_lock(lockaddr2_new
);
21 *(char*)varaddr2_new
= 43;
22 __tsan_java_mutex_unlock(lockaddr2_new
);
26 int main(int argc
, char **argv
) {
27 barrier_init(&barrier
, 2);
28 int const kHeapSize
= 1024 * 1024;
29 void *jheap
= malloc(kHeapSize
);
30 jheap
= (char*)jheap
+ 8;
31 __tsan_java_init((jptr
)jheap
, kHeapSize
);
32 const int kBlockSize
= 64;
34 varaddr1_old
= (jptr
)jheap
;
35 lockaddr1_old
= (jptr
)jheap
+ 1;
36 varaddr2_old
= (jptr
)jheap
+ kBlockSize
- 1;
37 lockaddr2_old
= (jptr
)jheap
+ kBlockSize
- 16;
38 varaddr1_new
= varaddr1_old
+ kMove
;
39 lockaddr1_new
= lockaddr1_old
+ kMove
;
40 varaddr2_new
= varaddr2_old
+ kMove
;
41 lockaddr2_new
= lockaddr2_old
+ kMove
;
43 // Move memory backwards.
44 varaddr1_old
+= kMove
;
45 lockaddr1_old
+= kMove
;
46 varaddr2_old
+= kMove
;
47 lockaddr2_old
+= kMove
;
48 varaddr1_new
-= kMove
;
49 lockaddr1_new
-= kMove
;
50 varaddr2_new
-= kMove
;
51 lockaddr2_new
-= kMove
;
53 __tsan_java_alloc(varaddr1_old
, kBlockSize
);
56 pthread_create(&th
, 0, Thread
, 0);
58 __tsan_java_mutex_lock(lockaddr1_old
);
59 *(char*)varaddr1_old
= 43;
60 __tsan_java_mutex_unlock(lockaddr1_old
);
61 __tsan_java_mutex_lock(lockaddr2_old
);
62 *(char*)varaddr2_old
= 43;
63 __tsan_java_mutex_unlock(lockaddr2_old
);
65 __tsan_java_move(varaddr1_old
, varaddr1_new
, kBlockSize
);
66 barrier_wait(&barrier
);
68 __tsan_java_free(varaddr1_new
, kBlockSize
);
69 fprintf(stderr
, "DONE\n");
70 return __tsan_java_fini();
73 // CHECK-NOT: WARNING: ThreadSanitizer: data race