File: external_markbits.c

package info (click to toggle)
euslisp 9.27%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 55,344 kB
  • sloc: ansic: 41,162; lisp: 3,339; makefile: 256; sh: 208; asm: 138; python: 53
file content (86 lines) | stat: -rw-r--r-- 1,970 bytes parent folder | download | duplicates (2)
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
/*
 * external_markbits.c: R.Hanai
 */

#include <stdio.h>
#include "external_markbits.h"
#include "rgc_utils.h"

#define bit_table_error(str)

unsigned int hmin, hmax;
static char *bit_table;
unsigned int mingcheap, maxgcheap;

void set_heap_range(unsigned int min, unsigned int max)
{
  if(mingcheap == 0 || min < mingcheap) mingcheap = min; 
  if(maxgcheap == 0 || max > maxgcheap) maxgcheap = max;
}

void allocate_bit_table()
{
  int size;

  ASSERT(mingcheap != maxgcheap);

  size = (maxgcheap-mingcheap+3)>>2;
  //size *= 2;
  hmin = mingcheap;
  hmax = mingcheap + (size<<2);
  //DPRINT2("allocate bit table [%x, %x)", hmin, hmax);
  bit_table = (char *)malloc(size);

  ASSERT(bit_table); // "failed to allocate an external bit table")
}

__inline__ void set_bit(unsigned int addr)
{
  ASSERT(hmin <= addr && addr < hmax);
//    DPRINT3("set: over the heap [%x;%x), addr=%x", hmin, hmax, addr);
//    DPRINT3("set: under the heap. [%x;%x], addr=%x", hmin, hmax, addr);

//  ASSERT(!(addr & 0x3));
//    DPRINT3("set: addr not word aligned, addr=%x", addr);
  
  bit_table[(addr - hmin) >> 2] = 1;
}

__inline__ char read_bit(unsigned int addr)
{
  ASSERT(hmin <= addr && addr < hmax);
//    DPRINT3("read: over the heap [%x;%x), addr=%x", hmin, hmax, addr);
//    DPRINT3("read: under the heap [%x;%x), addr=%x", hmin, hmax, addr);
  /* copyobj in leo.c:619 < leo.c:632 */

//  ASSERT(!(addr & 0x3));
//    DPRINT3("set: addr not word aligned, addr=%x", addr);
  
  return bit_table[(addr - hmin) >> 2];
}

/* 
 * copyobj in leo.c:619 < leo.c:632
 * SORT in sequence.c 978 
 * */

void clear_bit_table()
{
  memset(&bit_table[0], 0, (hmax-hmin+3)>>2);
}

void print_bit_table()
{
  int i, size, prod;
  size = (hmax-hmin+3)>>2;
  prod = 0;
  DPRINT2("bit-table size=%d", size);
  for(i = 0; i < size; i++){
    if(!(i&0xff)){
      fprintf(stderr, "%d", prod);
      prod = 0;
    }
    prod |= bit_table[i];
    if(!(i%(80*256))) fprintf(stderr, "\n");
  }
}