~ubuntu-branches/ubuntu/quantal/libgc/quantal

« back to all changes in this revision

Viewing changes to tests/test.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2011-02-19 12:19:56 UTC
  • mfrom: (1.3.2 upstream) (0.1.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110219121956-67rb69xlt5nud3v2
Tags: 1:7.1-5
Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
# else
37
37
#   include <assert.h>        /* Not normally used, but handy for debugging. */
38
38
# endif
39
 
# include <assert.h>    /* Not normally used, but handy for debugging. */
40
39
# include "gc.h"
41
40
# include "gc_typed.h"
42
 
# ifdef THREAD_LOCAL_ALLOC
43
 
#   include "gc_local_alloc.h"
44
 
# endif
45
41
# include "private/gc_priv.h"   /* For output, locking, MIN_WORDS,      */
46
 
                                /* and some statistics.                 */
47
 
# include "private/gcconfig.h"
 
42
                                /* and some statistics, and gcconfig.h. */
48
43
 
49
44
# if defined(MSWIN32) || defined(MSWINCE)
50
45
#   include <windows.h>
 
46
#   ifdef GC_DLL
 
47
#     define GC_print_stats 0   /* Not exported from DLL */
 
48
                                /* Redefine to 1 to generate output. */
 
49
#   endif
51
50
# endif
52
51
 
53
52
# ifdef PCR
54
53
#   include "th/PCR_ThCrSec.h"
55
54
#   include "th/PCR_Th.h"
56
 
#   undef GC_printf0
57
 
#   define GC_printf0 printf
58
 
#   undef GC_printf1
59
 
#   define GC_printf1 printf
60
 
# endif
61
 
 
62
 
# if defined(GC_SOLARIS_THREADS) && !defined(GC_SOLARIS_PTHREADS)
63
 
#   include <thread.h>
64
 
#   include <synch.h>
 
55
#   define GC_printf printf
65
56
# endif
66
57
 
67
58
# if defined(GC_PTHREADS)
76
67
# include <stdarg.h>
77
68
#endif
78
69
 
 
70
/* Call GC_INIT only on platforms on which we think we really need it,  */
 
71
/* so that we can test automatic initialization on the rest.            */
 
72
#if defined(CYGWIN32) || defined (AIX) || defined(DARWIN)
 
73
#  define GC_COND_INIT() GC_INIT()
 
74
#else
 
75
#  define GC_COND_INIT()
 
76
#endif
79
77
 
80
78
/* Allocation Statistics */
81
79
int stubborn_count = 0;
97
95
              ret=GC_malloc_explicitly_typed(lb,d);
98
96
                }
99
97
      if(ret==NULL){
100
 
        GC_printf0("Out of memory, (typed allocations are not directly "
101
 
                   "supported with the GC_AMIGA_FASTALLOC option.)\n");
 
98
        GC_printf("Out of memory, (typed allocations are not directly "
 
99
                  "supported with the GC_AMIGA_FASTALLOC option.)\n");
102
100
        FAIL;
103
101
      }
104
102
    }
112
110
              ret=GC_calloc_explicitly_typed(a,lb,d);
113
111
                }
114
112
      if(ret==NULL){
115
 
        GC_printf0("Out of memory, (typed allocations are not directly "
116
 
                   "supported with the GC_AMIGA_FASTALLOC option.)\n");
 
113
        GC_printf("Out of memory, (typed allocations are not directly "
 
114
                  "supported with the GC_AMIGA_FASTALLOC option.)\n");
117
115
        FAIL;
118
116
      }
119
117
    }
150
148
 
151
149
typedef struct SEXPR * sexpr;
152
150
 
153
 
# define INT_TO_SEXPR(x) ((sexpr)(unsigned long)(x))
 
151
# define INT_TO_SEXPR(x) ((sexpr)(GC_word)(x))
 
152
# define SEXPR_TO_INT(x) ((int)(GC_word)(x))
154
153
 
155
154
# undef nil
156
155
# define nil (INT_TO_SEXPR(0))
166
165
# ifdef VERY_SMALL_CONFIG
167
166
#   define cons small_cons
168
167
# else
169
 
sexpr cons (x, y)
170
 
sexpr x;
171
 
sexpr y;
 
168
sexpr cons (sexpr x, sexpr y)
172
169
{
173
 
    register sexpr r;
174
 
    register int *p;
175
 
    register int my_extra = extra_count;
 
170
    sexpr r;
 
171
    int *p;
 
172
    int my_extra = extra_count;
176
173
    
177
174
    stubborn_count++;
178
175
    r = (sexpr) GC_MALLOC_STUBBORN(sizeof(struct SEXPR) + my_extra);
179
176
    if (r == 0) {
180
 
        (void)GC_printf0("Out of memory\n");
 
177
        (void)GC_printf("Out of memory\n");
181
178
        exit(1);
182
179
    }
183
180
    for (p = (int *)r;
184
181
         ((char *)p) < ((char *)r) + my_extra + sizeof(struct SEXPR); p++) {
185
182
        if (*p) {
186
 
            (void)GC_printf1("Found nonzero at 0x%lx - allocator is broken\n",
187
 
                             (unsigned long)p);
 
183
            (void)GC_printf("Found nonzero at %p - allocator is broken\n", p);
188
184
            FAIL;
189
185
        }
190
 
        *p = 13;
 
186
        *p = (int)((13 << 12) + ((p - (int *)r) & 0xfff));
191
187
    }
192
188
#   ifdef AT_END
193
189
        r = (sexpr)((char *)r + (my_extra & ~7));
236
232
    }
237
233
    x = (sexpr)(addr + 1); /* Skip the vtable pointer. */
238
234
    mark_stack_ptr = GC_MARK_AND_PUSH(
239
 
                              (GC_PTR)(x -> sexpr_cdr), mark_stack_ptr,
240
 
                              mark_stack_limit, (GC_PTR *)&(x -> sexpr_cdr));
 
235
                              (void *)(x -> sexpr_cdr), mark_stack_ptr,
 
236
                              mark_stack_limit, (void * *)&(x -> sexpr_cdr));
241
237
    mark_stack_ptr = GC_MARK_AND_PUSH(
242
 
                              (GC_PTR)(x -> sexpr_car), mark_stack_ptr,
243
 
                              mark_stack_limit, (GC_PTR *)&(x -> sexpr_car));
 
238
                              (void *)(x -> sexpr_car), mark_stack_ptr,
 
239
                              mark_stack_limit, (void * *)&(x -> sexpr_car));
244
240
    return(mark_stack_ptr);
245
241
}
246
242
 
247
243
#endif /* GC_GCJ_SUPPORT */
248
244
 
249
 
#ifdef THREAD_LOCAL_ALLOC
250
 
 
251
 
#undef GC_REDIRECT_TO_LOCAL
252
 
#include "gc_local_alloc.h"
253
 
 
254
 
sexpr local_cons (x, y)
255
 
sexpr x;
256
 
sexpr y;
257
 
{
258
 
    register sexpr r;
259
 
    register int *p;
260
 
    register int my_extra = extra_count;
261
 
    static int my_random = 0;
262
 
    
263
 
    collectable_count++;
264
 
    r = (sexpr) GC_LOCAL_MALLOC(sizeof(struct SEXPR) + my_extra);
265
 
#   ifdef GC_GCJ_SUPPORT
266
 
      if (collectable_count % 2 == 0) {
267
 
        r = (sexpr) GC_LOCAL_GCJ_MALLOC(sizeof(struct SEXPR) + sizeof(GC_word) + my_extra,
268
 
                                        &gcj_class_struct1);
269
 
        r = (sexpr) ((GC_word *)r + 1);
270
 
      }
271
 
#   endif
272
 
    if (r == 0) {
273
 
        (void)GC_printf0("Out of memory\n");
274
 
        exit(1);
275
 
    }
276
 
    for (p = (int *)r;
277
 
         ((char *)p) < ((char *)r) + my_extra + sizeof(struct SEXPR); p++) {
278
 
        if (*p) {
279
 
            (void)GC_printf1("Found nonzero at 0x%lx (local) - allocator is broken\n",
280
 
                             (unsigned long)p);
281
 
            FAIL;
282
 
        }
283
 
        *p = 13;
284
 
    }
285
 
    r -> sexpr_car = x;
286
 
    r -> sexpr_cdr = y;
287
 
    my_extra++;
288
 
    if ( my_extra >= 5000 || my_extra == 200 && ++my_random % 37 != 0) {
289
 
        extra_count = 0;
290
 
    } else {
291
 
        extra_count = my_extra;
292
 
    }
293
 
    return(r);
294
 
}
295
 
#endif /* THREAD_LOCAL_ALLOC */
296
 
 
297
 
sexpr small_cons (x, y)
298
 
sexpr x;
299
 
sexpr y;
300
 
