gc_backptr.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
  3. * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
  4. * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
  5. * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
  6. * All rights reserved.
  7. *
  8. * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  9. * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
  10. *
  11. * Permission is hereby granted to use or copy this program
  12. * for any purpose, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. */
  17. /*
  18. * This is a simple API to implement pointer back tracing, i.e.
  19. * to answer questions such as "who is pointing to this" or
  20. * "why is this object being retained by the collector"
  21. *
  22. * Most of these calls yield useful information on only after
  23. * a garbage collection. Usually the client will first force
  24. * a full collection and then gather information, preferably
  25. * before much intervening allocation.
  26. *
  27. * The implementation of the interface is only about 99.9999%
  28. * correct. It is intended to be good enough for profiling,
  29. * but is not intended to be used with production code.
  30. *
  31. * Results are likely to be much more useful if all allocation is
  32. * accomplished through the debugging allocators.
  33. *
  34. * The implementation idea is due to A. Demers.
  35. */
  36. #ifndef GC_BACKPTR_H
  37. #define GC_BACKPTR_H
  38. #ifndef GC_H
  39. # include "gc.h"
  40. #endif
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /* Store information about the object referencing dest in *base_p */
  45. /* and *offset_p. */
  46. /* If multiple objects or roots point to dest, the one reported */
  47. /* will be the last on used by the garbage collector to trace the */
  48. /* object. */
  49. /* source is root ==> *base_p = address, *offset_p = 0 */
  50. /* source is heap object ==> *base_p != 0, *offset_p = offset */
  51. /* Returns 1 on success, 0 if source couldn't be determined. */
  52. /* Dest can be any address within a heap object. */
  53. typedef enum {
  54. GC_UNREFERENCED, /* No reference info available. */
  55. GC_NO_SPACE, /* Dest not allocated with debug alloc. */
  56. GC_REFD_FROM_ROOT, /* Referenced directly by root *base_p. */
  57. GC_REFD_FROM_REG, /* Referenced from a register, i.e. */
  58. /* a root without an address. */
  59. GC_REFD_FROM_HEAP, /* Referenced from another heap obj. */
  60. GC_FINALIZER_REFD /* Finalizable and hence accessible. */
  61. } GC_ref_kind;
  62. GC_API GC_ref_kind GC_CALL GC_get_back_ptr_info(void * /* dest */,
  63. void ** /* base_p */, size_t * /* offset_p */)
  64. GC_ATTR_NONNULL(1);
  65. /* Generate a random heap address. */
  66. /* The resulting address is in the heap, but */
  67. /* not necessarily inside a valid object. */
  68. GC_API void * GC_CALL GC_generate_random_heap_address(void);
  69. /* Generate a random address inside a valid marked heap object. */
  70. GC_API void * GC_CALL GC_generate_random_valid_address(void);
  71. /* Force a garbage collection and generate a backtrace from a */
  72. /* random heap address. */
  73. /* This uses the GC logging mechanism (GC_printf) to produce */
  74. /* output. It can often be called from a debugger. The */
  75. /* source in dbg_mlc.c also serves as a sample client. */
  76. GC_API void GC_CALL GC_generate_random_backtrace(void);
  77. /* Print a backtrace from a specific address. Used by the */
  78. /* above. The client should call GC_gcollect() immediately */
  79. /* before invocation. */
  80. GC_API void GC_CALL GC_print_backtrace(void *) GC_ATTR_NONNULL(1);
  81. #ifdef __cplusplus
  82. } /* extern "C" */
  83. #endif
  84. #endif /* GC_BACKPTR_H */