• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include "java.h"
3 #include <memory.h>
4 
__tsan_symbolize_external_ex(jptr pc,void (* add_frame)(void *,const char *,const char *,int,int),void * ctx)5 extern "C" void __tsan_symbolize_external_ex(
6     jptr pc, void (*add_frame)(void *, const char *, const char *, int, int),
7     void *ctx) {
8   if (pc == (1234 | kExternalPCBit)) {
9     add_frame(ctx, "MyInnerFunc", "MyInnerFile.java", 1234, 56);
10     add_frame(ctx, "MyOuterFunc", "MyOuterFile.java", 4321, 65);
11   }
12 }
13 
Thread(void * p)14 void *Thread(void *p) {
15   barrier_wait(&barrier);
16   __tsan_write1_pc((jptr)p, 1234 | kExternalPCBit);
17   return 0;
18 }
19 
main()20 int main() {
21   barrier_init(&barrier, 2);
22   int const kHeapSize = 1024 * 1024;
23   jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
24   __tsan_java_init(jheap, kHeapSize);
25   const int kBlockSize = 16;
26   __tsan_java_alloc(jheap, kBlockSize);
27   pthread_t th;
28   pthread_create(&th, 0, Thread, (void*)jheap);
29   __tsan_write1_pc((jptr)jheap, 1234 | kExternalPCBit);
30   barrier_wait(&barrier);
31   pthread_join(th, 0);
32   __tsan_java_free(jheap, kBlockSize);
33   fprintf(stderr, "DONE\n");
34   return __tsan_java_fini();
35 }
36 
37 // CHECK: WARNING: ThreadSanitizer: data race
38 // CHECK:     #0 MyInnerFunc MyInnerFile.java:1234:56
39 // CHECK:     #1 MyOuterFunc MyOuterFile.java:4321:65
40 // CHECK: DONE
41