GarbageCollector.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. struct Il2CppGuid;
  3. struct Il2CppIUnknown;
  4. struct Il2CppObject;
  5. struct Il2CppThread;
  6. namespace il2cpp
  7. {
  8. namespace gc
  9. {
  10. class GarbageCollector
  11. {
  12. public:
  13. static void Collect(int maxGeneration);
  14. static int32_t CollectALittle();
  15. static int32_t GetCollectionCount(int32_t generation);
  16. static int64_t GetUsedHeapSize();
  17. public:
  18. // internal
  19. typedef void (*FinalizerCallback)(void* object, void* client_data);
  20. // functions implemented in a GC agnostic manner
  21. static void InitializeFinalizer();
  22. static bool IsFinalizerThread(Il2CppThread* thread);
  23. static int32_t GetGeneration(void* addr);
  24. static void UninitializeFinalizers();
  25. static void UninitializeGC();
  26. static void NotifyFinalizers();
  27. static void RunFinalizer(void *obj, void *data);
  28. static void RegisterFinalizerForNewObject(Il2CppObject* obj);
  29. static void RegisterFinalizer(Il2CppObject* obj);
  30. static void SuppressFinalizer(Il2CppObject* obj);
  31. static void WaitForPendingFinalizers();
  32. static int32_t GetMaxGeneration();
  33. static void AddMemoryPressure(int64_t value);
  34. static Il2CppIUnknown* GetOrCreateCCW(Il2CppObject* obj, const Il2CppGuid& iid);
  35. // functions implemented in a GC specific manner
  36. static void Initialize();
  37. static void Enable();
  38. static void Disable();
  39. static FinalizerCallback RegisterFinalizerWithCallback(Il2CppObject* obj, FinalizerCallback callback);
  40. static int64_t GetAllocatedHeapSize();
  41. static void* MakeDescriptorForObject(size_t *bitmap, int numbits);
  42. static void* MakeDescriptorForString();
  43. static void* MakeDescriptorForArray();
  44. static void* AllocateFixed(size_t size, void *descr);
  45. static void FreeFixed(void* addr);
  46. static bool RegisterThread(void *baseptr);
  47. static bool UnregisterThread();
  48. static bool HasPendingFinalizers();
  49. static int32_t InvokeFinalizers();
  50. static void AddWeakLink(void **link_addr, Il2CppObject *obj, bool track);
  51. static void RemoveWeakLink(void **link_addr);
  52. static Il2CppObject *GetWeakLink(void **link_addr);
  53. /* Used by liveness code */
  54. static void StopWorld();
  55. static void StartWorld();
  56. typedef void (*HeapSectionCallback) (void* user_data, void* start, void* end);
  57. static void ForEachHeapSection(void* user_data, HeapSectionCallback callback);
  58. static size_t GetSectionCount();
  59. typedef void* (*GCCallWithAllocLockCallback)(void* user_data);
  60. static void* CallWithAllocLockHeld(GCCallWithAllocLockCallback callback, void* user_data);
  61. #if NET_4_0
  62. static void SetSkipThread(bool skip);
  63. #endif
  64. };
  65. } /* namespace vm */
  66. } /* namespace il2cpp */