@@ -26,10 +26,18 @@ static int initialized = 0;
26
26
A '1' is a pointer, a '0' is not a pointer.
27
27
*/
28
28
static const int TAG_IS_NOT_FORWARD_MASK = 1 ;
29
- static const int TAG_LENGTH_MASK = 126 ;
29
+ static const int TAG_LENGTH_MASK = 126 ; // 1111110
30
30
static const int TAG_LENGTH_RSHIFT = 1 ;
31
31
static const int TAG_PTR_BITFIELD_RSHIFT = 7 ;
32
32
33
+ static void print_vector (int64_t * vector_ptr );
34
+ static void print_heap (int64_t * * rootstack_ptr );
35
+
36
+ // cheney implements cheney's copying collection algorithm
37
+ // There is a stub and explaination below.
38
+ static void cheney (int64_t * * rootstack_ptr );
39
+
40
+
33
41
// Check to see if a tag is actually a forwarding pointer.
34
42
static inline int is_forwarding (int64_t tag ) {
35
43
return !(tag & TAG_IS_NOT_FORWARD_MASK );
@@ -49,11 +57,11 @@ static inline int64_t get_ptr_bitfield(int64_t tag){
49
57
// in dynamic-typing.rkt. -Jeremy
50
58
static const int ANY_TAG_MASK = 7 ;
51
59
static const int ANY_TAG_LEN = 3 ;
52
- static const int ANY_TAG_INT = 1 ;
53
- static const int ANY_TAG_BOOL = 4 ;
54
- static const int ANY_TAG_VEC = 2 ;
55
- static const int ANY_TAG_FUN = 3 ;
56
- static const int ANY_TAG_VOID = 5 ;
60
+ static const int ANY_TAG_INT = 1 ; // 001
61
+ static const int ANY_TAG_BOOL = 4 ; // 100
62
+ static const int ANY_TAG_VEC = 2 ; // 010
63
+ static const int ANY_TAG_FUN = 3 ; // 011
64
+ static const int ANY_TAG_VOID = 5 ; // 101
57
65
static const int ANY_TAG_PTR = 0 ; // not an any, a raw pointer
58
66
59
67
int any_tag (int64_t any ) {
@@ -113,13 +121,12 @@ void initialize(uint64_t rootstack_size, uint64_t heap_size)
113
121
114
122
}
115
123
116
- // cheney implements cheney's copying collection algorithm
117
- // There is a stub and explaination below.
118
- static void cheney (int64_t * * rootstack_ptr );
119
-
120
124
void collect (int64_t * * rootstack_ptr , uint64_t bytes_requested )
121
125
{
122
- //printf("collecting, need %lld\n", bytes_requested);
126
+ #if 0
127
+ printf ("collecting, need %lld\n" , bytes_requested );
128
+ print_heap (rootstack_ptr );
129
+ #endif
123
130
124
131
// 1. Check our assumptions about the world
125
132
assert (initialized );
@@ -169,8 +176,15 @@ void collect(int64_t** rootstack_ptr, uint64_t bytes_requested)
169
176
unsigned long old_len = fromspace_end - fromspace_begin ;
170
177
unsigned long old_bytes = old_len * sizeof (int64_t );
171
178
unsigned long new_bytes = old_bytes ;
172
-
173
- while (new_bytes < needed_bytes ) new_bytes = 2 * new_bytes ;
179
+
180
+ #if 1
181
+ while (new_bytes < needed_bytes ) {
182
+ new_bytes = 2 * new_bytes ;
183
+ }
184
+ #else
185
+ // this version is good for debugging purposes -Jeremy
186
+ new_bytes = needed_bytes ;
187
+ #endif
174
188
175
189
// Free and allocate a new tospace of size new_bytes
176
190
free (tospace_begin );
@@ -239,7 +253,11 @@ void collect(int64_t** rootstack_ptr, uint64_t bytes_requested)
239
253
}
240
254
#endif
241
255
242
- // printf("finished collecting\n\n");
256
+ #if 0
257
+ printf ("finished collecting\n" );
258
+ print_heap (rootstack_ptr );
259
+ printf ("---------------------------------------\n" );
260
+ #endif
243
261
} // collect
244
262
245
263
// copy_vector is responsible for doing a pointer oblivious
@@ -409,14 +427,16 @@ void cheney(int64_t** rootstack_ptr)
409
427
*/
410
428
void copy_vector (int64_t * * vector_ptr_loc )
411
429
{
412
- //printf("copy_vector %lld\n", (int64_t)*vector_ptr_loc);
413
430
414
431
int64_t * old_vector_ptr = * vector_ptr_loc ;
415
432
int old_tag = any_tag ((int64_t )old_vector_ptr );
416
433
417
434
if (! is_ptr (old_vector_ptr ))
418
435
return ;
419
436
old_vector_ptr = to_ptr (old_vector_ptr );
437
+ #if 0
438
+ printf ("copy_vector %lld\n" , (int64_t )old_vector_ptr );
439
+ #endif
420
440
421
441
int64_t tag = old_vector_ptr [0 ];
422
442
@@ -432,7 +452,9 @@ void copy_vector(int64_t** vector_ptr_loc)
432
452
* vector_ptr_loc = (int64_t * ) (tag | old_tag );
433
453
434
454
} else {
435
- //printf("\tfirst time copy\n");
455
+ #if 0
456
+ printf ("\tfirst time copy\n" );
457
+ #endif
436
458
// This is the first time we have followed this pointer.
437
459
438
460
// Since we are about to jumble all the pointers around lets
@@ -441,12 +463,16 @@ void copy_vector(int64_t** vector_ptr_loc)
441
463
// The tag we grabbed earlier contains some usefull info for
442
464
// forwarding copying the vector.
443
465
int length = get_length (tag );
444
- //printf("\tlen: %d\n", length);
466
+ #if 0
467
+ printf ("\tlen: %d\n" , length );
468
+ #endif
445
469
446
470
// The new vector is going to be where the free int64_t pointer
447
471
// currently points.
448
472
int64_t * new_vector_ptr = free_ptr ;
449
- //printf("\tto address: %lld\n", (int64_t)new_vector_ptr);
473
+ #if 0
474
+ printf ("\tto address: %lld\n" , (int64_t )new_vector_ptr );
475
+ #endif
450
476
451
477
// Copy the old vector to the new one.
452
478
// The "length" is the number of elements, so to include the
@@ -530,7 +556,7 @@ void print_any(int64_t any) {
530
556
unsigned char len = get_length (tag );
531
557
printf ("#(" );
532
558
for (int i = 0 ; i != len ; ++ i ) {
533
- print_any (vector_ptr [i + 1 ]);
559
+ print_any (vector_ptr [i + 1 ]); // this is wrong -Jeremy
534
560
}
535
561
printf (")" );
536
562
break ;
@@ -546,3 +572,44 @@ void print_any(int64_t any) {
546
572
exit (-1 );
547
573
}
548
574
}
575
+
576
+ void print_heap (int64_t * * rootstack_ptr )
577
+ {
578
+ printf ("rootstack len = %ld\n" , rootstack_ptr - rootstack_begin );
579
+ for (int64_t * * root_loc = rootstack_begin ;
580
+ root_loc != rootstack_ptr ;
581
+ ++ root_loc ) {
582
+ if (is_ptr (* root_loc )) {
583
+ print_vector (to_ptr (* root_loc ));
584
+ } else {
585
+ printf ("%lld" , (int64_t )* root_loc );
586
+ }
587
+ printf ("\n" );
588
+ }
589
+ printf ("\n" );
590
+ }
591
+
592
+ void print_vector (int64_t * vector_ptr )
593
+ {
594
+ int64_t tag = vector_ptr [0 ];
595
+ unsigned char len = get_length (tag );
596
+ int64_t * scan_ptr = vector_ptr ;
597
+ int64_t * next_ptr = vector_ptr + len + 1 ;
598
+
599
+ printf ("%lld=#(" , (int64_t )vector_ptr );
600
+ scan_ptr += 1 ;
601
+ int64_t isPointerBits = get_ptr_bitfield (tag );
602
+ while (scan_ptr != next_ptr ) {
603
+ if ((isPointerBits & 1 ) == 1 && is_ptr ((int64_t * )* scan_ptr )) {
604
+ print_vector (to_ptr ((int64_t * )* scan_ptr ));
605
+ } else {
606
+ printf ("%lld" , (int64_t )* scan_ptr );
607
+ }
608
+ isPointerBits = isPointerBits >> 1 ;
609
+ scan_ptr += 1 ;
610
+ if (scan_ptr != next_ptr ) {
611
+ printf (", " );
612
+ }
613
+ }
614
+ printf (")" );
615
+ }
0 commit comments