2014-05-01 05:34:17 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
|
2012-12-21 21:40:27 +08:00
|
|
|
#include "java.h"
|
|
|
|
|
|
|
|
int const kHeapSize = 1024 * 1024;
|
|
|
|
|
|
|
|
void stress(jptr addr) {
|
|
|
|
for (jptr sz = 8; sz <= 32; sz <<= 1) {
|
|
|
|
for (jptr i = 0; i < kHeapSize / 4 / sz; i++) {
|
|
|
|
__tsan_java_alloc(addr + i * sz, sz);
|
|
|
|
}
|
|
|
|
__tsan_java_move(addr, addr + kHeapSize / 2, kHeapSize / 4);
|
|
|
|
__tsan_java_free(addr + kHeapSize / 2, kHeapSize / 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Thread(void *p) {
|
|
|
|
stress((jptr)p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2014-05-29 21:50:54 +08:00
|
|
|
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
|
2012-12-21 21:40:27 +08:00
|
|
|
__tsan_java_init(jheap, kHeapSize);
|
|
|
|
pthread_t th;
|
2012-12-24 19:43:34 +08:00
|
|
|
pthread_create(&th, 0, Thread, (void*)(jheap + kHeapSize / 4));
|
2012-12-21 21:40:27 +08:00
|
|
|
stress(jheap);
|
|
|
|
pthread_join(th, 0);
|
2014-05-29 21:50:54 +08:00
|
|
|
if (__tsan_java_fini() != 0) {
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "FAILED\n");
|
2014-05-29 21:50:54 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "DONE\n");
|
2014-05-29 21:50:54 +08:00
|
|
|
return 0;
|
2012-12-21 21:40:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-NOT: WARNING: ThreadSanitizer: data race
|
2014-05-29 21:50:54 +08:00
|
|
|
// CHECK-NOT: FAILED
|
|
|
|
// CHECK: DONE
|