Path: blob/main/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_interface_java.h
35266 views
//===-- tsan_interface_java.h -----------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of ThreadSanitizer (TSan), a race detector.9//10// Interface for verification of Java or mixed Java/C++ programs.11// The interface is intended to be used from within a JVM and notify TSan12// about such events like Java locks and GC memory compaction.13//14// For plain memory accesses and function entry/exit a JVM is intended to use15// C++ interfaces: __tsan_readN/writeN and __tsan_func_enter/exit.16//17// For volatile memory accesses and atomic operations JVM is intended to use18// standard atomics API: __tsan_atomicN_load/store/etc.19//20// For usage examples see lit_tests/java_*.cpp21//===----------------------------------------------------------------------===//22#ifndef TSAN_INTERFACE_JAVA_H23#define TSAN_INTERFACE_JAVA_H2425#ifndef INTERFACE_ATTRIBUTE26# define INTERFACE_ATTRIBUTE __attribute__((visibility("default")))27#endif2829#ifdef __cplusplus30extern "C" {31#endif3233typedef unsigned long jptr;3435// Must be called before any other callback from Java.36void __tsan_java_init(jptr heap_begin, jptr heap_size) INTERFACE_ATTRIBUTE;37// Must be called when the application exits.38// Not necessary the last callback (concurrently running threads are OK).39// Returns exit status or 0 if tsan does not want to override it.40int __tsan_java_fini() INTERFACE_ATTRIBUTE;4142// Callback for memory allocations.43// May be omitted for allocations that are not subject to data races44// nor contain synchronization objects (e.g. String).45void __tsan_java_alloc(jptr ptr, jptr size) INTERFACE_ATTRIBUTE;46// Callback for memory free.47// Can be aggregated for several objects (preferably).48void __tsan_java_free(jptr ptr, jptr size) INTERFACE_ATTRIBUTE;49// Callback for memory move by GC.50// Can be aggregated for several objects (preferably).51// The ranges can overlap.52void __tsan_java_move(jptr src, jptr dst, jptr size) INTERFACE_ATTRIBUTE;53// This function must be called on the finalizer thread54// before executing a batch of finalizers.55// It ensures necessary synchronization between56// java object creation and finalization.57void __tsan_java_finalize() INTERFACE_ATTRIBUTE;58// Finds the first allocated memory block in the [*from_ptr, to) range, saves59// its address in *from_ptr and returns its size. Returns 0 if there are no60// allocated memory blocks in the range.61jptr __tsan_java_find(jptr *from_ptr, jptr to) INTERFACE_ATTRIBUTE;6263// Mutex lock.64// Addr is any unique address associated with the mutex.65// Can be called on recursive reentry.66void __tsan_java_mutex_lock(jptr addr) INTERFACE_ATTRIBUTE;67// Mutex unlock.68void __tsan_java_mutex_unlock(jptr addr) INTERFACE_ATTRIBUTE;69// Mutex read lock.70void __tsan_java_mutex_read_lock(jptr addr) INTERFACE_ATTRIBUTE;71// Mutex read unlock.72void __tsan_java_mutex_read_unlock(jptr addr) INTERFACE_ATTRIBUTE;73// Recursive mutex lock, intended for handling of Object.wait().74// The 'rec' value must be obtained from the previous75// __tsan_java_mutex_unlock_rec().76void __tsan_java_mutex_lock_rec(jptr addr, int rec) INTERFACE_ATTRIBUTE;77// Recursive mutex unlock, intended for handling of Object.wait().78// The return value says how many times this thread called lock()79// w/o a pairing unlock() (i.e. how many recursive levels it unlocked).80// It must be passed back to __tsan_java_mutex_lock_rec() to restore81// the same recursion level.82int __tsan_java_mutex_unlock_rec(jptr addr) INTERFACE_ATTRIBUTE;8384// Raw acquire/release primitives.85// Can be used to establish happens-before edges on volatile/final fields,86// in atomic operations, etc. release_store is the same as release, but it87// breaks release sequence on addr (see C++ standard 1.10/7 for details).88void __tsan_java_acquire(jptr addr) INTERFACE_ATTRIBUTE;89void __tsan_java_release(jptr addr) INTERFACE_ATTRIBUTE;90void __tsan_java_release_store(jptr addr) INTERFACE_ATTRIBUTE;9192#ifdef __cplusplus93} // extern "C"94#endif9596#undef INTERFACE_ATTRIBUTE9798#endif // #ifndef TSAN_INTERFACE_JAVA_H99100101