Skip to content

Commit

Permalink
[PCC] Optimized CS switching invoke.
Browse files Browse the repository at this point in the history
These checks can go away with threading system improvements, but avoiding this
function call which is almost always a do-nothing gives a modest performance
improvement to the default case of Sub's invoke.
  • Loading branch information
chromatic committed Sep 8, 2011
1 parent 60c22d7 commit e934aa8
Showing 1 changed file with 44 additions and 45 deletions.
89 changes: 44 additions & 45 deletions src/packfile/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1794,9 +1794,14 @@ Parrot_switch_to_cs(PARROT_INTERP, ARGIN(PackFile_ByteCode *new_cs), int really)

interp->code = new_cs;

Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp), really
? find_constants(interp, new_cs->const_table)
: new_cs->const_table);
if (really
&& (n_interpreters
&& interp->thread_data && interp->thread_data->tid != 0))
Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp),
find_constants(interp, new_cs->const_table));
else
Parrot_pcc_set_constants(interp, CURRENT_CONTEXT(interp),
new_cs->const_table);

if (really)
prepare_for_run(interp);
Expand Down Expand Up @@ -1860,55 +1865,49 @@ static PackFile_ConstTable *
find_constants(PARROT_INTERP, ARGIN(PackFile_ConstTable *ct))
{
ASSERT_ARGS(find_constants)
if (!n_interpreters
|| !interp->thread_data
|| interp->thread_data->tid == 0)
return ct;
else {
Hash *tables;
PackFile_ConstTable *new_ct;

PARROT_ASSERT(interp->thread_data);

if (!interp->thread_data->const_tables) {
interp->thread_data->const_tables = Parrot_hash_new_pointer_hash(interp);
}

tables = interp->thread_data->const_tables;
new_ct = (PackFile_ConstTable *)Parrot_hash_get(interp, tables, ct);
Hash *tables;
PackFile_ConstTable *new_ct;

if (!new_ct) {
/* need to construct it */
PARROT_ASSERT(interp->thread_data);

int i;

new_ct = mem_gc_allocate_zeroed_typed(interp, PackFile_ConstTable);

new_ct->num.const_count = ct->num.const_count;
new_ct->num.constants = mem_gc_allocate_n_zeroed_typed(interp,
ct->num.const_count, FLOATVAL);
memcpy(new_ct->num.constants, ct->num.constants,
ct->num.const_count * sizeof (FLOATVAL));
if (!interp->thread_data->const_tables) {
interp->thread_data->const_tables = Parrot_hash_new_pointer_hash(interp);
}

new_ct->str.const_count = ct->str.const_count;
new_ct->str.constants = mem_gc_allocate_n_zeroed_typed(interp,
ct->str.const_count, STRING *);
memcpy(new_ct->str.constants, ct->str.constants,
ct->str.const_count * sizeof (STRING *));
tables = interp->thread_data->const_tables;
new_ct = (PackFile_ConstTable *)Parrot_hash_get(interp, tables, ct);

new_ct->pmc.const_count = ct->pmc.const_count;
new_ct->pmc.constants = mem_gc_allocate_n_zeroed_typed(interp,
ct->pmc.const_count, PMC *);
memcpy(new_ct->pmc.constants, ct->pmc.constants,
ct->pmc.const_count * sizeof (PMC *));
for (i = 0; i < new_ct->pmc.const_count; ++i)
clone_constant(interp, &new_ct->pmc.constants[i]);
if (!new_ct) {
/* need to construct it */

Parrot_hash_put(interp, tables, ct, new_ct);
}
int i;

return new_ct;
new_ct = mem_gc_allocate_zeroed_typed(interp, PackFile_ConstTable);

new_ct->num.const_count = ct->num.const_count;
new_ct->num.constants = mem_gc_allocate_n_zeroed_typed(interp,
ct->num.const_count, FLOATVAL);
memcpy(new_ct->num.constants, ct->num.constants,
ct->num.const_count * sizeof (FLOATVAL));

new_ct->str.const_count = ct->str.const_count;
new_ct->str.constants = mem_gc_allocate_n_zeroed_typed(interp,
ct->str.const_count, STRING *);
memcpy(new_ct->str.constants, ct->str.constants,
ct->str.const_count * sizeof (STRING *));

new_ct->pmc.const_count = ct->pmc.const_count;
new_ct->pmc.constants = mem_gc_allocate_n_zeroed_typed(interp,
ct->pmc.const_count, PMC *);
memcpy(new_ct->pmc.constants, ct->pmc.constants,
ct->pmc.const_count * sizeof (PMC *));
for (i = 0; i < new_ct->pmc.const_count; ++i)
clone_constant(interp, &new_ct->pmc.constants[i]);

Parrot_hash_put(interp, tables, ct, new_ct);
}

return new_ct;
}


Expand Down

0 comments on commit e934aa8

Please sign in to comment.