{
301
 
    register sexpr r;
 
245
 
 
246
sexpr small_cons (sexpr x, sexpr y)
 
247
{
 
248
    sexpr r;
302
249
    
303
250
    collectable_count++;
304
251
    r = (sexpr) GC_MALLOC(sizeof(struct SEXPR));
305
252
    if (r == 0) {
306
 
        (void)GC_printf0("Out of memory\n");
 
253
        (void)GC_printf("Out of memory\n");
307
254
        exit(1);
308
255
    }
309
256
    r -> sexpr_car = x;
311
258
    return(r);
312
259
}
313
260
 
314
 
sexpr small_cons_uncollectable (x, y)
315
 
sexpr x;
316
 
sexpr y;
 
261
sexpr small_cons_uncollectable (sexpr x, sexpr y)
317
262
{
318
 
    register sexpr r;
 
263
    sexpr r;
319
264
    
320
265
    uncollectable_count++;
321
266
    r = (sexpr) GC_MALLOC_UNCOLLECTABLE(sizeof(struct SEXPR));
322
267
    if (r == 0) {
323
 
        (void)GC_printf0("Out of memory\n");
 
268
        (void)GC_printf("Out of memory\n");
324
269
        exit(1);
325
270
    }
326
271
    r -> sexpr_car = x;
327
 
    r -> sexpr_cdr = (sexpr)(~(unsigned long)y);
 
272
    r -> sexpr_cdr = (sexpr)(~(GC_word)y);
328
273
    return(r);
329
274
}
330
275
 
331
276
#ifdef GC_GCJ_SUPPORT
332
277
 
333
278
 
334
 
sexpr gcj_cons(x, y)
335
 
sexpr x;
336
 
sexpr y;
 
279
sexpr gcj_cons(sexpr x, sexpr y)
337
280
{
338
281
    GC_word * r;
339
282
    sexpr result;
340
283
    static int count = 0;
341
284
    
342
 
    if (++count & 1) {
343
 
#     ifdef USE_MARK_BYTES
344
 
        r = (GC_word *) GC_GCJ_FAST_MALLOC(4, &gcj_class_struct1);
345
 
#     else
346
 
        r = (GC_word *) GC_GCJ_FAST_MALLOC(3, &gcj_class_struct1);
347
 
#     endif
348
 
    } else {
349
 
        r = (GC_word *) GC_GCJ_MALLOC(sizeof(struct SEXPR)
350
 
                                      + sizeof(struct fake_vtable*),
351
 
                                      &gcj_class_struct2);
352
 
    }
 
285
    r = (GC_word *) GC_GCJ_MALLOC(sizeof(struct SEXPR)
 
286
                                  + sizeof(struct fake_vtable*),
 
287
                                   &gcj_class_struct2);
353
288
    if (r == 0) {
354
 
        (void)GC_printf0("Out of memory\n");
 
289
        (void)GC_printf("Out of memory\n");
355
290
        exit(1);
356
291
    }
357
292
    result = (sexpr)(r + 1);
362
297
#endif
363
298
 
364
299
/* Return reverse(x) concatenated with y */
365
 
sexpr reverse1(x, y)
366
 
sexpr x, y;
 
300
sexpr reverse1(sexpr x, sexpr y)
367
301
{
368
302
    if (is_nil(x)) {
369
303
        return(y);
372
306
    }
373
307
}
374
308
 
375
 
sexpr reverse(x)
376
 
sexpr x;
 
309
sexpr reverse(sexpr x)
377
310
{
378
311
#   ifdef TEST_WITH_SYSTEM_MALLOC
379
312
      malloc(100000);
381
314
    return( reverse1(x, nil) );
382
315
}
383
316
 
384
 
sexpr ints(low, up)
385
 
int low, up;
 
317
sexpr ints(int low, int up)
386
318
{
387
319
    if (low > up) {
388
320
        return(nil);
393
325
 
394
326
#ifdef GC_GCJ_SUPPORT
395
327
/* Return reverse(x) concatenated with y */
396
 
sexpr gcj_reverse1(x, y)
397
 
sexpr x, y;
 
328
sexpr gcj_reverse1(sexpr x, sexpr y)
398
329
{
399
330
    if (is_nil(x)) {
400
331
        return(y);
403
334
    }
404
335
}
405
336
 
406
 
sexpr gcj_reverse(x)
407
 
sexpr x;
 
337
sexpr gcj_reverse(sexpr x)
408
338
{
409
339
    return( gcj_reverse1(x, nil) );
410
340
}
411
341
 
412
 
sexpr gcj_ints(low, up)
413
 
int low, up;
 
342
sexpr gcj_ints(int low, int up)
414
343
{
415
344
    if (low > up) {
416
345
        return(nil);
420
349
}
421
350
#endif /* GC_GCJ_SUPPORT */
422
351
 
423
 
#ifdef THREAD_LOCAL_ALLOC
424
 
/* Return reverse(x) concatenated with y */
425
 
sexpr local_reverse1(x, y)
426
 
sexpr x, y;
427
 
{
428
 
    if (is_nil(x)) {
429
 
        return(y);
430
 
    } else {
431
 
        return( local_reverse1(cdr(x), local_cons(car(x), y)) );
432
 
    }
433
 
}
434
 
 
435
 
sexpr local_reverse(x)
436
 
sexpr x;
437
 
{
438
 
    return( local_reverse1(x, nil) );
439
 
}
440
 
 
441
 
sexpr local_ints(low, up)
442
 
int low, up;
443
 
{
444
 
    if (low > up) {
445
 
        return(nil);
446
 
    } else {
447
 
        return(local_cons(local_cons(INT_TO_SEXPR(low), nil), local_ints(low+1, up)));
448
 
    }
449
 
}
450
 
#endif /* THREAD_LOCAL_ALLOC */
451
 
 
452
352
/* To check uncollectable allocation we build lists with disguised cdr  */
453
353
/* pointers, and make sure they don't go away.                          */
454
 
sexpr uncollectable_ints(low, up)
455
 
int low, up;
 
354
sexpr uncollectable_ints(int low, int up)
456
355
{
457
356
    if (low > up) {
458
357
        return(nil);
462
361
    }
463
362
}
464
363
 
465
 
void check_ints(list, low, up)
466
 
sexpr list;
467
 
int low, up;
 
364
void check_ints(sexpr list, int low, int up)
468
365
{
469
 
    if ((int)(GC_word)(car(car(list))) != low) {
470
 
        (void)GC_printf0(
 
366
    if (SEXPR_TO_INT(car(car(list))) != low) {
 
367
        (void)GC_printf(
471
368
           "List reversal produced incorrect list - collector is broken\n");
472
369
        FAIL;
473
370
    }
474
371
    if (low == up) {
475
372
        if (cdr(list) != nil) {
476
 
           (void)GC_printf0("List too long - collector is broken\n");
 
373
           (void)GC_printf("List too long - collector is broken\n");
477
374
           FAIL;
478
375
        }
479
376
    } else {
481
378
    }
482
379
}
483
380
 
484
 
# define UNCOLLECTABLE_CDR(x) (sexpr)(~(unsigned long)(cdr(x)))
 
381
# define UNCOLLECTABLE_CDR(x) (sexpr)(~(GC_word)(cdr(x)))
485
382
 
486
 
void check_uncollectable_ints(list, low, up)
487
 
sexpr list;
488
 
int low, up;
 
383
void check_uncollectable_ints(sexpr list, int low, int up)
489
384
{
490
 
    if ((int)(GC_word)(car(car(list))) != low) {
491
 
        (void)GC_printf0(
 
385
    if (SEXPR_TO_INT(car(car(list))) != low) {
 
386
        (void)GC_printf(
492
387
           "Uncollectable list corrupted - collector is broken\n");
493
388
        FAIL;
494
389
    }
495
390
    if (low == up) {
496
391
        if (UNCOLLECTABLE_CDR(list) != nil) {
497
 
           (void)GC_printf0("Uncollectable list too long - collector is broken\n");
 
392
           (void)GC_printf("Uncollectable list too long - collector is broken\n");
498
393
           FAIL;
499
394
        }
500
395
    } else {
503
398
}
504
399
 
505
400
/* Not used, but useful for debugging: */
506
 
void print_int_list(x)
507
 
sexpr x;
 
401
void print_int_list(sexpr x)
508
402
{
509
403
    if (is_nil(x)) {
510
 
        (void)GC_printf0("NIL\n");
 
404
        (void)GC_printf("NIL\n");
511
405
    } else {
512
 
        (void)GC_printf1("(%ld)", (long)(car(car(x))));
 
406
        (void)GC_printf("(%d)", SEXPR_TO_INT(car(car(x))));
513
407
        if (!is_nil(cdr(x))) {
514
 
            (void)GC_printf0(", ");
 
408
            (void)GC_printf(", ");
515
409
            (void)print_int_list(cdr(x));
516
410
        } else {
517
 
            (void)GC_printf0("\n");
 
411
            (void)GC_printf("\n");
 
412
        }
 
413
    }
 
414
}
 
415
 
 
416
/* ditto: */
 
417
void check_marks_int_list(sexpr x)
 
418
{
 
419
    if (!GC_is_marked((ptr_t)x))
 
420
        GC_printf("[unm:%p]", x);
 
421
    else
 
422
        GC_printf("[mkd:%p]", x);
 
423
    if (is_nil(x)) {
 
424
        (void)GC_printf("NIL\n");
 
425
    } else {
 
426
        if (!GC_is_marked((ptr_t)car(x))) GC_printf("[unm car:%p]", car(x));
 
427
        (void)GC_printf("(%d)", SEXPR_TO_INT(car(car(x))));
 
428
        if (!is_nil(cdr(x))) {
 
429
            (void)GC_printf(", ");
 
430
            (void)check_marks_int_list(cdr(x));
 
431
        } else {
 
432
            (void)GC_printf("\n");
518
433
        }
519
434
    }
520
435
}
524
439
 */
525
440
#ifdef THREADS
526
441
 
527
 
# if defined(GC_WIN32_THREADS) && !defined(CYGWIN32)
 
442
# if defined(GC_WIN32_THREADS) && !defined(GC_PTHREADS)
528
443
    DWORD  __stdcall tiny_reverse_test(void * arg)
529
444
# else
530
445
    void * tiny_reverse_test(void * arg)
533
448
    int i;
534
449
    for (i = 0; i < 5; ++i) {
535
450
      check_ints(reverse(reverse(ints(1,10))), 1, 10);
536
 
#     ifdef THREAD_LOCAL_ALLOC
537
 
        check_ints(local_reverse(local_reverse(local_ints(1,10))), 1, 10);
538
 
#     endif
539
451
    }
540
452
    return 0;
541
453
}
546
458
      pthread_t t;
547
459
      int code;
548
460
      if ((code = pthread_create(&t, 0, tiny_reverse_test, 0)) != 0) {
549
 
        (void)GC_printf1("Small thread creation failed %lu\n",
550
 
                         (unsigned long)code);
 
461
        (void)GC_printf("Small thread creation failed %d\n", code);
551
462
        FAIL;
552
463
      }
553
464
      if ((code = pthread_join(t, 0)) != 0) {
554
 
        (void)GC_printf1("Small thread join failed %lu\n",
555
 
        (unsigned long)code);
 
465
        (void)GC_printf("Small thread join failed %d\n", code);
556
466
        FAIL;
557
467
      }
558
468
    }
564
474
        HANDLE h;
565
475
        h = GC_CreateThread(NULL, 0, tiny_reverse_test, 0, 0, &thread_id);
566
476
        if (h == (HANDLE)NULL) {
567
 
            (void)GC_printf1("Small thread creation failed %lu\n",
568
 
                             (unsigned long)GetLastError());
 
477
            (void)GC_printf("Small thread creation failed %d\n",
 
478
                            GetLastError());
569
479
            FAIL;
570
480
        }
571
481
        if (WaitForSingleObject(h, INFINITE) != WAIT_OBJECT_0) {
572
 
            (void)GC_printf1("Small thread wait failed %lu\n",
573
 
                             (unsigned long)GetLastError());
 
482
            (void)GC_printf("Small thread wait failed %d\n",
 
483
                            GetLastError());
574
484
            FAIL;
575
485
        }
576
486
    }
577
487
 
578
 
/* # elif defined(GC_SOLARIS_THREADS) */
579
 
 
580
488
# else
581
489
 
582
490
#   define fork_a_thread()
640
548
    collectable_count++;
641
549
    f = (sexpr *)GC_MALLOC(4 * sizeof(sexpr));
642
550
    realloc_count++;
643
 
    f = (sexpr *)GC_REALLOC((GC_PTR)f, 6 * sizeof(sexpr));
 
551
    f = (sexpr *)GC_REALLOC((void *)f, 6 * sizeof(sexpr));
644
552
    f[5] = ints(1,17);
645
553
    collectable_count++;
646
554
    g = (sexpr *)GC_MALLOC(513 * sizeof(sexpr));
647
555
    realloc_count++;
648
 
    g = (sexpr *)GC_REALLOC((GC_PTR)g, 800 * sizeof(sexpr));
 
556
    g = (sexpr *)GC_REALLOC((void *)g, 800 * sizeof(sexpr));
649
557
    g[799] = ints(1,18);
650
558
    collectable_count++;
651
559
    h = (sexpr *)GC_MALLOC(1025 * sizeof(sexpr));
652
560
    realloc_count++;
653
 
    h = (sexpr *)GC_REALLOC((GC_PTR)h, 2000 * sizeof(sexpr));
 
561
    h = (sexpr *)GC_REALLOC((void *)h, 2000 * sizeof(sexpr));
654
562
#   ifdef GC_GCJ_SUPPORT
655
563
      h[1999] = gcj_ints(1,200);
656
564
      for (i = 0; i < 51; ++i) 
686
594
        /* 49 integers.  Thus this is thread safe without locks,          */
687
595
        /* assuming atomic pointer assignments.                           */
688
596
        a = reverse(reverse(a));
689
 
#       ifdef THREAD_LOCAL_ALLOC
690
 
          a = local_reverse(local_reverse(a));
691
 
#       endif
692
597
#       if !defined(AT_END) && !defined(THREADS)
693
598
          /* This is not thread safe, since realloc explicitly deallocates */
694
599
          if (i & 1) {
695
 
            a = (sexpr)GC_REALLOC((GC_PTR)a, 500);
 
600
            a = (sexpr)GC_REALLOC((void *)a, 500);
696
601
          } else {
697
 
            a = (sexpr)GC_REALLOC((GC_PTR)a, 8200);
 
602
            a = (sexpr)GC_REALLOC((void *)a, 8200);
698
603
          }
699
604
#       endif
700
605
    }
730
635
 
731
636
int finalizable_count = 0;
732
637
int finalized_count = 0;
733
 
VOLATILE int dropped_something = 0;
 
638
volatile int dropped_something = 0;
734
639
 
735
640
# ifdef __STDC__
736
641
  void finalizer(void * obj, void * client_data)
745
650
# ifdef PCR
746
651
     PCR_ThCrSec_EnterSys();
747
652
# endif
748
 
# if defined(GC_SOLARIS_THREADS) && !defined(GC_SOLARIS_PTHREADS)
749
 
    static mutex_t incr_lock;
750
 
    mutex_lock(&incr_lock);
751
 
# endif
752
 
# if  defined(GC_PTHREADS)
 
653
# if defined(GC_PTHREADS)
753
654
    static pthread_mutex_t incr_lock = PTHREAD_MUTEX_INITIALIZER;
754
655
    pthread_mutex_lock(&incr_lock);
755
 
# else
756
 
#   ifdef GC_WIN32_THREADS
757
 
      EnterCriticalSection(&incr_cs);
758
 
#   endif
 
656
# elif defined(GC_WIN32_THREADS)
 
657
    EnterCriticalSection(&incr_cs);
759
658
# endif
760
659
  if ((int)(GC_word)client_data != t -> level) {
761
 
     (void)GC_printf0("Wrong finalization data - collector is broken\n");
 
660
     (void)GC_printf("Wrong finalization data - collector is broken\n");
762
661
     FAIL;
763
662
  }
764
663
  finalized_count++;
766
665
# ifdef PCR
767
666
    PCR_ThCrSec_ExitSys();
768
667
# endif
769
 
# if defined(GC_SOLARIS_THREADS) && !defined(GC_SOLARIS_PTHREADS)
770
 
    mutex_unlock(&incr_lock);
771
 
# endif
772
668
# if defined(GC_PTHREADS)
773
669
    pthread_mutex_unlock(&incr_lock);
774
 
# else
775
 
#   ifdef GC_WIN32_THREADS
776
 
      LeaveCriticalSection(&incr_cs);
777
 
#   endif
 
670
# elif defined(GC_WIN32_THREADS)
 
671
    LeaveCriticalSection(&incr_cs);
778
672
# endif
779
673
}
780
674
 
791
685
 
792
686
int live_indicators_count = 0;
793
687
 
794
 
tn * mktree(n)
795
 
int n;
 
688
tn * mktree(int n)
796
689
{
797
 
#   ifdef THREAD_LOCAL_ALLOC
798
 
      tn * result = (tn *)GC_LOCAL_MALLOC(sizeof(tn));
799
 
#   else
800
 
      tn * result = (tn *)GC_MALLOC(sizeof(tn));
801
 
#   endif
 
690
    tn * result = (tn *)GC_MALLOC(sizeof(tn));
802
691
    
803
692
    collectable_count++;
804
 
#   ifdef THREAD_LOCAL_ALLOC
805
 
       /* Minimally exercise thread local allocation */
806
 
       {
807
 
         char * result = (char *)GC_LOCAL_MALLOC_ATOMIC(17);
808
 
         memset(result, 'a', 17);
809
 
       }
810
 
#   endif /* THREAD_LOCAL_ALLOC */
811
693
#   if defined(MACOS)
812
694
        /* get around static data limitations. */
813
695
        if (!live_indicators)
814
696
                live_indicators =
815
697
                    (GC_word*)NewPtrClear(MAX_FINALIZED * sizeof(GC_word));
816
698
        if (!live_indicators) {
817
 
          (void)GC_printf0("Out of memory\n");
 
699
          (void)GC_printf("Out of memory\n");
818
700
          exit(1);
819
701
        }
820
702
#   endif
821
703
    if (n == 0) return(0);
822
704
    if (result == 0) {
823
 
        (void)GC_printf0("Out of memory\n");
 
705
        (void)GC_printf("Out of memory\n");
824
706
        exit(1);
825
707
    }
826
708
    result -> level = n;
839
721
#         ifdef PCR
840
722
            PCR_ThCrSec_EnterSys();
841
723
#         endif
842
 
#         if defined(GC_SOLARIS_THREADS) && !defined(GC_SOLARIS_PTHREADS)
843
 
            static mutex_t incr_lock;
844
 
            mutex_lock(&incr_lock);
845
 
#         endif
846
724
#         if defined(GC_PTHREADS)
847
725
            static pthread_mutex_t incr_lock = PTHREAD_MUTEX_INITIALIZER;
848
726
            pthread_mutex_lock(&incr_lock);
849
 
#         else
850
 
#           ifdef GC_WIN32_THREADS
851
 
              EnterCriticalSection(&incr_cs);
852
 
#           endif
 
727
#         elif defined(GC_WIN32_THREADS)
 
728
            EnterCriticalSection(&incr_cs);
853
729
#         endif
854
730
                /* Losing a count here causes erroneous report of failure. */
855
731
          finalizable_count++;
857
733
#         ifdef PCR
858
734
            PCR_ThCrSec_ExitSys();
859
735
#         endif
860
 
#         if defined(GC_SOLARIS_THREADS) && !defined(GC_SOLARIS_PTHREADS)
861
 
            mutex_unlock(&incr_lock);
862
 
#         endif
863
736
#         if defined(GC_PTHREADS)
864
737
            pthread_mutex_unlock(&incr_lock);
865
 
#         else
866
 
#           ifdef GC_WIN32_THREADS
867
 
              LeaveCriticalSection(&incr_cs);
868
 
#           endif
 
738
#         elif defined(GC_WIN32_THREADS)
 
739
            LeaveCriticalSection(&incr_cs);
869
740
#         endif
870
741
        }
871
742
 
872
 
        GC_REGISTER_FINALIZER((GC_PTR)result, finalizer, (GC_PTR)(GC_word)n,
873
 
                              (GC_finalization_proc *)0, (GC_PTR *)0);
 
743
        GC_REGISTER_FINALIZER((void *)result, finalizer, (void *)(GC_word)n,
 
744
                              (GC_finalization_proc *)0, (void * *)0);
874
745
        if (my_index >= MAX_FINALIZED) {
875
 
                GC_printf0("live_indicators overflowed\n");
 
746
                GC_printf("live_indicators overflowed\n");
876
747
                FAIL;
877
748
        }
878
749
        live_indicators[my_index] = 13;
879
750
        if (GC_GENERAL_REGISTER_DISAPPEARING_LINK(
880
 
                (GC_PTR *)(&(live_indicators[my_index])),
881
 
                (GC_PTR)result) != 0) {
882
 
                GC_printf0("GC_general_register_disappearing_link failed\n");
 
751
                (void * *)(&(live_indicators[my_index])),
 
752
                (void *)result) != 0) {
 
753
                GC_printf("GC_general_register_disappearing_link failed\n");
883
754
                FAIL;
884
755
        }
885
756
        if (GC_unregister_disappearing_link(
886
 
                (GC_PTR *)
 
757
                (void * *)
887
758
                   (&(live_indicators[my_index]))) == 0) {
888
 
                GC_printf0("GC_unregister_disappearing_link failed\n");
 
759
                GC_printf("GC_unregister_disappearing_link failed\n");
889
760
                FAIL;
890
761
        }
891
762
        if (GC_GENERAL_REGISTER_DISAPPEARING_LINK(
892
 
                (GC_PTR *)(&(live_indicators[my_index])),
893
 
                (GC_PTR)result) != 0) {
894
 
                GC_printf0("GC_general_register_disappearing_link failed 2\n");
 
763
                (void * *)(&(live_indicators[my_index])),
 
764
                (void *)result) != 0) {
 
765
                GC_printf("GC_general_register_disappearing_link failed 2\n");
895
766
                FAIL;
896
767
        }
 
768
        GC_reachable_here(result);
897
769
    }
898
770
    return(result);
899
771
}
900
772
 
901
 
void chktree(t,n)
902
 
tn *t;
903
 
int n;
 
773
void chktree(tn *t, int n)
904
774
{
905
775
    if (n == 0 && t != 0) {
906
 
        (void)GC_printf0("Clobbered a leaf - collector is broken\n");
 
776
        (void)GC_printf("Clobbered a leaf - collector is broken\n");
907
777
        FAIL;
908
778
    }
909
779
    if (n == 0) return;
910
780
    if (t -> level != n) {
911
 
        (void)GC_printf1("Lost a node at level %lu - collector is broken\n",
912
 
                         (unsigned long)n);
 
781
        (void)GC_printf("Lost a node at level %d - collector is broken\n", n);
913
782
        FAIL;
914
783
    }
915
784
    if (counter++ % 373 == 0) {
924
793
    chktree(t -> rchild, n-1);
925
794
}
926
795
 
927
 
# if defined(GC_SOLARIS_THREADS) && !defined(GC_SOLARIS_PTHREADS)
928
 
thread_key_t fl_key;
929
 
 
930
 
void * alloc8bytes()
931
 
{
932
 
# if defined(SMALL_CONFIG) || defined(GC_DEBUG)
933
 
    collectable_count++;
934
 
    return(GC_MALLOC(8));
935
 
# else
936
 
    void ** my_free_list_ptr;
937
 
    void * my_free_list;
938
 
    
939
 
    if (thr_getspecific(fl_key, (void **)(&my_free_list_ptr)) != 0) {
940
 
        (void)GC_printf0("thr_getspecific failed\n");
941
 
        FAIL;
942
 
    }
943
 
    if (my_free_list_ptr == 0) {
944
 
        uncollectable_count++;
945
 
        my_free_list_ptr = GC_NEW_UNCOLLECTABLE(void *);
946
 
        if (thr_setspecific(fl_key, my_free_list_ptr) != 0) {
947
 
            (void)GC_printf0("thr_setspecific failed\n");
948
 
            FAIL;
949
 
        }
950
 
    }
951
 
    my_free_list = *my_free_list_ptr;
952
 
    if (my_free_list == 0) {
953
 
        collectable_count++;
954
 
        my_free_list = GC_malloc_many(8);
955
 
        if (my_free_list == 0) {
956
 
            (void)GC_printf0("alloc8bytes out of memory\n");
957
 
            FAIL;
958
 
        }
959
 
    }
960
 
    *my_free_list_ptr = GC_NEXT(my_free_list);
961
 
    GC_NEXT(my_free_list) = 0;
962
 
    return(my_free_list);
963
 
# endif
964
 
}
965
 
 
966
 
#else
967
 
 
968
 
# if defined(GC_PTHREADS)
 
796
 
 
797
#if defined(GC_PTHREADS)
969
798
pthread_key_t fl_key;
970
799
 
971
800
void * alloc8bytes()
982
811
        uncollectable_count++;
983
812
        my_free_list_ptr = GC_NEW_UNCOLLECTABLE(void *);
984
813
        if (pthread_setspecific(fl_key, my_free_list_ptr) != 0) {
985
 
            (void)GC_printf0("pthread_setspecific failed\n");
 
814
            (void)GC_printf("pthread_setspecific failed\n");
986
815
            FAIL;
987
816
        }
988
817
    }
990
819
    if (my_free_list == 0) {
991
820
        my_free_list = GC_malloc_many(8);
992
821
        if (my_free_list == 0) {
993
 
            (void)GC_printf0("alloc8bytes out of memory\n");
 
822
            (void)GC_printf("alloc8bytes out of memory\n");
994
823
            FAIL;
995
824
        }
996
825
    }
1001
830
# endif
1002
831
}
1003
832
 
