Skip to content

Commit

Permalink
[gc] add new mark_... _alive functions, use it in a lot of mark vtabl…
Browse files Browse the repository at this point in the history
…e functions, and some cleanup related, TT #1062

git-svn-id: https://svn.parrot.org/parrot/trunk@41447 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
NotFound committed Sep 24, 2009
1 parent 8c03a5e commit 18dd147
Show file tree
Hide file tree
Showing 39 changed files with 176 additions and 208 deletions.
26 changes: 26 additions & 0 deletions include/parrot/gc_api.h
Expand Up @@ -111,12 +111,23 @@ PARROT_EXPORT
void Parrot_block_GC_sweep(PARROT_INTERP)
__attribute__nonnull__(1);

PARROT_EXPORT
void Parrot_gc_mark_PMC_alive_fun(PARROT_INTERP, ARGMOD_NULLOK(PMC *obj))
__attribute__nonnull__(1)
FUNC_MODIFIES(*obj);

PARROT_EXPORT
void Parrot_gc_mark_PObj_alive(PARROT_INTERP, ARGMOD(PObj *obj))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
FUNC_MODIFIES(*obj);

PARROT_EXPORT
void Parrot_gc_mark_STRING_alive_fun(PARROT_INTERP,
ARGMOD_NULLOK(STRING *obj))
__attribute__nonnull__(1)
FUNC_MODIFIES(*obj);

PARROT_EXPORT
unsigned int Parrot_is_blocked_GC_mark(PARROT_INTERP)
__attribute__nonnull__(1);
Expand Down Expand Up @@ -315,9 +326,14 @@ int Parrot_gc_total_sized_buffers(PARROT_INTERP)
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_block_GC_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_gc_mark_PMC_alive_fun __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_gc_mark_PObj_alive __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
&& PARROT_ASSERT_ARG(obj)
#define ASSERT_ARGS_Parrot_gc_mark_STRING_alive_fun \
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_is_blocked_GC_mark __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_is_blocked_GC_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = \
Expand Down Expand Up @@ -448,6 +464,16 @@ int Parrot_gc_total_sized_buffers(PARROT_INTERP)

void Parrot_gc_inf_init(PARROT_INTERP);

#ifdef NDEBUG
# define Parrot_gc_mark_PMC_alive(interp, obj) \
do if (! PMC_IS_NULL(obj)) Parrot_gc_mark_PObj_alive((interp), (PObj *)(obj)); while (0)
# define Parrot_gc_mark_STRING_alive(interp, obj) \
do if (! STRING_IS_NULL(obj)) Parrot_gc_mark_PObj_alive((interp), (PObj *)(obj)); while (0)
#else
# define Parrot_gc_mark_PMC_alive(interp, obj) Parrot_gc_mark_PMC_alive_fun((interp), (obj))
# define Parrot_gc_mark_STRING_alive(interp, obj) Parrot_gc_mark_STRING_alive_fun((interp), (obj))
#endif

#endif /* PARROT_GC_API_H_GUARD */

/*
Expand Down
42 changes: 42 additions & 0 deletions src/gc/api.c
Expand Up @@ -236,6 +236,48 @@ Parrot_gc_mark_PObj_alive(PARROT_INTERP, ARGMOD(PObj *obj))

/*
=item C<void Parrot_gc_mark_PMC_alive_fun(PARROT_INTERP, PMC *obj)>
A type safe wrapper of Parrot_gc_mark_PObj_alive for PMC.
=cut
*/

PARROT_EXPORT
void
Parrot_gc_mark_PMC_alive_fun(PARROT_INTERP, ARGMOD_NULLOK(PMC *obj))
{
ASSERT_ARGS(Parrot_gc_mark_PMC_alive_fun)
if (!PMC_IS_NULL(obj)) {
PARROT_ASSERT(PObj_is_PMC_TEST(obj));
Parrot_gc_mark_PObj_alive(interp, (PObj *)obj);
}
}

/*
=item C<void Parrot_gc_mark_STRING_alive_fun(PARROT_INTERP, STRING *obj)>
A type safe wrapper of Parrot_gc_mark_PObj_alive for STRING.
=cut
*/

PARROT_EXPORT
void
Parrot_gc_mark_STRING_alive_fun(PARROT_INTERP, ARGMOD_NULLOK(STRING *obj))
{
ASSERT_ARGS(Parrot_gc_mark_STRING_alive_fun)
if (!STRING_IS_NULL(obj)) {
PARROT_ASSERT(PObj_is_string_TEST(obj));
Parrot_gc_mark_PObj_alive(interp, (PObj *)obj);
}
}

