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