[e5072a]: src / c / gbc.d Maximize Restore History

Download this file

gbc.d    958 lines (827 with data), 21.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
/*
gbc.c -- Garbage collector.
*/
/*
Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya.
Copyright (c) 1990, Giuseppe Attardi and William F. Schelter.
Copyright (c) 2001, Juan Jose Garcia Ripoll.
ECL is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
See file '../Copyright' for full details.
*/
#include "ecl.h"
#include "page.h"
#include "internal.h"
#ifndef GBC_BOEHM
/******************************* EXPORTS ******************************/
bool GC_enable;
/******************************* ------- ******************************/
/*
mark_table[m]:i represents word w = 128*m + 4*i, where m = addr-DATA_START.
Therefore m = w >> 7, i = (w / 4) % 32 = (w >> 2) & 0x1f.
*/
static int *mark_table;
#define MTbit(x) ((ptr2int(x) >> 2) & 0x1f)
#define MTword(x) mark_table[((cl_ptr)x - heap_start) >> 7]
#define get_mark_bit(x) (MTword(x) >> MTbit(x) & 1)
#define set_mark_bit(x) (MTword(x) |= (1 << MTbit(x)))
#define clear_mark_bit(x) (MTword(x) ~= (~1 << MTbit(x)))
#define VALID_DATA_ADDRESS(pp) \
(!IMMEDIATE(pp) && (heap_start <= (cl_ptr)(pp)) && ((cl_ptr)(pp) < heap_end))
static bool debug = FALSE;
static int maxpage;
#define GC_ROOT_MAX 200
static cl_object *gc_root[GC_ROOT_MAX];
static int gc_roots;
static bool collect_blocks;
static int gc_time; /* Beppe */
/*
We must register location, since value may be reassigned (e.g. malloc_list)
*/
static void _mark_object (cl_object x);
static void _mark_contblock (void *p, cl_index s);
extern void sigint (void);
void
ecl_register_root(cl_object *p)
{
if (gc_roots >= GC_ROOT_MAX)
error("too many roots");
gc_root[gc_roots++] = p;
}
cl_object
si_gc(cl_object area)
{
if (!GC_enabled())
error("GC is not enabled");
if (Null(area))
ecl_gc(t_cons);
else
ecl_gc(t_contiguous);
@(return)
}
/*----------------------------------------------------------------------
* Mark phase
*----------------------------------------------------------------------
*/
/* Whenever two arrays are linked together by displacement,
if one is live, the other will be made live */
#define mark_displaced(ar) mark_object(ar)
#define mark_contblock(x,s) {if (collect_blocks) _mark_contblock(x,s); }
#if 1
#define mark_object(x) if ((x != OBJNULL) && !IMMEDIATE(x)) _mark_object(x)
#define mark_next(a) if ((a != OBJNULL) && !IMMEDIATE(a)) { x=(a); goto BEGIN; }
#else
#define mark_object(x) _mark_object(x)
#define mark_next(a) x=(a); goto BEGIN
#endif
/* We make bitvectors multiple of sizeof(int) in size allocated
Assume 8 = number of bits in char */
#define W_SIZE (8*sizeof(int))
static void
_mark_object(cl_object x)
{
cl_index i, j;
cl_object *p, y;
cl_ptr cp;
cs_check(x);
BEGIN:
#if 0
/* We cannot get here because mark_object() and mark_next() already check this */
if (IMMEDIATE(x)) return; /* fixnum, character or locative */
if (x == OBJNULL)
return;
#endif
if (x->d.m) {
if (x->d.m == FREE)
error("mark_object: pointer to free object.");
else
return;
}
x->d.m = TRUE;
switch (type_of(x)) {
case t_bignum:
if (collect_blocks) {
/* GMP may set num.alloc before actually allocating anything.
With these checks we make sure we do not move anything
we don't have to. Besides, we use big_dim as the size
of the object, because big_size might even be smaller.
*/
cl_ptr limbs = (cl_ptr)x->big.big_limbs;
cl_index size = x->big.big_dim * sizeof(mp_limb_t);
if (size) mark_contblock(limbs, size);
}
break;
case t_ratio:
mark_object(x->ratio.num);
mark_next(x->ratio.den);
break;
case t_shortfloat:
case t_longfloat:
break;
case t_complex:
mark_object(x->complex.imag);
mark_next(x->complex.real);
break;
case t_character:
break;
case t_symbol:
mark_object(x->symbol.name);
mark_object(x->symbol.plist);
mark_object(SYM_FUN(x));
mark_next(SYM_VAL(x));
break;
case t_package:
mark_object(x->pack.name);
mark_object(x->pack.nicknames);
mark_object(x->pack.shadowings);
mark_object(x->pack.uses);
mark_object(x->pack.usedby);
mark_object(x->pack.internal);
mark_next(x->pack.external);
break;
case t_cons:
mark_object(CAR(x));
mark_next(CDR(x));
break;
case t_hashtable:
mark_object(x->hash.rehash_size);
mark_object(x->hash.threshold);
if (x->hash.data == NULL)
break;
for (i = 0, j = x->hash.size; i < j; i++) {
mark_object(x->hash.data[i].key);
mark_object(x->hash.data[i].value);
}
mark_contblock(x->hash.data, j * sizeof(struct hashtable_entry));
break;
case t_array:
mark_contblock(x->array.dims, sizeof(x->array.dims[0])*x->array.rank);
case t_vector:
if ((y = x->array.displaced) != Cnil)
mark_displaced(y);
cp = (cl_ptr)x->array.self.t;
if (cp == NULL)
break;
switch ((cl_elttype)x->array.elttype) {
case aet_object:
if (x->array.displaced == Cnil || CAR(x->array.displaced) == Cnil) {
cl_object *p = x->array.self.t;
cl_index i;
if (x->array.t == t_vector && x->vector.hasfillp)
i = x->vector.fillp;
else
i = x->vector.dim;
while (i-- > 0)
mark_object(p[i]);
}
j = sizeof(cl_object)*x->array.dim;
break;
case aet_ch:
j = x->array.dim;
break;
case aet_bit:
j = sizeof(int) * ((x->vector.offset + x->vector.dim + W_SIZE -1)/W_SIZE);
break;
case aet_fix:
j = x->array.dim * sizeof(cl_fixnum);
break;
case aet_sf:
j = x->array.dim * sizeof(float);
break;
case aet_lf:
j = x->array.dim * sizeof(double);
break;
case aet_b8:
j = x->array.dim * sizeof(uint8_t);
break;
case aet_i8:
j = x->array.dim * sizeof(int8_t);
break;
default:
error("Allocation botch: unknown array element type");
}
goto COPY_ARRAY;
case t_string:
if ((y = x->string.displaced) != Cnil)
mark_displaced(y);
cp = x->string.self;
if (cp == NULL)
break;
j = x->string.dim+1;
COPY_ARRAY:
mark_contblock(cp, j);
break;
case t_bitvector:
if ((y = x->vector.displaced) != Cnil)
mark_displaced(y);
cp = x->vector.self.bit;
if (cp == NULL)
break;
j= sizeof(int) * ((x->vector.offset + x->vector.dim + W_SIZE -1)/W_SIZE);
goto COPY_ARRAY;
#ifndef CLOS
case t_structure:
mark_object(x->str.name);
p = x->str.self;
if (p == NULL)
break;
for (i = 0, j = x->str.length; i < j; i++)
mark_object(p[i]);
mark_contblock(p, j*sizeof(cl_object));
break;
#endif /* CLOS */
case t_stream:
switch ((enum smmode)x->stream.mode) {
case smm_closed:
/* Rest of fields are NULL */
mark_next(x->stream.object1);
break;
case smm_input:
case smm_output:
case smm_io:
case smm_probe:
mark_object(x->stream.object0);
mark_object(x->stream.object1);
mark_contblock(x->stream.buffer, BUFSIZ);
break;
case smm_synonym:
mark_next(x->stream.object0);
break;
case smm_broadcast:
case smm_concatenated:
mark_next(x->stream.object0);
break;
case smm_two_way:
case smm_echo:
mark_object(x->stream.object0);
mark_next(x->stream.object1);
break;
case smm_string_input:
case smm_string_output:
mark_next(x->stream.object0);
break;
default:
error("mark stream botch");
}
break;
case t_random:
break;
case t_readtable:
if (x->readtable.table == NULL)
break;
mark_contblock((cl_ptr)(x->readtable.table),
RTABSIZE*sizeof(struct readtable_entry));
for (i = 0; i < RTABSIZE; i++) {
cl_object *p = x->readtable.table[i].dispatch_table;
mark_object(x->readtable.table[i].macro);
if (p != NULL) {
mark_contblock(p, RTABSIZE*sizeof(cl_object));
for (j = 0; j < RTABSIZE; j++)
mark_object(p[j]);
}
}
break;
case t_pathname:
mark_object(x->pathname.host);
mark_object(x->pathname.device);
mark_object(x->pathname.directory);
mark_object(x->pathname.name);
mark_object(x->pathname.type);
mark_object(x->pathname.version);
break;
case t_bytecodes: {
cl_index i, size;
size = x->bytecodes.size;
mark_object(x->bytecodes.name);
mark_object(x->bytecodes.lex);
mark_object(x->bytecodes.specials);
mark_contblock(x->bytecodes.data, size * sizeof(cl_object));
for (i=0; i<size; i++)
mark_object(x->bytecodes.data[i]);
mark_next(x->bytecodes.definition);
break;
}
case t_cfun:
mark_object(x->cfun.block);
mark_next(x->cfun.name);
break;
case t_cclosure:
mark_object(x->cfun.block);
mark_next(x->cclosure.env);
break;
#ifdef THREADS
case t_cont:
mark_next(x->cn.cn_thread);
break;
case t_thread:
/* Already marked by malloc
mark_contblock(x->thread.data, x->thread.size);
*/
mark_next(x->thread.entry);
break;
#endif /* THREADS */
#ifdef CLOS
case t_instance:
mark_object(CLASS_OF(x));
p = x->instance.slots;
if (p == NULL)
break;
for (i = 0, j = x->instance.length; i < j; i++)
mark_object(p[i]);
mark_contblock(p, j*sizeof(cl_object));
break;
#endif /* CLOS */
case t_codeblock:
mark_object(x->cblock.name);
if (x->cblock.data) {
cl_index i = x->cblock.data_size;
cl_object *p = x->cblock.data;
while (i--)
mark_object(p[i]);
}
mark_next(x->cblock.next);
break;
#ifdef ECL_FFI
case t_foreign:
if (x->foreign.size)
mark_contblock(x->foreign.data, x->foreign.size);
mark_next(x->foreign.tag);
break;
#endif ECL_FFI
default:
if (debug)
printf("\ttype = %d\n", type_of(x));
error("mark botch");
}
}
static void
mark_stack_conservative(cl_ptr bottom, cl_ptr top)
{
int p, m;
cl_object x;
struct typemanager *tm;
cl_ptr j;
if (debug) { printf("Traversing C stack .."); fflush(stdout); }
/* On machines which align local pointers on multiple of 2 rather
than 4 we need to mark twice
if (offset) mark_stack_conservative(bottom, ((char *) top) + offset, 0);
*/
for (j = bottom ; j <= top ; j+=sizeof(cl_ptr)) {
cl_ptr aux = *((cl_ptr*)j);
/* improved Beppe: */
if (VALID_DATA_ADDRESS(aux) && type_map[p = page(aux)] < (char)t_end) {
tm = tm_of((cl_type)type_map[p]);
x = (cl_object)(aux - (aux - pagetochar(p)) % tm->tm_size);
m = x->d.m;
if (m != FREE && m != TRUE) {
if (m) {
fprintf(stderr,
"** bad value %d of d.m in gc page %d skipping mark **",
m, p); fflush(stderr);
} else
mark_object(x);
}
}}
if (debug) {printf(". done.\n"); fflush(stdout); }
}
static void
mark_phase(void)
{
int i;
bds_ptr bdp;
frame_ptr frp;
/* mark registered symbols & keywords */
for (i=0; i<cl_num_symbols_in_core; i++) {
cl_object s = (cl_object)(cl_symbols + i);
s->symbol.m = FALSE;
}
for (i=0; i<cl_num_symbols_in_core; i++) {
cl_object s = (cl_object)(cl_symbols + i);
mark_object(s);
}
#ifdef THREADS
{
pd *pdp;
lpd *old_clwp = clwp;
for (pdp = running_head; pdp != (pd *)NULL; pdp = pdp->pd_next) {
clwp = pdp->pd_lpd;
#endif /* THREADS */
mark_contblock(cl_stack, cl_stack_size * sizeof(*cl_stack));
mark_stack_conservative(cl_stack, cl_stack_top);
for (i=0; i<NValues; i++)
mark_object(VALUES(i));
mark_contblock(frs_org, frs_size * sizeof(*frs_org));
mark_contblock(bds_org, frs_size * sizeof(*bds_org));
for (bdp = bds_org; bdp <= bds_top; bdp++) {
mark_object(bdp->bds_sym);
mark_object(bdp->bds_val);
}
for (frp = frs_org; frp <= frs_top; frp++) {
mark_object(frp->frs_val);
}
mark_object(lex_env);
#ifdef THREADS
/* added to mark newly allocated objects */
mark_object(clwp->lwp_alloc_temporary);
mark_object(clwp->lwp_fmt_temporary_stream);
mark_object(clwp->lwp_PRINTstream);
mark_object(clwp->lwp_PRINTcase);
mark_object(clwp->lwp_READtable);
mark_object(clwp->lwp_token);
mark_object(clwp->lwp_CIRCLEstack);
/* (current-thread) can return it at any time
*/
mark_object(clwp->lwp_thread);
#endif /* THREADS */
/* now collect from the c-stack of the thread ... */
{ int *where;
volatile jmp_buf buf;
/* ensure flushing of register caches */
if (ecl_setjmp(buf) == 0) ecl_longjmp(buf, 1);
#ifdef THREADS
if (clwp != old_clwp) /* is not the executing stack */
# ifdef __linux
where = (int *)pdp->pd_env[0].__jmpbuf[0].__sp;
# else
where = (int *)pdp->pd_env[JB_SP];
# endif
else
#endif /* THREADS */
where = (int *)&where ;
/* If the locals of type object in a C function could be
aligned other than on multiples of sizeof (char *)
we would have to mark twice */
#if DOWN_STACK
/* if (where < cs_org) */
mark_stack_conservative((cl_ptr)where, (cl_ptr)cs_org);
#else
/* if (where > cs_org) */
mark_stack_conservative((cl_ptr)cs_org, (cl_ptr)where);
#endif
mark_stack_conservative(&buf, (&buf) + 1);
}
#ifdef THREADS
}
clwp = old_clwp;
}
#endif /* THREADS */
/* mark roots */
for (i = 0; i < gc_roots; i++)
mark_object(*gc_root[i]);
}
static void
sweep_phase(void)
{
register int i, j, k;
register cl_object x;
register cl_ptr p;
register struct typemanager *tm;
register cl_object f;
Cnil->symbol.m = FALSE;
Ct->symbol.m = FALSE;
if (debug)
printf("type map\n");
for (i = 0; i < maxpage; i++) {
if (type_map[i] == (int)t_contiguous) {
if (debug) {
printf("-");
continue;
}
}
if (type_map[i] >= (int)t_end)
continue;
tm = tm_of((cl_type)type_map[i]);
/*
general sweeper
*/
if (debug)
printf("%c", tm->tm_name[0]);
p = pagetochar(i);
f = tm->tm_free;
k = 0;
for (j = tm->tm_nppage; j > 0; --j, p += tm->tm_size) {
x = (cl_object)p;
if (x->d.m == FREE)
continue;
else if (x->d.m) {
/* FIXME!!! Here should come a finalization
procedure for streams */
x->d.m = FALSE;
continue;
}
((struct freelist *)x)->f_link = f;
x->d.m = FREE;
f = x;
k++;
}
tm->tm_free = f;
tm->tm_nfree += k;
tm->tm_nused -= k;
}
if (debug) {
putchar('\n');
fflush(stdout);
}
}
static void
contblock_sweep_phase(void)
{
register int i, j;
register cl_ptr s, e, p, q;
register struct contblock *cbp;
cb_pointer = NULL;
ncb = 0;
for (i = 0; i < maxpage;) {
if (type_map[i] != (int)t_contiguous) {
i++;
continue;
}
for (j = i+1;
j < maxpage && type_map[j] == (int)t_contiguous;
j++)
;
s = pagetochar(i);
e = pagetochar(j);
for (p = s; p < e;) {
if (get_mark_bit((int *)p)) {
p += 4;
continue;
}
q = p + 4;
while (q < e && !get_mark_bit((int *)q))
q += 4;
cl_dealloc(p, q - p);
p = q + 4;
}
i = j + 1;
}
if (debug) {
for (cbp = cb_pointer; cbp != NULL; cbp = cbp->cb_link)
printf("0x%p %d\n", cbp, cbp->cb_size);
fflush(stdout);
}
}
cl_object (*GC_enter_hook)() = NULL;
cl_object (*GC_exit_hook)() = NULL;
#ifdef THREADS
/*
* We execute the GC routine in the main stack.
* The idea is to switch over the main stack that is stopped in the intha
* and to call the GC from there on garbage_parameter. Then you can switch
* back after.
* In addition the interrupt is disabled.
*/
static int i, j;
static sigjmp_buf old_env;
static int val;
static lpd *old_clwp;
static cl_type t;
static bool stack_switched = FALSE;
static cl_type garbage_parameter;
void
ecl_gc(cl_type new_name)
{
int tm;
int gc_start = runtime();
start_critical_section();
t = new_name;
garbage_parameter = new_name;
#else
void
ecl_gc(cl_type t)
{
int i, j;
int tm;
int gc_start = runtime();
#endif /* THREADS */
if (!GC_enabled())
return;
if (SYM_VAL(@'si::*gc-verbose*') != Cnil) {
printf("\n[GC ..");
/* To use this should add entries in tm_table for reloc and contig.
fprintf(stdout, "\n[GC for %d %s pages ..",
tm_of(t)->tm_npage,
tm_table[(int)t].tm_name + 1); */
fflush(stdout);
}
debug = symbol_value(@'si::*gc-message*') != Cnil;
#ifdef THREADS
if (clwp != &main_lpd) {
if (debug) {
printf("*STACK SWITCH*\n");
fflush (stdout);
}
stack_switched = TRUE;
val = sigsetjmp(old_env, 1);
if (val == 0) {
/* informations used by the garbage collector need to be updated */
# ifdef __linux
running_head->pd_env[0].__jmpbuf[0].__sp = old_env[0].__jmpbuf[0].__sp;
# else
running_head->pd_env[JB_SP] = old_env[JB_SP];
# endif
old_clwp = clwp;
Values = main_lpd.lwp_Values;
clwp = &main_lpd;
siglongjmp(main_pd.pd_env, 2); /* new line */
}
}
else val = 1;
if (val == 1) {
#endif /* THREADS */
if (GC_enter_hook != NULL)
(*GC_enter_hook)();
interrupt_enable = FALSE;
collect_blocks = t > t_end;
if (collect_blocks)
cbgccount++;
else
tm_table[(int)t].tm_gccount++;
if (debug) {
if (collect_blocks)
printf("GC entered for collecting blocks\n");
else
printf("GC entered for collecting %s\n", tm_table[(int)t].tm_name);
fflush(stdout);
}
maxpage = page(heap_end);
if (collect_blocks) {
/*
1 page = 512 word
512 bit = 16 word
*/
int mark_table_size = maxpage * (LISP_PAGESIZE / 32);
extern void cl_resize_hole(cl_index);
if (holepage < mark_table_size*sizeof(int)/LISP_PAGESIZE + 1)
new_holepage = mark_table_size*sizeof(int)/LISP_PAGESIZE + 1;
if (new_holepage < HOLEPAGE)
new_holepage = HOLEPAGE;
cl_resize_hole(new_holepage);
mark_table = (int*)heap_end;
for (i = 0; i < mark_table_size; i++)
mark_table[i] = 0;
}
if (debug) {
printf("mark phase\n");
fflush(stdout);
tm = runtime();
}
mark_phase();
if (debug) {
printf("mark ended (%d)\n", runtime() - tm);
printf("sweep phase\n");
fflush(stdout);
tm = runtime();
}
sweep_phase();
if (debug) {
printf("sweep ended (%d)\n", runtime() - tm);
fflush(stdout);
}
if (t == t_contiguous) {
if (debug) {
printf("contblock sweep phase\n");
fflush(stdout);
tm = runtime();
}
contblock_sweep_phase();
if (debug)
printf("contblock sweep ended (%d)\n", runtime() - tm);
}
if (debug) {
for (i = 0, j = 0; i < (int)t_end; i++) {
if (tm_table[i].tm_type == (cl_type)i) {
printf("%13s: %8d used %8d free %4d/%d pages\n",
tm_table[i].tm_name,
tm_table[i].tm_nused,
tm_table[i].tm_nfree,
tm_table[i].tm_npage,
tm_table[i].tm_maxpage);
j += tm_table[i].tm_npage;
} else
printf("%13s: linked to %s\n",
tm_table[i].tm_name,
tm_table[(int)tm_table[i].tm_type].tm_name);
}
printf("contblock: %d blocks %d pages\n", ncb, ncbpage);
printf("hole: %d pages\n", holepage);
printf("GC ended\n");
fflush(stdout);
}
interrupt_enable = TRUE;
if (GC_exit_hook != NULL)
(*GC_exit_hook)();
#ifdef THREADS
/*
* Back in the right stack
*/
if (stack_switched) {
if (debug) {
printf("*STACK BACK*\n");
fflush (stdout);
}
stack_switched = FALSE;
end_critical_section(); /* we get here from the GC call in scheduler */
clwp = old_clwp;
Values = clwp->lwp_Values;
siglongjmp(old_env, 2);
}
}
#endif /* THREADS */
gc_time += (gc_start = runtime() - gc_start);
if (SYM_VAL(@'si::*gc-verbose*') != Cnil) {
/* Don't use fprintf since on Linux it calls malloc() */
printf(". finished in %.2f\"]", gc_start/60.0);
fflush(stdout);
}
if (interrupt_flag) sigint();
end_critical_section();
}
/*
*----------------------------------------------------------------------
*
* mark_contblock --
* sets the mark bit for words from address p to address p+s.
* Both p and p+s are rounded to word boundaries.
*
* Results:
* none.
*
* Side effects:
* mark_table
*
*----------------------------------------------------------------------
*/
static void
_mark_contblock(void *x, cl_index s)
{
cl_ptr p = x, q;
if (p >= heap_start && p < data_end) {
ptrdiff_t pg = page(p);
if ((cl_type)type_map[pg] == t_contiguous) {
cl_ptr q = p + s;
p = int2ptr(ptr2int(p) & ~3);
q = int2ptr(ptr2int(q + 3) & ~3);
for (; p < q; p+= 4)
set_mark_bit(p);
}
}
}
/*----------------------------------------------------------------------
* Utilities
*----------------------------------------------------------------------
*/
@(defun si::room_report ()
int i;
cl_object *tl;
@
NValues = 8;
VALUES(0) = MAKE_FIXNUM(real_maxpage);
VALUES(1) = MAKE_FIXNUM(available_pages());
VALUES(2) = MAKE_FIXNUM(ncbpage);
VALUES(3) = MAKE_FIXNUM(maxcbpage);
VALUES(4) = MAKE_FIXNUM(ncb);
VALUES(5) = MAKE_FIXNUM(cbgccount);
VALUES(6) = MAKE_FIXNUM(holepage);
VALUES(7) = Cnil;
tl = &VALUES(7);
for (i = 0; i < (int)t_end; i++) {
if (tm_table[i].tm_type == (cl_type)i) {
tl = &CDR(*tl = CONS(MAKE_FIXNUM(tm_table[i].tm_nused), Cnil));
tl = &CDR(*tl = CONS(MAKE_FIXNUM(tm_table[i].tm_nfree), Cnil));
tl = &CDR(*tl = CONS(MAKE_FIXNUM(tm_table[i].tm_npage), Cnil));
tl = &CDR(*tl = CONS(MAKE_FIXNUM(tm_table[i].tm_maxpage), Cnil));
tl = &CDR(*tl = CONS(MAKE_FIXNUM(tm_table[i].tm_gccount), Cnil));
} else {
tl = &CDR(*tl = CONS(Cnil, Cnil));
tl = &CDR(*tl = CONS(MAKE_FIXNUM(tm_table[i].tm_type), Cnil));
tl = &CDR(*tl = CONS(Cnil, Cnil));
tl = &CDR(*tl = CONS(Cnil, Cnil));
tl = &CDR(*tl = CONS(Cnil, Cnil));
}
}
return VALUES(0);
@)
@(defun si::reset_gc_count ()
int i;
@
cbgccount = 0;
for (i = 0; i < (int)t_end; i++)
tm_table[i].tm_gccount = 0;
@(return)
@)
@(defun si::gc_time ()
@
@(return MAKE_FIXNUM(gc_time))
@)
void
init_GC(void)
{
SYM_VAL(@'si::*gc-verbose*') = Cnil;
SYM_VAL(@'si::*gc-message*') = Cnil;
GC_enable();
gc_time = 0;
}
#endif