1004
 
# else
 
833
#else
1005
834
#   define alloc8bytes() GC_MALLOC_ATOMIC(8)
1006
 
# endif
1007
835
#endif
1008
836
 
1009
 
void alloc_small(n)
1010
 
int n;
 
837
void alloc_small(int n)
1011
838
{
1012
 
    register int i;
 
839
    int i;
1013
840
    
1014
841
    for (i = 0; i < n; i += 8) {
1015
842
        atomic_count++;
1016
843
        if (alloc8bytes() == 0) {
1017
 
            (void)GC_printf0("Out of memory\n");
 
844
            (void)GC_printf("Out of memory\n");
1018
845
            FAIL;
1019
846
        }
1020
847
    }
1036
863
void tree_test()
1037
864
{
1038
865
    tn * root;
1039
 
    register int i;
 
866
    int i;
1040
867
    
1041
868
    root = mktree(TREE_HEIGHT);
1042
869
#   ifndef VERY_SMALL_CONFIG
1044
871
#   endif
1045
872
    chktree(root, TREE_HEIGHT);
1046
873
    if (finalized_count && ! dropped_something) {
1047
 
        (void)GC_printf0("Premature finalization - collector is broken\n");
 
874
        (void)GC_printf("Premature finalization - collector is broken\n");
1048
875
        FAIL;
1049
876
    }
1050
877
    dropped_something = 1;
1085
912
    GC_word bm_large = 0xf7ff7fff;
1086
913
    GC_descr d1 = GC_make_descriptor(&bm3, 2);
1087
914
    GC_descr d2 = GC_make_descriptor(&bm2, 2);
1088
 
#   ifndef LINT
1089
 
      GC_descr dummy = GC_make_descriptor(&bm_large, 32);
1090
 
#   endif
1091
915
    GC_descr d3 = GC_make_descriptor(&bm_large, 32);
1092
916
    GC_descr d4 = GC_make_descriptor(bm_huge, 320);
1093
917
    GC_word * x = (GC_word *)GC_malloc_explicitly_typed(2000, d4);
1094
 
    register int i;
 
918
    int i;
1095
919
    
 
920
#   ifndef LINT
 
921
      (void)GC_make_descriptor(&bm_large, 32);
 
922
#   endif
1096
923
    collectable_count++;
1097
924
    old = 0;
1098
925
    for (i = 0; i < 4000; i++) {
1099
926
        collectable_count++;
1100
927
        new = (GC_word *) GC_malloc_explicitly_typed(4 * sizeof(GC_word), d1);
1101
928
        if (0 != new[0] || 0 != new[1]) {
1102
 
            GC_printf0("Bad initialization by GC_malloc_explicitly_typed\n");
 
929
            GC_printf("Bad initialization by GC_malloc_explicitly_typed\n");
1103
930
            FAIL;
1104
931
        }
1105
932
        new[0] = 17;
1130
957
                                                       3 * sizeof(GC_word),
1131
958
                                                       d2);
1132
959
          if (0 != new[0] || 0 != new[1]) {
1133
 
            GC_printf0("Bad initialization by GC_malloc_explicitly_typed\n");
 
960
            GC_printf("Bad initialization by GC_malloc_explicitly_typed\n");
1134
961
            FAIL;
1135
962
          }
1136
963
        }
1140
967
    }
