mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-09 22:17:33 +02:00
Update how GC handles strings in memory
This commit is contained in:
parent
85cff010b6
commit
e6880850bc
2 changed files with 30 additions and 21 deletions
|
@ -40,7 +40,8 @@ struct gc_heap_t {
|
||||||
|
|
||||||
typedef struct gc_header_type_t gc_header_type;
|
typedef struct gc_header_type_t gc_header_type;
|
||||||
struct gc_header_type_t {
|
struct gc_header_type_t {
|
||||||
unsigned char mark; // mark bits (only need 2)
|
//unsigned char mark; // mark bits (only need 2)
|
||||||
|
unsigned int mark; // mark bits (only need 2)
|
||||||
// TODO: forwarding address (probably not needed for mark/sweep), anything else???
|
// TODO: forwarding address (probably not needed for mark/sweep), anything else???
|
||||||
};
|
};
|
||||||
#define is_marked(x) (is_object_type(x) && ((list)x)->hdr.mark)
|
#define is_marked(x) (is_object_type(x) && ((list)x)->hdr.mark)
|
||||||
|
|
48
runtime.c
48
runtime.c
|
@ -2049,22 +2049,26 @@ char *transport(x, gcgen) char *x; int gcgen;
|
||||||
return (char *) nx;}
|
return (char *) nx;}
|
||||||
case string_tag:
|
case string_tag:
|
||||||
{register string_type *nx = (string_type *) allocp;
|
{register string_type *nx = (string_type *) allocp;
|
||||||
|
int str_size = gc_word_align(((string_type *)x)->len + 1);
|
||||||
type_of(nx) = string_tag;
|
type_of(nx) = string_tag;
|
||||||
TODO: below is changing, now we will need to always copy the cstring
|
nx->len = ((string_type *)x)->len;
|
||||||
along with the string_type. need to be careful of any off-by-one errors
|
nx->str = ((char *)nx) + sizeof(string_type);
|
||||||
here...
|
memcpy(nx->str, ((string_type *)x)->str, nx->len + 1);
|
||||||
if (gcgen == 0) {
|
//TODO: below is changing, now we will need to always copy the cstring
|
||||||
// Minor, data heap is not relocated
|
//along with the string_type. need to be careful of any off-by-one errors
|
||||||
nx->str = ((string_type *)x)->str;
|
//here...
|
||||||
} else {
|
// if (gcgen == 0) {
|
||||||
// Major collection, data heap is moving
|
// // Minor, data heap is not relocated
|
||||||
nx->str = dhallocp;
|
// nx->str = ((string_type *)x)->str;
|
||||||
int len = strlen(((string_type *) x)->str);
|
// } else {
|
||||||
memcpy(dhallocp, ((string_type *) x)->str, len + 1);
|
// // Major collection, data heap is moving
|
||||||
dhallocp += len + 1;
|
// nx->str = dhallocp;
|
||||||
}
|
// int len = strlen(((string_type *) x)->str);
|
||||||
|
// memcpy(dhallocp, ((string_type *) x)->str, len + 1);
|
||||||
|
// dhallocp += len + 1;
|
||||||
|
// }
|
||||||
forward(x) = nx; type_of(x) = forward_tag;
|
forward(x) = nx; type_of(x) = forward_tag;
|
||||||
x = (char *) nx; allocp = ((char *) nx)+sizeof(string_type);
|
x = (char *) nx; allocp = ((char *) nx)+sizeof(string_type)+str_size;
|
||||||
return (char *) nx;}
|
return (char *) nx;}
|
||||||
case integer_tag:
|
case integer_tag:
|
||||||
{register integer_type *nx = (integer_type *) allocp;
|
{register integer_type *nx = (integer_type *) allocp;
|
||||||
|
@ -2276,15 +2280,19 @@ void GC_loop(int major, closure cont, object *ans, int num_ans)
|
||||||
scanp += sizeof(vector_type) + sizeof(object) * n;
|
scanp += sizeof(vector_type) + sizeof(object) * n;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case string_tag:
|
case string_tag: {
|
||||||
#if DEBUG_GC
|
#if DEBUG_GC
|
||||||
printf("DEBUG transport string \n");
|
printf("DEBUG transport string \n");
|
||||||
#endif
|
#endif
|
||||||
scanp += sizeof(string_type); break;
|
string_type *x = (string_type *)scanp;
|
||||||
TODO: cstring is now after string_type, so need to skip that, too.
|
scanp += sizeof(string_type);
|
||||||
stack allocations should be OK since we are only scanning the newspace here,
|
scanp += gc_word_align(x->len + 1);
|
||||||
but should double-check that... (though we are not able to even scan the
|
break;
|
||||||
stack so should be fine)
|
}
|
||||||
|
//TODO: cstring is now after string_type, so need to skip that, too.
|
||||||
|
//stack allocations should be OK since we are only scanning the newspace here,
|
||||||
|
//but should double-check that... (though we are not able to even scan the
|
||||||
|
//stack so should be fine)
|
||||||
case integer_tag:
|
case integer_tag:
|
||||||
#if DEBUG_GC
|
#if DEBUG_GC
|
||||||
printf("DEBUG transport integer \n");
|
printf("DEBUG transport integer \n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue