PageRenderTime 243ms CodeModel.GetById 120ms app.highlight 4ms RepoModel.GetById 117ms app.codeStats 0ms

/libs/headers/gc/gc_typed.h

http://github.com/nddrylliog/ooc
C++ Header | 111 lines | 38 code | 13 blank | 60 comment | 0 complexity | e5a2690199a5700d490c9f9119393279 MD5 | raw file
  1/* 
  2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  3 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
  4 * Copyright 1996 Silicon Graphics.  All rights reserved.
  5 *
  6 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  7 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
  8 *
  9 * Permission is hereby granted to use or copy this program
 10 * for any purpose,  provided the above notices are retained on all copies.
 11 * Permission to modify the code and to distribute modified code is granted,
 12 * provided the above notices are retained, and a notice that the code was
 13 * modified is included with the above copyright notice.
 14 */
 15/*
 16 * Some simple primitives for allocation with explicit type information.
 17 * Facilities for dynamic type inference may be added later.
 18 * Should be used only for extremely performance critical applications,
 19 * or if conservative collector leakage is otherwise a problem (unlikely).
 20 * Note that this is implemented completely separately from the rest
 21 * of the collector, and is not linked in unless referenced.
 22 * This does not currently support GC_DEBUG in any interesting way.
 23 */
 24/* Boehm, May 19, 1994 2:13 pm PDT */
 25
 26#ifndef _GC_TYPED_H
 27# define _GC_TYPED_H
 28# ifndef _GC_H
 29#   include "gc.h"
 30# endif
 31
 32#ifdef __cplusplus
 33  extern "C" {
 34#endif
 35typedef GC_word * GC_bitmap;
 36	/* The least significant bit of the first word is one if	*/
 37	/* the first word in the object may be a pointer.		*/
 38	
 39# define GC_WORDSZ (8*sizeof(GC_word))
 40# define GC_get_bit(bm, index) \
 41		(((bm)[index/GC_WORDSZ] >> (index%GC_WORDSZ)) & 1)
 42# define GC_set_bit(bm, index) \
 43		(bm)[index/GC_WORDSZ] |= ((GC_word)1 << (index%GC_WORDSZ))
 44# define GC_WORD_OFFSET(t, f) (offsetof(t,f)/sizeof(GC_word))
 45# define GC_WORD_LEN(t) (sizeof(t)/ sizeof(GC_word))
 46# define GC_BITMAP_SIZE(t) ((GC_WORD_LEN(t) + GC_WORDSZ-1)/GC_WORDSZ)
 47
 48typedef GC_word GC_descr;
 49
 50GC_API GC_descr GC_make_descriptor(GC_bitmap bm, size_t len);
 51		/* Return a type descriptor for the object whose layout	*/
 52		/* is described by the argument.			*/
 53		/* The least significant bit of the first word is one	*/
 54		/* if the first word in the object may be a pointer.	*/
 55		/* The second argument specifies the number of		*/
 56		/* meaningful bits in the bitmap.  The actual object 	*/
 57		/* may be larger (but not smaller).  Any additional	*/
 58		/* words in the object are assumed not to contain 	*/
 59		/* pointers.						*/
 60		/* Returns a conservative approximation in the		*/
 61		/* (unlikely) case of insufficient memory to build	*/
 62		/* the descriptor.  Calls to GC_make_descriptor		*/
 63		/* may consume some amount of a finite resource.  This	*/
 64		/* is intended to be called once per type, not once	*/
 65		/* per allocation.					*/
 66
 67/* It is possible to generate a descriptor for a C type T with	*/
 68/* word aligned pointer fields f1, f2, ... as follows:			*/
 69/*									*/
 70/* GC_descr T_descr;                                                    */
 71/* GC_word T_bitmap[GC_BITMAP_SIZE(T)] = {0};				*/
 72/* GC_set_bit(T_bitmap, GC_WORD_OFFSET(T,f1));				*/
 73/* GC_set_bit(T_bitmap, GC_WORD_OFFSET(T,f2));				*/
 74/* ...									*/
 75/* T_descr = GC_make_descriptor(T_bitmap, GC_WORD_LEN(T));		*/
 76
 77GC_API void * GC_malloc_explicitly_typed(size_t size_in_bytes, GC_descr d);
 78		/* Allocate an object whose layout is described by d.	*/
 79		/* The resulting object MAY NOT BE PASSED TO REALLOC.	*/
 80		/* The returned object is cleared.			*/
 81
 82GC_API void * GC_malloc_explicitly_typed_ignore_off_page
 83                        (size_t size_in_bytes, GC_descr d);
 84		
 85GC_API void * GC_calloc_explicitly_typed(size_t nelements,
 86  				         size_t element_size_in_bytes,
 87  				         GC_descr d);
 88  	/* Allocate an array of nelements elements, each of the	*/
 89  	/* given size, and with the given descriptor.		*/
 90  	/* The elemnt size must be a multiple of the byte	*/
 91  	/* alignment required for pointers.  E.g. on a 32-bit	*/
 92  	/* machine with 16-bit aligned pointers, size_in_bytes	*/
 93  	/* must be a multiple of 2.				*/
 94	/* Returned object is cleared.				*/
 95
 96#ifdef GC_DEBUG
 97#   define GC_MALLOC_EXPLICITLY_TYPED(bytes, d) GC_MALLOC(bytes)
 98#   define GC_CALLOC_EXPLICITLY_TYPED(n, bytes, d) GC_MALLOC(n*bytes)
 99#else
100#  define GC_MALLOC_EXPLICITLY_TYPED(bytes, d) \
101	GC_malloc_explicitly_typed(bytes, d)
102#  define GC_CALLOC_EXPLICITLY_TYPED(n, bytes, d) \
103	GC_calloc_explicitly_typed(n, bytes, d)
104#endif /* !GC_DEBUG */
105
106#ifdef __cplusplus
107  } /* matches extern "C" */
108#endif
109
110#endif /* _GC_TYPED_H */
111