1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
4 int const kHeapSize
= 1024 * 1024;
6 static void verify_find(jptr from
, jptr to
, jptr expected_addr
,
9 jptr size
= __tsan_java_find(&addr
, to
);
12 fprintf(stderr
, "FAILED: range: [%p..%p): found nothing\n", (void *)from
,
15 } else if (expected_size
!= size
) {
16 fprintf(stderr
, "FAILED: range: [%p..%p): wrong size, %lu instead of %lu\n",
17 (void *)from
, (void *)to
, size
, expected_size
);
22 "FAILED: range [%p..%p): did not expect to find anything here\n",
23 (void *)from
, (void *)to
);
28 if (expected_addr
!= addr
) {
31 "FAILED: range [%p..%p): expected to find object at %p, found at %p\n",
32 (void *)from
, (void *)to
, (void *)expected_addr
, (void *)addr
);
37 const jptr jheap
= (jptr
)malloc(kHeapSize
+ 8) + 8;
38 const jptr jheap_end
= jheap
+ kHeapSize
;
39 __tsan_java_init(jheap
, kHeapSize
);
40 const jptr addr1
= jheap
;
42 __tsan_java_alloc(jheap
, size1
);
44 const jptr addr2
= addr1
+ size1
;
46 __tsan_java_alloc(jheap
+ size1
, size2
);
48 const jptr addr3
= addr2
+ size2
;
49 const int size3
= 1024;
50 __tsan_java_alloc(jheap
+ size1
+ size2
, size3
);
52 const jptr addr4
= addr3
+ size3
;
54 verify_find(jheap
, jheap_end
, addr1
, size1
);
55 verify_find(jheap
+ 8, jheap_end
, addr2
, size2
);
56 verify_find(addr2
+ 8, jheap_end
, addr3
, size3
);
57 verify_find(addr3
+ 8, jheap_end
, 0, 0);
59 __tsan_java_move(addr2
, addr4
, size2
);
60 verify_find(jheap
+ 8, jheap_end
, addr3
, size3
);
61 verify_find(addr3
+ 8, jheap_end
, addr4
, size2
);
62 verify_find(addr4
+ 8, jheap_end
, 0, 0);
64 fprintf(stderr
, "DONE\n");