/*
=item C<void Parrot_gc_initialize(PARROT_INTERP, void *stacktop)>
Initializes the memory allocator and the garbage collection subsystem.
Expand Down
3 changes: 1 addition & 2 deletions src/pmc/arrayiterator.pmc
Expand Up @@ -109,8 +109,7 @@ Marks the current idx/key and the aggregate as live.
VTABLE void mark() {
PMC *array;
GET_ATTR_array(INTERP, SELF, array);
if (array)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)array);
Parrot_gc_mark_PMC_alive(INTERP, array);
}

/*
Expand Down
9 changes: 3 additions & 6 deletions src/pmc/callsignature.pmc
Expand Up @@ -179,12 +179,9 @@ Mark any referenced strings and PMCs.
Parrot_CallSignature_attributes * const attrs = PARROT_CALLSIGNATURE(SELF);

if (attrs) {
if (attrs->returns)
Parrot_gc_mark_PObj_alive(interp, (PObj*)attrs->returns);
if (attrs->type_tuple)
Parrot_gc_mark_PObj_alive(interp, (PObj*)attrs->type_tuple);
if (attrs->short_sig)
Parrot_gc_mark_PObj_alive(interp, (PObj*)attrs->short_sig);
Parrot_gc_mark_PMC_alive(interp, attrs->returns);
Parrot_gc_mark_PMC_alive(interp, attrs->type_tuple);
Parrot_gc_mark_STRING_alive(interp, attrs->short_sig);
}
SUPER();
}
Expand Down
39 changes: 13 additions & 26 deletions src/pmc/class.pmc
Expand Up @@ -589,32 +589,19 @@ Marks any referenced strings and PMCs in the structure as live.

VTABLE void mark() {
Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);
if (_class->name)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->name);
if (_class->fullname)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->fullname);
if (_class->_namespace)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->_namespace);
if (_class->parents)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->parents);
if (_class->all_parents)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->all_parents);
if (_class->roles)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->roles);
if (_class->methods)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->methods);
if (_class->vtable_overrides)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->vtable_overrides);
if (_class->parent_overrides)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->parent_overrides);
if (_class->attrib_metadata)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->attrib_metadata);
if (_class->attrib_index)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->attrib_index);
if (_class->attrib_cache)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->attrib_cache);
if (_class->resolve_method)
Parrot_gc_mark_PObj_alive(interp, (PObj *)_class->resolve_method);
Parrot_gc_mark_STRING_alive(interp, _class->name);
Parrot_gc_mark_STRING_alive(interp, _class->fullname);
Parrot_gc_mark_PMC_alive(interp, _class->_namespace);
Parrot_gc_mark_PMC_alive(interp, _class->parents);
Parrot_gc_mark_PMC_alive(interp, _class->all_parents);
Parrot_gc_mark_PMC_alive(interp, _class->roles);
Parrot_gc_mark_PMC_alive(interp, _class->methods);
Parrot_gc_mark_PMC_alive(interp, _class->vtable_overrides);
Parrot_gc_mark_PMC_alive(interp, _class->parent_overrides);
Parrot_gc_mark_PMC_alive(interp, _class->attrib_metadata);
Parrot_gc_mark_PMC_alive(interp, _class->attrib_index);
Parrot_gc_mark_PMC_alive(interp, _class->attrib_cache);
Parrot_gc_mark_PMC_alive(interp, _class->resolve_method);
}


Expand Down
6 changes: 2 additions & 4 deletions src/pmc/continuation.pmc
Expand Up @@ -131,10 +131,8 @@ Marks the continuation as live.
if (!cc)
return;

if (cc->to_ctx)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *) cc->to_ctx);
if (cc->from_ctx)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *) cc->from_ctx);
Parrot_gc_mark_PMC_alive(INTERP, cc->to_ctx);
Parrot_gc_mark_PMC_alive(INTERP, cc->from_ctx);
}

/*
Expand Down
6 changes: 3 additions & 3 deletions src/pmc/cpointer.pmc
Expand Up @@ -84,18 +84,18 @@ pointer.
if (sig) {
void *pointer;
GET_ATTR_pointer(INTERP, SELF, pointer);
Parrot_gc_mark_PObj_alive(interp, (PObj *)sig);
Parrot_gc_mark_STRING_alive(interp, sig);

if (pointer) {
if (Parrot_str_equal(interp, sig, CONST_STRING(interp, "P"))) {
PMC ** const pmc_pointer = (PMC **) pointer;
PARROT_ASSERT(*pmc_pointer);
Parrot_gc_mark_PObj_alive(interp, (PObj *) *pmc_pointer);
Parrot_gc_mark_PMC_alive(interp, *pmc_pointer);
}
else if (Parrot_str_equal(interp, sig, CONST_STRING(interp, "S"))) {
STRING ** const str_pointer = (STRING **) pointer;
PARROT_ASSERT(*str_pointer);
Parrot_gc_mark_PObj_alive(interp, (PObj *) *str_pointer);
Parrot_gc_mark_STRING_alive(interp, *str_pointer);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/pmc/eval.pmc
Expand Up @@ -119,8 +119,7 @@ mark_subs(PARROT_INTERP, PMC *self)
opcode_t ci = e->offset;
PMC *sub = ct->constants[ci]->u.key;

if (!PMC_IS_NULL(sub))
Parrot_gc_mark_PObj_alive(interp, (PObj *)sub);
Parrot_gc_mark_PMC_alive(interp, sub);
}
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/pmc/eventhandler.pmc
Expand Up @@ -123,14 +123,9 @@ Marks this PMC and any of its contents as live.
Parrot_EventHandler_attributes * const e = PARROT_EVENTHANDLER(SELF);

if (e) {
if (e->type)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)e->type);

if (! PMC_IS_NULL(e->interp))
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)e->interp);

if (! PMC_IS_NULL(e->code))
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)e->code);
Parrot_gc_mark_STRING_alive(INTERP, e->type);
Parrot_gc_mark_PMC_alive(INTERP, e->interp);
Parrot_gc_mark_PMC_alive(INTERP, e->code);

SUPER();
}
Expand Down
21 changes: 7 additions & 14 deletions src/pmc/exception.pmc
Expand Up @@ -149,20 +149,13 @@ Mark any active exception data as live.

VTABLE void mark() {
Parrot_Exception_attributes * const core_struct = PARROT_EXCEPTION(SELF);
if (core_struct->message)
Parrot_gc_mark_PObj_alive(interp, (PObj *)core_struct->message);
if (core_struct->payload)
Parrot_gc_mark_PObj_alive(interp, (PObj *)core_struct->payload);
if (core_struct->resume)
Parrot_gc_mark_PObj_alive(interp, (PObj *)core_struct->resume);
if (core_struct->backtrace)
Parrot_gc_mark_PObj_alive(interp, (PObj *)core_struct->backtrace);
if (core_struct->handler_iter)
Parrot_gc_mark_PObj_alive(interp, (PObj *)core_struct->handler_iter);
if (core_struct->handler_ctx)
Parrot_gc_mark_PObj_alive(interp, (PObj *)core_struct->handler_ctx);
if (core_struct->thrower)
Parrot_gc_mark_PObj_alive(interp, (PObj *)core_struct->thrower);
Parrot_gc_mark_STRING_alive(interp, core_struct->message);
Parrot_gc_mark_PMC_alive(interp, core_struct->payload);
Parrot_gc_mark_PMC_alive(interp, core_struct->resume);
Parrot_gc_mark_PMC_alive(interp, core_struct->backtrace);
Parrot_gc_mark_PMC_alive(interp, core_struct->handler_iter);
Parrot_gc_mark_PMC_alive(interp, core_struct->handler_ctx);
Parrot_gc_mark_PMC_alive(interp, core_struct->thrower);
}

/*
Expand Down
6 changes: 2 additions & 4 deletions src/pmc/exceptionhandler.pmc
Expand Up @@ -68,10 +68,8 @@ Mark any active exception handler data as live.
VTABLE void mark() {
Parrot_ExceptionHandler_attributes * const attrs =
PARROT_EXCEPTIONHANDLER(SELF);
if (attrs->handled_types)
Parrot_gc_mark_PObj_alive(interp, (PObj *)attrs->handled_types);
if (attrs->handled_types_except)
Parrot_gc_mark_PObj_alive(interp, (PObj *)attrs->handled_types_except);
Parrot_gc_mark_PMC_alive(interp, attrs->handled_types);
Parrot_gc_mark_PMC_alive(interp, attrs->handled_types_except);
SUPER();
}

Expand Down
9 changes: 3 additions & 6 deletions src/pmc/exporter.pmc
Expand Up @@ -134,12 +134,9 @@ Mark referenced strings and PMCs in the structure as live.
GET_ATTR_ns_dest(INTERP, SELF, ns_dest);
GET_ATTR_globals(INTERP, SELF, globals);

if (ns_src)
Parrot_gc_mark_PObj_alive(interp, (PObj *)ns_src);
if (ns_dest)
Parrot_gc_mark_PObj_alive(interp, (PObj *)ns_dest);
if (globals)
Parrot_gc_mark_PObj_alive(interp, (PObj *)globals);
Parrot_gc_mark_PMC_alive(interp, ns_src);
Parrot_gc_mark_PMC_alive(interp, ns_dest);
Parrot_gc_mark_PMC_alive(interp, globals);
}


Expand Down
9 changes: 3 additions & 6 deletions src/pmc/filehandle.pmc
Expand Up @@ -119,12 +119,9 @@ Mark active filehandle data as live.

VTABLE void mark() {
Parrot_FileHandle_attributes * const data_struct = PARROT_FILEHANDLE(SELF);
if (data_struct->mode)
Parrot_gc_mark_PObj_alive(interp, (PObj *)data_struct->mode);
if (data_struct->filename)
Parrot_gc_mark_PObj_alive(interp, (PObj *)data_struct->filename);
if (data_struct->encoding)
Parrot_gc_mark_PObj_alive(interp, (PObj *)data_struct->encoding);
Parrot_gc_mark_STRING_alive(interp, data_struct->mode);
Parrot_gc_mark_STRING_alive(interp, data_struct->filename);
Parrot_gc_mark_STRING_alive(interp, data_struct->encoding);
}

/*
Expand Down
3 changes: 1 addition & 2 deletions src/pmc/fixedpmcarray.pmc
Expand Up @@ -787,8 +787,7 @@ Mark the array.
return;

for (i = PMC_size(SELF) - 1; i >= 0; --i)
if (data[i])
Parrot_gc_mark_PObj_alive(interp, (PObj *)data[i]);
Parrot_gc_mark_PMC_alive(interp, data[i]);
}


Expand Down
3 changes: 1 addition & 2 deletions src/pmc/fixedstringarray.pmc
Expand Up @@ -118,8 +118,7 @@ Marks the array as live.
GET_ATTR_size(INTERP, SELF, size);

for (i = 0; i < size; i++) {
if (str_array[i])
Parrot_gc_mark_PObj_alive(INTERP, (PObj *) str_array[i]);
Parrot_gc_mark_STRING_alive(INTERP, str_array[i]);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/pmc/hashiterator.pmc
Expand Up @@ -126,8 +126,7 @@ Marks the hash as live.

VTABLE void mark() {
PMC *hash = PARROT_HASHITERATOR(SELF)->pmc_hash;
if (hash)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)hash);
Parrot_gc_mark_PMC_alive(INTERP, hash);
/* We don't mark underlying parrot_hash. Hash PMC will mark it */
}

