Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial implementation of object/STable repossession; not really poss…
…ible to test until the serializer is updated.
  • Loading branch information
jnthn committed Feb 28, 2012
1 parent 93cbec9 commit 608ee61
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
38 changes: 38 additions & 0 deletions src/6model/serialization_context.c
Expand Up @@ -122,3 +122,41 @@ void SC_set_code(PARROT_INTERP, PMC *sc, INTVAL idx, PMC *code) {
GETATTR_SerializationContext_root_codes(interp, sc, codes);
VTABLE_set_pmc_keyed_int(interp, codes, idx, code);
}

/* Takes an object and adds it to this SC's root set, and installs a
* reposession entry. */
void SC_repossess_object(PARROT_INTERP, PMC *target_sc, PMC *orig_sc, PMC *object) {
PMC *rep_indexes, *rep_scs;

/* Add to root set. */
PMC *objects;
INTVAL new_slot;
GETATTR_SerializationContext_root_objects(interp, target_sc, objects);
new_slot = VTABLE_elements(interp, objects);
VTABLE_set_pmc_keyed_int(interp, objects, new_slot, object);

/* Add repossession entry. */
GETATTR_SerializationContext_rep_indexes(interp, target_sc, rep_indexes);
GETATTR_SerializationContext_rep_scs(interp, target_sc, rep_scs);
VTABLE_push_integer(interp, rep_indexes, new_slot);
VTABLE_push_pmc(interp, rep_scs, orig_sc);
}

/* Takes an STable and adds it to this SC's root set, and installs a
* reposession entry. */
void SC_repossess_stable(PARROT_INTERP, PMC *target_sc, PMC *orig_sc, PMC *st_pmc) {
PMC *rep_indexes, *rep_scs;

/* Add to root set. */
PMC *stables;
INTVAL new_slot;
GETATTR_SerializationContext_root_stables(interp, target_sc, stables);
new_slot = VTABLE_elements(interp, stables);
VTABLE_set_pmc_keyed_int(interp, stables, new_slot, st_pmc);

/* Add repossession entry. */
GETATTR_SerializationContext_rep_indexes(interp, target_sc, rep_indexes);
GETATTR_SerializationContext_rep_scs(interp, target_sc, rep_scs);
VTABLE_push_integer(interp, rep_indexes, new_slot);
VTABLE_push_pmc(interp, rep_scs, orig_sc);
}
2 changes: 2 additions & 0 deletions src/6model/serialization_context.h
Expand Up @@ -12,4 +12,6 @@ PMC * SC_get_stable(PARROT_INTERP, PMC *sc, INTVAL idx);
PMC * SC_get_object(PARROT_INTERP, PMC *sc, INTVAL idx);
PMC * SC_get_code(PARROT_INTERP, PMC *sc, INTVAL idx);
void SC_set_code(PARROT_INTERP, PMC *sc, INTVAL idx, PMC *code);
void SC_repossess_object(PARROT_INTERP, PMC *target_sc, PMC *orig_sc, PMC *object);
void SC_repossess_stable(PARROT_INTERP, PMC *target_sc, PMC *orig_sc, PMC *st_pmc);
#endif
10 changes: 8 additions & 2 deletions src/ops/nqp.ops
Expand Up @@ -46,7 +46,10 @@ PMC *compiling_scs = NULL;
/* SC write barrier for objects. */
static void SC_write_barrier_obj(PARROT_INTERP, PMC *obj) {
if (VTABLE_get_bool(interp, compiling_scs)) {
if (VTABLE_get_pmc_keyed_int(interp, compiling_scs, 0) != SC_PMC(obj)) {
PMC *comp_sc = VTABLE_get_pmc_keyed_int(interp, compiling_scs, 0);
if (SC_PMC(obj) != comp_sc) {
SC_repossess_object(interp, comp_sc, SC_PMC(obj), obj);
SC_PMC(obj) = comp_sc;
printf("SC OBJECT WRITE BARRIER HIT (%s)\n",
Parrot_str_cstring(interp, VTABLE_name(interp, obj)));
}
Expand All @@ -56,7 +59,10 @@ static void SC_write_barrier_obj(PARROT_INTERP, PMC *obj) {
/* SC write barrier for STables. */
static void SC_write_barrier_st(PARROT_INTERP, STable *st) {
if (VTABLE_get_bool(interp, compiling_scs)) {
if (VTABLE_get_pmc_keyed_int(interp, compiling_scs, 0) != st->sc) {
PMC *comp_sc = VTABLE_get_pmc_keyed_int(interp, compiling_scs, 0);
if (st->sc != comp_sc) {
SC_repossess_stable(interp, comp_sc, st->sc, st->stable_pmc);
st->sc = comp_sc;
printf("SC STABLE WRITE BARRIER HIT (%s)\n",
Parrot_str_cstring(interp, VTABLE_name(interp, st->WHAT)));
}
Expand Down

0 comments on commit 608ee61

Please sign in to comment.