array *factor_vm::allot_array(cell capacity, cell fill_)
{
gc_root<object> fill(fill_,this);
- gc_root<array> new_array(allot_array_internal<array>(capacity),this);
+ gc_root<array> new_array(allot_uninitialized_array<array>(capacity),this);
-
- if(fill.value() == tag_fixnum(0))
- memset(new_array->data(),'\0',capacity * sizeof(cell));
- else
- {
- /* No need for write barrier here. Either the object is in
- the nursery, or it was allocated directly in tenured space
- and the write barrier is already hit for us in that case. */
- for(cell i = 0; i < capacity; i++)
- new_array->data()[i] = fill.value();
- }
+ memset_cell(new_array->data(),fill.value(),capacity * sizeof(cell));
return new_array.untagged();
}
* It is up to the caller to fill in the object's fields in a meaningful
* fashion!
*/
- object *factor_vm::allot_object(header header, cell size)
+ object *factor_vm::allot_large_object(header header, cell size)
{
- #ifdef GC_DEBUG
- if(!gc_off)
- /* If tenured space does not have enough room, collect */
- if(data->tenured->here + size > data->tenured->end)
-- primitive_full_gc();
- #endif
-
- object *obj;
--
- /* If the object is smaller than the nursery, allocate it in the nursery,
- after a GC if needed */
- if(size < nursery.size)
- /* If it still won't fit, grow the heap */
- if(data->tenured->here + size > data->tenured->end)
++ /* If tenured space does not have enough room, collect and compact */
++ if(!data->tenured->can_allot_p(size))
{
- /* If there is insufficient room, collect the nursery */
- if(nursery.here + size > nursery.end)
- primitive_minor_gc();
- gc(collect_growing_heap_op,
- size, /* requested size */
- true, /* trace contexts? */
- false /* compact code heap? */);
++ primitive_compact_gc();
+
- obj = nursery.allot(size);
- }
- else
- {
- /* If tenured space does not have enough room, collect and compact */
++ /* If it still won't fit, grow the heap */
+ if(!data->tenured->can_allot_p(size))
+ {
- primitive_compact_gc();
-
- /* If it still won't fit, grow the heap */
- if(!data->tenured->can_allot_p(size))
- {
- gc(collect_growing_heap_op,
- size, /* requested size */
- true /* trace contexts? */);
- }
++ gc(collect_growing_heap_op,
++ size, /* requested size */
++ true /* trace contexts? */);
+ }
+ }
- obj = data->tenured->allot(size);
+ object *obj = data->tenured->allot(size);
- /* Allows initialization code to store old->new pointers
- without hitting the write barrier in the common case of
- a nursery allocation */
- char *start = (char *)obj;
- for(cell offset = 0; offset < size; offset += card_size)
- write_barrier((cell *)(start + offset));
- }
+ /* Allows initialization code to store old->new pointers
+ without hitting the write barrier in the common case of
+ a nursery allocation */
+ char *start = (char *)obj;
+ for(cell offset = 0; offset < size; offset += card_size)
+ write_barrier((cell *)(start + offset));
obj->h = header;
return obj;
#include "words.hpp"
#include "float_bits.hpp"
#include "io.hpp"
-#include "mark_bits.hpp"
-#include "heap.hpp"
#include "image.hpp"
#include "alien.hpp"
-#include "code_heap.hpp"
#include "callbacks.hpp"
#include "vm.hpp"
+ #include "allot.hpp"
#include "tagged.hpp"
#include "local_roots.hpp"
+#include "slot_visitor.hpp"
#include "collector.hpp"
#include "copying_collector.hpp"
#include "nursery_collector.hpp"
namespace factor
{
- vm_char *safe_strdup(const vm_char *str);
- void print_cell_hex_pad(cell x);
- cell read_cell_hex();
+
+ inline static void memset_cell(void *dst, cell pattern, size_t size)
+ {
+ #ifdef __APPLE__
+ #ifdef FACTOR_64
+ memset_pattern8(dst,&pattern,size);
+ #else
+ memset_pattern4(dst,&pattern,size);
+ #endif
+ #else
+ if(pattern == 0)
+ memset(dst,0,size);
+ else
+ {
+ cell *start = (cell *)dst;
+ cell *end = (cell *)((cell)dst + size);
+ while(start < end)
+ {
+ *start = pattern;
+ start++;
+ }
+ }
+ #endif
+ }
+
+ vm_char *safe_strdup(const vm_char *str);
-void print_string(const char *str);
-void nl();
-void print_cell(cell x);
-void print_cell_hex(cell x);
-void print_cell_hex_pad(cell x);
-void print_fixnum(fixnum x);
+ cell read_cell_hex();
+
}
void primitive_minor_gc();
void primitive_full_gc();
void primitive_compact_gc();
- void primitive_gc_stats();
- void clear_gc_stats();
void primitive_become();
void inline_gc(cell *gc_roots_base, cell gc_roots_size);
- object *allot_object(header header, cell size);
+ void primitive_enable_gc_events();
+ void primitive_disable_gc_events();
+ object *allot_object(header header, cell size);
+ object *allot_large_object(header header, cell size);
- void add_gc_stats(generation_statistics *stats, growable_array *result);
- void primitive_clear_gc_stats();
template<typename Type> Type *allot(cell size)
{
void primitive_uninitialized_byte_array();
void primitive_resize_byte_array();
+ template<typename T> byte_array *byte_array_from_value(T *value);
+ template<typename T> byte_array *byte_array_from_values(T *values, cell len);
+
//tuples
- tuple *allot_tuple(cell layout_);
void primitive_tuple();
void primitive_tuple_boa();