home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / gc_md.h < prev    next >
C/C++ Source or Header  |  1997-11-24  |  4KB  |  109 lines

  1. /*
  2.  * @(#)gc_md.h    1.4 96/11/23
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. #ifndef _GC_MD_H_
  24. #define _GC_MD_H_
  25.  
  26. /*---- Win32 defines for garbage collection ----*/
  27.  
  28. #ifdef DEBUG
  29. /* local debug & error checking flag */
  30. /* #define LDEBUG  1 */
  31. /* Define below if you want lots of verbose info at runtime */
  32. /* #define TRACEGC 1 */
  33. /* define to send strs to debugger (on Mac) */
  34. #undef DPRINTFDEBUG
  35. #endif
  36.  
  37. #ifdef TRACEGC
  38. /* define below for REALLY detailed print */
  39. #undef TRACEMARK
  40. #undef TRACEFREE
  41. #undef TRACECOMPACT
  42. #undef PDEBUG
  43. #endif
  44.  
  45. #ifdef PAGED_HEAPS  /************ PAGED HEAPS: ********************/
  46.  
  47. /* In order for the OS to allocate many chunks of aligned memory, leave a little
  48.  * room at the end of our chunks that the OS can use for it's own purposes for 
  49.  * the next allocation.
  50.  */ 
  51. #define OS_BLOCK_OVERHEAD  0        /* in bytes */
  52.  
  53. /* On MacOS for instance, sysMemAlign allocates a block that may not be aligned
  54.  * and returns an aligned pointer into that block.  We may be able to use that
  55.  * space, so keep track of it.
  56.  */
  57. #undef WASTED_SPACE_IN_LEADER
  58.  
  59. /* TUNING ISSUES:
  60.  * On machines that don't have a real memalign, WASTED_SPACE_IN_LEADER will be
  61.  * true.  So chosing a page size is a trade off between wasting up to a page
  62.  * per chunk to achive alignment, and using up memory for a large page map.
  63.  * Note that a page is the smallest ammount that the gc will request from the
  64.  * OS, so it should be reasonable (eg. not 1M on a 4M machine!)
  65.  *
  66.  * AlignmentWaste(worst) = PAGE_ALIGNMENT / MIN_XXX_PAGES * 
  67.  *                         memory used / PAGE_ALIGNMENT;
  68.  *                       = memory used / MIN_XXX_PAGES;
  69.  * AlignmentWaste(avg)   = memory used / (2 * MIN_XXX_PAGES);
  70.  *
  71.  * PageMapSize(worst) = address space / PAGE_ALIGNMENT * 8
  72.  *
  73.  * MITIGATING FACTORS:
  74.  *   A) The allocator tries to store the mark bits for a chunk in the aligment
  75.  *      waste area.  Note that we need two mark bits for every two words, so:
  76.  *          MarkBitsSize = memory used / 32;
  77.  *      There are various round-off issues, but accounting for the savings of 
  78.  *      storing the marks in the waste:
  79.  * AlignmentWaste(mitigated_avg) = memory used / (2 * MIN_XXX_PAGES) - 
  80.  *                                 memory used / 32;
  81.  *      So, if you keep    MIN_XXX_PAGES > 16, AlignmentWaste approaches zero.
  82.  *
  83.  *   B) The page map is only large enough to span the pages handed to us by the
  84.  *      OS, and it's unlikly that the OS will give us some pages at 0x00000000,
  85.  *      then a few more pages near 0xFFFFFFFF.
  86.  *
  87.  * So, keep MIN_XXX_PAGES > 16, maximize PAGE_ALIGNMENT (especially if address 
  88.  * space is large), but try to keep PAGE_ALIGNMENT * MIN_XXX_PAGES to a
  89.  * size that the OS will usually be able to allocate.
  90.  *
  91.  */
  92. #define PAGE_ALIGNMENT        (64 * 1024)  /* page size is the same. */
  93.  
  94. /* # of bits to shift a pointer to get a page number
  95.  * 2 ^ PTR_2_PAGE_SHIFT == PAGE_ALIGNMENT  */
  96. #define PTR_2_PAGE_SHIFT    (16)
  97.  
  98.  
  99. #ifdef LDEBUG        /* stress testing */
  100. #define MIN_OBJ_PAGES (2)      /* min # of pages to allocate for objects */
  101. #define MIN_HANDLE_PAGES (2)      /* min # of pages to allocate for handles */
  102. #else
  103. #define MIN_OBJ_PAGES (32)      /* min # of pages to allocate for objects */
  104. #define MIN_HANDLE_PAGES (8)      /* min # of pages to allocate for handles */
  105. #endif /* LDEBUG */
  106.  
  107. #endif  /************ END PAGED HEAPS ********************/
  108. #endif /* !_GC_MD_H_ */
  109.