<commit_before>/*
Copyright (C) 2001-2010, Parrot Foundation.

=head1 NAME

src/gc/api.c - general Parrot API for GC functions

=head1 DESCRIPTION

This file implements the external-facing API for Parrot's garbage collector.
The collector itself is composed of various interchangable cores that each
may operate very differently internally. The functions in this file can be used
throughout Parrot without having to be concerned about the internal operations
of the GC. This is documented in PDD 9 with supplementary notes in
F<docs/memory_internals.pod>.

=head1 GC OVERVIEW

The GC is broken into a number of different files that each represent different
components.

=over 4

=item F<src/gc/api.c>

This is the main API file which provides access to functions which are used by
the rest of Parrot core.  Only the functions provided in this file should be
visible to files outside the src/gc/ directory.  Because this represents a
public-facing API, the functions in this file are not related by theme.

=item F<src/gc/alloc_memory.c>

This file provides a number of functions and macros for allocating memory from
the OS. These are typically wrapper functions around malloc, calloc and realloc
with additional error-handling code.

=item F<src/gc/alloc_resources.c>

This file implements handling logic for strings and arbitrary-sized memory
buffers.  String storage is managed by special Variable_Size_Pool structures.
A separate compacting garbage collector is used to keep track of them.

=item F<src/gc/gc_ms.c>

=item F<src/gc/gc_ms2.c>

=item F<src/gc/gc_inf.c>

These files are the individual GC cores which implement the primary tracing
and sweeping logic. gc_ms.c is the mark & sweep collector core which is used in
Parrot by default. gc_ms2.c implements a generational mark & sweep allocator.
gc_inf.c implements an "infinite" allocator which never frees any memory.  The
infinite allocator is not recommended except for debugging.

=item F<src/gc/mark_sweep.c>

This file implements some generic utility functions that are commonly needed by
various GC cores and provide an abstraction layer that a GC core can use to
interact with some of the architecture of Parrot.

=item F<src/gc/system.c>

This file implements low-level logic for tracing processor registers and the
system stack.  Here be dragons.

=item F<src/gc/malloc.c>

=item F<src/gc/malloc_trace.c>

These two files implement various unused features, including a custom malloc
implementation, and malloc wrappers for various purposes. These are unused.

=back


=head1 FUNCTIONS

=over 4

=cut

*/

#define GC_C_SOURCE
#include "parrot/parrot.h"
#include "parrot/gc_api.h"
#include "gc_private.h"

/* HEADERIZER HFILE: include/parrot/gc_api.h */

/*

=item C<void Parrot_gc_mark_PObj_alive(PARROT_INTERP, PObj *obj)>

Marks the PObj as "alive" for the Garbage Collector. Takes a pointer to a PObj,
and performs necessary marking to ensure the PMC and its direct children nodes
are marked alive. Implementation is generally dependant on the particular
garbage collector in use.

Previously known as C<pobject_lives>.

=cut

*/

PARROT_EXPORT
void
Parrot_gc_mark_PObj_alive(PARROT_INTERP, ARGMOD(PObj *obj))
{
    ASSERT_ARGS(Parrot_gc_mark_PObj_alive)

    /* if object is live or on free list return */
    // FIXME Disable this logic. We use MARK for moving objects
    // between generations. And they are definitely alive.
    //if (PObj_is_live_or_free_TESTALL(obj))
    //    return;

    if (PObj_is_PMC_TEST(obj)) {
        interp->gc_sys->mark_pmc_header(interp, (PMC*) obj);
    }
    else {
        interp->gc_sys->mark_str_header(interp, (STRING*) 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)
    interp->gc_sys->mark_pmc_header(interp, obj);
}

/*

=item C<void Parrot_gc_mark_STRING_alive_fun(PARROT_INTERP, STRING *obj)><commit_msg>Undisable old shortcut.<commit_after>/*
Copyright (C) 2001-2010, Parrot Foundation.

=head1 NAME

src/gc/api.c - general Parrot API for GC functions

=head1 DESCRIPTION

This file implements the external-facing API for Parrot's garbage collector.
The collector itself is composed of various interchangable cores that each
may operate very differently internally. The functions in this file can be used
throughout Parrot without having to be concerned about the internal operations
of the GC. This is documented in PDD 9 with supplementary notes in
F<docs/memory_internals.pod>.

=head1 GC OVERVIEW

The GC is broken into a number of different files that each represent different
components.

=over 4

=item F<src/gc/api.c>

This is the main API file which provides access to functions which are used by
the rest of Parrot core.  Only the functions provided in this file should be
visible to files outside the src/gc/ directory.  Because this represents a
public-facing API, the functions in this file are not related by theme.

=item F<src/gc/alloc_memory.c>

This file provides a number of functions and macros for allocating memory from
the OS. These are typically wrapper functions around malloc, calloc and realloc
with additional error-handling code.

=item F<src/gc/alloc_resources.c>

This file implements handling logic for strings and arbitrary-sized memory
buffers.  String storage is managed by special Variable_Size_Pool structures.
A separate compacting garbage collector is used to keep track of them.

=item F<src/gc/gc_ms.c>

=item F<src/gc/gc_ms2.c>

=item F<src/gc/gc_inf.c>

These files are the individual GC cores which implement the primary tracing
and sweeping logic. gc_ms.c is the mark & sweep collector core which is used in
Parrot by default. gc_ms2.c implements a generational mark & sweep allocator.
gc_inf.c implements an "infinite" allocator which never frees any memory.  The
infinite allocator is not recommended except for debugging.

=item F<src/gc/mark_sweep.c>

This file implements some generic utility functions that are commonly needed by
various GC cores and provide an abstraction layer that a GC core can use to
interact with some of the architecture of Parrot.

=item F<src/gc/system.c>

This file implements low-level logic for tracing processor registers and the
system stack.  Here be dragons.

=item F<src/gc/malloc.c>

=item F<src/gc/malloc_trace.c>

These two files implement various unused features, including a custom malloc
implementation, and malloc wrappers for various purposes. These are unused.

=back


=head1 FUNCTIONS

=over 4

=cut

*/

#define GC_C_SOURCE
#include "parrot/parrot.h"
#include "parrot/gc_api.h"
#include "gc_private.h"

/* HEADERIZER HFILE: include/parrot/gc_api.h */

/*

=item C<void Parrot_gc_mark_PObj_alive(PARROT_INTERP, PObj *obj)>

Marks the PObj as "alive" for the Garbage Collector. Takes a pointer to a PObj,
and performs necessary marking to ensure the PMC and its direct children nodes
are marked alive. Implementation is generally dependant on the particular
garbage collector in use.

Previously known as C<pobject_lives>.

=cut

*/

PARROT_EXPORT
void
Parrot_gc_mark_PObj_alive(PARROT_INTERP, ARGMOD(PObj *obj))
{
    ASSERT_ARGS(Parrot_gc_mark_PObj_alive)

    /* if object is live or on free list return */
    if (PObj_is_live_or_free_TESTALL(obj))
        return;

    if (PObj_is_PMC_TEST(obj)) {
        interp->gc_sys->mark_pmc_header(interp, (PMC*) obj);
    }
    else {
        interp->gc_sys->mark_str_header(interp, (STRING*) 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)
    interp->gc_sys->mark_pmc_header(interp, obj);
}

/*

=item C<void Parrot_gc_mark_STRING_alive_fun(PARROT_INTERP, STRING *obj)>
{'fraction_non_alphanumeric': 0.0670404984423676, 'fraction_numerical': 0.004236760124610592, 'mean_word_length': 4.467302452316076, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3982367', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2535, 'n_words': 974}