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
11 void *Thread(void *p
) {
12 barrier_wait(&barrier
);
13 *(int*)varaddr1_new
= 43;
14 *(int*)varaddr2_new
= 43;
18 int main(int argc
, char **argv
) {
19 barrier_init(&barrier
, 2);
20 int const kHeapSize
= 1024 * 1024;
21 void *jheap
= malloc(kHeapSize
);
22 jheap
= (char*)jheap
+ 8;
23 __tsan_java_init((jptr
)jheap
, kHeapSize
);
24 const int kBlockSize
= 64;
26 varaddr1_old
= (jptr
)jheap
;
27 varaddr2_old
= (jptr
)jheap
+ kBlockSize
- 1;
28 varaddr1_new
= varaddr1_old
+ kMove
;
29 varaddr2_new
= varaddr2_old
+ kMove
;
31 // Move memory backwards.
32 varaddr1_old
+= kMove
;
33 varaddr2_old
+= kMove
;
34 varaddr1_new
-= kMove
;
35 varaddr2_new
-= kMove
;
37 __tsan_java_alloc(varaddr1_old
, kBlockSize
);
40 pthread_create(&th
, 0, Thread
, 0);
42 *(int*)varaddr1_old
= 43;
43 *(int*)varaddr2_old
= 43;
45 __tsan_java_move(varaddr1_old
, varaddr1_new
, kBlockSize
);
46 barrier_wait(&barrier
);
48 __tsan_java_free(varaddr1_new
, kBlockSize
);
49 fprintf(stderr
, "DONE\n");
50 return __tsan_java_fini();
53 // Note: there is a race on the moved object (which we used to detect),
54 // but now __tsan_java_move resets the object shadow, so we don't detect it anymore.
55 // CHECK-NOT: WARNING: ThreadSanitizer: data race