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; }
/* Grow/shrink the virtual array VA to N elements. Zero any new elements allocated. */ varray_type varray_grow (varray_type va, size_t n) { size_t old_elements = va->num_elements; if (n != old_elements) { size_t elem_size = element[va->type].size; size_t old_data_size = old_elements * elem_size; size_t data_size = n * elem_size; #ifdef GATHER_STATISTICS struct varray_descriptor *desc = varray_descriptor (va->name); varray_type oldva = va; if (data_size > old_data_size) desc->allocated += data_size - old_data_size; desc->resized ++; #endif if (element[va->type].uses_ggc) va = ggc_realloc (va, VARRAY_HDR_SIZE + data_size); else va = xrealloc (va, VARRAY_HDR_SIZE + data_size); va->num_elements = n; if (n > old_elements) memset (&va->data.vdt_c[old_data_size], 0, data_size - old_data_size); #ifdef GATHER_STATISTICS if (oldva != va) desc->copied++; #endif } return va; }