2 % (c) Parade/AQUA Projects, Glasgow University, 1995
3 % Kevin Hammond, February 15th. 1995
5 % This is for GUM only.
7 %************************************************************************
9 \section[Unpack.lc]{Unpacking closures which have been exported to remote processors}
11 %************************************************************************
13 This module defines routines for unpacking closures in the parallel runtime
17 #ifdef PAR /* whole file */
20 EXTDATA_RO(FetchMe_info);
26 static globalAddr PendingGABuffer[(PACK_BUFFER_SIZE-PACK_HDR_SIZE)*2];
29 @CommonUp@ commons up two closures which we have discovered to be
30 variants of the same object. One is made an indirection to the other.
41 switch (INFO_TYPE(INFO_PTR(src))) {
42 case INFO_SPEC_RBH_TYPE:
43 bqe = (P_) SPEC_RBH_BQ(src);
45 case INFO_GEN_RBH_TYPE:
46 bqe = (P_) GEN_RBH_BQ(src);
48 case INFO_FETCHME_TYPE:
52 bqe = (P_) FMBQ_ENTRIES(src);
55 /* Don't common up anything else */
59 /* Note that UPD_IND does *not* awaken the bq */
61 ASSERT(!IS_BIG_MOTHER(INFO_PTR(dst)));
62 if (IS_MUTABLE(INFO_PTR(bqe)))
63 AwakenBlockingQueue(bqe);
68 @UnpackGraph@ unpacks the graph contained in a message buffer. It
69 returns a pointer to the new graph. The @gamap@ parameter is set to
70 point to an array of (oldGA,newGA) pairs which were created as a
71 result of unpacking the buffer; @nGAs@ is set to the number of GA
72 pairs which were created.
74 The format of graph in the pack buffer is as defined in @Pack.lc@.
78 UnpackGraph(buffer, gamap, nGAs)
83 W_ size, ptrs, nonptrs, vhs;
85 P_ bufptr = buffer + PACK_HDR_SIZE;
94 P_ graphroot, graph, parent;
95 W_ pptr = 0, pptrs = 0, pvhs;
99 globalAddr *gaga = PendingGABuffer;
103 /* Unpack the header */
108 graph = AllocateHeap(bufsize);
109 ASSERT(graph != NULL);
115 /* This is where we will ultimately save the closure's address */
118 /* First, unpack the next GA or PLC */
119 ga.weight = *bufptr++;
122 ga.loc.gc.gtid = *bufptr++;
123 ga.loc.gc.slot = *bufptr++;
125 ga.loc.plc = (P_) *bufptr++;
127 /* Now unpack the closure body, if there is one */
129 /* No more to unpack; just set closure to local address */
131 fprintf(stderr, "Unpacked PLC at %x \n", ga.loc.plc);
133 closure = ga.loc.plc;
134 } else if (isOffset(&ga)) {
135 /* No more to unpack; just set closure to cached address */
136 ASSERT(parent != NULL);
137 closure = (P_) buffer[ga.loc.gc.slot];
140 /* Now we have to build something. */
145 * Close your eyes. You don't want to see where we're looking. You
146 * can't get closure info until you've unpacked the variable header,
147 * but you don't know how big it is until you've got closure info.
148 * So...we trust that the closure in the buffer is organized the
149 * same way as they will be in the heap...at least up through the
150 * end of the variable header.
152 ip = get_closure_info(bufptr, &size, &ptrs, &nonptrs, &vhs);
154 /* Fill in the fixed header */
155 for (i = 0; i < FIXED_HS; i++)
156 graph[i] = *bufptr++;
158 if (INFO_TYPE(ip) == INFO_FETCHME_TYPE)
159 size = ptrs = nonptrs = vhs = 0;
161 /* Fill in the packed variable header */
162 for (i = 0; i < vhs; i++)
163 graph[FIXED_HS + i] = *bufptr++;
165 /* Pointers will be filled in later */
167 /* Fill in the packed non-pointers */
168 for (i = 0; i < nonptrs; i++)
169 graph[FIXED_HS + i + vhs + ptrs] = *bufptr++;
171 /* Indirections are never packed */
172 ASSERT(INFO_PTR(graph) != (W_) Ind_info);
174 /* Add to queue for processing */
178 * Common up the new closure with any existing closure having the same
182 if ((existing = GALAlookup(&ga)) == NULL) {
184 /* Just keep the new object */
186 fprintf(stderr, "Unpacking new (%x, %d, %x)\n",
187 ga.loc.gc.gtid, ga.loc.gc.slot, ga.weight);
190 newGA = setRemoteGA(graph, &ga, rtsTrue);
191 if (INFO_TYPE(ip) == INFO_FETCHME_TYPE)
192 FETCHME_GA(closure) = newGA;
194 /* Two closures, one global name. Someone loses */
195 oldip = (P_) INFO_PTR(existing);
197 if ((INFO_TYPE(oldip) == INFO_FETCHME_TYPE || IS_BLACK_HOLE(oldip)) &&
198 INFO_TYPE(ip) != INFO_FETCHME_TYPE) {
200 /* What we had wasn't worth keeping */
202 CommonUp(existing, graph);
206 * Either we already had something worthwhile by this name or
207 * the new thing is just another FetchMe. However, the thing we
208 * just unpacked has to be left as-is, or the child unpacking
209 * code will fail. Remember that the way pointer words are
210 * filled in depends on the info pointers of the parents being
211 * the same as when they were packed.
214 fprintf(stderr, "Unpacking old (%x, %d, %x), keeping %#lx\n",
215 ga.loc.gc.gtid, ga.loc.gc.slot, ga.weight, existing);
219 /* Pool the total weight in the stored ga */
220 (void) addWeight(&ga);
223 /* Sort out the global address mapping */
224 if ((IS_THUNK(ip) && IS_UPDATABLE(ip)) ||
225 (IS_MUTABLE(ip) && INFO_TYPE(ip) != INFO_FETCHME_TYPE)) {
226 /* Make up new GAs for single-copy closures */
227 globalAddr *newGA = MakeGlobal(closure, rtsTrue);
229 ASSERT(closure == graph);
231 /* Create an old GA to new GA mapping */
233 splitWeight(gaga, newGA);
234 ASSERT(gaga->weight == 1L << (BITS_IN(unsigned) - 1));
237 graph += FIXED_HS + (size < MIN_UPD_SIZE ? MIN_UPD_SIZE : size);
241 * Set parent pointer to point to chosen closure. If we're at the top of
242 * the graph (our parent is NULL), then we want to arrange to return the
243 * chosen closure to our caller (possibly in place of the allocated graph
249 parent[FIXED_HS + pvhs + pptr] = (W_) closure;
251 /* Save closure pointer for resolving offsets */
252 *slotptr = (W_) closure;
254 /* Locate next parent pointer */
256 while (pptr + 1 > pptrs) {
257 parent = DeQueueClosure();
262 (void) get_closure_info(parent, &size, &pptrs, &nonptrs, &pvhs);
266 } while (parent != NULL);
268 ASSERT(bufsize == 0 || graph - 1 <= SAVE_Hp);
270 *gamap = PendingGABuffer;
271 *nGAs = (gaga - PendingGABuffer) / 2;
273 /* ToDo: are we *certain* graphroot has been set??? WDP 95/07 */
279 #endif /* PAR -- whole file */