Raymond Toy pushed to branch issue-243-weak-pointer-to-static-array at cmucl / cmucl

Commits:

1 changed file:

Changes:

  • src/lisp/gencgc.c
    ... ... @@ -5421,7 +5421,8 @@ size_weak_pointer(lispobj * where)
    5421 5421
     static void
    
    5422 5422
     scan_static_vectors(struct weak_pointer *static_vector_list)
    
    5423 5423
     {
    
    5424
    -    struct weak_pointer *wp;
    
    5424
    +    struct weak_pointer *wp = static_vector_list;
    
    5425
    +    struct weak_pointer *previous = wp;
    
    5425 5426
     
    
    5426 5427
         DPRINTF(debug_static_array_p,
    
    5427 5428
                 (stdout, "Phase 2: Visit unused static vectors\n"));
    
    ... ... @@ -5432,7 +5433,9 @@ scan_static_vectors(struct weak_pointer *static_vector_list)
    5432 5433
          * in the header to say we've visited it.  If we've already
    
    5433 5434
          * visited the static vector, break the weak pointer.
    
    5434 5435
          */
    
    5435
    -    for (wp = static_vector_list; wp; wp = wp->next) {
    
    5436
    +
    
    5437
    +    while (wp) {
    
    5438
    +        struct weak_pointer *next = wp->next;
    
    5436 5439
             lispobj *header = (lispobj *) PTR(wp->value);
    
    5437 5440
     
    
    5438 5441
             DPRINTF(debug_static_array_p,
    
    ... ... @@ -5456,8 +5459,32 @@ scan_static_vectors(struct weak_pointer *static_vector_list)
    5456 5459
     
    
    5457 5460
                     wp->value = NIL;
    
    5458 5461
                     wp->broken = T;
    
    5462
    +                /*
    
    5463
    +                 * Remove this weak pointer from static_vector_list;
    
    5464
    +                 * we're done processing it.
    
    5465
    +                 *
    
    5466
    +                 * Three cases here:
    
    5467
    +                 *
    
    5468
    +                 *   1. wp is the first in the list; update
    
    5469
    +                 *   static_vector_list to skip over this pointer.
    
    5470
    +                 *
    
    5471
    +                 *   2. wp is the last (next = NULL); set the next
    
    5472
    +                 *   slot of the previous pointer to NULL.
    
    5473
    +                 *
    
    5474
    +                 *   3. wp is in the middle; update the next slot of
    
    5475
    +                 *   the previous pointer to the next value.
    
    5476
    +                 */
    
    5477
    +                if (wp == static_vector_list) {
    
    5478
    +                    static_vector_list = next;
    
    5479
    +                } else if (next == NULL) {
    
    5480
    +                    previous->next = NULL;
    
    5481
    +                } else {
    
    5482
    +                    previous->next = next;
    
    5483
    +                }
    
    5459 5484
                 }
    
    5460 5485
             }
    
    5486
    +        previous = wp;
    
    5487
    +        wp = next;
    
    5461 5488
         }
    
    5462 5489
         
    
    5463 5490
     
    
    ... ... @@ -5473,29 +5500,31 @@ scan_static_vectors(struct weak_pointer *static_vector_list)
    5473 5500
          * free the static vector.  Also break the weak pointer too, since
    
    5474 5501
          * the space has been freed.
    
    5475 5502
          */
    
    5476
    -    for (wp = static_vector_list; wp; wp = wp->next) {
    
    5503
    +    wp = static_vector_list;
    
    5504
    +    while (wp) {
    
    5505
    +        struct weak_pointer *next = wp->next;
    
    5506
    +        lispobj *header = (lispobj *) PTR(wp->value);
    
    5477 5507
             /* Skip over broken weak pointers */
    
    5478
    -        if (wp->broken == NIL) {
    
    5479
    -            lispobj *header = (lispobj *) PTR(wp->value);
    
    5480 5508
     
    
    5481
    -            DPRINTF(debug_static_array_p,
    
    5482
    -                    (stdout, "  wp %p value %p header 0x%08lx\n",
    
    5483
    -                     wp, (lispobj*) wp->value, *header));
    
    5509
    +        DPRINTF(debug_static_array_p,
    
    5510
    +                (stdout, "  wp %p value %p header 0x%08lx\n",
    
    5511
    +                 wp, (lispobj*) wp->value, *header));
    
    5484 5512
     
    
    5485
    -            /*
    
    5486
    -             * Only free the arrays where the mark bit is clear.
    
    5487
    -             */
    
    5488
    -            if ((*header & STATIC_VECTOR_MARK_BIT) == 0)  {
    
    5489
    -                lispobj *static_array = (lispobj *) PTR(wp->value);
    
    5490
    -                DPRINTF(debug_static_array_p,
    
    5491
    -                        (stdout, "    Free static vector\n"));
    
    5513
    +        gc_assert(wp->broken == NIL);
    
    5514
    +        /*
    
    5515
    +         * Only free the arrays where the mark bit is clear.
    
    5516
    +         */
    
    5517
    +        if ((*header & STATIC_VECTOR_MARK_BIT) == 0)  {
    
    5518
    +            lispobj *static_array = (lispobj *) PTR(wp->value);
    
    5519
    +            DPRINTF(debug_static_array_p,
    
    5520
    +                    (stdout, "    Free static vector\n"));
    
    5492 5521
     
    
    5493
    -                wp->value = NIL;
    
    5494
    -                wp->broken = T;
    
    5522
    +            wp->value = NIL;
    
    5523
    +            wp->broken = T;
    
    5495 5524
     
    
    5496
    -                free(static_array);
    
    5497
    -            }
    
    5525
    +            free(static_array);
    
    5498 5526
             }
    
    5527
    +        wp = next;
    
    5499 5528
         }
    
    5500 5529
         
    
    5501 5530