mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-21 06:39:16 +02:00
Issue #472 - Avoid races with tracing GC when allocating large vectors
This commit is contained in:
parent
543ce4f4be
commit
14d4c27eac
2 changed files with 13 additions and 4 deletions
|
@ -6,6 +6,10 @@ Features
|
||||||
|
|
||||||
- Initiate major garbage collections faster after allocating a huge object (more than 500K). This allows the system to reclaim the memory faster and keep overall memory usage low for certain workloads.
|
- Initiate major garbage collections faster after allocating a huge object (more than 500K). This allows the system to reclaim the memory faster and keep overall memory usage low for certain workloads.
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
|
||||||
|
- When allocating a large vector we now guarantee all vector elements are initialized before the major collector can trace those elements. This avoids the potential for a race condition which could lead to a segmentation fault.
|
||||||
|
|
||||||
## 0.31.0 - July 27, 2021
|
## 0.31.0 - July 27, 2021
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
13
runtime.c
13
runtime.c
|
@ -2972,8 +2972,8 @@ object Cyc_make_vector(void *data, object cont, int argc, object len, ...)
|
||||||
((vector) v)->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color;
|
((vector) v)->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color;
|
||||||
((vector) v)->hdr.grayed = 0;
|
((vector) v)->hdr.grayed = 0;
|
||||||
((vector) v)->hdr.immutable = 0;
|
((vector) v)->hdr.immutable = 0;
|
||||||
((vector) v)->tag = vector_tag;
|
((vector) v)->tag = double_tag; // Avoid race conditions w/GC tracing
|
||||||
((vector) v)->num_elements = ulen;
|
((vector) v)->num_elements = 0; // until array is filled
|
||||||
((vector) v)->elements = (object *)(((char *)v) + sizeof(vector_type));
|
((vector) v)->elements = (object *)(((char *)v) + sizeof(vector_type));
|
||||||
// Use write barrier to ensure fill is moved to heap if it is on the stack
|
// Use write barrier to ensure fill is moved to heap if it is on the stack
|
||||||
// Otherwise if next minor GC misses fill it could be catastrophic
|
// Otherwise if next minor GC misses fill it could be catastrophic
|
||||||
|
@ -3000,6 +3000,9 @@ object Cyc_make_vector(void *data, object cont, int argc, object len, ...)
|
||||||
for (i = 0; i < ((vector) v)->num_elements; i++) {
|
for (i = 0; i < ((vector) v)->num_elements; i++) {
|
||||||
((vector) v)->elements[i] = fill;
|
((vector) v)->elements[i] = fill;
|
||||||
}
|
}
|
||||||
|
((vector) v)->tag = vector_tag;
|
||||||
|
((vector) v)->num_elements = ulen;
|
||||||
|
|
||||||
_return_closcall1(data, cont, v);
|
_return_closcall1(data, cont, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3411,8 +3414,8 @@ object Cyc_list2vector(void *data, object cont, object l)
|
||||||
((vector) v)->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color;
|
((vector) v)->hdr.mark = ((gc_thread_data *)data)->gc_alloc_color;
|
||||||
((vector) v)->hdr.grayed = 0;
|
((vector) v)->hdr.grayed = 0;
|
||||||
((vector) v)->hdr.immutable = 0;
|
((vector) v)->hdr.immutable = 0;
|
||||||
((vector) v)->tag = vector_tag;
|
((vector) v)->tag = double_tag; // Avoid race with GC tracing until
|
||||||
((vector) v)->num_elements = len;
|
((vector) v)->num_elements = 0; // array is initialized
|
||||||
((vector) v)->elements = (object *)(((char *)v) + sizeof(vector_type));
|
((vector) v)->elements = (object *)(((char *)v) + sizeof(vector_type));
|
||||||
// TODO: do we need to worry about stack object in the list????
|
// TODO: do we need to worry about stack object in the list????
|
||||||
//// Use write barrier to ensure fill is moved to heap if it is on the stack
|
//// Use write barrier to ensure fill is moved to heap if it is on the stack
|
||||||
|
@ -3437,6 +3440,8 @@ object Cyc_list2vector(void *data, object cont, object l)
|
||||||
((vector) v)->elements[i++] = car(lst);
|
((vector) v)->elements[i++] = car(lst);
|
||||||
lst = cdr(lst);
|
lst = cdr(lst);
|
||||||
}
|
}
|
||||||
|
((vector) v)->tag = vector_tag;
|
||||||
|
((vector) v)->num_elements = len;
|
||||||
_return_closcall1(data, cont, v);
|
_return_closcall1(data, cont, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue