9 #define ldnode(addr) ((word) (addr & 0xFF))
10 #define ldpix(addr) ((word) ((addr >> 8) & 0xFF))
11 #define staddr(node, pix) ((word) ((pix << 8) | node))
16 * These are converters from global to process pointers in memory
17 * to global process pointers in message.
18 * M denotes memory in which pair (pointer,object) exists or has to exist.
19 * We want to create object denoting remote process instead of
20 * dummy pointer without object.
21 * The object will be like an arrayof integer of size 2.
22 * arr[1..3] : arr[1]=node, arr[2]=pix.
25 void obj2mess(word *M, virtaddr *obj, procaddr *mess)
29 if(obj->mark != M[obj->addr + 1]){
40 mess->node=ldnode(obj->addr);
41 mess->pix =ldpix (obj->addr);
46 void mess2obj(procdescr *p, procaddr *mess, virtaddr *obj)
51 word currpix = thispix;
53 extern int compactify_allowed;
54 compactify_allowed = 0;
55 transfer(p - process);
58 newarry(1, 4, APROCESS, obj, &am);
66 compactify_allowed = 1;
69 obj->addr=staddr(mess->node, mess->pix);
76 bool isprocess(virtaddr *v) {
80 /*assert(v->mark<=M[v->addr+1]);*/
81 if(v->mark != M[v->addr + 1] ) {
84 return (M[am + 1] == APROCESS);
95 /* hash entry is a word pointing to dictionary or 0 if empty */
98 static int hash_check_item(word, procaddr *);
99 static void hash_new_item(virtaddr *, procaddr *);
100 static int hash_mess(procaddr *);
101 static int hash_2(int);
103 static int hash_check_item();
104 static void hash_new_item();
107 void hash_create(procdescr *p, int size) {
108 /* create hash table for p process */
113 p->hash = mallocate(size);
117 for (i = 0; i < p->hash_size; i++)
123 * find pointer in hash table, add if not exists
125 void hash_find(procaddr *mess, virtaddr *obj) {
128 first = hash_mess(mess);
129 jump = hash_2(first);
130 for (i = first; thisp->hash[i] != 0; ) {
131 if (hash_check_item(thisp->hash[i], mess)) {
132 obj->addr=thisp->hash[i];
133 obj->mark=M[thisp->hash[i] + 1];
136 i = (i + jump) % thisp->hash_size;
138 int *curhash = thisp->hash;
139 int cursize = thisp->hash_size;
140 /* the rest is not debugged yet */
142 thisp->hash_size = cursize * 3 - 1;
143 thisp->hash = mallocate(thisp->hash_size);
144 if(thisp->hash == NULL)
147 for (i = 0; i < thisp->hash_size; i++)
150 for (i = 0; i < cursize; i++) {
154 obj.addr = curhash[i];
155 obj.mark = M[curhash[i] + 1];
156 obj2mess(M, &obj, &mess);
157 hash_set(&mess, curhash[i]);
160 hash_new_item(obj, mess);
161 hash_set(mess, obj->addr);
166 hash_new_item(obj, mess);
167 thisp->hash[i] = obj->addr;
170 void hash_set(procaddr *mess, word ah) {
173 first = hash_mess(mess);
174 jump = hash_2(first);
175 for(i = first; thisp->hash[i] != 0; ) {
176 assert(!hash_check_item(thisp->hash[i], mess));
177 i = (i + jump) % thisp->hash_size;
182 assert(thisp->hash[i] == 0);
188 static int hash_check_item(word ah, procaddr *mess) {
190 return (mess->node == M[am + 2] && mess->pix == M[am + 3] &&
191 mess->mark == M[am + 4]);
194 static void hash_new_item(virtaddr *obj, procaddr *mess) {
196 newarry(1, 4, APROCESS, obj, &am);
197 M[am + 2] = mess->node;
198 M[am + 3] = mess->pix;
199 M[am + 4] = mess->mark;
202 static int hash_mess(procaddr *mess) {
203 word hash = mess->pix;
204 hash *= abs(mess->mark);
206 return hash % (thisp->hash_size);
209 static int hash_2(int hash_1 ) {
210 return thisp->hash_size -2 - (hash_1 % (thisp->hash_size - 2));