Back to index

plt-scheme  4.2.1
test.c
Go to the documentation of this file.
00001 
00002 #include <sys/types.h>
00003 #include "sgc.h"
00004 
00005 void *x;
00006 void *y;
00007 
00008 void work()
00009 {
00010   char *v, *w;
00011 
00012   x = (char *)GC_malloc(20);
00013   y = (char *)GC_malloc(2000);
00014 
00015   v = (char *)GC_malloc(2);
00016   GC_gcollect();
00017   v[0] = 0;
00018   v = (char *)GC_malloc(10);
00019   GC_gcollect();
00020   v[0] = 0;
00021   v = (char *)GC_malloc(10000);
00022   w = (char *)GC_malloc(11000);
00023   GC_gcollect();
00024   v[0] = 0;
00025   v = (char *)GC_malloc(10);
00026   GC_gcollect();
00027   v[0] = 0;
00028   w[0] = 0;
00029 }
00030 
00031 typedef struct Chained
00032 {
00033   struct Chained *next;
00034   int data[1];
00035 } Chained;
00036 
00037 #define MAX_C_SIZE 70
00038 #define CHAIN_DEPTH 100
00039 #define NUM_REPEATS 10
00040 
00041 #define CHAINS_AS_LOCAL 1
00042 
00043 #if !CHAINS_AS_LOCAL
00044 Chained *chains[MAX_C_SIZE];
00045 #endif
00046 
00047 work2()
00048 {
00049   int broken = 15;
00050   int i, j, k, l;
00051 #if CHAINS_AS_LOCAL
00052   Chained *chains[MAX_C_SIZE];
00053 #endif
00054 
00055 #if !CHAINS_AS_LOCAL
00056   GC_add_roots((void *)chains, ((char *)chains) + sizeof(chains) + 1);
00057 #endif
00058 
00059   printf("chains at %lx\n", (long)chains);
00060 
00061   for (l = NUM_REPEATS; l--; ) {
00062     printf("cycle: %d\n", NUM_REPEATS - l);
00063 
00064     for (i = 0; i < MAX_C_SIZE; i++)
00065       chains[i] = 0L;
00066 
00067     if (l & 1) {
00068       /* Same size together: */
00069       for (i = 0; i < MAX_C_SIZE; i++) {
00070        for (k = CHAIN_DEPTH; k--; ) {
00071          Chained *c;
00072          
00073          c = (Chained *)GC_malloc(sizeof(Chained) + (i - 1) * sizeof(int));
00074          for (j = 0; j < i; j++) {
00075            c->data[j] = i;
00076          }
00077          
00078          c->next = chains[i];
00079          chains[i] = c;
00080        }
00081       }
00082     } else {
00083       /* Sizes shuffled: */
00084       for (k = CHAIN_DEPTH; k--; ) {
00085        for (i = 0; i < MAX_C_SIZE; i++) {
00086          Chained *c;
00087          
00088          c = (Chained *)GC_malloc(sizeof(Chained) + (i - 1) * sizeof(int));
00089          for (j = 0; j < i; j++) {
00090            c->data[j] = i;
00091          }
00092          
00093          c->next = chains[i];
00094          chains[i] = c;
00095        }
00096       }      
00097     }
00098 
00099     for (i = 0; i < MAX_C_SIZE; i++) {
00100       Chained *c;
00101       
00102       c = chains[i];
00103       for (k = CHAIN_DEPTH; k--; c = c->next) {
00104        for (j = 0; j < i; j++)
00105          if (c->data[j] != i) {
00106            printf("broken: %d[%d][%d] = %d\n", i, (CHAIN_DEPTH - k), j, c->data[j]);
00107            if (!(broken--))
00108              return;
00109          }
00110       }
00111     }
00112   }
00113 }
00114 
00115 main()
00116 {
00117   int dummy;
00118 
00119   GC_set_stack_base((void *)&dummy);
00120 
00121   GC_add_roots((void *)&y, ((char *)&y) + sizeof(y) + 1);
00122   GC_add_roots((void *)&x, ((char *)&x) + sizeof(x) + 1);
00123 
00124   work();
00125 
00126   work2();
00127 }