gc_gcj.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  3. * Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
  4. * Copyright 1996-1999 by Silicon Graphics. All rights reserved.
  5. * Copyright 1999 by Hewlett-Packard Company. All rights reserved.
  6. *
  7. * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  8. * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
  9. *
  10. * Permission is hereby granted to use or copy this program
  11. * for any purpose, provided the above notices are retained on all copies.
  12. * Permission to modify the code and to distribute modified code is granted,
  13. * provided the above notices are retained, and a notice that the code was
  14. * modified is included with the above copyright notice.
  15. */
  16. /* This file assumes the collector has been compiled with GC_GCJ_SUPPORT. */
  17. /*
  18. * We allocate objects whose first word contains a pointer to a struct
  19. * describing the object type. This struct contains a garbage collector mark
  20. * descriptor at offset MARK_DESCR_OFFSET. Alternatively, the objects
  21. * may be marked by the mark procedure passed to GC_init_gcj_malloc.
  22. */
  23. #ifndef GC_GCJ_H
  24. #define GC_GCJ_H
  25. /* Gcj keeps GC descriptor as second word of vtable. This */
  26. /* probably needs to be adjusted for other clients. */
  27. /* We currently assume that this offset is such that: */
  28. /* - all objects of this kind are large enough to have */
  29. /* a value at that offset, and */
  30. /* - it is not zero. */
  31. /* These assumptions allow objects on the free list to be */
  32. /* marked normally. */
  33. #ifndef GC_H
  34. # include "gc.h"
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /* The following allocators signal an out of memory condition with */
  40. /* return GC_oom_fn(bytes); */
  41. /* The following function must be called before the gcj allocators */
  42. /* can be invoked. */
  43. /* mp_index and mp are the index and mark_proc (see gc_mark.h) */
  44. /* respectively for the allocated objects. Mark_proc will be */
  45. /* used to build the descriptor for objects allocated through the */
  46. /* debugging interface. The mark_proc will be invoked on all such */
  47. /* objects with an "environment" value of 1. The client may choose */
  48. /* to use the same mark_proc for some of its generated mark descriptors.*/
  49. /* In that case, it should use a different "environment" value to */
  50. /* detect the presence or absence of the debug header. */
  51. /* Mp is really of type mark_proc, as defined in gc_mark.h. We don't */
  52. /* want to include that here for namespace pollution reasons. */
  53. /* Passing in mp_index here instead of having GC_init_gcj_malloc() */
  54. /* internally call GC_new_proc() is quite ugly, but in typical usage */
  55. /* scenarios a compiler also has to know about mp_index, so */
  56. /* generating it dynamically is not acceptable. Mp_index will */
  57. /* typically be an integer < RESERVED_MARK_PROCS, so that it doesn't */
  58. /* collide with GC_new_proc allocated indices. If the application */
  59. /* needs no other reserved indices, zero */
  60. /* (GC_GCJ_RESERVED_MARK_PROC_INDEX in gc_mark.h) is an obvious choice. */
  61. GC_API void GC_CALL GC_init_gcj_malloc(int /* mp_index */,
  62. void * /* really mark_proc */ /* mp */);
  63. /* Allocate an object, clear it, and store the pointer to the */
  64. /* type structure (vtable in gcj). */
  65. /* This adds a byte at the end of the object if GC_malloc would.*/
  66. GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL
  67. GC_gcj_malloc(size_t /* lb */,
  68. void * /* ptr_to_struct_containing_descr */);
  69. /* The debug versions allocate such that the specified mark_proc */
  70. /* is always invoked. */
  71. GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL
  72. GC_debug_gcj_malloc(size_t /* lb */,
  73. void * /* ptr_to_struct_containing_descr */,
  74. GC_EXTRA_PARAMS);
  75. /* Similar to GC_gcj_malloc, but assumes that a pointer to near the */
  76. /* beginning of the resulting object is always maintained. */
  77. GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void * GC_CALL
  78. GC_gcj_malloc_ignore_off_page(size_t /* lb */,
  79. void * /* ptr_to_struct_containing_descr */);
  80. /* The kind numbers of normal and debug gcj objects. */
  81. /* Useful only for debug support, we hope. */
  82. GC_API int GC_gcj_kind;
  83. GC_API int GC_gcj_debug_kind;
  84. #ifdef GC_DEBUG
  85. # define GC_GCJ_MALLOC(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS)
  86. # define GC_GCJ_MALLOC_IGNORE_OFF_PAGE(s,d) GC_debug_gcj_malloc(s,d,GC_EXTRAS)
  87. #else
  88. # define GC_GCJ_MALLOC(s,d) GC_gcj_malloc(s,d)
  89. # define GC_GCJ_MALLOC_IGNORE_OFF_PAGE(s,d) GC_gcj_malloc_ignore_off_page(s,d)
  90. #endif
  91. #ifdef __cplusplus
  92. } /* extern "C" */
  93. #endif
  94. #endif /* GC_GCJ_H */