[svn:parrot] r44172 - branches/sys_mem_reduce/src
bacek at svn.parrot.org
bacek at svn.parrot.org
Fri Feb 19 13:26:24 UTC 2010
Author: bacek
Date: Fri Feb 19 13:26:23 2010
New Revision: 44172
URL: https://trac.parrot.org/parrot/changeset/44172
Log:
Switch pbc_merge to GC allocations.
Modified:
branches/sys_mem_reduce/src/pbc_merge.c
Modified: branches/sys_mem_reduce/src/pbc_merge.c
==============================================================================
--- branches/sys_mem_reduce/src/pbc_merge.c Fri Feb 19 13:26:04 2010 (r44171)
+++ branches/sys_mem_reduce/src/pbc_merge.c Fri Feb 19 13:26:23 2010 (r44172)
@@ -257,7 +257,7 @@
/* Read in program. Nabbed from Parrot_pbc_read. */
chunk_size = program_size > 0 ? program_size : 1024;
- program_code = (char *)mem_sys_allocate(chunk_size);
+ program_code = mem_gc_allocate_n_typed(interp, chunk_size, char);
wanted = program_size;
program_size = 0;
cursor = (char *)program_code;
@@ -267,8 +267,8 @@
if (program_size == wanted)
break;
chunk_size = 1024;
- program_code =
- (char *)mem_sys_realloc(program_code, program_size + chunk_size);
+ mem_gc_realloc_n_typed(interp, program_code,
+ program_size + chunk_size, char);
cursor = (char *)program_code + program_size;
}
@@ -314,7 +314,7 @@
{
ASSERT_ARGS(pbc_merge_bytecode)
int i;
- opcode_t *bc = mem_allocate_typed(opcode_t);
+ opcode_t *bc = mem_gc_allocate_typed(interp, opcode_t);
opcode_t cursor = 0;
/* Add a bytecode segment. */
@@ -378,7 +378,7 @@
ARGMOD(PackFile_ByteCode *bc))
{
ASSERT_ARGS(pbc_merge_constants)
- PackFile_Constant **constants = mem_allocate_typed(PackFile_Constant *);
+ PackFile_Constant **constants = mem_gc_allocate_typed(interp, PackFile_Constant *);
opcode_t cursor = 0;
opcode_t output_const_num = 0;
@@ -414,14 +414,15 @@
/* Allocate space for the constant list, provided we have some. */
if (in_seg->const_count > 0)
- constants = (PackFile_Constant **)mem_sys_realloc(constants,
- (cursor + in_seg->const_count) * sizeof (Parrot_Pointer));
+ mem_gc_realloc_n_typed(interp, constants,
+ cursor + in_seg->const_count, PackFile_Constant*);
/* Loop over the constants and copy them to the output PBC. */
for (j = 0; j < in_seg->const_count; j++) {
/* Get the entry and allocate space for copy. */
PackFile_Constant *cur_entry = in_seg->constants[j];
- PackFile_Constant *copy = mem_allocate_typed(PackFile_Constant);
+ PackFile_Constant *copy = mem_gc_allocate_typed(interp,
+ PackFile_Constant);
STRUCT_COPY(copy, cur_entry);
/* If it's a sub PMC, need to deal with offsets. */
@@ -477,7 +478,8 @@
{
ASSERT_ARGS(pbc_merge_fixups)
PackFile_FixupTable *fixup_seg;
- PackFile_FixupEntry **fixups = mem_allocate_typed(PackFile_FixupEntry *);
+ PackFile_FixupEntry **fixups = mem_gc_allocate_typed(interp,
+ PackFile_FixupEntry *);
opcode_t cursor = 0;
int i, j;
@@ -503,8 +505,8 @@
/* Allocate space for these fixups, provided we have some. */
if (in_seg->fixup_count > 0) {
- fixups = (PackFile_FixupEntry **)mem_sys_realloc(fixups,
- (cursor + in_seg->fixup_count) * sizeof (Parrot_Pointer));
+ mem_gc_realloc_n_typed(interp, fixups,
+ cursor + in_seg->fixup_count, PackFile_FixupEntry*);
}
/* Loop over the fixups and copy them to the output PBC, correcting
@@ -512,10 +514,10 @@
for (j = 0; j < in_seg->fixup_count; j++) {
/* Get the entry and allocate space for copies. */
PackFile_FixupEntry *cur_entry = in_seg->fixups[j];
- PackFile_FixupEntry *copy = mem_allocate_typed(
- PackFile_FixupEntry);
- char *name_copy = (char *)mem_sys_allocate(
- strlen(cur_entry->name) + 1);
+ PackFile_FixupEntry *copy = mem_gc_allocate_typed(interp,
+ PackFile_FixupEntry);
+ char *name_copy = mem_gc_allocate_n_typed(interp,
+ strlen(cur_entry->name) + 1, char);
/* Copy type and name. */
copy->type = cur_entry->type;
@@ -564,9 +566,10 @@
{
ASSERT_ARGS(pbc_merge_debugs)
PackFile_Debug *debug_seg;
- opcode_t *lines = mem_allocate_typed(opcode_t);
+ opcode_t *lines = mem_gc_allocate_typed(interp,
+ opcode_t);
PackFile_DebugFilenameMapping **mappings =
- mem_allocate_typed(PackFile_DebugFilenameMapping *);
+ mem_gc_allocate_typed(interp, PackFile_DebugFilenameMapping *);
opcode_t num_mappings = 0;
opcode_t num_lines = 0;
@@ -580,19 +583,20 @@
PackFile_Debug *in_seg = inputs[i]->pf->cur_cs->debugs;
/* Concatenate line numbers. */
- lines = (opcode_t *)mem_sys_realloc(lines,
- (num_lines + in_seg->base.size) * sizeof (opcode_t));
+ mem_gc_realloc_n_typed(interp, lines,
+ num_lines + in_seg->base.size, opcode_t);
memcpy(lines + num_lines, in_seg->base.data,
in_seg->base.size * sizeof (opcode_t));
/* Concatenate mappings. */
- mappings = (PackFile_DebugFilenameMapping **)mem_sys_realloc(mappings,
- (num_mappings + in_seg->num_mappings) *
- sizeof (Parrot_Pointer));
+ mem_gc_realloc_n_typed(interp, mappings,
+ num_mappings + in_seg->num_mappings,
+ PackFile_DebugFilenameMapping*);
+
for (j = 0; j < in_seg->num_mappings; j++) {
- PackFile_DebugFilenameMapping *mapping = mem_allocate_typed(
- PackFile_DebugFilenameMapping);
+ PackFile_DebugFilenameMapping *mapping = mem_gc_allocate_typed(
+ interp, PackFile_DebugFilenameMapping);
STRUCT_COPY(mapping, in_seg->mappings[j]);
mapping->offset += num_lines;
mapping->filename += inputs[i]->const_start;
@@ -607,9 +611,9 @@
with merged ones we have created. */
debug_seg = Parrot_new_debug_seg(interp, bc, num_lines);
PackFile_add_segment(interp, &pf->directory, (PackFile_Segment*)debug_seg);
- mem_sys_free(debug_seg->base.data);
+ mem_gc_free(interp, debug_seg->base.data);
debug_seg->base.data = lines;
- mem_sys_free(debug_seg->mappings);
+ mem_gc_free(interp, debug_seg->mappings);
debug_seg->mappings = mappings;
debug_seg->num_mappings = num_mappings;
@@ -738,7 +742,8 @@
PackFile_Segment *seg = (PackFile_Segment *)pf_dir->segments[j];
if (seg->type == PF_CONST_SEG) {
opcode_t const_count = ((PackFile_ConstTable *)seg)->const_count;
- inputs[i]->const_map = mem_allocate_n_typed(const_count, opcode_t);
+ inputs[i]->const_map = mem_gc_allocate_n_typed(interp,
+ const_count, opcode_t);
}
}
}
@@ -755,7 +760,7 @@
pbc_merge_ctpointers(interp, inputs, num_inputs, bc);
for (i = 0; i < num_inputs; i++) {
- mem_sys_free(inputs[i]->const_map);
+ mem_gc_free(interp, inputs[i]->const_map);
}
/* Return merged result. */
@@ -784,7 +789,7 @@
const size_t size = PackFile_pack_size(interp, pf) * sizeof (opcode_t);
/* Allocate memory. */
- opcode_t * const pack = (opcode_t*) mem_sys_allocate(size);
+ opcode_t * const pack = (opcode_t*) Parrot_gc_allocate_memory_chunk(interp, size);
/* Write and clean up. */
PackFile_pack(interp, pf, pack);
@@ -797,7 +802,7 @@
Parrot_exit(interp, 1);
}
fclose(fp);
- mem_sys_free(pack);
+ mem_gc_free(interp, pack);
}
@@ -858,12 +863,11 @@
/* Load each packfile that we are to merge and set up an input
structure for each of them. */
- input_files = (pbc_merge_input **)mem_sys_allocate(
- argc * sizeof (Parrot_Pointer));
+ input_files = mem_gc_allocate_n_typed(interp, argc, pbc_merge_input*);
for (i = 0; i < argc; i++) {
/* Allocate a struct. */
- input_files[i] = mem_allocate_typed(pbc_merge_input);
+ input_files[i] = mem_gc_allocate_typed(interp, pbc_merge_input);
/* Set filename */
input_files[i]->filename = *argv;
More information about the parrot-commits
mailing list