1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "java.h"
3
4jptr varaddr;
5jptr varaddr2;
6
7void *Thread(void *p) {
8 barrier_wait(&barrier);
9 *(int*)varaddr2 = 42;
10 return 0;
11}
12
13int main() {
14 barrier_init(&barrier, 2);
15 int const kHeapSize = 1024 * 1024;
16 jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
17 __tsan_java_init(jheap, kHeapSize);
18 const int kBlockSize = 64;
19 int const kMove = 1024;
20 __tsan_java_alloc(jheap, kBlockSize);
21 varaddr = jheap + 16;
22 varaddr2 = varaddr + kMove;
23 pthread_t th;
24 pthread_create(&th, 0, Thread, 0);
25 *(int*)varaddr = 43;
26 __tsan_java_move(varaddr, varaddr2, kBlockSize);
27 barrier_wait(&barrier);
28 pthread_join(th, 0);
29 __tsan_java_free(varaddr2, kBlockSize);
30 fprintf(stderr, "DONE\n");
31 return __tsan_java_fini();
32}
33
34// CHECK: WARNING: ThreadSanitizer: data race
35// CHECK: DONE
36