Skip to content

Commit e4937be

Browse files
committed
First cut at the barrier applicability logic, which just emits a debug message for now.
1 parent 10d5a9c commit e4937be

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/6model/sixmodelobject.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,22 @@ struct SixModel_REPROps {
351351
#define MARK_AS_TYPE_OBJECT(o) PObj_flag_SET(private0, (o))
352352

353353
/* Write barriers for noticing changes to objects or STables with an SC. */
354-
#define OBJ_SC_WRITE_BARRIER(o) if (SC_PMC(o)) { }
355-
#define ST_SC_WRITE_BARRIER(st) if ((st)->sc) { }
354+
typedef void (* obj_sc_barrier_func) (PARROT_INTERP, PMC *obj);
355+
typedef void (* st_sc_barrier_func) (PARROT_INTERP, STable *st);
356+
#define OBJ_SC_WRITE_BARRIER(o) \
357+
if (SC_PMC(o)) { \
358+
((obj_sc_barrier_func) \
359+
D2FPTR(VTABLE_get_pointer(interp, \
360+
VTABLE_get_pmc_keyed_str(interp, interp->root_namespace, \
361+
Parrot_str_new_constant(interp, "_OBJ_SC_BARRIER")))))(interp, o); \
362+
}
363+
#define ST_SC_WRITE_BARRIER(st) \
364+
if ((st)->sc) { \
365+
((st_sc_barrier_func) \
366+
D2FPTR(VTABLE_get_pointer(interp, \
367+
VTABLE_get_pmc_keyed_str(interp, interp->root_namespace, \
368+
Parrot_str_new_constant(interp, "_ST_SC_BARRIER")))))(interp, st); \
369+
}
356370

357371
/* Object model initialization. */
358372
void SixModelObject_initialize(PARROT_INTERP, PMC **knowhow, PMC **knowhow_attribute);

src/ops/nqp.ops

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ static INTVAL nqpdebflags_i = 0;
4343
* may have multiple on the go due to compiling nested module dependencies. */
4444
PMC *compiling_scs = NULL;
4545

46+
/* SC write barrier for objects. */
47+
static void SC_write_barrier_obj(PARROT_INTERP, PMC *obj) {
48+
if (VTABLE_get_bool(interp, compiling_scs)) {
49+
if (VTABLE_get_pmc_keyed_int(interp, compiling_scs, 0) != SC_PMC(obj)) {
50+
printf("SC OBJECT WRITE BARRIER HIT (%s)\n",
51+
Parrot_str_cstring(interp, VTABLE_name(interp, obj)));
52+
}
53+
}
54+
}
55+
56+
/* SC write barrier for STables. */
57+
static void SC_write_barrier_st(PARROT_INTERP, STable *st) {
58+
if (VTABLE_get_bool(interp, compiling_scs)) {
59+
if (VTABLE_get_pmc_keyed_int(interp, compiling_scs, 0) != st->sc) {
60+
printf("SC STABLE WRITE BARRIER HIT (%s)\n",
61+
Parrot_str_cstring(interp, VTABLE_name(interp, st->WHAT)));
62+
}
63+
}
64+
}
65+
4666
END_OPS_PREAMBLE
4767

4868
/*
@@ -56,7 +76,7 @@ Does various setup tasks for the benefit of the other dynops.
5676
*/
5777
inline op nqp_dynop_setup() :base_core {
5878
if (!initialized) {
59-
initialized = 1;
79+
PMC *obj_sc_barrier, *st_sc_barrier;
6080

6181
/* Look up and cache some type IDs. */
6282
stable_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "STable", 0));
@@ -69,6 +89,20 @@ inline op nqp_dynop_setup() :base_core {
6989
/* Initialize compiling SCs list. */
7090
compiling_scs = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
7191
Parrot_pmc_gc_register(interp, compiling_scs);
92+
93+
/* Set up write barrier functions. */
94+
/* XXX Really want a better, cheaper place to put them... */
95+
obj_sc_barrier = Parrot_pmc_new(interp, enum_class_Pointer);
96+
VTABLE_set_pointer(interp, obj_sc_barrier, SC_write_barrier_obj);
97+
VTABLE_set_pmc_keyed_str(interp, interp->root_namespace,
98+
Parrot_str_new_constant(interp, "_OBJ_SC_BARRIER"), obj_sc_barrier);
99+
st_sc_barrier = Parrot_pmc_new(interp, enum_class_Pointer);
100+
VTABLE_set_pointer(interp, st_sc_barrier, SC_write_barrier_st);
101+
VTABLE_set_pmc_keyed_str(interp, interp->root_namespace,
102+
Parrot_str_new_constant(interp, "_ST_SC_BARRIER"), st_sc_barrier);
103+
104+
/* Mark initialized. */
105+
initialized = 1;
72106
}
73107
}
74108

0 commit comments

Comments
 (0)