⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gc_md.h

📁 《移动Agent技术》一书的所有章节源代码。
💻 H
字号:
/*
 * @(#)gc_md.h  1.4 96/11/23
 *
 * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * CopyrightVersion 1.1_beta
 *
 */

#ifndef _GC_MD_H_
#define _GC_MD_H_

/*---- Win32 defines for garbage collection ----*/

#ifdef JMS_TRL                                                          /*ibm.5331*/

unsigned char *gc_locked(int acall, unsigned int free);   /* export */
unsigned char *gc0_locked(int acall, unsigned int free);  /* import */

#ifdef IBM_OS2                                                          /*ibm*/
extern mutex_t  _heap_lock;

#define sysHeapLockInit() mutexInit(&_heap_lock)
#define sysHeapLock()     mutexLock(&_heap_lock)
#define sysHeapUnlock()   mutexUnlock(&_heap_lock)
#define sysHeapLocked()   mutexLocked(&_heap_lock)
#else                                                                   /*ibm*/
#include "monitor_md.h"                                                 /*ibm.5344*/
extern sys_mon_t  _heap_lock;                                           /*ibm.6255*/

#ifdef IBM_LOCK_INSTRUM                                                 /*ibm.6406*/
#define sysHeapLockInit()     sysLockInit(_heap_lock)
#define sysHeapLock()         sysLock(_heap_lock)
#define sysHeapUnlock()       sysUnlock(_heap_lock)
#define sysHeapLocked()       sysLocked(_heap_lock)
#else                                                                   /*ibm.6406*/
#define sysHeapLockInit()     monitorRegister(&_heap_lock, "Heap Lock") /*ibm.6255*/
#define sysHeapLock()         sysMonitorEnter(&_heap_lock)              /*ibm.6255*/
#define sysHeapUnlock()       sysMonitorExit(&_heap_lock)               /*ibm.6255*/
#define sysHeapLocked()       sysMonitorEntered(&_heap_lock)            /*ibm.6255*/
#endif                                                                  /*ibm.6406*/
#endif                                                                  /*ibm*/

/* TODO: when supports both compaction and awt. */
/*
#define IMPORT __declspec(dllimport)
#define EXPORT __declspec(dllexport)

EXPORT void pin_handle(JHandle*);
EXPORT void unpin_handle(JHandle*);
*/
#endif /* JMS_TRL */                                                    /*ibm.5331*/

#ifdef DEBUG
/* local debug & error checking flag */
/* #define LDEBUG  1 */
/* Define below if you want lots of verbose info at runtime */
/* #define TRACEGC 1 */
/* define to send strs to debugger (on Mac) */
#undef DPRINTFDEBUG
#endif

#ifdef TRACEGC
/* define below for REALLY detailed print */
#undef TRACEMARK
#undef TRACEFREE
#undef TRACECOMPACT
#undef PDEBUG
#endif

#ifdef PAGED_HEAPS  /************ PAGED HEAPS: ********************/

/* In order for the OS to allocate many chunks of aligned memory, leave a little
 * room at the end of our chunks that the OS can use for it's own purposes for
 * the next allocation.
 */
#define OS_BLOCK_OVERHEAD  0        /* in bytes */

/* On MacOS for instance, sysMemAlign allocates a block that may not be aligned
 * and returns an aligned pointer into that block.  We may be able to use that
 * space, so keep track of it.
 */
#undef WASTED_SPACE_IN_LEADER

/* TUNING ISSUES:
 * On machines that don't have a real memalign, WASTED_SPACE_IN_LEADER will be
 * true.  So chosing a page size is a trade off between wasting up to a page
 * per chunk to achive alignment, and using up memory for a large page map.
 * Note that a page is the smallest ammount that the gc will request from the
 * OS, so it should be reasonable (eg. not 1M on a 4M machine!)
 *
 * AlignmentWaste(worst) = PAGE_ALIGNMENT / MIN_XXX_PAGES *
 *                         memory used / PAGE_ALIGNMENT;
 *                       = memory used / MIN_XXX_PAGES;
 * AlignmentWaste(avg)   = memory used / (2 * MIN_XXX_PAGES);
 *
 * PageMapSize(worst) = address space / PAGE_ALIGNMENT * 8
 *
 * MITIGATING FACTORS:
 *   A) The allocator tries to store the mark bits for a chunk in the aligment
 *      waste area.  Note that we need two mark bits for every two words, so:
 *          MarkBitsSize = memory used / 32;
 *      There are various round-off issues, but accounting for the savings of
 *      storing the marks in the waste:
 * AlignmentWaste(mitigated_avg) = memory used / (2 * MIN_XXX_PAGES) -
 *                                 memory used / 32;
 *      So, if you keep MIN_XXX_PAGES > 16, AlignmentWaste approaches zero.
 *
 *   B) The page map is only large enough to span the pages handed to us by the
 *      OS, and it's unlikly that the OS will give us some pages at 0x00000000,
 *      then a few more pages near 0xFFFFFFFF.
 *
 * So, keep MIN_XXX_PAGES > 16, maximize PAGE_ALIGNMENT (especially if address
 * space is large), but try to keep PAGE_ALIGNMENT * MIN_XXX_PAGES to a
 * size that the OS will usually be able to allocate.
 *
 */
#define PAGE_ALIGNMENT      (64 * 1024)  /* page size is the same. */

/* # of bits to shift a pointer to get a page number
 * 2 ^ PTR_2_PAGE_SHIFT == PAGE_ALIGNMENT  */
#define PTR_2_PAGE_SHIFT    (16)


#ifdef LDEBUG           /* stress testing */
#define MIN_OBJ_PAGES (2)         /* min # of pages to allocate for objects */
#define MIN_HANDLE_PAGES (2)      /* min # of pages to allocate for handles */
#else
#define MIN_OBJ_PAGES (32)        /* min # of pages to allocate for objects */
#define MIN_HANDLE_PAGES (8)      /* min # of pages to allocate for handles */
#endif /* LDEBUG */

#endif  /************ END PAGED HEAPS ********************/
#endif /* !_GC_MD_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -