mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-04 03:36:34 +02:00
Reorder types in gc_move/gc_copy
Attempt to speed things up by moving more commonly-used objects up, and lesser-used ones down.
This commit is contained in:
parent
81124e6be3
commit
d02437a0c5
2 changed files with 107 additions and 107 deletions
144
gc.c
144
gc.c
|
@ -363,39 +363,6 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (type_of(obj)) {
|
switch (type_of(obj)) {
|
||||||
case pair_tag:{
|
|
||||||
list hp = dest;
|
|
||||||
hp->hdr.mark = thd->gc_alloc_color;
|
|
||||||
type_of(hp) = pair_tag;
|
|
||||||
car(hp) = car(obj);
|
|
||||||
cdr(hp) = cdr(obj);
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
|
||||||
case macro_tag:{
|
|
||||||
macro_type *hp = dest;
|
|
||||||
mark(hp) = thd->gc_alloc_color;
|
|
||||||
type_of(hp) = macro_tag;
|
|
||||||
hp->fn = ((macro) obj)->fn;
|
|
||||||
hp->num_args = ((macro) obj)->num_args;
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
|
||||||
case closure0_tag:{
|
|
||||||
closure0_type *hp = dest;
|
|
||||||
mark(hp) = thd->gc_alloc_color;
|
|
||||||
type_of(hp) = closure0_tag;
|
|
||||||
hp->fn = ((closure0) obj)->fn;
|
|
||||||
hp->num_args = ((closure0) obj)->num_args;
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
|
||||||
case closure1_tag:{
|
|
||||||
closure1_type *hp = dest;
|
|
||||||
mark(hp) = thd->gc_alloc_color;
|
|
||||||
type_of(hp) = closure1_tag;
|
|
||||||
hp->fn = ((closure1) obj)->fn;
|
|
||||||
hp->num_args = ((closure1) obj)->num_args;
|
|
||||||
hp->element = ((closure1) obj)->element;
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
|
||||||
case closureN_tag:{
|
case closureN_tag:{
|
||||||
int i;
|
int i;
|
||||||
closureN_type *hp = dest;
|
closureN_type *hp = dest;
|
||||||
|
@ -410,6 +377,40 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
|
||||||
}
|
}
|
||||||
return (char *)hp;
|
return (char *)hp;
|
||||||
}
|
}
|
||||||
|
case closure0_tag:{
|
||||||
|
closure0_type *hp = dest;
|
||||||
|
mark(hp) = thd->gc_alloc_color;
|
||||||
|
type_of(hp) = closure0_tag;
|
||||||
|
hp->fn = ((closure0) obj)->fn;
|
||||||
|
hp->num_args = ((closure0) obj)->num_args;
|
||||||
|
return (char *)hp;
|
||||||
|
}
|
||||||
|
case pair_tag:{
|
||||||
|
list hp = dest;
|
||||||
|
hp->hdr.mark = thd->gc_alloc_color;
|
||||||
|
type_of(hp) = pair_tag;
|
||||||
|
car(hp) = car(obj);
|
||||||
|
cdr(hp) = cdr(obj);
|
||||||
|
return (char *)hp;
|
||||||
|
}
|
||||||
|
case string_tag:{
|
||||||
|
char *s;
|
||||||
|
string_type *hp = dest;
|
||||||
|
s = ((char *)hp) + sizeof(string_type);
|
||||||
|
memcpy(s, string_str(obj), string_len(obj) + 1);
|
||||||
|
mark(hp) = thd->gc_alloc_color;
|
||||||
|
type_of(hp) = string_tag;
|
||||||
|
string_len(hp) = string_len(obj);
|
||||||
|
string_str(hp) = s;
|
||||||
|
return (char *)hp;
|
||||||
|
}
|
||||||
|
case double_tag:{
|
||||||
|
double_type *hp = dest;
|
||||||
|
mark(hp) = thd->gc_alloc_color;
|
||||||
|
type_of(hp) = double_tag;
|
||||||
|
hp->value = ((double_type *) obj)->value;
|
||||||
|
return (char *)hp;
|
||||||
|
}
|
||||||
case vector_tag:{
|
case vector_tag:{
|
||||||
int i;
|
int i;
|
||||||
vector_type *hp = dest;
|
vector_type *hp = dest;
|
||||||
|
@ -431,22 +432,14 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
|
||||||
memcpy(hp->data, ((bytevector) obj)->data, hp->len);
|
memcpy(hp->data, ((bytevector) obj)->data, hp->len);
|
||||||
return (char *)hp;
|
return (char *)hp;
|
||||||
}
|
}
|
||||||
case string_tag:{
|
case port_tag:{
|
||||||
char *s;
|
port_type *hp = dest;
|
||||||
string_type *hp = dest;
|
|
||||||
s = ((char *)hp) + sizeof(string_type);
|
|
||||||
memcpy(s, string_str(obj), string_len(obj) + 1);
|
|
||||||
mark(hp) = thd->gc_alloc_color;
|
mark(hp) = thd->gc_alloc_color;
|
||||||
type_of(hp) = string_tag;
|
type_of(hp) = port_tag;
|
||||||
string_len(hp) = string_len(obj);
|
hp->fp = ((port_type *) obj)->fp;
|
||||||
string_str(hp) = s;
|
hp->mode = ((port_type *) obj)->mode;
|
||||||
return (char *)hp;
|
hp->mem_buf = ((port_type *)obj)->mem_buf;
|
||||||
}
|
hp->mem_buf_len = ((port_type *)obj)->mem_buf_len;
|
||||||
case integer_tag:{
|
|
||||||
integer_type *hp = dest;
|
|
||||||
mark(hp) = thd->gc_alloc_color;
|
|
||||||
type_of(hp) = integer_tag;
|
|
||||||
hp->value = ((integer_type *) obj)->value;
|
|
||||||
return (char *)hp;
|
return (char *)hp;
|
||||||
}
|
}
|
||||||
case bignum_tag:{
|
case bignum_tag:{
|
||||||
|
@ -459,23 +452,6 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
|
||||||
((bignum_type *)hp)->bn.dp = ((bignum_type *)obj)->bn.dp;
|
((bignum_type *)hp)->bn.dp = ((bignum_type *)obj)->bn.dp;
|
||||||
return (char *)hp;
|
return (char *)hp;
|
||||||
}
|
}
|
||||||
case double_tag:{
|
|
||||||
double_type *hp = dest;
|
|
||||||
mark(hp) = thd->gc_alloc_color;
|
|
||||||
type_of(hp) = double_tag;
|
|
||||||
hp->value = ((double_type *) obj)->value;
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
|
||||||
case port_tag:{
|
|
||||||
port_type *hp = dest;
|
|
||||||
mark(hp) = thd->gc_alloc_color;
|
|
||||||
type_of(hp) = port_tag;
|
|
||||||
hp->fp = ((port_type *) obj)->fp;
|
|
||||||
hp->mode = ((port_type *) obj)->mode;
|
|
||||||
hp->mem_buf = ((port_type *)obj)->mem_buf;
|
|
||||||
hp->mem_buf_len = ((port_type *)obj)->mem_buf_len;
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
|
||||||
case cvar_tag:{
|
case cvar_tag:{
|
||||||
cvar_type *hp = dest;
|
cvar_type *hp = dest;
|
||||||
mark(hp) = thd->gc_alloc_color;
|
mark(hp) = thd->gc_alloc_color;
|
||||||
|
@ -483,13 +459,6 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
|
||||||
hp->pvar = ((cvar_type *) obj)->pvar;
|
hp->pvar = ((cvar_type *) obj)->pvar;
|
||||||
return (char *)hp;
|
return (char *)hp;
|
||||||
}
|
}
|
||||||
case c_opaque_tag:{
|
|
||||||
c_opaque_type *hp = dest;
|
|
||||||
mark(hp) = thd->gc_alloc_color;
|
|
||||||
type_of(hp) = c_opaque_tag;
|
|
||||||
hp->ptr = ((c_opaque_type *) obj)->ptr;
|
|
||||||
return (char *)hp;
|
|
||||||
}
|
|
||||||
case mutex_tag:{
|
case mutex_tag:{
|
||||||
mutex_type *hp = dest;
|
mutex_type *hp = dest;
|
||||||
mark(hp) = thd->gc_alloc_color;
|
mark(hp) = thd->gc_alloc_color;
|
||||||
|
@ -504,6 +473,30 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
|
||||||
// NOTE: don't copy cond_var itself, caller will do that (this is a special case)
|
// NOTE: don't copy cond_var itself, caller will do that (this is a special case)
|
||||||
return (char *)hp;
|
return (char *)hp;
|
||||||
}
|
}
|
||||||
|
case macro_tag:{
|
||||||
|
macro_type *hp = dest;
|
||||||
|
mark(hp) = thd->gc_alloc_color;
|
||||||
|
type_of(hp) = macro_tag;
|
||||||
|
hp->fn = ((macro) obj)->fn;
|
||||||
|
hp->num_args = ((macro) obj)->num_args;
|
||||||
|
return (char *)hp;
|
||||||
|
}
|
||||||
|
case closure1_tag:{
|
||||||
|
closure1_type *hp = dest;
|
||||||
|
mark(hp) = thd->gc_alloc_color;
|
||||||
|
type_of(hp) = closure1_tag;
|
||||||
|
hp->fn = ((closure1) obj)->fn;
|
||||||
|
hp->num_args = ((closure1) obj)->num_args;
|
||||||
|
hp->element = ((closure1) obj)->element;
|
||||||
|
return (char *)hp;
|
||||||
|
}
|
||||||
|
case c_opaque_tag:{
|
||||||
|
c_opaque_type *hp = dest;
|
||||||
|
mark(hp) = thd->gc_alloc_color;
|
||||||
|
type_of(hp) = c_opaque_tag;
|
||||||
|
hp->ptr = ((c_opaque_type *) obj)->ptr;
|
||||||
|
return (char *)hp;
|
||||||
|
}
|
||||||
case forward_tag:
|
case forward_tag:
|
||||||
return (char *)forward(obj);
|
return (char *)forward(obj);
|
||||||
case eof_tag:
|
case eof_tag:
|
||||||
|
@ -511,6 +504,13 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
|
||||||
case boolean_tag:
|
case boolean_tag:
|
||||||
case symbol_tag:
|
case symbol_tag:
|
||||||
break;
|
break;
|
||||||
|
case integer_tag:{
|
||||||
|
integer_type *hp = dest;
|
||||||
|
mark(hp) = thd->gc_alloc_color;
|
||||||
|
type_of(hp) = integer_tag;
|
||||||
|
hp->value = ((integer_type *) obj)->value;
|
||||||
|
return (char *)hp;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "gc_copy_obj: bad tag obj=%p obj.tag=%d\n", (object) obj,
|
fprintf(stderr, "gc_copy_obj: bad tag obj=%p obj.tag=%d\n", (object) obj,
|
||||||
type_of(obj));
|
type_of(obj));
|
||||||
|
|
70
runtime.c
70
runtime.c
|
@ -4700,13 +4700,12 @@ char *gc_move(char *obj, gc_thread_data * thd, int *alloci, int *heap_grown)
|
||||||
if (!is_object_type(obj))
|
if (!is_object_type(obj))
|
||||||
return obj;
|
return obj;
|
||||||
switch (type_of(obj)) {
|
switch (type_of(obj)) {
|
||||||
case pair_tag:{
|
case closureN_tag:{
|
||||||
list hp = gc_alloc(heap, sizeof(pair_type), obj, thd, heap_grown);
|
closureN_type *hp = gc_alloc(heap,
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
sizeof(closureN_type) +
|
||||||
}
|
sizeof(object) *
|
||||||
case macro_tag:{
|
(((closureN) obj)->num_elements),
|
||||||
macro_type *hp =
|
obj, thd, heap_grown);
|
||||||
gc_alloc(heap, sizeof(macro_type), obj, thd, heap_grown);
|
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
}
|
}
|
||||||
case closure0_tag:{
|
case closure0_tag:{
|
||||||
|
@ -4714,17 +4713,19 @@ char *gc_move(char *obj, gc_thread_data * thd, int *alloci, int *heap_grown)
|
||||||
gc_alloc(heap, sizeof(closure0_type), obj, thd, heap_grown);
|
gc_alloc(heap, sizeof(closure0_type), obj, thd, heap_grown);
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
}
|
}
|
||||||
case closure1_tag:{
|
case pair_tag:{
|
||||||
closure1_type *hp =
|
list hp = gc_alloc(heap, sizeof(pair_type), obj, thd, heap_grown);
|
||||||
gc_alloc(heap, sizeof(closure1_type), obj, thd, heap_grown);
|
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
}
|
}
|
||||||
case closureN_tag:{
|
case string_tag:{
|
||||||
closureN_type *hp = gc_alloc(heap,
|
string_type *hp = gc_alloc(heap,
|
||||||
sizeof(closureN_type) +
|
sizeof(string_type) + ((string_len(obj) + 1)),
|
||||||
sizeof(object) *
|
obj, thd, heap_grown);
|
||||||
(((closureN) obj)->num_elements),
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
obj, thd, heap_grown);
|
}
|
||||||
|
case double_tag:{
|
||||||
|
double_type *hp =
|
||||||
|
gc_alloc(heap, sizeof(double_type), obj, thd, heap_grown);
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
}
|
}
|
||||||
case vector_tag:{
|
case vector_tag:{
|
||||||
|
@ -4742,15 +4743,9 @@ char *gc_move(char *obj, gc_thread_data * thd, int *alloci, int *heap_grown)
|
||||||
obj, thd, heap_grown);
|
obj, thd, heap_grown);
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
}
|
}
|
||||||
case string_tag:{
|
case port_tag:{
|
||||||
string_type *hp = gc_alloc(heap,
|
port_type *hp =
|
||||||
sizeof(string_type) + ((string_len(obj) + 1)),
|
gc_alloc(heap, sizeof(port_type), obj, thd, heap_grown);
|
||||||
obj, thd, heap_grown);
|
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
|
||||||
}
|
|
||||||
case integer_tag:{
|
|
||||||
integer_type *hp =
|
|
||||||
gc_alloc(heap, sizeof(integer_type), obj, thd, heap_grown);
|
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
}
|
}
|
||||||
case bignum_tag:{
|
case bignum_tag:{
|
||||||
|
@ -4758,21 +4753,21 @@ char *gc_move(char *obj, gc_thread_data * thd, int *alloci, int *heap_grown)
|
||||||
gc_alloc(heap, sizeof(bignum_type), obj, thd, heap_grown);
|
gc_alloc(heap, sizeof(bignum_type), obj, thd, heap_grown);
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
}
|
}
|
||||||
case double_tag:{
|
|
||||||
double_type *hp =
|
|
||||||
gc_alloc(heap, sizeof(double_type), obj, thd, heap_grown);
|
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
|
||||||
}
|
|
||||||
case port_tag:{
|
|
||||||
port_type *hp =
|
|
||||||
gc_alloc(heap, sizeof(port_type), obj, thd, heap_grown);
|
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
|
||||||
}
|
|
||||||
case cvar_tag:{
|
case cvar_tag:{
|
||||||
cvar_type *hp =
|
cvar_type *hp =
|
||||||
gc_alloc(heap, sizeof(cvar_type), obj, thd, heap_grown);
|
gc_alloc(heap, sizeof(cvar_type), obj, thd, heap_grown);
|
||||||
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
}
|
}
|
||||||
|
case macro_tag:{
|
||||||
|
macro_type *hp =
|
||||||
|
gc_alloc(heap, sizeof(macro_type), obj, thd, heap_grown);
|
||||||
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
|
}
|
||||||
|
case closure1_tag:{
|
||||||
|
closure1_type *hp =
|
||||||
|
gc_alloc(heap, sizeof(closure1_type), obj, thd, heap_grown);
|
||||||
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
|
}
|
||||||
case c_opaque_tag:{
|
case c_opaque_tag:{
|
||||||
c_opaque_type *hp =
|
c_opaque_type *hp =
|
||||||
gc_alloc(heap, sizeof(c_opaque_type), obj, thd, heap_grown);
|
gc_alloc(heap, sizeof(c_opaque_type), obj, thd, heap_grown);
|
||||||
|
@ -4788,6 +4783,11 @@ char *gc_move(char *obj, gc_thread_data * thd, int *alloci, int *heap_grown)
|
||||||
break;
|
break;
|
||||||
case symbol_tag:
|
case symbol_tag:
|
||||||
break; // JAE TODO: raise an error here? Should not be possible in real code, though (IE, without GC DEBUG flag)
|
break; // JAE TODO: raise an error here? Should not be possible in real code, though (IE, without GC DEBUG flag)
|
||||||
|
case integer_tag:{
|
||||||
|
integer_type *hp =
|
||||||
|
gc_alloc(heap, sizeof(integer_type), obj, thd, heap_grown);
|
||||||
|
return gc_fixup_moved_obj(thd, alloci, obj, hp);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "gc_move: bad tag obj=%p obj.tag=%d\n", (object) obj,
|
fprintf(stderr, "gc_move: bad tag obj=%p obj.tag=%d\n", (object) obj,
|
||||||
type_of(obj));
|
type_of(obj));
|
||||||
|
|
Loading…
Add table
Reference in a new issue