Ejemplo n.º 1
0
static void
set_constant_entry (CPool *cpool, int index, int tag, jword value)
{
    if (cpool->data == NULL)
    {
        cpool->capacity = 100;
        cpool->tags = ggc_alloc_cleared (sizeof(uint8) * cpool->capacity);
        cpool->data = ggc_alloc_cleared (sizeof(union cpool_entry)
                                         * cpool->capacity);
        cpool->count = 1;
    }
    if (index >= cpool->capacity)
    {
        int old_cap = cpool->capacity;
        cpool->capacity *= 2;
        if (index >= cpool->capacity)
            cpool->capacity = index + 10;
        cpool->tags = ggc_realloc (cpool->tags,
                                   sizeof(uint8) * cpool->capacity);
        cpool->data = ggc_realloc (cpool->data,
                                   sizeof(union cpool_entry) * cpool->capacity);

        /* Make sure GC never sees uninitialized tag values.  */
        memset (cpool->tags + old_cap, 0, cpool->capacity - old_cap);
        memset (cpool->data + old_cap, 0,
                (cpool->capacity - old_cap) * sizeof (union cpool_entry));
    }
    if (index >= cpool->count)
        cpool->count = index + 1;
    cpool->tags[index] = tag;
    cpool->data[index].w = value;
}
Ejemplo n.º 2
0
Archivo: varray.c Proyecto: 0mp/freebsd
/* Allocate a virtual array with NUM_ELEMENT elements, each of which is
   ELEMENT_SIZE bytes long, named NAME.  Array elements are zeroed.  */
varray_type
varray_init (size_t num_elements, enum varray_data_enum element_kind,
	     const char *name)
{
  size_t data_size = num_elements * element[element_kind].size;
  varray_type ptr;
#ifdef GATHER_STATISTICS
  struct varray_descriptor *desc = varray_descriptor (name);

  desc->created++;
  desc->allocated += data_size + VARRAY_HDR_SIZE;
#endif
  if (element[element_kind].uses_ggc)
    ptr = ggc_alloc_cleared (VARRAY_HDR_SIZE + data_size);
  else
    ptr = xcalloc (VARRAY_HDR_SIZE + data_size, 1);

  ptr->num_elements = num_elements;
  ptr->elements_used = 0;
  ptr->type = element_kind;
  ptr->name = name;
  return ptr;
}
Ejemplo n.º 3
0
/* Like ggc_alloc_cleared, but performs a multiplication.  */
void *
ggc_calloc (size_t s1, size_t s2)
{
  return ggc_alloc_cleared (s1 * s2);
}