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

📄 gc_pmark.h

📁 著名的boost库
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
 * Copyright (c) 2001 by Hewlett-Packard Company. All rights reserved.
 *
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 *
 * Permission is hereby granted to use or copy this program
 * for any purpose,  provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */

/* Private declarations of GC marker data structures and macros */

/*
 * Declarations of mark stack.  Needed by marker and client supplied mark
 * routines.  Transitively include gc_priv.h.
 * (Note that gc_priv.h should not be included before this, since this
 * includes dbg_mlc.h, which wants to include gc_priv.h AFTER defining
 * I_HIDE_POINTERS.)
 */
#ifndef GC_PMARK_H
# define GC_PMARK_H

# if defined(KEEP_BACK_PTRS) || defined(PRINT_BLACK_LIST)
#   include "dbg_mlc.h"
# endif
# ifndef GC_MARK_H
#   include "../gc_mark.h"
# endif
# ifndef GC_PRIVATE_H
#   include "gc_priv.h"
# endif

/* The real declarations of the following is in gc_priv.h, so that	*/
/* we can avoid scanning the following table.				*/
/*
extern mark_proc GC_mark_procs[MAX_MARK_PROCS];
*/

/*
 * Mark descriptor stuff that should remain private for now, mostly
 * because it's hard to export WORDSZ without including gcconfig.h.
 */
# define BITMAP_BITS (WORDSZ - GC_DS_TAG_BITS)
# define PROC(descr) \
	(GC_mark_procs[((descr) >> GC_DS_TAG_BITS) & (GC_MAX_MARK_PROCS-1)])
# define ENV(descr) \
	((descr) >> (GC_DS_TAG_BITS + GC_LOG_MAX_MARK_PROCS))
# define MAX_ENV \
  	(((word)1 << (WORDSZ - GC_DS_TAG_BITS - GC_LOG_MAX_MARK_PROCS)) - 1)


extern unsigned GC_n_mark_procs;

/* Number of mark stack entries to discard on overflow.	*/
#define GC_MARK_STACK_DISCARDS (INITIAL_MARK_STACK_SIZE/8)

typedef struct GC_ms_entry {
    ptr_t mse_start;   /* First word of object */
    GC_word mse_descr;	/* Descriptor; low order two bits are tags,	*/
    			/* identifying the upper 30 bits as one of the	*/
    			/* following:					*/
} mse;

extern size_t GC_mark_stack_size;

extern mse * GC_mark_stack_limit;

#ifdef PARALLEL_MARK
  extern mse * volatile GC_mark_stack_top;
#else
  extern mse * GC_mark_stack_top;
#endif

extern mse * GC_mark_stack;

#ifdef PARALLEL_MARK
    /*
     * Allow multiple threads to participate in the marking process.
     * This works roughly as follows:
     *  The main mark stack never shrinks, but it can grow.
     *
     *	The initiating threads holds the GC lock, and sets GC_help_wanted.
     *  
     *  Other threads:
     *     1) update helper_count (while holding mark_lock.)
     *	   2) allocate a local mark stack
     *     repeatedly:
     *		3) Steal a global mark stack entry by atomically replacing
     *		   its descriptor with 0.
     *		4) Copy it to the local stack.
     *	        5) Mark on the local stack until it is empty, or
     *		   it may be profitable to copy it back.
     *	        6) If necessary, copy local stack to global one,
     *		   holding mark lock.
     *    7) Stop when the global mark stack is empty.
     *    8) decrement helper_count (holding mark_lock).
     *
     * This is an experiment to see if we can do something along the lines
     * of the University of Tokyo SGC in a less intrusive, though probably
     * also less performant, way.
     */
    void GC_do_parallel_mark();
		/* inititate parallel marking.	*/

    extern GC_bool GC_help_wanted;	/* Protected by mark lock	*/
    extern unsigned GC_helper_count;	/* Number of running helpers.	*/
					/* Protected by mark lock	*/
    extern unsigned GC_active_count;	/* Number of active helpers.	*/
					/* Protected by mark lock	*/
					/* May increase and decrease	*/
					/* within each mark cycle.  But	*/
					/* once it returns to 0, it	*/
					/* stays zero for the cycle.	*/
    /* GC_mark_stack_top is also protected by mark lock.	*/
    /*
     * GC_notify_all_marker() is used when GC_help_wanted is first set,
     * when the last helper becomes inactive,
     * when something is added to the global mark stack, and just after
     * GC_mark_no is incremented.
     * This could be split into multiple CVs (and probably should be to
     * scale to really large numbers of processors.)
     */
#endif /* PARALLEL_MARK */

/* Return a pointer to within 1st page of object.  	*/
/* Set *new_hdr_p to corr. hdr.				*/
ptr_t GC_find_start(ptr_t current, hdr *hhdr, hdr **new_hdr_p);

