Skip to content
Snippets Groups Projects
misc.c 32.3 KiB
Newer Older
tromey's avatar
tromey committed
/* 
 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
 * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
 * Copyright (c) 1999-2001 by Hewlett-Packard Company. All rights reserved.
tromey's avatar
tromey committed
 *
 * 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.
 */
/* Boehm, July 31, 1995 5:02 pm PDT */


#include <stdio.h>
#ifndef _WIN32_WCE
tromey's avatar
tromey committed
#include <signal.h>
#endif
tromey's avatar
tromey committed

#define I_HIDE_POINTERS	/* To make GC_call_with_alloc_lock visible */
#include "private/gc_pmark.h"
tromey's avatar
tromey committed

tromey's avatar
tromey committed
# include <sys/syscall.h>
#endif
#if defined(MSWIN32) || defined(MSWINCE)
# define WIN32_LEAN_AND_MEAN
# define NOSERVICE
tromey's avatar
tromey committed
# include <windows.h>
# include <tchar.h>
tromey's avatar
tromey committed
#endif

# ifdef THREADS
#   ifdef PCR
#     include "il/PCR_IL.h"
      PCR_Th_ML GC_allocate_ml;
#   else
#     ifdef SRC_M3
	/* Critical section counter is defined in the M3 runtime 	*/
	/* That's all we use.						*/
#     else
#	ifdef GC_SOLARIS_THREADS
tromey's avatar
tromey committed
	  mutex_t GC_allocate_ml;	/* Implicitly initialized.	*/
#	else
jsturm's avatar
jsturm committed
#          if defined(GC_WIN32_THREADS) 
#             if defined(GC_PTHREADS)
		  pthread_mutex_t GC_allocate_ml = PTHREAD_MUTEX_INITIALIZER;
#	      elif defined(GC_DLL)
		 __declspec(dllexport) CRITICAL_SECTION GC_allocate_ml;
#	      else
		 CRITICAL_SECTION GC_allocate_ml;
#	      endif
tromey's avatar
tromey committed
#          else
#             if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS)
#		if defined(USE_SPIN_LOCK)
	          pthread_t GC_lock_holder = NO_THREAD;
#	        else
		  pthread_mutex_t GC_allocate_ml = PTHREAD_MUTEX_INITIALIZER;
	          pthread_t GC_lock_holder = NO_THREAD;
			/* Used only for assertions, and to prevent	 */
			/* recursive reentry in the system call wrapper. */
	          --> declare allocator lock here
tromey's avatar
tromey committed
#	      endif
#	   endif
#	endif
#     endif
#   endif
# endif

green's avatar
green committed
#if defined(NOSYS) || defined(ECOS)
#undef STACKBASE
#endif

jsturm's avatar
jsturm committed
/* Dont unnecessarily call GC_register_main_static_data() in case 	*/
/* dyn_load.c isn't linked in.						*/
#ifdef DYNAMIC_LOADING
# define GC_REGISTER_MAIN_STATIC_DATA() GC_register_main_static_data()
#else
# define GC_REGISTER_MAIN_STATIC_DATA() TRUE
#endif

tromey's avatar
tromey committed
GC_FAR struct _GC_arrays GC_arrays /* = { 0 } */;


GC_bool GC_debugging_started = FALSE;
	/* defined here so we don't have to load debug_malloc.o */

void (*GC_check_heap) GC_PROTO((void)) = (void (*) GC_PROTO((void)))0;
jsturm's avatar
jsturm committed
void (*GC_print_all_smashed) GC_PROTO((void)) = (void (*) GC_PROTO((void)))0;
tromey's avatar
tromey committed

void (*GC_start_call_back) GC_PROTO((void)) = (void (*) GC_PROTO((void)))0;
tromey's avatar
tromey committed

ptr_t GC_stackbottom = 0;

#ifdef IA64
  ptr_t GC_register_stackbottom = 0;
#endif

tromey's avatar
tromey committed
GC_bool GC_dont_gc = 0;

GC_bool GC_dont_precollect = 0;

tromey's avatar
tromey committed
GC_bool GC_quiet = 0;

GC_bool GC_print_stats = 0;

GC_bool GC_print_back_height = 0;

jsturm's avatar
jsturm committed
#ifndef NO_DEBUGGING
  GC_bool GC_dump_regularly = 0;  /* Generate regular debugging dumps. */
#endif

bryce's avatar
bryce committed
#ifdef KEEP_BACK_PTRS
  long GC_backtraces = 0;	/* Number of random backtraces to 	*/
  				/* generate for each GC.		*/
#endif

#ifdef FIND_LEAK
  int GC_find_leak = 1;
#else
  int GC_find_leak = 0;
#endif

#ifdef ALL_INTERIOR_POINTERS
  int GC_all_interior_pointers = 1;
#else
  int GC_all_interior_pointers = 0;
#endif

long GC_large_alloc_warn_interval = 5;
	/* Interval between unsuppressed warnings.	*/

long GC_large_alloc_warn_suppressed = 0;
	/* Number of warnings suppressed so far.	*/

tromey's avatar
tromey committed
/*ARGSUSED*/
GC_PTR GC_default_oom_fn GC_PROTO((size_t bytes_requested))
{
    return(0);
}

GC_PTR (*GC_oom_fn) GC_PROTO((size_t bytes_requested)) = GC_default_oom_fn;

extern signed_word GC_mem_found;

jsturm's avatar
jsturm committed
void * GC_project2(arg1, arg2)
void *arg1;
void *arg2;
{
  return arg2;
}

tromey's avatar
tromey committed
# ifdef MERGE_SIZES
    /* Set things up so that GC_size_map[i] >= words(i),		*/
    /* but not too much bigger						*/
    /* and so that size_map contains relatively few distinct entries 	*/
    /* This is stolen from Russ Atkinson's Cedar quantization		*/
    /* alogrithm (but we precompute it).				*/


    void GC_init_size_map()
    {
	register unsigned i;

	/* Map size 0 to something bigger.			*/
	/* This avoids problems at lower levels.		*/
	/* One word objects don't have to be 2 word aligned,	*/
	/* unless we're using mark bytes.	   		*/
	  for (i = 0; i < sizeof(word); i++) {
	      GC_size_map[i] = MIN_WORDS;
tromey's avatar
tromey committed
	  }
#	  if MIN_WORDS > 1
	    GC_size_map[sizeof(word)] = MIN_WORDS;
#	  else
	    GC_size_map[sizeof(word)] = ROUNDED_UP_WORDS(sizeof(word));
#	  endif
tromey's avatar
tromey committed
	for (i = sizeof(word) + 1; i <= 8 * sizeof(word); i++) {
	    GC_size_map[i] = ALIGNED_WORDS(i);
tromey's avatar
tromey committed
	}
	for (i = 8*sizeof(word) + 1; i <= 16 * sizeof(word); i++) {
	      GC_size_map[i] = (ROUNDED_UP_WORDS(i) + 1) & (~1);
	}
#	ifdef GC_GCJ_SUPPORT
	   /* Make all sizes up to 32 words predictable, so that a 	*/
	   /* compiler can statically perform the same computation,	*/
	   /* or at least a computation that results in similar size	*/
	   /* classes.							*/
	   for (i = 16*sizeof(word) + 1; i <= 32 * sizeof(word); i++) {
	      GC_size_map[i] = (ROUNDED_UP_WORDS(i) + 3) & (~3);
	   }
#	endif
tromey's avatar
tromey committed
	/* We leave the rest of the array to be filled in on demand. */
    }
    
Loading
Loading full blame...