Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
| 2 | #include "java.h" |
| 3 | #include <memory.h> |
| 4 | |
| 5 | extern "C" bool __tsan_symbolize_external(jptr pc, |
| 6 | char *func_buf, jptr func_siz, |
| 7 | char *file_buf, jptr file_siz, |
| 8 | int *line, int *col) { |
| 9 | if (pc == (1234 | kExternalPCBit)) { |
| 10 | memcpy(func_buf, "MyFunc", sizeof("MyFunc")); |
| 11 | memcpy(file_buf, "MyFile.java", sizeof("MyFile.java")); |
| 12 | *line = 1234; |
| 13 | *col = 56; |
| 14 | return true; |
| 15 | } |
| 16 | return false; |
| 17 | } |
| 18 | |
| 19 | void *Thread(void *p) { |
| 20 | barrier_wait(&barrier); |
| 21 | __tsan_write1_pc((jptr)p, 1234 | kExternalPCBit); |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | int main() { |
| 26 | barrier_init(&barrier, 2); |
| 27 | int const kHeapSize = 1024 * 1024; |
| 28 | jptr jheap = (jptr)malloc(kHeapSize + 8) + 8; |
| 29 | __tsan_java_init(jheap, kHeapSize); |
| 30 | const int kBlockSize = 16; |
| 31 | __tsan_java_alloc(jheap, kBlockSize); |
| 32 | pthread_t th; |
| 33 | pthread_create(&th, 0, Thread, (void*)jheap); |
| 34 | __tsan_write1_pc((jptr)jheap, 1234 | kExternalPCBit); |
| 35 | barrier_wait(&barrier); |
| 36 | pthread_join(th, 0); |
| 37 | __tsan_java_free(jheap, kBlockSize); |
| 38 | fprintf(stderr, "DONE\n"); |
| 39 | return __tsan_java_fini(); |
| 40 | } |
| 41 | |
| 42 | // CHECK: WARNING: ThreadSanitizer: data race |
| 43 | // CHECK: #0 MyFunc MyFile.java:1234:56 |
| 44 | // CHECK: DONE |