mse * GC_signal_mark_stack_overflow(mse *msp);

/* Push the object obj with corresponding heap block header hhdr onto 	*/
/* the mark stack.							*/
# define PUSH_OBJ(obj, hhdr, mark_stack_top, mark_stack_limit) \
{ \
    register word _descr = (hhdr) -> hb_descr; \
        \
    if (_descr != 0) { \
        mark_stack_top++; \
        if (mark_stack_top >= mark_stack_limit) { \
          mark_stack_top = GC_signal_mark_stack_overflow(mark_stack_top); \
        } \
        mark_stack_top -> mse_start = (obj); \
        mark_stack_top -> mse_descr = _descr; \
    } \
}

/* Push the contents of current onto the mark stack if it is a valid	*/
/* ptr to a currently unmarked object.  Mark it.			*/
/* If we assumed a standard-conforming compiler, we could probably	*/
/* generate the exit_label transparently.				*/
# define PUSH_CONTENTS(current, mark_stack_top, mark_stack_limit, \
		       source, exit_label) \
{ \
    hdr * my_hhdr; \
 \
    HC_GET_HDR(current, my_hhdr, source, exit_label); \
    PUSH_CONTENTS_HDR(current, mark_stack_top, mark_stack_limit, \
		  source, exit_label, my_hhdr, TRUE);	\
exit_label: ; \
}

/* Set mark bit, exit if it was already set.	*/

# ifdef USE_MARK_BITS
#   ifdef PARALLEL_MARK
      /* The following may fail to exit even if the bit was already set.    */
      /* For our uses, that's benign:                                       */
#     define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
        { \
          if (!(*(addr) & (mask))) { \
            AO_or((AO_t *)(addr), (mask); \
          } else { \
            goto label; \
          } \
        }
#   else
#     define OR_WORD_EXIT_IF_SET(addr, bits, exit_label) \
        { \
           word old = *(addr); \
           word my_bits = (bits); \
           if (old & my_bits) goto exit_label; \
           *(addr) = (old | my_bits); \
         }
#   endif /* !PARALLEL_MARK */
#   define SET_MARK_BIT_EXIT_IF_SET(hhdr,bit_no,exit_label) \
    { \
        word * mark_word_addr = hhdr -> hb_marks + divWORDSZ(bit_no); \
      \
        OR_WORD_EXIT_IF_SET(mark_word_addr, (word)1 << modWORDSZ(bit_no), \
                            exit_label); \
    }
# endif


#ifdef USE_MARK_BYTES
# if defined(I386) && defined(__GNUC__)
#  define LONG_MULT(hprod, lprod, x, y) { \
	asm("mull %2" : "=a"(lprod), "=d"(hprod) : "g"(y), "0"(x)); \
   }
# else /* No in-line X86 assembly code */
#  define LONG_MULT(hprod, lprod, x, y) { \
	unsigned long long prod = (unsigned long long)x \
				  * (unsigned long long)y; \
	hprod = prod >> 32;  \
	lprod = (unsigned32)prod;  \
   }
# endif

  /* There is a race here, and we may set				*/
  /* the bit twice in the concurrent case.  This can result in the	*/
  /* object being pushed twice.  But that's only a performance issue.	*/
# define SET_MARK_BIT_EXIT_IF_SET(hhdr,bit_no,exit_label) \
    { \
        char * mark_byte_addr = (char *)hhdr -> hb_marks + (bit_no); \
        char mark_byte = *mark_byte_addr; \
          \
	if (mark_byte) goto exit_label; \
	*mark_byte_addr = 1;  \
    } 
#endif /* USE_MARK_BYTES */

#ifdef PARALLEL_MARK
# define INCR_MARKS(hhdr) \
	AO_store(&(hhdr -> hb_n_marks), AO_load(&(hhdr -> hb_n_marks))+1);
#else
# define INCR_MARKS(hhdr) ++(hhdr -> hb_n_marks)
#endif

#ifdef ENABLE_TRACE
# define TRACE(source, cmd) \
	if (GC_trace_addr != 0 && (ptr_t)(source) == GC_trace_addr) cmd
# define TRACE_TARGET(target, cmd) \
	if (GC_trace_addr != 0 && (target) == *(ptr_t *)GC_trace_addr) cmd
#else
# define TRACE(source, cmd)
# define TRACE_TARGET(source, cmd)
#endif
/* If the mark bit corresponding to current is not set, set it, and 	*/
/* push the contents of the object on the mark stack.  Current points	*/
/* to the bginning of the object.  We rely on the fact that the 	*/
/* preceding header calculation will succeed for a pointer past the 	*/
/* forst page of an object, only if it is in fact a valid pointer	*/
/* to the object.  Thus we can omit the otherwise necessary tests	*/

⌨️ 快捷键说明

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