... |
... |
@@ -5393,13 +5393,42 @@ size_weak_pointer(lispobj * where) |
5393
|
5393
|
return WEAK_POINTER_NWORDS;
|
5394
|
5394
|
}
|
5395
|
5395
|
|
|
5396
|
+
|
|
5397
|
+static void
|
|
5398
|
+update_static_vector_list(lispobj value, lispobj* vectors_to_free, int* num_static_vectors)
|
|
5399
|
+{
|
|
5400
|
+ /*
|
|
5401
|
+ * We have a static array with the mark cleared which means it's
|
|
5402
|
+ * not used.
|
|
5403
|
+ *
|
|
5404
|
+ * Only add it if we don't already have it. We don't want
|
|
5405
|
+ * duplicates because we'll end up trying to free things multiple
|
|
5406
|
+ * times.
|
|
5407
|
+ */
|
|
5408
|
+ int m;
|
|
5409
|
+ int found = 0;
|
|
5410
|
+
|
|
5411
|
+ for (m = 0; m < *num_static_vectors; ++m) {
|
|
5412
|
+ if (value == vectors_to_free[m]) {
|
|
5413
|
+ printf("Found %p at %d\n", (lispobj *) value, m);
|
|
5414
|
+ found = 1;
|
|
5415
|
+ break;
|
|
5416
|
+ }
|
|
5417
|
+ }
|
|
5418
|
+ if (!found) {
|
|
5419
|
+ printf("Adding %p at %d\n", (lispobj *) value, *num_static_vectors);
|
|
5420
|
+ vectors_to_free[*num_static_vectors] = value;
|
|
5421
|
+ ++*num_static_vectors;
|
|
5422
|
+ }
|
|
5423
|
+}
|
|
5424
|
+
|
5396
|
5425
|
void
|
5397
|
5426
|
scan_weak_pointers(void)
|
5398
|
5427
|
{
|
5399
|
5428
|
struct weak_pointer *wp;
|
5400
|
5429
|
lispobj* vectors_to_free = NULL;
|
5401
|
|
- int max_vectors = 0;
|
5402
|
|
- int k = 0;
|
|
5430
|
+ int num_weak_pointers = 0;
|
|
5431
|
+ int num_static_vectors = 0;
|
5403
|
5432
|
int n;
|
5404
|
5433
|
|
5405
|
5434
|
/*
|
... |
... |
@@ -5408,20 +5437,21 @@ scan_weak_pointers(void) |
5408
|
5437
|
*/
|
5409
|
5438
|
|
5410
|
5439
|
for (wp = weak_pointers; wp; wp = wp->next) {
|
5411
|
|
- max_vectors++;
|
|
5440
|
+ num_weak_pointers++;
|
5412
|
5441
|
}
|
5413
|
5442
|
|
5414
|
|
- printf("weak pointer count = %d\n", max_vectors);
|
|
5443
|
+ printf("weak pointer count = %d\n", num_weak_pointers);
|
5415
|
5444
|
|
5416
|
5445
|
/* Nothing to do if there are no weak pointers */
|
5417
|
|
- if (max_vectors == 0) {
|
|
5446
|
+ if (num_weak_pointers == 0) {
|
5418
|
5447
|
return;
|
5419
|
5448
|
}
|
5420
|
5449
|
|
5421
|
5450
|
/*
|
5422
|
|
- * Allocate max space
|
|
5451
|
+ * Allocate enough space to hold all weak pointers in case they
|
|
5452
|
+ * all point to static vectors.
|
5423
|
5453
|
*/
|
5424
|
|
- vectors_to_free = (lispobj*) malloc(max_vectors * sizeof(lispobj));
|
|
5454
|
+ vectors_to_free = (lispobj*) malloc(num_weak_pointers * sizeof(lispobj));
|
5425
|
5455
|
gc_assert(vectors_to_free);
|
5426
|
5456
|
|
5427
|
5457
|
printf("vectors_to_free = %p\n", vectors_to_free);
|
... |
... |
@@ -5446,32 +5476,17 @@ scan_weak_pointers(void) |
5446
|
5476
|
/* The value may be a static vector */
|
5447
|
5477
|
lispobj *header = (lispobj *) PTR(value);
|
5448
|
5478
|
|
5449
|
|
- printf("value %p, header = %p\n", (lispobj*) value, header);
|
|
5479
|
+ printf("value %p, header = %0lx\n", (lispobj*) value, *header);
|
5450
|
5480
|
|
5451
|
5481
|
if (maybe_static_array_p(*header)) {
|
|
5482
|
+ /*
|
|
5483
|
+ * A header value of 1 means we have a static
|
|
5484
|
+ * vector with the in-use bit cleared, so we can
|
|
5485
|
+ * collect the vector.
|
|
5486
|
+ */
|
5452
|
5487
|
if (HeaderValue(*header) == 1) {
|
5453
|
|
- /*
|
5454
|
|
- * We have a static array with the mark
|
5455
|
|
- * cleared which means it's not used.
|
5456
|
|
- *
|
5457
|
|
- * Only add it if we don't already have it.
|
5458
|
|
- */
|
5459
|
|
- int m;
|
5460
|
|
- int found = 0;
|
|
5488
|
+ update_static_vector_list(value, vectors_to_free, &num_static_vectors);
|
5461
|
5489
|
|
5462
|
|
- for (m = 0; m < k; ++m) {
|
5463
|
|
- if (value == vectors_to_free[m]) {
|
5464
|
|
- printf("Found %p at %d\n", (lispobj *) value, m);
|
5465
|
|
- found = 1;
|
5466
|
|
- break;
|
5467
|
|
- }
|
5468
|
|
- }
|
5469
|
|
- if (!found) {
|
5470
|
|
- printf("Adding %p at %d\n", (lispobj *) value, k);
|
5471
|
|
- vectors_to_free[k] = value;
|
5472
|
|
- ++k;
|
5473
|
|
- }
|
5474
|
|
-
|
5475
|
5490
|
/*
|
5476
|
5491
|
* Now we can break the weak pointer to the static vector.
|
5477
|
5492
|
*/
|
... |
... |
@@ -5486,9 +5501,9 @@ scan_weak_pointers(void) |
5486
|
5501
|
/*
|
5487
|
5502
|
* Free up any unreferenced static vectors now
|
5488
|
5503
|
*/
|
5489
|
|
- printf("%d static vectors to be freed\n", k);
|
|
5504
|
+ printf("%d static vectors to be freed\n", num_static_vectors);
|
5490
|
5505
|
|
5491
|
|
- for (n = 0; n < k; ++n) {
|
|
5506
|
+ for (n = 0; n < num_static_vectors; ++n) {
|
5492
|
5507
|
lispobj *header = (lispobj *) PTR(vectors_to_free[n]);
|
5493
|
5508
|
printf("free %p: %p\n", (void*) vectors_to_free[n], header);
|
5494
|
5509
|
free(header);
|