1141
968
    for (i = 0; i < 20000; i++) {
1142
969
        if (new[0] != 17) {
1143
 
            (void)GC_printf1("typed alloc failed at %lu\n",
1144
 
                             (unsigned long)i);
 
970
            (void)GC_printf("typed alloc failed at %lu\n",
 
971
                            (unsigned long)i);
1145
972
            FAIL;
1146
973
        }
1147
974
        new[0] = 0;
1157
984
#ifndef __STDC__
1158
985
/*ARGSUSED*/
1159
986
void fail_proc1(x)
1160
 
GC_PTR x;
 
987
void * x;
1161
988
{
1162
989
    fail_count++;
1163
990
}
1165
992
#else
1166
993
 
1167
994
/*ARGSUSED*/
1168
 
void fail_proc1(GC_PTR x)
 
995
void fail_proc1(void * x)
1169
996
{
1170
997
    fail_count++;
1171
998
}   
1181
1008
  for (i=0; i<n; i++)
1182
1009
    for (j=0; j<i; j++)
1183
1010
      if (q[i] == q[j]) {
1184
 
        GC_printf0(
1185
 
              "Apparently failed to mark form some function arguments.\n"
 
1011
        GC_printf(
 
1012
              "Apparently failed to mark from some function arguments.\n"
1186
1013
              "Perhaps GC_push_regs was configured incorrectly?\n"
1187
1014
        );
1188
1015
        FAIL;
1200
1027
void run_one_test()
1201
1028
{
1202
1029
    char *x;
 
1030
    char **z;
1203
1031
#   ifdef LINT
1204
1032
        char *y = 0;
1205
1033
#   else
1206
1034
        char *y = (char *)(size_t)fail_proc1;
1207
1035
#   endif
 
1036
    CLOCK_TYPE start_time;
 
1037
    CLOCK_TYPE reverse_time;
 
1038
    CLOCK_TYPE typed_time;
 
1039
    CLOCK_TYPE tree_time;
 
1040
    unsigned long time_diff;
1208
1041
    DCL_LOCK_STATE;
1209
1042
    
1210
1043
#   ifdef FIND_LEAK
1211
 
        (void)GC_printf0(
 
1044
        GC_printf(
1212
1045
                "This test program is not designed for leak detection mode\n");
1213
 
        (void)GC_printf0("Expect lots of problems.\n");
 
1046
        GC_printf("Expect lots of problems.\n");
1214
1047
#   endif
1215
1048
    GC_FREE(0);
1216
1049
#   ifndef DBG_HDRS_ALL
1217
1050
      collectable_count += 3;
1218
 
      if (GC_size(GC_malloc(7)) != 8 &&
1219
 
          GC_size(GC_malloc(7)) != MIN_WORDS * sizeof(GC_word)
 
1051
      if ((GC_size(GC_malloc(7)) != 8 &&
 
1052
           GC_size(GC_malloc(7)) != MIN_WORDS * sizeof(GC_word))
1220
1053
        || GC_size(GC_malloc(15)) != 16) {
1221
 
            (void)GC_printf0("GC_size produced unexpected results\n");
 
1054
            GC_printf("GC_size produced unexpected results\n");
1222
1055
            FAIL;
1223
1056
      }
1224
1057
      collectable_count += 1;
1225
1058
      if (GC_size(GC_malloc(0)) != MIN_WORDS * sizeof(GC_word)) {
1226
 
        (void)GC_printf1("GC_malloc(0) failed: GC_size returns %ld\n",
1227
 
                         GC_size(GC_malloc(0)));
1228
 
            FAIL;
 
1059
        GC_printf("GC_malloc(0) failed: GC_size returns %ld\n",
 
1060
                        (unsigned long)GC_size(GC_malloc(0)));
 
1061
        FAIL;
1229
1062
      }
1230
1063
      collectable_count += 1;
1231
1064
      if (GC_size(GC_malloc_uncollectable(0)) != MIN_WORDS * sizeof(GC_word)) {
1232
 
        (void)GC_printf0("GC_malloc_uncollectable(0) failed\n");
1233
 
            FAIL;
 
1065
        GC_printf("GC_malloc_uncollectable(0) failed\n");
 
1066
        FAIL;
1234
1067
      }
1235
1068
      GC_is_valid_displacement_print_proc = fail_proc1;
1236
1069
      GC_is_visible_print_proc = fail_proc1;
1237
1070
      collectable_count += 1;
1238
1071
      x = GC_malloc(16);
1239
1072
      if (GC_base(x + 13) != x) {
1240
 
        (void)GC_printf0("GC_base(heap ptr) produced incorrect result\n");
 
1073
        GC_printf("GC_base(heap ptr) produced incorrect result\n");
1241
1074
        FAIL;
1242
1075
      }
1243
1076
#     ifndef PCR
1244
1077
        if (GC_base(y) != 0) {
1245
 
          (void)GC_printf0("GC_base(fn_ptr) produced incorrect result\n");
 
1078
          GC_printf("GC_base(fn_ptr) produced incorrect result\n");
1246
1079
          FAIL;
1247
1080
        }
1248
1081
#     endif
1249
1082
      if (GC_same_obj(x+5, x) != x + 5) {
1250
 
        (void)GC_printf0("GC_same_obj produced incorrect result\n");
 
1083
        GC_printf("GC_same_obj produced incorrect result\n");
1251
1084
        FAIL;
1252
1085
      }
1253
1086
      if (GC_is_visible(y) != y || GC_is_visible(x) != x) {
1254
 
        (void)GC_printf0("GC_is_visible produced incorrect result\n");
 
1087
        GC_printf("GC_is_visible produced incorrect result\n");
1255
1088
        FAIL;
1256
1089
      }
 
1090
      z = GC_malloc(8);
 
1091
      GC_PTR_STORE(z, x);
 
1092
      if (*z != x) {
 
1093
        GC_printf("GC_PTR_STORE failed: %p != %p\n", *z, x);
 
1094
        FAIL;
 
1095
      }
1257
1096
      if (!TEST_FAIL_COUNT(1)) {
1258
 
#       if!(defined(RS6000) || defined(POWERPC) || defined(IA64)) || defined(M68K)
1259
 
          /* ON RS6000s function pointers point to a descriptor in the  */
 
1097
#       if!(defined(POWERPC) || defined(IA64)) || defined(M68K)
 
1098
          /* On POWERPCs function pointers point to a descriptor in the */
1260
1099
          /* data segment, so there should have been no failures.       */
1261
1100
          /* The same applies to IA64.  Something similar seems to      */
1262
1101
          /* be going on with NetBSD/M68K.                              */
1263
 
          (void)GC_printf0("GC_is_visible produced wrong failure indication\n");
 
1102
          GC_printf("GC_is_visible produced wrong failure indication\n");
1264
1103
          FAIL;
1265
1104
#       endif
1266
1105
      }
1267
1106
      if (GC_is_valid_displacement(y) != y
1268
1107
        || GC_is_valid_displacement(x) != x
1269
1108
        || GC_is_valid_displacement(x + 3) != x + 3) {
1270
 
        (void)GC_printf0(
 
1109
        GC_printf(
1271
1110
                "GC_is_valid_displacement produced incorrect result\n");
1272
1111
        FAIL;
1273
1112
      }
1291
1130
        if (GC_all_interior_pointers && !TEST_FAIL_COUNT(1)
1292
1131
            || !GC_all_interior_pointers && !TEST_FAIL_COUNT(2)) {
1293
1132
#      endif
1294
 
          (void)GC_printf0("GC_is_valid_displacement produced wrong failure indication\n");
 
1133
          GC_printf("GC_is_valid_displacement produced wrong failure indication\n");
1295
1134
          FAIL;
1296
1135
        }
1297
1136
#     endif
1298
1137
#   endif /* DBG_HDRS_ALL */
1299
1138
    /* Test floating point alignment */
1300
 
   collectable_count += 2;
1301
 
        *(double *)GC_MALLOC(sizeof(double)) = 1.0;
1302
 
        *(double *)GC_MALLOC(sizeof(double)) = 1.0;
 
1139
        collectable_count += 2;
 
1140
        *(double *)GC_MALLOC(sizeof(double)) = 1.0;
 
1141
        *(double *)GC_MALLOC(sizeof(double)) = 1.0;
 
1142
    /* Test size 0 allocation a bit more */
 
1143
        {
 
1144
           size_t i;
 
1145
           for (i = 0; i < 10000; ++i) {
 
1146
             GC_MALLOC(0);
 
1147
             GC_FREE(GC_MALLOC(0));
 
1148
             GC_MALLOC_ATOMIC(0);
 
1149
             GC_FREE(GC_MALLOC_ATOMIC(0));
 
1150
           }
 
1151
         }
1303
1152
#   ifdef GC_GCJ_SUPPORT
1304
1153
      GC_REGISTER_DISPLACEMENT(sizeof(struct fake_vtable *));
1305
1154
      GC_init_gcj_malloc(0, (void *)fake_gcj_mark_proc);
1319
1168
        (GC_gcollect(),GC_malloc(12)),
1320
1169
        (void *)0);
1321
1170
#   endif
 
1171
    /* GC_malloc(0) must return NULL or something we can deallocate. */
 
1172
        GC_free(GC_malloc(0));
 
1173
        GC_free(GC_malloc_atomic(0));
 
1174
        GC_free(GC_malloc(0));
 
1175
        GC_free(GC_malloc_atomic(0));
1322
1176
    /* Repeated list reversal test. */
 
1177
        GET_TIME(start_time);
1323
1178
        reverse_test();
1324
 
#   ifdef PRINTSTATS
1325
 
        GC_printf0("-------------Finished reverse_test\n");
1326
 
#   endif
 
1179
        if (GC_print_stats) {
 
1180
          GET_TIME(reverse_time);
 
1181
          time_diff = MS_TIME_DIFF(reverse_time, start_time);
 
1182
          GC_log_printf("-------------Finished reverse_test at time %u (%p)\n",
 
1183
                        (unsigned) time_diff, &start_time);
 
1184
        }
1327
1185
#   ifndef DBG_HDRS_ALL
1328
1186
      typed_test();
1329
 
#     ifdef PRINTSTATS
1330
 
        GC_printf0("-------------Finished typed_test\n");
1331
 
#     endif
 
1187
      if (GC_print_stats) {
 
1188
        GET_TIME(typed_time);
 
1189
        time_diff = MS_TIME_DIFF(typed_time, start_time);
 
1190
        GC_log_printf("-------------Finished typed_test at time %u (%p)\n",
 
1191
                      (unsigned) time_diff, &start_time);
 
1192
      }
1332
1193
#   endif /* DBG_HDRS_ALL */
1333
1194
    tree_test();
 
1195
    if (GC_print_stats) {
 
1196
      GET_TIME(tree_time);
 
1197
      time_diff = MS_TIME_DIFF(tree_time, start_time);
 
1198
      GC_log_printf("-------------Finished tree_test at time %u (%p)\n",
 
1199
                      (unsigned) time_diff, &start_time);
 
1200
    }
1334
1201
    LOCK();
1335
1202
    n_tests++;
1336
1203
    UNLOCK();
1339
1206
        GC_gcollect();
1340
1207
        tiny_reverse_test(0);
1341
1208
        GC_gcollect();
1342
 
        GC_printf0("Finished a child process\n");
 
1209
        if (GC_print_stats)
 
1210
          GC_log_printf("Finished a child process\n");
1343
1211
        exit(0);
1344
1212
      }
1345
1213
#   endif
1346
 
    /* GC_printf1("Finished %x\n", pthread_self()); */
 
1214
    if (GC_print_stats)
 
1215
      GC_log_printf("Finished %p\n", &start_time);
1347
1216
}
1348
1217
 
1349
1218
void check_heap_stats()
1350
1219
{
1351
 
    unsigned long max_heap_sz;
1352
 
    register int i;
 
1220
    size_t max_heap_sz;
 
1221
    int i;
1353
1222
    int still_live;
1354
1223
    int late_finalize_count = 0;
1355
1224
    
1367
1236
        max_heap_sz = 11000000;
1368
1237
    }
1369
1238
#   endif
1370
 
#   ifndef ALIGN_DOUBLE
1371
 
        /* We end up needing more small object pages. */
1372
 
        max_heap_sz += 2000000;
1373
 
#   endif
1374
1239
#   ifdef GC_DEBUG
1375
1240
        max_heap_sz *= 2;
1376
1241
#       ifdef SAVE_CALL_CHAIN
1387
1252
        GC_gcollect();
1388
1253
        late_finalize_count += GC_invoke_finalizers();
1389
1254
      }
1390
 
    (void)GC_printf1("Completed %lu tests\n", (unsigned long)n_tests);
1391
 
    (void)GC_printf1("Allocated %lu collectable objects\n", (unsigned long)collectable_count);
1392
 
    (void)GC_printf1("Allocated %lu uncollectable objects\n", (unsigned long)uncollectable_count);
1393
 
    (void)GC_printf1("Allocated %lu atomic objects\n", (unsigned long)atomic_count);
1394
 
    (void)GC_printf1("Allocated %lu stubborn objects\n", (unsigned long)stubborn_count);
1395
 
    (void)GC_printf2("Finalized %lu/%lu objects - ",
1396
 
                     (unsigned long)finalized_count,
1397
 
                     (unsigned long)finalizable_count);
 
1255
    (void)GC_printf("Completed %u tests\n", n_tests);
 
1256
    (void)GC_printf("Allocated %d collectable objects\n", collectable_count);
 
1257
    (void)GC_printf("Allocated %d uncollectable objects\n",
 
1258
                    uncollectable_count);
 
1259
    (void)GC_printf("Allocated %d atomic objects\n", atomic_count);
 
1260
    (void)GC_printf("Allocated %d stubborn objects\n", stubborn_count);
 
1261
    (void)GC_printf("Finalized %d/%d objects - ",
 
1262
                    finalized_count, finalizable_count);
1398
1263
#   ifdef FINALIZE_ON_DEMAND
1399
1264
        if (finalized_count != late_finalize_count) {
1400
 
            (void)GC_printf0("Demand finalization error\n");
 
1265
            (void)GC_printf("Demand finalization error\n");
1401
1266
            FAIL;
1402
1267
        }
1403
1268
#   endif
1404
1269
    if (finalized_count > finalizable_count
1405
1270
        || finalized_count < finalizable_count/2) {
1406
 
        (void)GC_printf0("finalization is probably broken\n");
 
1271
        (void)GC_printf("finalization is probably broken\n");
1407
1272
        FAIL;
1408
1273
    } else {
1409
 
        (void)GC_printf0("finalization is probably ok\n");
 
1274
        (void)GC_printf("finalization is probably ok\n");
1410
1275
    }
1411
1276
    still_live = 0;
1412
1277
    for (i = 0; i < MAX_FINALIZED; i++) {
1416
1281
    }
1417
1282
    i = finalizable_count - finalized_count - still_live;
1418
1283
    if (0 != i) {
1419
 
        (void)GC_printf2
1420
 
            ("%lu disappearing links remain and %ld more objects were not finalized\n",
1421
 
             (unsigned long) still_live, (long)i);
 
1284
        GC_printf("%d disappearing links remain and %d more objects "
 
1285
                  "were not finalized\n", still_live, i);
1422
1286
        if (i > 10) {
1423
 
            GC_printf0("\tVery suspicious!\n");
 
1287
            GC_printf("\tVery suspicious!\n");
1424
1288
        } else {
1425
 
            GC_printf0("\tSlightly suspicious, but probably OK.\n");
 
1289
            GC_printf("\tSlightly suspicious, but probably OK.\n");
1426
1290
        }
1427
1291
    }
1428
 
    (void)GC_printf1("Total number of bytes allocated is %lu\n",
 
1292
    (void)GC_printf("Total number of bytes allocated is %lu\n",
1429
1293
                (unsigned long)
1430
 
                   WORDS_TO_BYTES(GC_words_allocd + GC_words_allocd_before_gc));
1431
 
    (void)GC_printf1("Final heap size is %lu bytes\n",
1432
 
                     (unsigned long)GC_get_heap_size());
1433
 
    if (WORDS_TO_BYTES(GC_words_allocd + GC_words_allocd_before_gc)
 
1294
                   (GC_bytes_allocd + GC_bytes_allocd_before_gc));
 
1295
    (void)GC_printf("Final heap size is %lu bytes\n",
 
1296
                    (unsigned long)GC_get_heap_size());
 
1297
    if (GC_bytes_allocd + GC_bytes_allocd_before_gc
1434
1298
#   ifdef VERY_SMALL_CONFIG
1435
1299
        < 2700000*n_tests) {
1436
1300
#   else
1437
1301
        < 33500000*n_tests) {
1438
1302
#   endif
1439
 
        (void)GC_printf0("Incorrect execution - missed some allocations\n");
 
1303
        (void)GC_printf("Incorrect execution - missed some allocations\n");
1440
1304
        FAIL;
1441
1305
    }
1442
1306
    if (GC_get_heap_size() > max_heap_sz*n_tests) {
1443
 
        (void)GC_printf0("Unexpected heap growth - collector may be broken\n");
 
1307
        (void)GC_printf("Unexpected heap growth - collector may be broken\n");
1444
1308
        FAIL;
1445
1309
    }
1446
 
    (void)GC_printf0("Collector appears to work\n");
 
1310
    (void)GC_printf("Collector appears to work\n");
1447
1311
}
1448
1312
 
1449
1313
#if defined(MACOS)
1472
1336
    GC_word p;
1473
1337
#endif
1474
1338
{
1475
 
    GC_printf1(msg, (unsigned long)p);
 
1339
    GC_printf(msg, (unsigned long)p);
1476
1340
    /*FAIL;*/
1477
1341
}
1478
1342
 
1479
1343
 
1480
 
#if !defined(PCR) && !defined(GC_SOLARIS_THREADS) \
 
1344
#if !defined(PCR) \
1481
1345
    && !defined(GC_WIN32_THREADS) && !defined(GC_PTHREADS) \
1482
1346
    || defined(LINT)
1483
1347
#if defined(MSWIN32) && !defined(__MINGW32__)
1494
1358
#   if defined(DJGPP)
1495
1359
        /* No good way to determine stack base from library; do it */
1496
1360
        /* manually on this platform.                              */
1497
 
        GC_stackbottom = (GC_PTR)(&dummy);
 
1361
        GC_stackbottom = (void *)(&dummy);
1498
1362
#   endif
1499
1363
#   if defined(MACOS)
1500
1364
        /* Make sure we have lots and lots of stack space.      */
1502
1366
        /* Cheat and let stdio initialize toolbox for us.       */
1503
1367
        printf("Testing GC Macintosh port.\n");
1504
1368
#   endif
1505
 
    GC_INIT();  /* Only needed on a few platforms.      */
1506
 
    (void) GC_set_warn_proc(warn_proc);
1507
 
#   if (defined(MPROTECT_VDB) || defined(PROC_VDB)) \
1508
 
          && !defined(MAKE_BACK_GRAPH)
 
1369
    GC_COND_INIT();
 
1370
    GC_set_warn_proc(warn_proc);
 
1371
#   if (defined(MPROTECT_VDB) || defined(PROC_VDB) || defined(GWW_VDB)) \
 
1372
          && !defined(MAKE_BACK_GRAPH) && !defined(NO_INCREMENTAL)
1509
1373
      GC_enable_incremental();
1510
 
      (void) GC_printf0("Switched to incremental mode\n");
 
1374
      GC_printf("Switched to incremental mode\n");
1511
1375
#     if defined(MPROTECT_VDB)
1512
 
        (void)GC_printf0("Emulating dirty bits with mprotect/signals\n");
 
1376
        GC_printf("Emulating dirty bits with mprotect/signals\n");
1513
1377
#     else
1514
1378
#       ifdef PROC_VDB
1515
 
        (void)GC_printf0("Reading dirty bits from /proc\n");
 
1379
          GC_printf("Reading dirty bits from /proc\n");
1516
1380
#       else
1517
 
    (void)GC_printf0("Using DEFAULT_VDB dirty bit implementation\n");
 
1381
          GC_printf("Using DEFAULT_VDB dirty bit implementation\n");
1518
1382
#       endif
1519
1383
#      endif
1520
1384
#   endif
1521
1385
    run_one_test();
1522
1386
    check_heap_stats();
1523
1387
#   ifndef MSWINCE
1524
 
    (void)fflush(stdout);
 
1388
      fflush(stdout);
1525
1389
#   endif
1526
1390
#   ifdef LINT
1527
1391
        /* Entry points we should be testing, but aren't.                  */
1547
1411
}
1548
1412
# endif
1549
1413
 
1550
 
#if defined(GC_WIN32_THREADS) && !defined(CYGWIN32)
 
1414
#if defined(GC_WIN32_THREADS) && !defined(GC_PTHREADS)
1551
1415
 
1552
1416
DWORD __stdcall thr_run_one_test(void *arg)
1553
1417
{
1564
1428
  LRESULT ret = 0;
1565
1429
  switch (uMsg) {
1566
1430
    case WM_HIBERNATE:
1567
 
      GC_printf0("Received WM_HIBERNATE, calling GC_gcollect\n");
 
1431
      GC_printf("Received WM_HIBERNATE, calling GC_gcollect\n");
1568
1432
      GC_gcollect();
1569
1433
      break;
1570
1434
    case WM_CLOSE:
1571
 
      GC_printf0("Received WM_CLOSE, closing window\n");
 
1435
      GC_printf("Received WM_CLOSE, closing window\n");
1572
1436
      DestroyWindow(hwnd);
1573
1437
      break;
1574
1438
    case WM_DESTROY:
1644
1508
    HANDLE win_thr_h;
1645
1509
# endif
1646
1510
  DWORD thread_id;
1647
 
# if 0
 
1511
 
 
1512
# ifdef GC_DLL
 
1513
    GC_use_DllMain();  /* Test with implicit thread registration if possible. */
 
1514
    GC_printf("Using DllMain to track threads\n");
 
1515
# endif
 
1516
  GC_COND_INIT();
 
1517
# ifndef NO_INCREMENTAL
1648
1518
    GC_enable_incremental();
1649
1519
# endif
1650
 
  GC_init();
1651
1520
  InitializeCriticalSection(&incr_cs);
1652
1521
  (void) GC_set_warn_proc(warn_proc);
1653
1522
# ifdef MSWINCE
1654
1523
    win_created_h = CreateEvent(NULL, FALSE, FALSE, NULL);
1655
1524
    if (win_created_h == (HANDLE)NULL) {
1656
 
      (void)GC_printf1("Event creation failed %lu\n", (unsigned long)GetLastError());
 
1525
      (void)GC_printf("Event creation failed %\n", GetLastError());
1657
1526
      FAIL;
1658
1527
    }
1659
1528
    win_thr_h = GC_CreateThread(NULL, 0, thr_window, 0, 0, &thread_id);
1660
1529
    if (win_thr_h == (HANDLE)NULL) {
1661
 
      (void)GC_printf1("Thread creation failed %lu\n", (unsigned long)GetLastError());
 
1530
      (void)GC_printf("Thread creation failed %d\n", GetLastError());
1662
1531
      FAIL;
1663
1532
    }
1664
1533
    if (WaitForSingleObject(win_created_h, INFINITE) != WAIT_OBJECT_0)
1669
1538
   for (i = 0; i < NTEST; i++) {
1670
1539
    h[i] = GC_CreateThread(NULL, 0, thr_run_one_test, 0, 0, &thread_id);
1671
1540
    if (h[i] == (HANDLE)NULL) {
1672
 
      (void)GC_printf1("Thread creation failed %lu\n", (unsigned long)GetLastError());
 
1541
      (void)GC_printf("Thread creation failed %d\n", GetLastError());
1673
1542
      FAIL;
1674
1543
    }
1675
1544
   }
1678
1547
# if NTEST > 0
1679
1548
   for (i = 0; i < NTEST; i++) {
1680
1549
    if (WaitForSingleObject(h[i], INFINITE) != WAIT_OBJECT_0) {
1681
 
      (void)GC_printf1("Thread wait failed %lu\n", (unsigned long)GetLastError());
 
1550
      (void)GC_printf("Thread wait failed %d\n", GetLastError());
1682
1551
      FAIL;
1683
1552
    }
1684
1553
   }
1710
1579
    run_one_test();
1711
1580
    if (PCR_Th_T_Join(th1, &code, NIL, PCR_allSigsBlocked, PCR_waitForever)
1712
1581
        != PCR_ERes_okay || code != 0) {
1713
 
        (void)GC_printf0("Thread 1 failed\n");
 
1582
        (void)GC_printf("Thread 1 failed\n");
1714
1583
    }
1715
1584
    if (PCR_Th_T_Join(th2, &code, NIL, PCR_allSigsBlocked, PCR_waitForever)
1716
1585
        != PCR_ERes_okay || code != 0) {
1717
 
        (void)GC_printf0("Thread 2 failed\n");
 
1586
        (void)GC_printf("Thread 2 failed\n");
1718
1587
    }
1719
1588
    check_heap_stats();
1720
1589
    return(0);
1721
1590
}
1722
1591
#endif
1723
1592
 
1724
 
#if defined(GC_SOLARIS_THREADS) || defined(GC_PTHREADS)
 
1593
#if defined(GC_PTHREADS)
1725
1594
void * thr_run_one_test(void * arg)
1726
1595
{
1727
1596
    run_one_test();
1732
1601
#  define GC_free GC_debug_free
1733
1602
#endif
1734
1603
 
1735
 
#if defined(GC_SOLARIS_THREADS) && !defined(GC_SOLARIS_PTHREADS)
1736
 
main()
1737
 
{
1738
 
    thread_t th1;
1739
 
    thread_t th2;
1740
 
    int code;
1741
 
 
1742
 
    n_tests = 0;
1743
 
    GC_INIT();  /* Only needed if gc is dynamic library.        */
1744
 
#   ifndef MAKE_BACK_GRAPH
1745
 
      GC_enable_incremental();
1746
 
#   endif
1747
 
    (void) GC_set_warn_proc(warn_proc);
1748
 
    if (thr_keycreate(&fl_key, GC_free) != 0) {
1749
 
        (void)GC_printf1("Key creation failed %lu\n", (unsigned long)code);
1750
 
        FAIL;
1751
 
    }
1752
 
    if ((code = thr_create(0, 1024*1024, thr_run_one_test, 0, 0, &th1)) != 0) {
1753
 
        (void)GC_printf1("Thread 1 creation failed %lu\n", (unsigned long)code);
1754
 
        FAIL;
1755
 
    }
1756
 
    if ((code = thr_create(0, 1024*1024, thr_run_one_test, 0, THR_NEW_LWP, &th2)) != 0) {
1757
 
        (void)GC_printf1("Thread 2 creation failed %lu\n", (unsigned long)code);
1758
 
        FAIL;
1759
 
    }
1760
 
    run_one_test();
1761
 
    if ((code = thr_join(th1, 0, 0)) != 0) {
1762
 
        (void)GC_printf1("Thread 1 failed %lu\n", (unsigned long)code);
1763
 
        FAIL;
1764
 
    }
1765
 
    if (thr_join(th2, 0, 0) != 0) {
1766
 
        (void)GC_printf1("Thread 2 failed %lu\n", (unsigned long)code);
1767
 
        FAIL;
1768
 
    }
1769
 
    check_heap_stats();
1770
 
    (void)fflush(stdout);
1771
 
    return(0);
1772
 
}
1773
 
#else /* pthreads */
1774
 
 
1775
 
#ifndef GC_PTHREADS
1776
 
  --> bad news
1777
 
#endif
1778
 
 
1779
 
main()
 
1604
int main()
1780
1605
{
1781
1606
    pthread_t th1;
1782
1607
    pthread_t th2;
1783
1608
    pthread_attr_t attr;
1784
1609
    int code;
1785
 
 
1786
1610
#   ifdef GC_IRIX_THREADS
1787
1611
        /* Force a larger stack to be preallocated      */
1788
1612
        /* Since the initial cant always grow later.    */
1792
1616
        /* Default stack size is too small, especially with the 64 bit ABI */
1793
1617
        /* Increase it.                                                    */
1794
1618
        if (pthread_default_stacksize_np(1024*1024, 0) != 0) {
1795
 
          (void)GC_printf0("pthread_default_stacksize_np failed.\n");
 
1619
          (void)GC_printf("pthread_default_stacksize_np failed.\n");
1796
1620
        }
1797
1621
#   endif       /* GC_HPUX_THREADS */
1798
 
    GC_INIT();
 
1622
#   ifdef PTW32_STATIC_LIB
 
1623
        pthread_win32_process_attach_np ();
 
1624
        pthread_win32_thread_attach_np ();
 
1625
#   endif
 
1626
    GC_COND_INIT();
1799
1627
 
1800
1628
    pthread_attr_init(&attr);
1801
1629
#   if defined(GC_IRIX_THREADS) || defined(GC_FREEBSD_THREADS) \
1805
1633
    n_tests = 0;
1806
1634
#   if (defined(MPROTECT_VDB)) \
1807
1635
            && !defined(PARALLEL_MARK) &&!defined(REDIRECT_MALLOC) \
1808
 
            && !defined(MAKE_BACK_GRAPH)
 
1636
            && !defined(MAKE_BACK_GRAPH) && !defined(USE_PROC_FOR_LIBRARIES) \
 
1637
            && !defined(NO_INCREMENTAL)
1809
1638
        GC_enable_incremental();
1810
 
        (void) GC_printf0("Switched to incremental mode\n");
 
1639
        (void) GC_printf("Switched to incremental mode\n");
1811
1640
#     if defined(MPROTECT_VDB)
1812
 
        (void)GC_printf0("Emulating dirty bits with mprotect/signals\n");
 
1641
        (void)GC_printf("Emulating dirty bits with mprotect/signals\n");
1813
1642
#     else
1814
1643
#       ifdef PROC_VDB
1815
 
            (void)GC_printf0("Reading dirty bits from /proc\n");
 
1644
            (void)GC_printf("Reading dirty bits from /proc\n");
1816
1645
#       else
1817
 
            (void)GC_printf0("Using DEFAULT_VDB dirty bit implementation\n");
 
1646
            (void)GC_printf("Using DEFAULT_VDB dirty bit implementation\n");
1818
1647
#       endif
1819
1648
#     endif
1820
1649
#   endif
1821
1650
    (void) GC_set_warn_proc(warn_proc);
1822
1651
    if ((code = pthread_key_create(&fl_key, 0)) != 0) {
1823
 
        (void)GC_printf1("Key creation failed %lu\n", (unsigned long)code);
 
1652
        (void)GC_printf("Key creation failed %d\n", code);
1824
1653
        FAIL;
1825
1654
    }
1826
1655
    if ((code = pthread_create(&th1, &attr, thr_run_one_test, 0)) != 0) {
1827
 
        (void)GC_printf1("Thread 1 creation failed %lu\n", (unsigned long)code);
 
1656
        (void)GC_printf("Thread 1 creation failed %d\n", code);
1828
1657
        FAIL;
1829
1658
    }
1830
1659
    if ((code = pthread_create(&th2, &attr, thr_run_one_test, 0)) != 0) {
1831
 
        (void)GC_printf1("Thread 2 creation failed %lu\n", (unsigned long)code);
 
1660
        (void)GC_printf("Thread 2 creation failed %d\n", code);
1832
1661
        FAIL;
1833
1662
    }
1834
1663
    run_one_test();
1835
1664
    if ((code = pthread_join(th1, 0)) != 0) {
1836
 
        (void)GC_printf1("Thread 1 failed %lu\n", (unsigned long)code);
 
1665
        (void)GC_printf("Thread 1 failed %d\n", code);
1837
1666
        FAIL;
1838
1667
    }
1839
1668
    if (pthread_join(th2, 0) != 0) {
1840
 
        (void)GC_printf1("Thread 2 failed %lu\n", (unsigned long)code);
 
1669
        (void)GC_printf("Thread 2 failed %d\n", code);
1841
1670
        FAIL;
1842
1671
    }
1843
1672
    check_heap_stats();
1844
1673
    (void)fflush(stdout);
1845
1674
    pthread_attr_destroy(&attr);
1846
 
    GC_printf1("Completed %d collections\n", GC_gc_no);
 
1675
    GC_printf("Completed %d collections\n", GC_gc_no);
 
1676
#   ifdef PTW32_STATIC_LIB
 
1677
        pthread_win32_thread_detach_np ();
 
1678
        pthread_win32_process_detach_np ();
 
1679
#   endif
1847
1680
    return(0);
1848
1681
}
1849
1682
#endif /* GC_PTHREADS */
1850
 
#endif /* GC_SOLARIS_THREADS || GC_PTHREADS */