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 int const kHeapSize = 1024 * 1024;
      5 
      6 void stress(jptr addr) {
      7   for (jptr sz = 8; sz <= 32; sz <<= 1) {
      8     for (jptr i = 0; i < kHeapSize / 4 / sz; i++) {
      9       __tsan_java_alloc(addr + i * sz, sz);
     10     }
     11     __tsan_java_move(addr, addr + kHeapSize / 2, kHeapSize / 4);
     12     __tsan_java_free(addr + kHeapSize / 2, kHeapSize / 4);
     13   }
     14 }
     15 
     16 void *Thread(void *p) {
     17   stress((jptr)p);
     18   return 0;
     19 }
     20 
     21 int main() {
     22   jptr jheap = (jptr)malloc(kHeapSize);
     23   __tsan_java_init(jheap, kHeapSize);
     24   pthread_t th;
     25   pthread_create(&th, 0, Thread, (void*)(jheap + kHeapSize / 4));
     26   stress(jheap);
     27   pthread_join(th, 0);
     28   printf("OK\n");
     29   return __tsan_java_fini();
     30 }
     31 
     32 // CHECK-NOT: WARNING: ThreadSanitizer: data race
     33