Home | History | Annotate | Download | only in lit_tests
      1 // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
      2 #include "java.h"
      3 
      4 jptr varaddr;
      5 jptr lockaddr;
      6 jptr varaddr2;
      7 jptr lockaddr2;
      8 
      9 void *Thread(void *p) {
     10   sleep(1);
     11   __tsan_java_mutex_lock(lockaddr2);
     12   *(int*)varaddr2 = 42;
     13   __tsan_java_mutex_unlock(lockaddr2);
     14   return 0;
     15 }
     16 
     17 int main() {
     18   int const kHeapSize = 1024 * 1024;
     19   void *jheap = malloc(kHeapSize);
     20   __tsan_java_init((jptr)jheap, kHeapSize);
     21   const int kBlockSize = 64;
     22   int const kMove = 1024;
     23   __tsan_java_alloc((jptr)jheap, kBlockSize);
     24   varaddr = (jptr)jheap;
     25   lockaddr = (jptr)jheap + 46;
     26   varaddr2 = varaddr + kMove;
     27   lockaddr2 = lockaddr + kMove;
     28   pthread_t th;
     29   pthread_create(&th, 0, Thread, 0);
     30   __tsan_java_mutex_lock(lockaddr);
     31   *(int*)varaddr = 43;
     32   __tsan_java_mutex_unlock(lockaddr);
     33   __tsan_java_move(varaddr, varaddr2, kBlockSize);
     34   pthread_join(th, 0);
     35   __tsan_java_free(varaddr2, kBlockSize);
     36   printf("OK\n");
     37   return __tsan_java_fini();
     38 }
     39 
     40 // CHECK-NOT: WARNING: ThreadSanitizer: data race
     41