tsan_interface_java.h revision 245614
1245614Sandrew//===-- tsan_interface_java.h -----------------------------------*- C++ -*-===// 2245614Sandrew// 3245614Sandrew// The LLVM Compiler Infrastructure 4245614Sandrew// 5245614Sandrew// This file is distributed under the University of Illinois Open Source 6245614Sandrew// License. See LICENSE.TXT for details. 7245614Sandrew// 8245614Sandrew//===----------------------------------------------------------------------===// 9245614Sandrew// 10245614Sandrew// This file is a part of ThreadSanitizer (TSan), a race detector. 11245614Sandrew// 12245614Sandrew// Interface for verification of Java or mixed Java/C++ programs. 13245614Sandrew// The interface is intended to be used from within a JVM and notify TSan 14245614Sandrew// about such events like Java locks and GC memory compaction. 15245614Sandrew// 16245614Sandrew// For plain memory accesses and function entry/exit a JVM is intended to use 17245614Sandrew// C++ interfaces: __tsan_readN/writeN and __tsan_func_enter/exit. 18245614Sandrew// 19245614Sandrew// For volatile memory accesses and atomic operations JVM is intended to use 20245614Sandrew// standard atomics API: __tsan_atomicN_load/store/etc. 21245614Sandrew// 22245614Sandrew// For usage examples see lit_tests/java_*.cc 23245614Sandrew//===----------------------------------------------------------------------===// 24245614Sandrew#ifndef TSAN_INTERFACE_JAVA_H 25245614Sandrew#define TSAN_INTERFACE_JAVA_H 26245614Sandrew 27245614Sandrew#ifndef INTERFACE_ATTRIBUTE 28245614Sandrew# define INTERFACE_ATTRIBUTE __attribute__((visibility("default"))) 29245614Sandrew#endif 30245614Sandrew 31245614Sandrew#ifdef __cplusplus 32245614Sandrewextern "C" { 33245614Sandrew#endif 34245614Sandrew 35245614Sandrewtypedef unsigned long jptr; // NOLINT 36245614Sandrew 37245614Sandrew// Must be called before any other callback from Java. 38245614Sandrewvoid __tsan_java_init(jptr heap_begin, jptr heap_size) INTERFACE_ATTRIBUTE; 39245614Sandrew// Must be called when the application exits. 40245614Sandrew// Not necessary the last callback (concurrently running threads are OK). 41245614Sandrew// Returns exit status or 0 if tsan does not want to override it. 42245614Sandrewint __tsan_java_fini() INTERFACE_ATTRIBUTE; 43245614Sandrew 44245614Sandrew// Callback for memory allocations. 45245614Sandrew// May be omitted for allocations that are not subject to data races 46245614Sandrew// nor contain synchronization objects (e.g. String). 47245614Sandrewvoid __tsan_java_alloc(jptr ptr, jptr size) INTERFACE_ATTRIBUTE; 48245614Sandrew// Callback for memory free. 49245614Sandrew// Can be aggregated for several objects (preferably). 50245614Sandrewvoid __tsan_java_free(jptr ptr, jptr size) INTERFACE_ATTRIBUTE; 51245614Sandrew// Callback for memory move by GC. 52245614Sandrew// Can be aggregated for several objects (preferably). 53245614Sandrew// The ranges must not overlap. 54245614Sandrewvoid __tsan_java_move(jptr src, jptr dst, jptr size) INTERFACE_ATTRIBUTE; 55245614Sandrew 56245614Sandrew// Mutex lock. 57245614Sandrew// Addr is any unique address associated with the mutex. 58245614Sandrew// Must not be called on recursive reentry. 59245614Sandrew// Object.wait() is handled as a pair of unlock/lock. 60245614Sandrewvoid __tsan_java_mutex_lock(jptr addr) INTERFACE_ATTRIBUTE; 61245614Sandrew// Mutex unlock. 62245614Sandrewvoid __tsan_java_mutex_unlock(jptr addr) INTERFACE_ATTRIBUTE; 63245614Sandrew// Mutex read lock. 64245614Sandrewvoid __tsan_java_mutex_read_lock(jptr addr) INTERFACE_ATTRIBUTE; 65245614Sandrew// Mutex read unlock. 66245614Sandrewvoid __tsan_java_mutex_read_unlock(jptr addr) INTERFACE_ATTRIBUTE; 67245614Sandrew 68245614Sandrew#ifdef __cplusplus 69245614Sandrew} // extern "C" 70245614Sandrew#endif 71245614Sandrew 72245614Sandrew#undef INTERFACE_ATTRIBUTE 73245614Sandrew 74245614Sandrew#endif // #ifndef TSAN_INTERFACE_JAVA_H 75