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

Commits:

1 changed file:

Changes:

  • src/lisp/gencgc.c
    ... ... @@ -5418,11 +5418,11 @@ size_weak_pointer(lispobj * where)
    5418 5418
     
    
    5419 5419
     
    
    5420 5420
     static void
    
    5421
    -scan_static_vectors(void)
    
    5421
    +scan_static_vectors(struct weak_pointer *static_vector_list)
    
    5422 5422
     {
    
    5423 5423
         struct weak_pointer *wp;
    
    5424
    -    struct weak_pointer *static_vector_list = NULL;
    
    5425 5424
     
    
    5425
    +#if 0
    
    5426 5426
         if (debug_static_array_p) {
    
    5427 5427
             printf("Phase 1: Find static vectors\n");
    
    5428 5428
         }
    
    ... ... @@ -5462,10 +5462,10 @@ scan_static_vectors(void)
    5462 5462
             }
    
    5463 5463
             wp = next;
    
    5464 5464
         }
    
    5465
    +#endif
    
    5465 5466
     
    
    5466
    -    if (debug_static_array_p) {
    
    5467
    -        printf("Phase 2: Visit unused static vectors\n");
    
    5468
    -    }
    
    5467
    +    DPRINTF(debug_static_array_p,
    
    5468
    +            (stdout, "Phase 2: Visit unused static vectors\n"));
    
    5469 5469
         
    
    5470 5470
         /*
    
    5471 5471
          * static_vector_list now points to all weak pointers to static
    
    ... ... @@ -5476,10 +5476,9 @@ scan_static_vectors(void)
    5476 5476
         for (wp = static_vector_list; wp; wp = wp->next) {
    
    5477 5477
             lispobj *header = (lispobj *) PTR(wp->value);
    
    5478 5478
     
    
    5479
    -        if (debug_static_array_p) {
    
    5480
    -            printf("  wp %p value %p header 0x%08lx\n",
    
    5481
    -                   wp, (lispobj *) wp->value, *header);
    
    5482
    -        }
    
    5479
    +        DPRINTF(debug_static_array_p,
    
    5480
    +                (stdout, "  wp %p value %p header 0x%08lx\n",
    
    5481
    +                 wp, (lispobj *) wp->value, *header));
    
    5483 5482
     
    
    5484 5483
             /*
    
    5485 5484
              * If the static vector is unused (mark bit clear) and if we
    
    ... ... @@ -5489,15 +5488,12 @@ scan_static_vectors(void)
    5489 5488
             if ((*header & STATIC_VECTOR_MARK_BIT) == 0) {
    
    5490 5489
                 /* Unused static vector */
    
    5491 5490
                 if ((*header & STATIC_VECTOR_VISITED_BIT) == 0) {
    
    5492
    -                if (debug_static_array_p) {
    
    5493
    -                    printf("    Mark vector\n");
    
    5494
    -                }
    
    5491
    +                DPRINTF(debug_static_array_p, (stdout, "    Mark vector\n"));
    
    5495 5492
     
    
    5496 5493
                     *header |= STATIC_VECTOR_VISITED_BIT;
    
    5497 5494
                 } else {
    
    5498
    -                if (debug_static_array_p) {
    
    5499
    -                    printf("    Break weak pointer %p\n", wp);
    
    5500
    -                }
    
    5495
    +                DPRINTF(debug_static_array_p,
    
    5496
    +                        (stdout, "    Break weak pointer %p\n", wp));
    
    5501 5497
     
    
    5502 5498
                     wp->value = NIL;
    
    5503 5499
                     wp->broken = T;
    
    ... ... @@ -5506,9 +5502,8 @@ scan_static_vectors(void)
    5506 5502
         }
    
    5507 5503
         
    
    5508 5504
     
    
    5509
    -    if (debug_static_array_p) {
    
    5510
    -        printf("Phase 3: Free static vectors\n");
    
    5511
    -    }
    
    5505
    +    DPRINTF(debug_static_array_p,
    
    5506
    +            (stdout, "Phase 3: Free static vectors\n"));
    
    5512 5507
     
    
    5513 5508
         /*
    
    5514 5509
          * static_vector_list now contains either broken weak pointers or
    
    ... ... @@ -5524,19 +5519,17 @@ scan_static_vectors(void)
    5524 5519
             if (wp->broken == NIL) {
    
    5525 5520
                 lispobj *header = (lispobj *) PTR(wp->value);
    
    5526 5521
     
    
    5527
    -            if (debug_static_array_p) {
    
    5528
    -                printf("  wp %p value %p header 0x%08lx\n",
    
    5529
    -                       wp, (lispobj*) wp->value, *header);
    
    5530
    -            }
    
    5522
    +            DPRINTF(debug_static_array_p,
    
    5523
    +                    (stdout, "  wp %p value %p header 0x%08lx\n",
    
    5524
    +                     wp, (lispobj*) wp->value, *header));
    
    5531 5525
     
    
    5532 5526
                 /*
    
    5533 5527
                  * Only free the arrays where the mark bit is clear.
    
    5534 5528
                  */
    
    5535 5529
                 if ((*header & STATIC_VECTOR_MARK_BIT) == 0)  {
    
    5536 5530
                     lispobj *static_array = (lispobj *) PTR(wp->value);
    
    5537
    -                if (debug_static_array_p) {
    
    5538
    -                    printf("    Free static vector\n");
    
    5539
    -                }
    
    5531
    +                DPRINTF(debug_static_array_p,
    
    5532
    +                        (stdout, "    Free static vector\n"));
    
    5540 5533
     
    
    5541 5534
                     wp->value = NIL;
    
    5542 5535
                     wp->broken = T;
    
    ... ... @@ -5547,9 +5540,8 @@ scan_static_vectors(void)
    5547 5540
         }
    
    5548 5541
         
    
    5549 5542
     
    
    5550
    -    if (debug_static_array_p) {
    
    5551
    -        printf("Phase 4: unmark static vectors\n");
    
    5552
    -    }
    
    5543
    +    DPRINTF(debug_static_array_p,
    
    5544
    +            (stdout, "Phase 4: unmark static vectors\n"));
    
    5553 5545
     
    
    5554 5546
         /*
    
    5555 5547
          * At this point, static_vector_list contains weak pointers that
    
    ... ... @@ -5563,15 +5555,13 @@ scan_static_vectors(void)
    5563 5555
             if (wp->broken == NIL) {
    
    5564 5556
                 lispobj *header = (lispobj *) PTR(wp->value);
    
    5565 5557
     
    
    5566
    -            if (debug_static_array_p) {
    
    5567
    -                printf("  wp %p value %p broken %d header 0x%08lx\n",
    
    5568
    -                       wp, (lispobj*) wp->value, wp->broken == T, *header);
    
    5569
    -            }
    
    5558
    +            DPRINTF(debug_static_array_p,
    
    5559
    +                    (stdout, "  wp %p value %p broken %d header 0x%08lx\n",
    
    5560
    +                     wp, (lispobj*) wp->value, wp->broken == T, *header));
    
    5570 5561
     
    
    5571 5562
                 if ((*header & STATIC_VECTOR_MARK_BIT) != 0) {
    
    5572
    -                if (debug_static_array_p) {
    
    5573
    -                    printf("    Clearing mark bit\n");
    
    5574
    -                }
    
    5563
    +                DPRINTF(debug_static_array_p,
    
    5564
    +                        (stdout, "    Clearing mark bit\n"));
    
    5575 5565
     
    
    5576 5566
                     *header &= ~STATIC_VECTOR_MARK_BIT;
    
    5577 5567
                 }
    
    ... ... @@ -5582,24 +5572,57 @@ scan_static_vectors(void)
    5582 5572
     void
    
    5583 5573
     scan_weak_pointers(void)
    
    5584 5574
     {
    
    5585
    -    struct weak_pointer *wp;
    
    5575
    +    struct weak_pointer *wp = weak_pointers;
    
    5576
    +    struct weak_pointer *static_vector_list = NULL;
    
    5586 5577
     
    
    5587
    -    for (wp = weak_pointers; wp; wp = wp->next) {
    
    5578
    +    /*
    
    5579
    +     * Scan through all the weak pointers, updating the value or
    
    5580
    +     * breaking the weak pointer.
    
    5581
    +     *
    
    5582
    +     * Also find any weak pointers to static vectors.  This
    
    5583
    +     * destructively modifies the next slot of the weak pointer to
    
    5584
    +     * chain all the weak pointers to static vectors together.
    
    5585
    +     */
    
    5586
    +    DPRINTF(debug_static_array_p,
    
    5587
    +            (stdout, "Phase 0: Process weak pointers\n"));
    
    5588
    +
    
    5589
    +    while (wp) {
    
    5590
    +        struct weak_pointer *next = wp->next;
    
    5588 5591
     	lispobj value = wp->value;
    
    5589 5592
     	lispobj *first_pointer = (lispobj *) PTR(value);
    
    5590 5593
     
    
    5591 5594
     	wp->mark_bit = NIL;
    
    5592
    -	if (Pointerp(value) && from_space_p(value)) {
    
    5593
    -	    if (first_pointer[0] == 0x01)
    
    5594
    -		wp->value = first_pointer[1];
    
    5595
    -	    else {
    
    5596
    -		wp->value = NIL;
    
    5597
    -		wp->broken = T;
    
    5598
    -	    }
    
    5599
    -	}
    
    5595
    +	if (Pointerp(value)) {
    
    5596
    +            if (from_space_p(value)) {
    
    5597
    +                if (first_pointer[0] == 0x01)
    
    5598
    +                    wp->value = first_pointer[1];
    
    5599
    +                else {
    
    5600
    +                    wp->value = NIL;
    
    5601
    +                    wp->broken = T;
    
    5602
    +                }
    
    5603
    +            } else {
    
    5604
    +                /* The value may be a static vector */
    
    5605
    +                lispobj header = *(lispobj *) PTR(value);
    
    5606
    +
    
    5607
    +                if (maybe_static_array_p(header)) {
    
    5608
    +
    
    5609
    +                    DPRINTF(debug_static_array_p,
    
    5610
    +                            (stdout, "  Add static vector:  wp %p value %p header 0x%08lx\n",
    
    5611
    +                             wp, (lispobj *) wp->value, header));
    
    5612
    +
    
    5613
    +                    wp->next = static_vector_list;
    
    5614
    +                    static_vector_list = wp;
    
    5615
    +                } else {
    
    5616
    +                    DPRINTF(debug_static_array_p,
    
    5617
    +                            (stdout, "  Skip: wp %p value %p header 0x%08lx\n",
    
    5618
    +                             wp, (lispobj *) wp->value, header));
    
    5619
    +                }
    
    5620
    +            }
    
    5621
    +        }
    
    5622
    +        wp = next;
    
    5600 5623
         }
    
    5601 5624
     
    
    5602
    -    scan_static_vectors();
    
    5625
    +    scan_static_vectors(static_vector_list);
    
    5603 5626
     }
    
    5604 5627
     
    
    5605 5628