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

📄 test.c

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 C
📖 第 1 页 / 共 4 页
字号:
# if defined(GC_SOLARIS_THREADS) && !defined(GC_SOLARIS_PTHREADS)thread_key_t fl_key;void * alloc8bytes(){# if defined(SMALL_CONFIG) || defined(GC_DEBUG)    collectable_count++;    return(GC_MALLOC(8));# else    void ** my_free_list_ptr;    void * my_free_list;        if (thr_getspecific(fl_key, (void **)(&my_free_list_ptr)) != 0) {    	(void)GC_printf0("thr_getspecific failed\n");    	FAIL;    }    if (my_free_list_ptr == 0) {        uncollectable_count++;        my_free_list_ptr = GC_NEW_UNCOLLECTABLE(void *);        if (thr_setspecific(fl_key, my_free_list_ptr) != 0) {    	    (void)GC_printf0("thr_setspecific failed\n");    	    FAIL;        }    }    my_free_list = *my_free_list_ptr;    if (my_free_list == 0) {        collectable_count++;        my_free_list = GC_malloc_many(8);        if (my_free_list == 0) {            (void)GC_printf0("alloc8bytes out of memory\n");    	    FAIL;        }    }    *my_free_list_ptr = GC_NEXT(my_free_list);    GC_NEXT(my_free_list) = 0;    return(my_free_list);# endif}#else# if defined(GC_PTHREADS)pthread_key_t fl_key;void * alloc8bytes(){# if defined(SMALL_CONFIG) || defined(GC_DEBUG)    collectable_count++;    return(GC_MALLOC(8));# else    void ** my_free_list_ptr;    void * my_free_list;        my_free_list_ptr = (void **)pthread_getspecific(fl_key);    if (my_free_list_ptr == 0) {        uncollectable_count++;        my_free_list_ptr = GC_NEW_UNCOLLECTABLE(void *);        if (pthread_setspecific(fl_key, my_free_list_ptr) != 0) {    	    (void)GC_printf0("pthread_setspecific failed\n");    	    FAIL;        }    }    my_free_list = *my_free_list_ptr;    if (my_free_list == 0) {        my_free_list = GC_malloc_many(8);        if (my_free_list == 0) {            (void)GC_printf0("alloc8bytes out of memory\n");    	    FAIL;        }    }    *my_free_list_ptr = GC_NEXT(my_free_list);    GC_NEXT(my_free_list) = 0;    collectable_count++;    return(my_free_list);# endif}# else#   define alloc8bytes() GC_MALLOC_ATOMIC(8)# endif#endifvoid alloc_small(n)int n;{    register int i;        for (i = 0; i < n; i += 8) {        atomic_count++;        if (alloc8bytes() == 0) {            (void)GC_printf0("Out of memory\n");            FAIL;        }    }}# if defined(THREADS) && defined(GC_DEBUG)#   ifdef VERY_SMALL_CONFIG#     define TREE_HEIGHT 12#   else#     define TREE_HEIGHT 15#   endif# else#   ifdef VERY_SMALL_CONFIG#     define TREE_HEIGHT 13#   else#     define TREE_HEIGHT 16#   endif# endifvoid tree_test(){    tn * root;    register int i;        root = mktree(TREE_HEIGHT);#   ifndef VERY_SMALL_CONFIG      alloc_small(5000000);#   endif    chktree(root, TREE_HEIGHT);    if (finalized_count && ! dropped_something) {        (void)GC_printf0("Premature finalization - collector is broken\n");        FAIL;    }    dropped_something = 1;    GC_noop(root);	/* Root needs to remain live until	*/    			/* dropped_something is set.		*/    root = mktree(TREE_HEIGHT);    chktree(root, TREE_HEIGHT);    for (i = TREE_HEIGHT; i >= 0; i--) {        root = mktree(i);        chktree(root, i);    }#   ifndef VERY_SMALL_CONFIG      alloc_small(5000000);#   endif}unsigned n_tests = 0;GC_word bm_huge[10] = {    0xffffffff,    0xffffffff,    0xffffffff,    0xffffffff,    0xffffffff,    0xffffffff,    0xffffffff,    0xffffffff,    0xffffffff,    0x00ffffff,};/* A very simple test of explicitly typed allocation	*/void typed_test(){    GC_word * old, * new;    GC_word bm3 = 0x3;    GC_word bm2 = 0x2;    GC_word bm_large = 0xf7ff7fff;    GC_descr d1 = GC_make_descriptor(&bm3, 2);    GC_descr d2 = GC_make_descriptor(&bm2, 2);#   ifndef LINT      GC_descr dummy = GC_make_descriptor(&bm_large, 32);#   endif    GC_descr d3 = GC_make_descriptor(&bm_large, 32);    GC_descr d4 = GC_make_descriptor(bm_huge, 320);    GC_word * x = (GC_word *)GC_malloc_explicitly_typed(2000, d4);    register int i;        collectable_count++;    old = 0;    for (i = 0; i < 4000; i++) {	collectable_count++;        new = (GC_word *) GC_malloc_explicitly_typed(4 * sizeof(GC_word), d1);        if (0 != new[0] || 0 != new[1]) {	    GC_printf0("Bad initialization by GC_malloc_explicitly_typed\n");	    FAIL;	}        new[0] = 17;        new[1] = (GC_word)old;        old = new;	collectable_count++;        new = (GC_word *) GC_malloc_explicitly_typed(4 * sizeof(GC_word), d2);        new[0] = 17;        new[1] = (GC_word)old;        old = new;	collectable_count++;        new = (GC_word *) GC_malloc_explicitly_typed(33 * sizeof(GC_word), d3);        new[0] = 17;        new[1] = (GC_word)old;        old = new;	collectable_count++;        new = (GC_word *) GC_calloc_explicitly_typed(4, 2 * sizeof(GC_word),        					     d1);        new[0] = 17;        new[1] = (GC_word)old;        old = new;	collectable_count++;        if (i & 0xff) {          new = (GC_word *) GC_calloc_explicitly_typed(7, 3 * sizeof(GC_word),        					     d2);        } else {          new = (GC_word *) GC_calloc_explicitly_typed(1001,          					       3 * sizeof(GC_word),        					       d2);          if (0 != new[0] || 0 != new[1]) {	    GC_printf0("Bad initialization by GC_malloc_explicitly_typed\n");	    FAIL;	  }        }        new[0] = 17;        new[1] = (GC_word)old;        old = new;    }    for (i = 0; i < 20000; i++) {        if (new[0] != 17) {            (void)GC_printf1("typed alloc failed at %lu\n",            		     (unsigned long)i);            FAIL;        }        new[0] = 0;        old = new;        new = (GC_word *)(old[1]);    }    GC_gcollect();    GC_noop(x);}int fail_count = 0;#ifndef __STDC__/*ARGSUSED*/void fail_proc1(x)GC_PTR x;{    fail_count++;}#else/*ARGSUSED*/void fail_proc1(GC_PTR x){    fail_count++;}   static void uniq(void *p, ...) {  va_list a;  void *q[100];  int n = 0, i, j;  q[n++] = p;  va_start(a,p);  for (;(q[n] = va_arg(a,void *));n++) ;  va_end(a);  for (i=0; i<n; i++)    for (j=0; j<i; j++)      if (q[i] == q[j]) {        GC_printf0(              "Apparently failed to mark form some function arguments.\n"              "Perhaps GC_push_regs was configured incorrectly?\n"        );	FAIL;      }}#endif /* __STDC__ */#ifdef THREADS#   define TEST_FAIL_COUNT(n) 1#else #   define TEST_FAIL_COUNT(n) (fail_count >= (n))#endifvoid run_one_test(){    char *x;#   ifdef LINT    	char *y = 0;#   else    	char *y = (char *)(size_t)fail_proc1;#   endif    DCL_LOCK_STATE;    #   ifdef FIND_LEAK	(void)GC_printf0(		"This test program is not designed for leak detection mode\n");	(void)GC_printf0("Expect lots of problems.\n");#   endif    GC_FREE(0);#   ifndef DBG_HDRS_ALL      collectable_count += 3;      if (GC_size(GC_malloc(7)) != 8 &&	  GC_size(GC_malloc(7)) != MIN_WORDS * sizeof(GC_word)	|| GC_size(GC_malloc(15)) != 16) {	    (void)GC_printf0("GC_size produced unexpected results\n");	    FAIL;      }      collectable_count += 1;      if (GC_size(GC_malloc(0)) != MIN_WORDS * sizeof(GC_word)) {    	(void)GC_printf1("GC_malloc(0) failed: GC_size returns %ld\n",			 GC_size(GC_malloc(0)));	    FAIL;      }      collectable_count += 1;      if (GC_size(GC_malloc_uncollectable(0)) != MIN_WORDS * sizeof(GC_word)) {    	(void)GC_printf0("GC_malloc_uncollectable(0) failed\n");	    FAIL;      }      GC_is_valid_displacement_print_proc = fail_proc1;      GC_is_visible_print_proc = fail_proc1;      collectable_count += 1;      x = GC_malloc(16);      if (GC_base(x + 13) != x) {    	(void)GC_printf0("GC_base(heap ptr) produced incorrect result\n");	FAIL;      }#     ifndef PCR        if (GC_base(y) != 0) {    	  (void)GC_printf0("GC_base(fn_ptr) produced incorrect result\n");	  FAIL;        }#     endif      if (GC_same_obj(x+5, x) != x + 5) {    	(void)GC_printf0("GC_same_obj produced incorrect result\n");	FAIL;      }      if (GC_is_visible(y) != y || GC_is_visible(x) != x) {    	(void)GC_printf0("GC_is_visible produced incorrect result\n");	FAIL;      }      if (!TEST_FAIL_COUNT(1)) {#	if!(defined(RS6000) || defined(POWERPC) || defined(IA64)) || defined(M68K)	  /* ON RS6000s function pointers point to a descriptor in the	*/	  /* data segment, so there should have been no failures.	*/	  /* The same applies to IA64.  Something similar seems to	*/	  /* be going on with NetBSD/M68K.				*/    	  (void)GC_printf0("GC_is_visible produced wrong failure indication\n");    	  FAIL;#	endif      }      if (GC_is_valid_displacement(y) != y        || GC_is_valid_displacement(x) != x        || GC_is_valid_displacement(x + 3) != x + 3) {    	(void)GC_printf0(    		"GC_is_valid_displacement produced incorrect result\n");	FAIL;      }#     if defined(__STDC__) && !defined(MSWIN32) && !defined(MSWINCE)        /* Harder to test under Windows without a gc.h declaration.  */        {	  size_t i;	  extern void *GC_memalign();	  GC_malloc(17);	  for (i = sizeof(GC_word); i < 512; i *= 2) {	    GC_word result = (GC_word) GC_memalign(i, 17);	    if (result % i != 0 || result == 0 || *(int *)result != 0) FAIL;	  } 	}#     endif#     ifndef ALL_INTERIOR_POINTERS#      if defined(RS6000) || defined(POWERPC)        if (!TEST_FAIL_COUNT(1)) {#      else        if (GC_all_interior_pointers && !TEST_FAIL_COUNT(1)	    || !GC_all_interior_pointers && !TEST_FAIL_COUNT(2)) {#      endif    	  (void)GC_printf0("GC_is_valid_displacement produced wrong failure indication\n");    	  FAIL;        }#     endif#   endif /* DBG_HDRS_ALL */    /* Test floating point alignment */   collectable_count += 2;	*(double *)GC_MALLOC(sizeof(double)) = 1.0;	*(double *)GC_MALLOC(sizeof(double)) = 1.0;#   ifdef GC_GCJ_SUPPORT      GC_REGISTER_DISPLACEMENT(sizeof(struct fake_vtable *));      GC_init_gcj_malloc(0, (void *)fake_gcj_mark_proc);#   endif    /* Make sure that fn arguments are visible to the collector.	*/#   ifdef __STDC__      uniq(        GC_malloc(12), GC_malloc(12), GC_malloc(12),        (GC_gcollect(),GC_malloc(12)),        GC_malloc(12), GC_malloc(12), GC_malloc(12),	(GC_gcollect(),GC_malloc(12)),        GC_malloc(12), GC_malloc(12), GC_malloc(12),	(GC_gcollect(),GC_malloc(12)),        GC_malloc(12), GC_malloc(12), GC_malloc(12),	(GC_gcollect(),GC_malloc(12)),        GC_malloc(12), GC_malloc(12), GC_malloc(12),	(GC_gcollect(),GC_malloc(12)),        (void *)0);#   endif    /* Repeated list reversal test. */	reverse_test();#   ifdef PRINTSTATS	GC_printf0("-------------Finished reverse_test\n");#   endif#   ifndef DBG_HDRS_ALL      typed_test();#     ifdef PRINTSTATS	GC_printf0("-------------Finished typed_test\n");#     endif#   endif /* DBG_HDRS_ALL */    tree_test();    LOCK();    n_tests++;    UNLOCK();#   if defined(THREADS) && defined(HANDLE_FORK)      if (fork() == 0) {	GC_gcollect();	tiny_reverse_test(0);	GC_gcollect();	GC_printf0("Finished a child process\n");	exit(0);      }#   endif    /* GC_printf1("Finished %x\n", pthread_self()); */}void check_heap_stats(){    unsigned long max_heap_sz;    register int i;    int still_live;    int late_finalize_count = 0;    #   ifdef VERY_SMALL_CONFIG    /* these are something of a guess */    if (sizeof(char *) > 4) {        max_heap_sz = 4500000;    } else {    	max_heap_sz = 2800000;    }#   else    if (sizeof(char *) > 4) {        max_heap_sz = 19000000;    } else {    	max_heap_sz = 11000000;    }#   endif#   ifndef ALIGN_DOUBLE        /* We end up needing more small object pages. */        max_heap_sz += 2000000;#   endif#   ifdef GC_DEBUG	max_heap_sz *= 2;#       ifdef SAVE_CALL_CHAIN	    max_heap_sz *= 3;#           ifdef SAVE_CALL_COUNT		max_heap_sz += max_heap_sz * SAVE_CALL_COUNT/4;#	    endif#       endif#   endif    /* Garbage collect repeatedly so that all inaccessible objects	*/    /* can be finalized.						*/      while (GC_collect_a_little()) { }      for (i = 0; i < 16; i++) {        GC_gcollect();        late_finalize_count += GC_invoke_finalizers();      }

⌨️ 快捷键说明

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