9 #define ldnode(addr) ((word) (addr & 0xFF))
10 #define ldpix(addr) ((word) ((addr >> 8) & 0xFF))
11 #define staddr(node, pix) ((word) ((pix << 8) | node))
15 These are converters from global to process pointers in memory
16 to global process pointers in message.
17 M denotes memory in which pair (pointer,object) exists or has to exist.
18 We want to create object denoting remote process instead of
19 dummy pointer without object.
20 The object will be like an arrayof integer of size 2.
21 arr[1..3] : arr[1]=node, arr[2]=pix.
24 void obj2mess(word *M, virtaddr *obj, procaddr *mess)
28 if(obj->mark != M[obj->addr + 1]){
39 mess->node=ldnode(obj->addr);
40 mess->pix =ldpix (obj->addr);
45 void mess2obj(procdescr *p, procaddr *mess, virtaddr *obj)
50 word currpix = thispix;
52 extern int compactify_allowed;
53 compactify_allowed = 0;
54 transfer(p - process);
57 newarry(1, 4, APROCESS, obj, &am);
65 compactify_allowed = 1;
68 obj->addr=staddr(mess->node, mess->pix);
75 bool isprocess(virtaddr *v) {
79 /*assert(v->mark<=M[v->addr+1]);*/
80 if(v->mark != M[v->addr + 1] ) {
83 return (M[am + 1] == APROCESS);
94 /* hash entry is a word pointing to dictionary or 0 if empty */
97 static int hash_check_item(word, procaddr *);
98 static void hash_new_item(virtaddr *, procaddr *);
99 static int hash_mess(procaddr *);
100 static int hash_2(int);
102 static int hash_check_item();
103 static void hash_new_item();
106 void hash_create(procdescr *p, int size) {
107 /* create hash table for p process */
112 p->hash = mallocate(size);
116 for (i = 0; i < p->hash_size; i++)
122 * find pointer in hash table, add if not exists
124 void hash_find(procaddr *mess, virtaddr *obj) {
127 first = hash_mess(mess);
128 jump = hash_2(first);
129 for (i = first; thisp->hash[i] != 0; ) {
130 if (hash_check_item(thisp->hash[i], mess)) {
131 obj->addr=thisp->hash[i];
132 obj->mark=M[thisp->hash[i] + 1];
135 i = (i + jump) % thisp->hash_size;
137 int *curhash = thisp->hash;
138 int cursize = thisp->hash_size;
139 /* the rest is not debugged yet */
141 thisp->hash_size = cursize * 3 - 1;
142 thisp->hash = mallocate(thisp->hash_size);
143 if(thisp->hash == NULL)
146 for (i = 0; i < thisp->hash_size; i++)
149 for (i = 0; i < cursize; i++) {
153 obj.addr = curhash[i];
154 obj.mark = M[curhash[i] + 1];
155 obj2mess(M, &obj, &mess);
156 hash_set(&mess, curhash[i]);
159 hash_new_item(obj, mess);
160 hash_set(mess, obj->addr);
165 hash_new_item(obj, mess);
166 thisp->hash[i] = obj->addr;
169 void hash_set(procaddr *mess, word ah) {
172 first = hash_mess(mess);
173 jump = hash_2(first);
174 for(i = first; thisp->hash[i] != 0; ) {
175 assert(!hash_check_item(thisp->hash[i], mess));
176 i = (i + jump) % thisp->hash_size;
181 assert(thisp->hash[i] == 0);
187 static int hash_check_item(word ah, procaddr *mess) {
189 return (mess->node == M[am + 2] && mess->pix == M[am + 3] &&
190 mess->mark == M[am + 4]);
193 static void hash_new_item(virtaddr *obj, procaddr *mess) {
195 newarry(1, 4, APROCESS, obj, &am);
196 M[am + 2] = mess->node;
197 M[am + 3] = mess->pix;
198 M[am + 4] = mess->mark;
201 static int hash_mess(procaddr *mess) {
202 word hash = mess->pix;
203 hash *= abs(mess->mark);
205 return hash % (thisp->hash_size);
208 static int hash_2( hash_1 ) hash_1;{
209 return thisp->hash_size -2 - (hash_1 % (thisp->hash_size - 2));