From 963f5490e2140547b217174c9a168a7d7c98978c Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 14 Dec 2016 18:20:18 +0000 Subject: [PATCH] tsan: allow Java VM iterate over allocated objects Objects may move during the garbage collection, and JVM needs to notify ThreadAnalyzer about that. The new function __tsan_java_find eliminates the need to maintain these objects both in ThreadAnalyzer and JVM. Author: Alexander Smundak (asmundak) Reviewed in https://reviews.llvm.org/D27720 llvm-svn: 289682 --- compiler-rt/lib/tsan/rtl/tsan_interface_java.cc | 17 +++++++++++++++++ compiler-rt/lib/tsan/rtl/tsan_interface_java.h | 4 ++++ compiler-rt/test/tsan/java.h | 1 + 3 files changed, 22 insertions(+) diff --git a/compiler-rt/lib/tsan/rtl/tsan_interface_java.cc b/compiler-rt/lib/tsan/rtl/tsan_interface_java.cc index 95be85994c64..5bdc04f07567 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interface_java.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interface_java.cc @@ -150,6 +150,23 @@ void __tsan_java_move(jptr src, jptr dst, jptr size) { } } +jptr __tsan_java_find(jptr *from_ptr, jptr to) { + SCOPED_JAVA_FUNC(__tsan_java_find); + DPrintf("#%d: java_find(&%p, %p)\n", *from_ptr, to); + CHECK_EQ((*from_ptr) % kHeapAlignment, 0); + CHECK_EQ(to % kHeapAlignment, 0); + CHECK_GE(*from_ptr, jctx->heap_begin); + CHECK_LE(to, jctx->heap_begin + jctx->heap_size); + for (uptr from = *from_ptr; from < to; from += kHeapAlignment) { + MBlock *b = ctx->metamap.GetBlock(from); + if (b) { + *from_ptr = from; + return b->siz; + } + } + return 0; +} + void __tsan_java_finalize() { SCOPED_JAVA_FUNC(__tsan_java_finalize); DPrintf("#%d: java_mutex_finalize()\n", thr->tid); diff --git a/compiler-rt/lib/tsan/rtl/tsan_interface_java.h b/compiler-rt/lib/tsan/rtl/tsan_interface_java.h index 30153a1d8505..0bd49ac3c999 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interface_java.h +++ b/compiler-rt/lib/tsan/rtl/tsan_interface_java.h @@ -57,6 +57,10 @@ void __tsan_java_move(jptr src, jptr dst, jptr size) INTERFACE_ATTRIBUTE; // It ensures necessary synchronization between // java object creation and finalization. void __tsan_java_finalize() INTERFACE_ATTRIBUTE; +// Finds the first allocated memory block in the [*from_ptr, to) range, saves +// its address in *from_ptr and returns its size. Returns 0 if there are no +// allocated memory blocks in the range. +jptr __tsan_java_find(jptr *from_ptr, jptr to) INTERFACE_ATTRIBUTE; // Mutex lock. // Addr is any unique address associated with the mutex. diff --git a/compiler-rt/test/tsan/java.h b/compiler-rt/test/tsan/java.h index 565a7a7fdabf..e9aa4ee2440b 100644 --- a/compiler-rt/test/tsan/java.h +++ b/compiler-rt/test/tsan/java.h @@ -7,6 +7,7 @@ void __tsan_java_init(jptr heap_begin, jptr heap_size); int __tsan_java_fini(); void __tsan_java_alloc(jptr ptr, jptr size); void __tsan_java_free(jptr ptr, jptr size); +jptr __tsan_java_find(jptr *from_ptr, jptr to); void __tsan_java_move(jptr src, jptr dst, jptr size); void __tsan_java_finalize(); void __tsan_java_mutex_lock(jptr addr);