-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003 Free Software Foundation, Inc.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this software; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
- *
- * As a special exception, the Free Software Foundation gives permission
- * for additional uses of the text contained in its release of GUILE.
- *
- * The exception is that, if you link the GUILE library with other files
- * to produce an executable, this does not by itself cause the
- * resulting executable to be covered by the GNU General Public License.
- * Your use of that executable is in no way restricted on account of
- * linking the GUILE library code into it.
- *
- * This exception does not however invalidate any other reasons why
- * the executable file might be covered by the GNU General Public License.
- *
- * This exception applies only to the code released by the
- * Free Software Foundation under the name GUILE. If you copy
- * code from other Free Software Foundation releases into a copy of
- * GUILE, as the General Public License permits, the exception does
- * not apply to the code that you add in this way. To avoid misleading
- * anyone as to the status of such modified files, you must delete
- * this exception notice from them.
- *
- * If you write modifications of your own for GUILE, it is your choice
- * whether to permit this exception to apply to your modifications.
- * If you do not wish that, delete this exception notice. */
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
/* #define DEBUGINFO */
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
#include <stdio.h>
#include <errno.h>
unsigned int scm_gc_running_p = 0;
+/* Lock this mutex before doing lazy sweeping.
+ */
+scm_t_rec_mutex scm_i_sweep_mutex;
+
/* Set this to != 0 if every cell that is accessed shall be checked:
*/
int scm_debug_cell_accesses_p = 0;
else
{
counter = scm_debug_cells_gc_interval;
- scm_i_thread_put_to_sleep ();
scm_igc ("scm_assert_cell_valid");
- scm_i_thread_wake_up ();
}
}
}
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
-#else
-/*
- Provide a stub, so people can use their Scheme code on non-debug
- versions of GUILE as well.
- */
-SCM_DEFINE (scm_set_debug_cell_accesses_x, "set-debug-cell-accesses!", 1, 0, 0,
- (SCM flag),
- "This function is used to turn on checking for a debug version of GUILE. This version does not support this functionality\n")
-#define FUNC_NAME s_scm_set_debug_cell_accesses_x
-{
-
- /*
- do nothing
- */
- fprintf (stderr, "\nWARNING: GUILE was not compiled with SCM_DEBUG_CELL_ACCESSES");
- scm_remember_upto_here (flag);
- return SCM_UNSPECIFIED;
-}
-#undef FUNC_NAME
#endif /* SCM_DEBUG_CELL_ACCESSES == 1 */
double scm_gc_cells_swept_acc = 0.;
int scm_gc_cell_yield_percentage =0;
int scm_gc_malloc_yield_percentage = 0;
+unsigned long protected_obj_count = 0;
SCM_SYMBOL (sym_cells_allocated, "cells-allocated");
SCM_SYMBOL (sym_cells_swept, "cells-swept");
SCM_SYMBOL (sym_malloc_yield, "malloc-yield");
SCM_SYMBOL (sym_cell_yield, "cell-yield");
+SCM_SYMBOL (sym_protected_objects, "protected-objects");
unsigned long int local_scm_gc_time_taken;
unsigned long int local_scm_gc_times;
unsigned long int local_scm_gc_mark_time_taken;
+ unsigned long int local_protected_obj_count;
double local_scm_gc_cells_swept;
double local_scm_gc_cells_marked;
SCM answer;
local_scm_gc_times = scm_gc_times;
local_scm_gc_malloc_yield_percentage = scm_gc_malloc_yield_percentage;
local_scm_gc_cell_yield_percentage= scm_gc_cell_yield_percentage;
-
+ local_protected_obj_count = protected_obj_count;
local_scm_gc_cells_swept =
(double) scm_gc_cells_swept_acc
+ (double) scm_gc_cells_swept;
scm_cons (sym_cells_marked, scm_i_dbl2big (local_scm_gc_cells_marked)),
scm_cons (sym_cells_swept, scm_i_dbl2big (local_scm_gc_cells_swept)),
scm_cons (sym_malloc_yield, scm_long2num (local_scm_gc_malloc_yield_percentage)),
- scm_cons (sym_cell_yield, scm_long2num (local_scm_gc_cell_yield_percentage)),
+ scm_cons (sym_cell_yield, scm_long2num (local_scm_gc_cell_yield_percentage)),
+ scm_cons (sym_protected_objects, scm_ulong2num (local_protected_obj_count)),
scm_cons (sym_heap_segments, heap_segs),
SCM_UNDEFINED);
SCM_ALLOW_INTS;
"no longer accessible.")
#define FUNC_NAME s_scm_gc
{
- SCM_DEFER_INTS;
- scm_i_thread_put_to_sleep ();
scm_igc ("call");
- scm_i_thread_wake_up ();
- SCM_ALLOW_INTS;
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
{
SCM cell;
- scm_i_thread_put_to_sleep ();
+ scm_rec_mutex_lock (&scm_i_sweep_mutex);
*free_cells = scm_i_sweep_some_segments (freelist);
if (*free_cells == SCM_EOL && scm_i_gc_grow_heap_p (freelist))
*free_cells = SCM_FREE_CELL_CDR (cell);
- scm_i_thread_wake_up ();
+ scm_rec_mutex_unlock (&scm_i_sweep_mutex);
return cell;
}
void
scm_igc (const char *what)
{
+ scm_rec_mutex_lock (&scm_i_sweep_mutex);
++scm_gc_running_p;
scm_c_hook_run (&scm_before_gc_c_hook, 0);
#endif
/* During the critical section, only the current thread may run. */
-#if 0 /* MDJ 021207 <djurfeldt@nada.kth.se>
- Currently, a much larger piece of the GC is single threaded.
- Can we shrink it again? */
- SCM_CRITICAL_SECTION_START;
-#endif
+ scm_i_thread_put_to_sleep ();
if (!scm_root || !scm_stack_base || scm_block_gc)
{
/*
TODO: this hook should probably be moved to just before the mark,
since that's where the sweep is finished in lazy sweeping.
+
+ MDJ 030219 <djurfeldt@nada.kth.se>: No, probably not. The
+ original meaning implied at least two things: that it would be
+ called when
+
+ 1. the freelist is re-initialized (no evaluation possible, though)
+
+ and
+
+ 2. the heap is "fresh"
+ (it is well-defined what data is used and what is not)
+
+ Neither of these conditions would hold just before the mark phase.
+
+ Of course, the lazy sweeping has muddled the distinction between
+ scm_before_sweep_c_hook and scm_after_sweep_c_hook, but even if
+ there were no difference, it would still be useful to have two
+ distinct classes of hook functions since this can prevent some
+ bad interference when several modules adds gc hooks.
*/
scm_c_hook_run (&scm_after_sweep_c_hook, 0);
gc_end_stats ();
-#if 0 /* MDJ 021207 <djurfeldt@nada.kth.se> */
- SCM_CRITICAL_SECTION_END;
-#endif
+ scm_i_thread_wake_up ();
/*
See above.
*/
scm_c_hook_run (&scm_after_gc_c_hook, 0);
--scm_gc_running_p;
+ scm_rec_mutex_unlock (&scm_i_sweep_mutex);
/*
For debugging purposes, you could do
* scm_remember_upto_here_1 (str); // str will be alive up to this point.
*/
+/* Remove any macro versions of these while defining the functions.
+ Functions are always included in the library, for upward binary
+ compatibility and in case combinations of GCC and non-GCC are used. */
+#undef scm_remember_upto_here_1
+#undef scm_remember_upto_here_2
+
void
scm_remember_upto_here_1 (SCM obj SCM_UNUSED)
{
scm_gc_protect_object(X) increments and scm_gc_unprotect_object(X) decrements.
*/
+
+
SCM
scm_gc_protect_object (SCM obj)
{
handle = scm_hashq_create_handle_x (scm_protects, obj, SCM_MAKINUM (0));
SCM_SETCDR (handle, scm_sum (SCM_CDR (handle), SCM_MAKINUM (1)));
+ protected_obj_count ++;
+
SCM_REALLOW_INTS;
return obj;
else
SCM_SETCDR (handle, count);
}
+ protected_obj_count --;
SCM_REALLOW_INTS;
return res;
}
+void
+scm_storage_prehistory ()
+{
+ scm_c_hook_init (&scm_before_gc_c_hook, 0, SCM_C_HOOK_NORMAL);
+ scm_c_hook_init (&scm_before_mark_c_hook, 0, SCM_C_HOOK_NORMAL);
+ scm_c_hook_init (&scm_before_sweep_c_hook, 0, SCM_C_HOOK_NORMAL);
+ scm_c_hook_init (&scm_after_sweep_c_hook, 0, SCM_C_HOOK_NORMAL);
+ scm_c_hook_init (&scm_after_gc_c_hook, 0, SCM_C_HOOK_NORMAL);
+}
int
scm_init_storage ()
{
size_t j;
+ /* Fixme: Should use mutexattr from the low-level API. */
+ scm_rec_mutex_init (&scm_i_sweep_mutex, &scm_i_plugin_rec_mutex);
+
j = SCM_NUM_PROTECTS;
while (j)
scm_sys_protects[--j] = SCM_BOOL_F;
j = SCM_HEAP_SEG_SIZE;
-
- scm_c_hook_init (&scm_before_gc_c_hook, 0, SCM_C_HOOK_NORMAL);
- scm_c_hook_init (&scm_before_mark_c_hook, 0, SCM_C_HOOK_NORMAL);
- scm_c_hook_init (&scm_before_sweep_c_hook, 0, SCM_C_HOOK_NORMAL);
- scm_c_hook_init (&scm_after_sweep_c_hook, 0, SCM_C_HOOK_NORMAL);
- scm_c_hook_init (&scm_after_gc_c_hook, 0, SCM_C_HOOK_NORMAL);
-
/* Initialise the list of ports. */
scm_i_port_table = (scm_t_port **)
malloc (sizeof (scm_t_port *) * scm_i_port_table_room);
be GC-protected instead. */
*SCM_FREELIST_LOC (scm_i_freelist) = SCM_EOL;
*SCM_FREELIST_LOC (scm_i_freelist2) = SCM_EOL;
+
+ /* Invalidate the freelists of other threads. */
+ scm_i_thread_invalidate_freelists ();
}
#undef FUNC_NAME