Expand Down
15 changes: 5 additions & 10 deletions src/pmc/namespace.pmc
Expand Up @@ -162,16 +162,11 @@ Marks the namespace as live.
VTABLE void mark() {
Parrot_NameSpace_attributes * const nsinfo = PARROT_NAMESPACE(SELF);
SUPER();
if (nsinfo->parent)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)nsinfo->parent);
if (nsinfo->name)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)nsinfo->name);
if (nsinfo->_class)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)nsinfo->_class);
if (nsinfo->vtable)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)nsinfo->vtable);
if (nsinfo->methods)
Parrot_gc_mark_PObj_alive(INTERP, (PObj *)nsinfo->methods);
Parrot_gc_mark_PMC_alive(INTERP, nsinfo->parent);
Parrot_gc_mark_STRING_alive(INTERP, nsinfo->name);
Parrot_gc_mark_PMC_alive(INTERP, nsinfo->_class);
Parrot_gc_mark_PMC_alive(INTERP, nsinfo->vtable);
Parrot_gc_mark_PMC_alive(INTERP, nsinfo->methods);
}

/*
Expand Down
12 changes: 4 additions & 8 deletions src/pmc/nci.pmc
Expand Up @@ -232,14 +232,10 @@ Mark any referenced strings and PMCs.
if (PARROT_NCI(SELF)) {
Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);

if (nci_info->signature)
Parrot_gc_mark_PObj_alive(interp, (PObj*)nci_info->signature);
if (nci_info->pcc_params_signature)
Parrot_gc_mark_PObj_alive(interp, (PObj*)nci_info->pcc_params_signature);
if (nci_info->long_signature)
Parrot_gc_mark_PObj_alive(interp, (PObj*)nci_info->long_signature);
if (nci_info->multi_sig)
Parrot_gc_mark_PObj_alive(interp, (PObj*)nci_info->multi_sig);
Parrot_gc_mark_STRING_alive(interp, nci_info->signature);
Parrot_gc_mark_STRING_alive(interp, nci_info->pcc_params_signature);
Parrot_gc_mark_STRING_alive(interp, nci_info->long_signature);
Parrot_gc_mark_PMC_alive(interp, nci_info->multi_sig);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/pmc/object.pmc
Expand Up @@ -190,10 +190,8 @@ Mark any referenced strings and PMCs.
if (PARROT_OBJECT(SELF)) {
Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);

if (obj->_class)
Parrot_gc_mark_PObj_alive(interp, (PObj*)obj->_class);
if (obj->attrib_store)
Parrot_gc_mark_PObj_alive(interp, (PObj*)obj->attrib_store);
Parrot_gc_mark_PMC_alive(interp, obj->_class);
Parrot_gc_mark_PMC_alive(interp, obj->attrib_store);
}
}

Expand Down

0 comments on commit 18dd147

Please sign in to comment.