ems_gc.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. /**
  6. * @file ems_gc.h
  7. * @date Wed Aug 3 10:46:38 2011
  8. *
  9. * @brief This file defines GC modules types and interfaces.
  10. *
  11. *
  12. */
  13. #ifndef _EMS_GC_H
  14. #define _EMS_GC_H
  15. #include "bh_platform.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #define GC_HEAD_PADDING 4
  20. #define NULL_REF ((gc_object_t)NULL)
  21. #define GC_SUCCESS (0)
  22. #define GC_ERROR (-1)
  23. #define GC_TRUE (1)
  24. #define GC_FALSE (0)
  25. #define GC_MAX_HEAP_SIZE (256 * BH_KB)
  26. typedef void * gc_handle_t;
  27. typedef void * gc_object_t;
  28. typedef int64 gc_int64;
  29. typedef uint32 gc_uint32;
  30. typedef int32 gc_int32;
  31. typedef uint16 gc_uint16;
  32. typedef int16 gc_int16;
  33. typedef uint8 gc_uint8;
  34. typedef int8 gc_int8;
  35. typedef uint32 gc_size_t;
  36. typedef enum {
  37. GC_STAT_TOTAL = 0,
  38. GC_STAT_FREE,
  39. GC_STAT_HIGHMARK,
  40. } GC_STAT_INDEX;
  41. /**
  42. * GC initialization from a buffer
  43. *
  44. * @param buf the buffer to be initialized to a heap
  45. * @param buf_size the size of buffer
  46. *
  47. * @return gc handle if success, NULL otherwise
  48. */
  49. gc_handle_t
  50. gc_init_with_pool(char *buf, gc_size_t buf_size);
  51. /**
  52. * Destroy heap which is initilized from a buffer
  53. *
  54. * @param handle handle to heap needed destroy
  55. *
  56. * @return GC_SUCCESS if success
  57. * GC_ERROR for bad parameters or failed system resource freeing.
  58. */
  59. int
  60. gc_destroy_with_pool(gc_handle_t handle);
  61. /**
  62. * Get Heap Stats
  63. *
  64. * @param stats [out] integer array to save heap stats
  65. * @param size [in] the size of stats
  66. * @param mmt [in] type of heap, MMT_SHARED or MMT_INSTANCE
  67. */
  68. void *
  69. gc_heap_stats(void *heap, uint32* stats, int size);
  70. #if BH_ENABLE_GC_VERIFY == 0
  71. gc_object_t
  72. gc_alloc_vo(void *heap, gc_size_t size);
  73. gc_object_t
  74. gc_realloc_vo(void *heap, void *ptr, gc_size_t size);
  75. int
  76. gc_free_vo(void *heap, gc_object_t obj);
  77. #else /* else of BH_ENABLE_GC_VERIFY */
  78. gc_object_t
  79. gc_alloc_vo_internal(void *heap, gc_size_t size,
  80. const char *file, int line);
  81. gc_object_t
  82. gc_realloc_vo_internal(void *heap, void *ptr, gc_size_t size,
  83. const char *file, int line);
  84. int
  85. gc_free_vo_internal(void *heap, gc_object_t obj,
  86. const char *file, int line);
  87. #define gc_alloc_vo(heap, size) \
  88. gc_alloc_vo_internal(heap, size, __FILE__, __LINE__)
  89. #define gc_realloc_vo(heap, ptr, size) \
  90. gc_realloc_vo_internal(heap, ptr, size, __FILE__, __LINE__)
  91. #define gc_free_vo(heap, obj) \
  92. gc_free_vo_internal(heap, obj, __FILE__, __LINE__)
  93. #endif /* end of BH_ENABLE_GC_VERIFY */
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif