tsan_interface_java.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //===-- tsan_interface_java.h -----------------------------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  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 TSan
  12. // 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 use
  15. // C++ interfaces: __tsan_readN/writeN and __tsan_func_enter/exit.
  16. //
  17. // For volatile memory accesses and atomic operations JVM is intended to use
  18. // standard atomics API: __tsan_atomicN_load/store/etc.
  19. //
  20. // For usage examples see lit_tests/java_*.cc
  21. //===----------------------------------------------------------------------===//
  22. #ifndef TSAN_INTERFACE_JAVA_H
  23. #define TSAN_INTERFACE_JAVA_H
  24. #ifndef INTERFACE_ATTRIBUTE
  25. # define INTERFACE_ATTRIBUTE __attribute__((visibility("default")))
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. typedef unsigned long jptr; // NOLINT
  31. // Must be called before any other callback from Java.
  32. void __tsan_java_init(jptr heap_begin, jptr heap_size) INTERFACE_ATTRIBUTE;
  33. // Must be called when the application exits.
  34. // Not necessary the last callback (concurrently running threads are OK).
  35. // Returns exit status or 0 if tsan does not want to override it.
  36. int __tsan_java_fini() INTERFACE_ATTRIBUTE;
  37. // Callback for memory allocations.
  38. // May be omitted for allocations that are not subject to data races
  39. // nor contain synchronization objects (e.g. String).
  40. void __tsan_java_alloc(jptr ptr, jptr size) INTERFACE_ATTRIBUTE;
  41. // Callback for memory free.
  42. // Can be aggregated for several objects (preferably).
  43. void __tsan_java_free(jptr ptr, jptr size) INTERFACE_ATTRIBUTE;
  44. // Callback for memory move by GC.
  45. // Can be aggregated for several objects (preferably).
  46. // The ranges can overlap.
  47. void __tsan_java_move(jptr src, jptr dst, jptr size) INTERFACE_ATTRIBUTE;
  48. // This function must be called on the finalizer thread
  49. // before executing a batch of finalizers.
  50. // It ensures necessary synchronization between
  51. // java object creation and finalization.
  52. void __tsan_java_finalize() INTERFACE_ATTRIBUTE;
  53. // Mutex lock.
  54. // Addr is any unique address associated with the mutex.
  55. // Can be called on recursive reentry.
  56. void __tsan_java_mutex_lock(jptr addr) INTERFACE_ATTRIBUTE;
  57. // Mutex unlock.
  58. void __tsan_java_mutex_unlock(jptr addr) INTERFACE_ATTRIBUTE;
  59. // Mutex read lock.
  60. void __tsan_java_mutex_read_lock(jptr addr) INTERFACE_ATTRIBUTE;
  61. // Mutex read unlock.
  62. void __tsan_java_mutex_read_unlock(jptr addr) INTERFACE_ATTRIBUTE;
  63. // Recursive mutex lock, intended for handling of Object.wait().
  64. // The 'rec' value must be obtained from the previous
  65. // __tsan_java_mutex_unlock_rec().
  66. void __tsan_java_mutex_lock_rec(jptr addr, int rec) INTERFACE_ATTRIBUTE;
  67. // Recursive mutex unlock, intended for handling of Object.wait().
  68. // The return value says how many times this thread called lock()
  69. // w/o a pairing unlock() (i.e. how many recursive levels it unlocked).
  70. // It must be passed back to __tsan_java_mutex_lock_rec() to restore
  71. // the same recursion level.
  72. int __tsan_java_mutex_unlock_rec(jptr addr) INTERFACE_ATTRIBUTE;
  73. #ifdef __cplusplus
  74. } // extern "C"
  75. #endif
  76. #undef INTERFACE_ATTRIBUTE
  77. #endif // #ifndef TSAN_INTERFACE_JAVA_H