tsan_interface_java.h revision 280031
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). 53276789Sdim// The ranges can overlap. 54245614Sandrewvoid __tsan_java_move(jptr src, jptr dst, jptr size) INTERFACE_ATTRIBUTE; 55276789Sdim// This function must be called on the finalizer thread 56276789Sdim// before executing a batch of finalizers. 57276789Sdim// It ensures necessary synchronization between 58276789Sdim// java object creation and finalization. 59276789Sdimvoid __tsan_java_finalize() INTERFACE_ATTRIBUTE; 60245614Sandrew 61245614Sandrew// Mutex lock. 62245614Sandrew// Addr is any unique address associated with the mutex. 63251034Sed// Can be called on recursive reentry. 64245614Sandrewvoid __tsan_java_mutex_lock(jptr addr) INTERFACE_ATTRIBUTE; 65245614Sandrew// Mutex unlock. 66245614Sandrewvoid __tsan_java_mutex_unlock(jptr addr) INTERFACE_ATTRIBUTE; 67245614Sandrew// Mutex read lock. 68245614Sandrewvoid __tsan_java_mutex_read_lock(jptr addr) INTERFACE_ATTRIBUTE; 69245614Sandrew// Mutex read unlock. 70245614Sandrewvoid __tsan_java_mutex_read_unlock(jptr addr) INTERFACE_ATTRIBUTE; 71251034Sed// Recursive mutex lock, intended for handling of Object.wait(). 72251034Sed// The 'rec' value must be obtained from the previous 73251034Sed// __tsan_java_mutex_unlock_rec(). 74251034Sedvoid __tsan_java_mutex_lock_rec(jptr addr, int rec) INTERFACE_ATTRIBUTE; 75251034Sed// Recursive mutex unlock, intended for handling of Object.wait(). 76251034Sed// The return value says how many times this thread called lock() 77251034Sed// w/o a pairing unlock() (i.e. how many recursive levels it unlocked). 78251034Sed// It must be passed back to __tsan_java_mutex_lock_rec() to restore 79251034Sed// the same recursion level. 80251034Sedint __tsan_java_mutex_unlock_rec(jptr addr) INTERFACE_ATTRIBUTE; 81245614Sandrew 82280031Sdim// Raw acquire/release primitives. 83280031Sdim// Can be used to establish happens-before edges on volatile/final fields, 84280031Sdim// in atomic operations, etc. release_store is the same as release, but it 85280031Sdim// breaks release sequence on addr (see C++ standard 1.10/7 for details). 86280031Sdimvoid __tsan_java_acquire(jptr addr) INTERFACE_ATTRIBUTE; 87280031Sdimvoid __tsan_java_release(jptr addr) INTERFACE_ATTRIBUTE; 88280031Sdimvoid __tsan_java_release_store(jptr addr) INTERFACE_ATTRIBUTE; 89280031Sdim 90245614Sandrew#ifdef __cplusplus 91245614Sandrew} // extern "C" 92245614Sandrew#endif 93245614Sandrew 94245614Sandrew#undef INTERFACE_ATTRIBUTE 95245614Sandrew 96245614Sandrew#endif // #ifndef TSAN_INTERFACE_JAVA_H 97