Reading Gauche/Reading Gauche 0.9/gc/misc.c/GC_init_inner


Top / Reading Gauche / Reading Gauche 0.9 / gc / misc.c / GC_init_inner

GC_init_inner()

概要

現在、編集中、ひら終了後、作成予定。

void GC_init_inner()
{
#   if !defined(THREADS) && defined(GC_ASSERTIONS)
        word dummy;
#   endif
    word initial_heap_sz = (word)MINHINCR;
    IF_CANCEL(int cancel_state;)
   
    if (GC_is_initialized) return;

    DISABLE_CANCEL(cancel_state);

    /* Note that although we are nominally called with the */
    /* allocation lock held, the allocation lock is now	   */
    /* only really acquired once a second thread is forked.*/
    /* And the initialization code needs to run before     */
    /* then.  Thus we really don't hold any locks, and can */
   /* in fact safely initialize them here.		   */
#   ifdef THREADS
      GC_ASSERT(!GC_need_to_lock);
#   endif
#   if defined(GC_WIN32_THREADS) && !defined(GC_PTHREADS)
      if (!GC_is_initialized) {
        BOOL (WINAPI *pfn) (LPCRITICAL_SECTION, DWORD) = NULL;
        HMODULE hK32 = GetModuleHandleA("kernel32.dll");
        if (hK32)
  	  pfn = (BOOL (WINAPI *) (LPCRITICAL_SECTION, DWORD))
  		GetProcAddress (hK32,
 				"InitializeCriticalSectionAndSpinCount");
        if (pfn)
            pfn(&GC_allocate_ml, 4000);
        else
 	   InitializeCriticalSection (&GC_allocate_ml);
      }
#endif /* MSWIN32 */
#   if defined(MSWIN32) || defined(MSWINCE)
      InitializeCriticalSection(&GC_write_cs);
#   endif
#   if (!defined(SMALL_CONFIG))
       if (0 != GETENV("GC_PRINT_STATS")) {
        GC_print_stats = 1;
      } 
      if (0 != GETENV("GC_PRINT_VERBOSE_STATS")) {
        GC_print_stats = VERBOSE;
      } 
#     if defined(UNIX_LIKE)
        { 
	  char * file_name = GETENV("GC_LOG_FILE");
          if (0 != file_name) { 
	    int log_d = open(file_name, O_CREAT|O_WRONLY|O_APPEND, 0666);
	    if (log_d < 0) {
	      GC_log_printf("Failed to open %s as log file\n", file_name);
	    } else {
	      GC_log = log_d;
	    }
	  }
	}
#     endif
#   endif
#   ifndef NO_DEBUGGING
      if (0 != GETENV("GC_DUMP_REGULARLY")) {
        GC_dump_regularly = 1;
      }
#   endif
#   ifdef KEEP_BACK_PTRS
       {
        char * backtraces_string = GETENV("GC_BACKTRACES");
        if (0 != backtraces_string) {
          GC_backtraces = atol(backtraces_string);
	  if (backtraces_string[0] == '\0') GC_backtraces = 1;
        }
      }
#   endif
    if (0 != GETENV("GC_FIND_LEAK")) {
      GC_find_leak = 1;
      atexit(GC_exit_check);
    }
    if (0 != GETENV("GC_ALL_INTERIOR_POINTERS")) {
      GC_all_interior_pointers = 1;
    }
    if (0 != GETENV("GC_DONT_GC")) {
      GC_dont_gc = 1;
    }
    if (0 != GETENV("GC_PRINT_BACK_HEIGHT")) {
      GC_print_back_height = 1;
    }
    if (0 != GETENV("GC_NO_BLACKLIST_WARNING")) {
      GC_large_alloc_warn_interval = LONG_MAX;
    }
    {
      char * addr_string = GETENV("GC_TRACE");
      if (0 != addr_string) {
#       ifndef ENABLE_TRACE
	  WARN("Tracing not enabled: Ignoring GC_TRACE value\n", 0);
#       else
#	  ifdef STRTOULL
	    long long addr = strtoull(addr_string, NULL, 16);
#	  else
	    long addr = strtoul(addr_string, NULL, 16);
#	  endif
	  if (addr < 0x1000)
	      WARN("Unlikely trace address: 0x%lx\n", (GC_word)addr);
	  GC_trace_addr = (ptr_t)addr;
#	endif
      }
    }
    {
      char * time_limit_string = GETENV("GC_PAUSE_TIME_TARGET");
      if (0 != time_limit_string) {
        long time_limit = atol(time_limit_string);
        if (time_limit < 5) {
	  WARN("GC_PAUSE_TIME_TARGET environment variable value too small "
	       "or bad syntax: Ignoring\n", 0);
        } else {
	  GC_time_limit = time_limit;
        }
      }
    }
    {
      char * interval_string = GETENV("GC_LARGE_ALLOC_WARN_INTERVAL");
      if (0 != interval_string) {
        long interval = atol(interval_string);
        if (interval <= 0) {
	  WARN("GC_LARGE_ALLOC_WARN_INTERVAL environment variable has "
	       "bad value: Ignoring\n", 0);
        } else {
	  GC_large_alloc_warn_interval = interval;
        }
      }
    }
    maybe_install_looping_handler();
    /* Adjust normal object descriptor for extra allocation.	*/
    if (ALIGNMENT > GC_DS_TAGS && EXTRA_BYTES != 0) {
      GC_obj_kinds[NORMAL].ok_descriptor = ((word)(-ALIGNMENT) | GC_DS_LENGTH);
    }
    GC_setpagesize();
    GC_exclude_static_roots(beginGC_arrays, endGC_arrays);
    GC_exclude_static_roots(beginGC_obj_kinds, endGC_obj_kinds);
#   ifdef SEPARATE_GLOBALS
      GC_exclude_static_roots(beginGC_objfreelist, endGC_objfreelist);
      GC_exclude_static_roots(beginGC_aobjfreelist, endGC_aobjfreelist);
#   endif
#   ifdef MSWIN32
 	GC_init_win32();
#   endif
#   if defined(USE_PROC_FOR_LIBRARIES) && defined(GC_LINUX_THREADS)
	WARN("USE_PROC_FOR_LIBRARIES + GC_LINUX_THREADS performs poorly.\n", 0);
	/* If thread stacks are cached, they tend to be scanned in 	*/
	/* entirety as part of the root set.  This wil grow them to	*/
	/* maximum size, and is generally not desirable.		*/
#   endif
#   if defined(SEARCH_FOR_DATA_START)
	GC_init_linux_data_start();
#   endif
#   if (defined(NETBSD) || defined(OPENBSD)) && defined(__ELF__)
	GC_init_netbsd_elf();
#   endif
#   if !defined(THREADS) || defined(GC_PTHREADS) || defined(GC_WIN32_THREADS) \
	|| defined(GC_SOLARIS_THREADS)
      if (GC_stackbottom == 0) {
	GC_stackbottom = GC_get_main_stack_base();
#       if (defined(LINUX) || defined(HPUX)) && defined(IA64)
	  GC_register_stackbottom = GC_get_register_stack_base();
#       endif
      } else {
#       if (defined(LINUX) || defined(HPUX)) && defined(IA64)
	  if (GC_register_stackbottom == 0) {
	    WARN("GC_register_stackbottom should be set with GC_stackbottom\n",  0);
	    /* The following may fail, since we may rely on	 	*/
	    /* alignment properties that may not hold with a user set	*/
	    /* GC_stackbottom.						*/
	    GC_register_stackbottom = GC_get_register_stack_base();
	  }
#	endif
      }
#    endif
    /* Ignore gcc -Wall warnings on the following. */
    GC_STATIC_ASSERT(sizeof (ptr_t) == sizeof(word));
    GC_STATIC_ASSERT(sizeof (signed_word) == sizeof(word));
    GC_STATIC_ASSERT(sizeof (struct hblk) == HBLKSIZE);
#   ifndef THREADS
#     ifdef STACK_GROWS_DOWN
        GC_ASSERT((word)(&dummy) <= (word)GC_stackbottom);
#     else
        GC_ASSERT((word)(&dummy) >= (word)GC_stackbottom);
#     endif
#   endif
#   if !defined(_AUX_SOURCE) || defined(__GNUC__)
      GC_ASSERT((word)(-1) > (word)0);
      /* word should be unsigned */
#   endif
    GC_ASSERT((ptr_t)(word)(-1) > (ptr_t)0);
    	/* Ptr_t comparisons should behave as unsigned comparisons.	*/
    GC_ASSERT((signed_word)(-1) < (signed_word)0);
#   if !defined(SMALL_CONFIG)
      if (GC_incremental || 0 != GETENV("GC_ENABLE_INCREMENTAL")) {
	/* This used to test for !GC_no_win32_dlls.  Why? */
        GC_setpagesize();
	/* For GWW_MPROTECT on Win32, this needs to happen before any	*/
	/* heap memory is allocated.					*/
        GC_dirty_init();
        GC_ASSERT(GC_bytes_allocd == 0)
    	GC_incremental = TRUE;
      }
#   endif /* !SMALL_CONFIG */
    
    /* Add initial guess of root sets.  Do this first, since sbrk(0)	*/
    /* might be used.							*/
      if (GC_REGISTER_MAIN_STATIC_DATA()) GC_register_data_segments();
    GC_init_headers();
    GC_bl_init();
    GC_mark_init();
    {
	char * sz_str = GETENV("GC_INITIAL_HEAP_SIZE");
	if (sz_str != NULL) {
	  initial_heap_sz = atoi(sz_str);
	  if (initial_heap_sz <= MINHINCR * HBLKSIZE) {
	    WARN("Bad initial heap size %s - ignoring it.\n",
		 sz_str);
	  } 
	  initial_heap_sz = divHBLKSZ(initial_heap_sz);
	}
    }
    {
	char * sz_str = GETENV("GC_MAXIMUM_HEAP_SIZE");
	if (sz_str != NULL) {
	  word max_heap_sz = (word)atol(sz_str);
	  if (max_heap_sz < initial_heap_sz * HBLKSIZE) {
	    WARN("Bad maximum heap size %s - ignoring it.\n",
		 sz_str);
	  } 
	  if (0 == GC_max_retries) GC_max_retries = 2;
	  GC_set_max_heap_size(max_heap_sz);
	}
    }
    if (!GC_expand_hp_inner(initial_heap_sz)) {
        GC_err_printf("Can't start up: not enough memory\n");
        EXIT();
    }
    GC_initialize_offsets();
    GC_register_displacement_inner(0L);
#   if defined(GC_LINUX_THREADS) && defined(REDIRECT_MALLOC)
      if (!GC_all_interior_pointers) {
	/* TLS ABI uses pointer-sized offsets for dtv. */
        GC_register_displacement_inner(sizeof(void *));
      }
#   endif
    GC_init_size_map();
#   ifdef PCR
      if (PCR_IL_Lock(PCR_Bool_false, PCR_allSigsBlocked, PCR_waitForever)
          != PCR_ERes_okay) {
          ABORT("Can't lock load state\n");
      } else if (PCR_IL_Unlock() != PCR_ERes_okay) {
          ABORT("Can't unlock load state\n");
      }
      PCR_IL_Unlock();
      GC_pcr_install();
#   endif
    GC_is_initialized = TRUE;
#   if defined(GC_PTHREADS) || defined(GC_WIN32_THREADS)
        GC_thr_init();
#   endif
    COND_DUMP;
    /* Get black list set up and/or incremental GC started */
      if (!GC_dont_precollect || GC_incremental) GC_gcollect_inner();
#   ifdef STUBBORN_ALLOC
    	GC_stubborn_init();
#   endif
    /* Convince lint that some things are used */
#   ifdef LINT
      {
          extern char * GC_copyright[];
           extern int GC_read();
          extern void GC_register_finalizer_no_order();
         
          GC_noop(GC_copyright, GC_find_header,
                  GC_push_one, GC_call_with_alloc_lock, GC_read,
                  GC_dont_expand,
#		  ifndef NO_DEBUGGING
		    GC_dump,
#		  endif
                  GC_register_finalizer_no_order);
      }
#   endif

    /* The rest of this again assumes we don't really hold	*/
    /* the allocation lock.					*/
#   if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC)
	/* Make sure marker threads and started and thread local */
	/* allocation is initialized, in case we didn't get 	 */
	/* called from GC_init_parallel();			 */
        {
	  GC_init_parallel();
	}
#   endif /* PARALLEL_MARK || THREAD_LOCAL_ALLOC */

#   if defined(DYNAMIC_LOADING) && defined(DARWIN)
    {
        /* This must be called WITHOUT the allocation lock held
        and before any threads are created */
        extern void GC_init_dyld();
        GC_init_dyld();
    }
#   endif
    RESTORE_CANCEL(cancel_state);
}

調べるもの

参照元

コメント

コメントはありません。 コメント/Reading Gauche/Reading Gauche 0.9/gc/misc.c/GC_init_inner?

お名前:

MENU

now: 7

リンク


最新の20件
2020-05-22 2020-05-14 2020-05-12 2020-05-10 2020-04-27 2020-03-23
最新の20件
2010-02-01 2010-01-31 2010-01-30 2010-01-29 2010-01-16

Counter: 1642, today: 1, yesterday: 0

リロード   新規 編集 凍結 差分 添付 複製 改名   トップ 一覧 検索 最終更新 バックアップ   ヘルプ   最終更新のRSS

Last-modified: 2010-01-04 (月) 23:42:06 (3794d);  Modified by mona
PukiWiki 1.4.6 Copyright © 2001-2005 PukiWiki Developers Team. License is GPL.
Based on "PukiWiki" 1.3 by yu-ji
Powered by PHP 5.2.17
HTML convert time to 0.064 sec.