Commit 9110a741 by Bryce McKinlay Committed by Bryce McKinlay

Imported version version 6.0alpha7.

	* README, README.Mac, README.OS2, README.QUICK, README.alpha,
	README.amiga, README.debugging, README.dj, README.hp, README.linux,
	README.rs6000, README.sgi, README.solaris2, README.uts,
	README.win32, SCoptions.amiga, backptr.h, barrett_diagram,
	dbg_mlc.h, gc.h, gc.man, gc_alloc.h, gc_cpp.h, gc_hdrs.h, gc_mark.h,
	gc_priv.h, gc_private.h, gc_typed.h, gcconfig.h,
	hpux_irix_threads.c, makefile.depend, nursery.c,
	solaris_threads.h, test.c, test_cpp.cc, weakpointer.h, cord/README,
	cord/SCOPTIONS.amiga, cord/SMakefile.amiga, cord/cord.h,
	cord/ec.h, cord/gc.h, cord/private/cord_pos.h, include/backptr.h,
	include/gc_copy_descr.h, include/gc_nursery.h: Remove obsolete/moved
	files.

From-SVN: r42379
parent a6951ca5
......@@ -47,9 +47,9 @@ gc.lib: $(OBJS)
$(XXXOBJS:XXX=+)
|
gctest.exe: test.obj gc.lib
gctest.exe: tests\test.obj gc.lib
$(cc) @&&|
$(cflags) -W -e$* test.obj gc.lib
$(cflags) -W -e$* tests\test.obj gc.lib
|
cord\de.obj cord\de_win.obj: cord\cord.h cord\private\cord_pos.h cord\de_win.h \
......@@ -68,8 +68,8 @@ gc_cpp.obj: gc_cpp.h gc.h
gc_cpp.cpp: gc_cpp.cc
copy gc_cpp.cc gc_cpp.cpp
test_cpp.cpp: test_cpp.cc
copy test_cpp.cc test_cpp.cpp
test_cpp.cpp: tests\test_cpp.cc
copy tests\test_cpp.cc test_cpp.cpp
test_cpp.exe: test_cpp.obj gc_cpp.h gc.h gc.lib
$(cc) @&&|
......
2001-05-21 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
Imported version version 6.0alpha7.
* README, README.Mac, README.OS2, README.QUICK, README.alpha,
README.amiga, README.debugging, README.dj, README.hp, README.linux,
README.rs6000, README.sgi, README.solaris2, README.uts,
README.win32, SCoptions.amiga, backptr.h, barrett_diagram,
dbg_mlc.h, gc.h, gc.man, gc_alloc.h, gc_cpp.h, gc_hdrs.h, gc_mark.h,
gc_priv.h, gc_private.h, gc_typed.h, gcconfig.h,
hpux_irix_threads.c, makefile.depend, nursery.c,
solaris_threads.h, test.c, test_cpp.cc, weakpointer.h, cord/README,
cord/SCOPTIONS.amiga, cord/SMakefile.amiga, cord/cord.h,
cord/ec.h, cord/gc.h, cord/private/cord_pos.h, include/backptr.h,
include/gc_copy_descr.h, include/gc_nursery.h: Remove obsolete/moved
files.
2001-05-19 Hans Boehm <hans_boehm@hp.com>
* configure.host: Build with -fexceptions.
......
......@@ -77,7 +77,7 @@ $(OBJS) test.o: $(srcdir)/gc_priv.h $(srcdir)/gc_hdrs.h $(srcdir)/gc.h \
# options such as -DSILENT affects the size of GC_arrays,
# invalidating all .o files that rely on gc_priv.h
mark.o typd_mlc.o finalize.o: $(srcdir)/gc_mark.h
mark.o typd_mlc.o finalize.o: $(srcdir)/include/gc_mark.h $(srcdir)/include/private/gc_pmark.h
gc.a: $(OBJS)
$(AR) ru gc.a $(OBJS)
......@@ -120,13 +120,13 @@ cord/de.exe: $(srcdir)/cord/de.c $(srcdir)/cord/cordbscs.o $(srcdir)/cord/cordxt
$(CC) $(CFLAGS) -o cord/de.exe $(srcdir)/cord/de.c $(srcdir)/cord/cordbscs.o $(srcdir)/cord/cordxtra.o gc.a $(CURSES)
clean:
rm -f gc.a test.o gctest.exe output-local output-diff $(OBJS) \
rm -f gc.a tests/test.o gctest.exe output-local output-diff $(OBJS) \
setjmp_test mon.out gmon.out a.out core \
$(CORD_OBJS) cord/cordtest.exe cord/de.exe
-rm -f *~
gctest.exe: test.o gc.a
$(CC) $(CFLAGS) -o gctest.exe test.o gc.a
gctest.exe: tests/test.o gc.a
$(CC) $(CFLAGS) -o gctest.exe tests/test.o gc.a
# If an optimized setjmp_test generates a segmentation fault,
# odds are your compiler is broken. Gctest may still work.
......
......@@ -25,13 +25,11 @@ endif
toolexeclib_LTLIBRARIES = $(target_all)
EXTRA_LTLIBRARIES = libgcjgc.la
libgcjgc_la_SOURCES = allchblk.c alloc.c blacklst.c checksums.c \
gcconfig.h dbg_mlc.c dyn_load.c finalize.c gc.h gc_alloc.h gc_cpp.h \
gc_hdrs.h gc_mark.h gc_priv.h gc_private.h gc_typed.h gcj_mlc.c headers.c \
hpux_irix_threads.c linux_threads.c malloc.c mallocx.c mark.c mark_rts.c \
misc.c new_hblk.c obj_map.c os_dep.c pcr_interface.c ptr_chck.c \
real_malloc.c reclaim.c solaris_pthreads.c solaris_threads.c \
solaris_threads.h stubborn.c typd_mlc.c version.h weakpointer.h
libgcjgc_la_SOURCES = allchblk.c alloc.c blacklst.c checksums.c dbg_mlc.c \
dyn_load.c finalize.c gc_dlopen.c gcj_mlc.c headers.c irix_threads.c \
linux_threads.c malloc.c mallocx.c mark.c mark_rts.c misc.c new_hblk.c \
obj_map.c os_dep.c pcr_interface.c ptr_chck.c real_malloc.c reclaim.c \
solaris_pthreads.c solaris_threads.c specific.c stubborn.c typd_mlc.c`
# Include THREADLIBS here to ensure that the correct versions of
# linuxthread semaphore functions get linked:
......@@ -39,9 +37,10 @@ libgcjgc_la_LIBADD = @addobjs@ $(THREADLIBS)
libgcjgc_la_DEPENDENCIES = @addobjs@
libgcjgc_la_LDFLAGS = -version-info 1:1:0 -rpath $(toolexeclibdir)
EXTRA_libgcjgc_la_SOURCES = alpha_mach_dep.s mips_sgi_mach_dep.s \
mips_ultrix_mach_dep.s rs6000_mach_dep.s sparc_mach_dep.s \
sparc_sunos4_mach_dep.s mach_dep.c ecos.cc
EXTRA_libgcjgc_la_SOURCES = alpha_mach_dep.s hpux_test_and_clear.s \
mips_sgi_mach_dep.s mips_ultrix_mach_dep.s powerpc_macosx_mach_dep.s \
rs6000_mach_dep.s sparc_mach_dep.s sparc_netbsd_mach_dep.s \
sparc_sunos4_mach_dep.s
AM_CXXFLAGS = @BOEHM_GC_CFLAGS@
AM_CFLAGS = @BOEHM_GC_CFLAGS@
......@@ -55,7 +54,8 @@ TESTS = gctest
## FIXME: relies on internal code generated by automake.
all_objs = @addobjs@ $(libgcjgc_la_OBJECTS)
$(all_objs) : gcconfig.h gc_priv.h gc_hdrs.h gc.h gc_mark.h
$(all_objs) : include/private/gcconfig.h include/private/gc_priv.h \
include/private/gc_hdrs.h include/gc.h include/gc_gcj.h include/gc_mark.h
## FIXME: we shouldn't have to do this, but automake forces us to.
.s.lo:
......
......@@ -102,22 +102,17 @@ MULTIDIRS =
MULTISUBDIR =
MULTIDO = true
MULTICLEAN = true
@USE_LIBDIR_TRUE@toolexeclibdir = \
@USE_LIBDIR_TRUE@$(libdir)$(MULTISUBDIR)
@USE_LIBDIR_FALSE@toolexeclibdir = \
@USE_LIBDIR_FALSE@$(toolexecdir)/lib$(MULTISUBDIR)
@USE_LIBDIR_FALSE@toolexecdir = \
@USE_LIBDIR_FALSE@$(exec_prefix)/$(target_alias)
@USE_LIBDIR_TRUE@toolexeclibdir = @USE_LIBDIR_TRUE@$(libdir)$(MULTISUBDIR)
@USE_LIBDIR_FALSE@toolexeclibdir = @USE_LIBDIR_FALSE@$(toolexecdir)/lib$(MULTISUBDIR)
@USE_LIBDIR_FALSE@toolexecdir = @USE_LIBDIR_FALSE@$(exec_prefix)/$(target_alias)
toolexeclib_LTLIBRARIES = $(target_all)
EXTRA_LTLIBRARIES = libgcjgc.la
libgcjgc_la_SOURCES = allchblk.c alloc.c blacklst.c checksums.c \
gcconfig.h dbg_mlc.c dyn_load.c finalize.c gc.h gc_alloc.h gc_cpp.h \
gc_hdrs.h gc_mark.h gc_priv.h gc_private.h gc_typed.h gcj_mlc.c headers.c \
hpux_irix_threads.c linux_threads.c malloc.c mallocx.c mark.c mark_rts.c \
misc.c new_hblk.c obj_map.c os_dep.c pcr_interface.c ptr_chck.c \
real_malloc.c reclaim.c solaris_pthreads.c solaris_threads.c \
solaris_threads.h stubborn.c typd_mlc.c version.h weakpointer.h
libgcjgc_la_SOURCES = allchblk.c alloc.c blacklst.c checksums.c dbg_mlc.c \
dyn_load.c finalize.c gc_dlopen.c gcj_mlc.c headers.c irix_threads.c \
linux_threads.c malloc.c mallocx.c mark.c mark_rts.c misc.c new_hblk.c \
obj_map.c os_dep.c pcr_interface.c ptr_chck.c real_malloc.c reclaim.c \
solaris_pthreads.c solaris_threads.c specific.c stubborn.c typd_mlc.c`
# Include THREADLIBS here to ensure that the correct versions of
......@@ -126,9 +121,10 @@ libgcjgc_la_LIBADD = @addobjs@ $(THREADLIBS)
libgcjgc_la_DEPENDENCIES = @addobjs@
libgcjgc_la_LDFLAGS = -version-info 1:1:0 -rpath $(toolexeclibdir)
EXTRA_libgcjgc_la_SOURCES = alpha_mach_dep.s mips_sgi_mach_dep.s \
mips_ultrix_mach_dep.s rs6000_mach_dep.s sparc_mach_dep.s \
sparc_sunos4_mach_dep.s mach_dep.c ecos.cc
EXTRA_libgcjgc_la_SOURCES = alpha_mach_dep.s hpux_test_and_clear.s \
mips_sgi_mach_dep.s mips_ultrix_mach_dep.s powerpc_macosx_mach_dep.s \
rs6000_mach_dep.s sparc_mach_dep.s sparc_netbsd_mach_dep.s \
sparc_sunos4_mach_dep.s
AM_CXXFLAGS = @BOEHM_GC_CFLAGS@
......@@ -206,19 +202,14 @@ CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libgcjgc_la_OBJECTS = allchblk.lo alloc.lo blacklst.lo checksums.lo \
dbg_mlc.lo dyn_load.lo finalize.lo gcj_mlc.lo headers.lo \
hpux_irix_threads.lo linux_threads.lo malloc.lo mallocx.lo mark.lo \
dbg_mlc.lo dyn_load.lo finalize.lo gc_dlopen.lo gcj_mlc.lo headers.lo \
irix_threads.lo linux_threads.lo malloc.lo mallocx.lo mark.lo \
mark_rts.lo misc.lo new_hblk.lo obj_map.lo os_dep.lo pcr_interface.lo \
ptr_chck.lo real_malloc.lo reclaim.lo solaris_pthreads.lo \
solaris_threads.lo stubborn.lo typd_mlc.lo
solaris_threads.lo specific.lo stubborn.lo
check_PROGRAMS = gctest$(EXEEXT)
gctest_OBJECTS = test.$(OBJEXT)
gctest_DEPENDENCIES = ./libgcjgc.la
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(LIBTOOL) --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
......@@ -228,14 +219,14 @@ aclocal.m4 configure configure.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
TAR = gtar
GZIP_ENV = --best
SOURCES = $(libgcjgc_la_SOURCES) $(EXTRA_libgcjgc_la_SOURCES) $(gctest_SOURCES)
OBJECTS = $(libgcjgc_la_OBJECTS) $(gctest_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .cc .lo .o .obj .s
.SUFFIXES: .S .c .lo .o .obj .s
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --cygnus Makefile
......@@ -332,12 +323,6 @@ maintainer-clean-checkPROGRAMS:
gctest$(EXEEXT): $(gctest_OBJECTS) $(gctest_DEPENDENCIES)
@rm -f gctest$(EXEEXT)
$(LINK) $(gctest_LDFLAGS) $(gctest_OBJECTS) $(gctest_LDADD) $(LIBS)
.cc.o:
$(CXXCOMPILE) -c $<
.cc.obj:
$(CXXCOMPILE) -c `cygpath -w $<`
.cc.lo:
$(LTCXXCOMPILE) -c $<
tags: TAGS
......@@ -409,7 +394,7 @@ distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
if test -f $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
......@@ -526,7 +511,8 @@ install-am install uninstall-am uninstall all-redirect all-am all \
installdirs mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
$(all_objs) : gcconfig.h gc_priv.h gc_hdrs.h gc.h gc_mark.h
$(all_objs) : include/private/gcconfig.h include/private/gc_priv.h \
include/private/gc_hdrs.h include/gc.h include/gc_gcj.h include/gc_mark.h
.s.lo:
$(LTCOMPILE) -Wp,-P -x assembler-with-cpp -c $<
......
......@@ -10,29 +10,29 @@ OBJS= alloc.obj reclaim.obj allchblk.obj misc.obj mach_dep.obj os_dep.obj mark_r
all: gctest.exe cord\de.exe test_cpp.exe
.c.obj:
$(cc) $(cdebug) $(cflags) $(cvars) -DSILENT -DALL_INTERIOR_POINTERS -D__STDC__ $*.c /Fo$*.obj
$(cc) $(cdebug) $(cflags) $(cvars) -Iinclude -DSILENT -DALL_INTERIOR_POINTERS -D__STDC__ -DGC_NOT_DLL $*.c /Fo$*.obj
.cpp.obj:
$(cc) $(cdebug) $(cflags) $(cvars) -DSILENT -DALL_INTERIOR_POINTERS $*.CPP /Fo$*.obj
$(cc) $(cdebug) $(cflags) $(cvars) -Iinclude -DSILENT -DALL_INTERIOR_POINTERS -DGC_NOT_DLL $*.CPP /Fo$*.obj
$(OBJS) test.obj: gc_priv.h gc_hdrs.h gc.h
$(OBJS) tests\test.obj: include\private\gc_priv.h include\private\gc_hdrs.h include\gc.h include\private\gcconfig.h include\private\gc_locks.h include\private\gc_pmark.h include\gc_mark.h
gc.lib: $(OBJS)
lib /MACHINE:i386 /out:gc.lib $(OBJS)
# The original NT SDK used lib32 instead of lib
gctest.exe: test.obj gc.lib
gctest.exe: tests\test.obj gc.lib
# The following works for win32 debugging. For win32s debugging use debugtype:coff
# and add mapsympe line.
# This produces a "GUI" applications that opens no windows and writes to the log file
# "gc.log". This is done to make the result runnable under win32s.
$(link) -debug:full -debugtype:cv $(guiflags) -stack:131072 -out:$*.exe test.obj $(guilibs) gc.lib
$(link) -debug:full -debugtype:cv $(guiflags) -stack:131072 -out:$*.exe tests\test.obj $(guilibs) gc.lib
# mapsympe -n -o gctest.sym gctest.exe
cord\de_win.rbj: cord\de_win.res
cvtres -$(CPU) cord\de_win.res -o cord\de_win.rbj
cord\de.obj cord\de_win.obj: cord\cord.h cord\private\cord_pos.h cord\de_win.h cord\de_cmds.h
cord\de.obj cord\de_win.obj: include\cord.h include\private\cord_pos.h cord\de_win.h cord\de_cmds.h
cord\de_win.res: cord\de_win.rc cord\de_win.h cord\de_cmds.h
$(rc) $(rcvars) -r -fo cord\de_win.res $(cvars) cord\de_win.rc
......@@ -41,18 +41,18 @@ cord\de_win.res: cord\de_win.rc cord\de_win.h cord\de_cmds.h
cord\de.exe: cord\cordbscs.obj cord\cordxtra.obj cord\de.obj cord\de_win.obj cord\de_win.rbj gc.lib
$(link) -debug:full -debugtype:cv $(guiflags) -stack:16384 -out:cord\de.exe cord\cordbscs.obj cord\cordxtra.obj cord\de.obj cord\de_win.obj cord\de_win.rbj gc.lib $(guilibs)
gc_cpp.obj: gc_cpp.h gc.h
gc_cpp.obj: include\gc_cpp.h include\gc.h
gc_cpp.cpp: gc_cpp.cc
copy gc_cpp.cc gc_cpp.cpp
test_cpp.cpp: test_cpp.cc
copy test_cpp.cc test_cpp.cpp
test_cpp.cpp: tests\test_cpp.cc
copy tests\test_cpp.cc test_cpp.cpp
# This generates the C++ test executable. The executable expects
# a single numeric argument, which is the number of iterations.
# The output appears in the file "gc.log".
test_cpp.exe: test_cpp.obj gc_cpp.h gc.h gc.lib
test_cpp.exe: test_cpp.obj include\gc_cpp.h include\gc.h gc.lib
$(link) -debug:full -debugtype:cv $(guiflags) -stack:16384 -out:test_cpp.exe test_cpp.obj gc.lib $(guilibs)
......
......@@ -17,7 +17,7 @@ CFLAGS= /O /Q /DSILENT /DSMALL_CONFIG /DALL_INTERIOR_POINTERS
all: $(OBJS) gctest.exe cord\cordtest.exe
$(OBJS) test.obj: gc_priv.h gc_hdrs.h gc.h
$(OBJS) test.obj: include\private\gc_priv.h include\private\gc_hdrs.h include\gc.h include\private\gcconfig.h
## ERASE THE LIB FIRST - if it is already there then this command will fail
## (make sure its there or erase will fail!)
......@@ -32,14 +32,14 @@ mach_dep.obj: mach_dep.c
gctest.exe: test.obj gc.lib
$(CC) $(CFLAGS) /B"/STACK:524288" /Fegctest test.obj gc.lib
cord\cordbscs.obj: cord\cordbscs.c cord\cord.h cord\private\cord_pos.h
cord\cordbscs.obj: cord\cordbscs.c include\cord.h include\private\cord_pos.h
$(CC) $(CFLAGS) /C /Focord\cordbscs cord\cordbscs.c
cord\cordxtra.obj: cord\cordxtra.c cord\cord.h cord\private\cord_pos.h cord\ec.h
cord\cordxtra.obj: cord\cordxtra.c include\cord.h include\private\cord_pos.h include\ec.h
$(CC) $(CFLAGS) /C /Focord\cordxtra cord\cordxtra.c
cord\cordprnt.obj: cord\cordprnt.c cord\cord.h cord\private\cord_pos.h cord\ec.h
cord\cordprnt.obj: cord\cordprnt.c include\cord.h include\private\cord_pos.h include\ec.h
$(CC) $(CFLAGS) /C /Focord\cordprnt cord\cordprnt.c
cord\cordtest.exe: cord\cordtest.c cord\cord.h cord\private\cord_pos.h cord\ec.h $(CORDOBJS) gc.lib
cord\cordtest.exe: cord\cordtest.c include\cord.h include\private\cord_pos.h include\ec.h $(CORDOBJS) gc.lib
$(CC) $(CFLAGS) /B"/STACK:65536" /Fecord\cordtest cord\cordtest.c gc.lib $(CORDOBJS)
The code assumes static linking, and a single thread. The editor de has
not been ported. The cord test program has. The supplied OS2_MAKEFILE
assumes the IBM C Set/2 environment, but the code shouldn't.
Since we haven't figured out hoe to do perform partial links or to build static
libraries, clients currently need to link against a long list of executables.
Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
Copyright (c) 1999 by Hewlett-Packard. All rights reserved.
THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
Permission is hereby granted to use or copy this program
for any purpose, provided the above notices are retained on all copies.
Permission to modify the code and to distribute modified code is granted,
provided the above notices are retained, and a notice that the code was
modified is included with the above copyright notice.
For more details and the names of other contributors, see the
README file and gc.h. This file describes typical use of
the collector on a machine that is already supported.
INSTALLATION:
Under UN*X, type "make test". Under OS/2 or Windows NT, copy the
appropriate makefile to MAKEFILE, read it, and type "nmake test".
Read the machine specific README if one exists. The only way to
develop code with the collector for Windows 3.1 is to develop under
Windows NT, and then to use win32S.
If you wish to use the cord (structured string) library type
"make cords". (This requires an ANSI C compiler. You may need
to redefine CC in the Makefile.)
If you wish to use the collector from C++, type
"make c++". These add further files to gc.a and to the include
subdirectory. See cord/cord.h and gc_c++.h.
TYPICAL USE:
Include "gc.h" from this directory. Link against the appropriate library
("gc.a" under UN*X). Replace calls to malloc by calls to GC_MALLOC,
and calls to realloc by calls to GC_REALLOC. If the object is known
to never contain pointers, use GC_MALLOC_ATOMIC instead of
GC_MALLOC.
Define GC_DEBUG before including gc.h for additional checking.
Should work under OSF/1 and Linux. Currently no VMS or NT support, though
the latter shouldn't be hard.
Incremental gc not yet supported under Linux because signal handler
for SIGSEGV can't get a hold of fault address. Dynamic library support
is also missing from Linux/alpha, probably for no good reason.
Currently there is no thread support in the standard distribution. There
exists a separate port to DEC Unix pthreads. It should be possible to
port the X86 Linux threads support to Alpha without much trouble.
If you get asssembler errors, be sure to read the first few lines of the
Makefile.
From Philippe Queinnec:
System: DEC/Alpha OSF1 v3.2, vendor cc
Problem: can't link if libgc has been compiled with "cc -std1".
It works if the library has been compiled with either gcc or "cc"
alone. The problem is because the variable "end" is not defined if
compiling in std1 mode (see man ld).
Proposed fix: none. Don't use cc -std1 !
===========================================================================
Martin Tauchmann's notes (1-Apr-99)
===========================================================================
Works now, also with the GNU-C compiler V2.7.2.1. <ftp://ftp.unina.it/pub/amiga/geekgadgets/amiga/m68k/snapshots/971125/amiga-bin/>
Modify the `Makefile`
CC=cc $(ABI_FLAG)
to
CC=gcc $(ABI_FLAG)
TECHNICAL NOTES
- `GC_get_stack_base()`, `GC_register_data_segments()` works now with every
C compiler; also Workbench.
- Removed AMIGA_SKIP_SEG, but the Code-Segment must not be scanned by GC.
PROBLEMS
- When the Linker, does`t merge all Code-Segments to an single one. LD of GCC
do it always.
- With ixemul.library V47.3, when an GC program launched from another program
(example: `Make` or `if_mach M68K AMIGA gctest`), `GC_register_data_segments()`
found the Segment-List of the caller program.
Can be fixed, if the run-time initialization code (for C programs, usually *crt0*)
support `__data` and `__bss`.
- PowerPC Amiga currently not supported.
- Dynamic libraries (dyn_load.c) not supported.
TESTED WITH SOFTWARE
`Optimized Oberon 2 C` (oo2c) <http://cognac.informatik.uni-kl.de/download/index.html>
TESTED WITH HARDWARE
MC68030
CONTACT
Please, contact me at <martintauchmann@bigfoot.com>, when you change the
Amiga port. <http://martintauchmann.home.pages.de>
===========================================================================
Michel Schinz's notes
===========================================================================
WHO DID WHAT
The original Amiga port was made by Jesper Peterson. I (Michel Schinz)
modified it slightly to reflect the changes made in the new official
distributions, and to take advantage of the new SAS/C 6.x features. I also
created a makefile to compile the "cord" package (see the cord
subdirectory).
TECHNICAL NOTES
In addition to Jesper's notes, I have the following to say:
- Starting with version 4.3, gctest checks to see if the code segment is
added to the root set or not, and complains if it is. Previous versions
of this Amiga port added the code segment to the root set, so I tried to
fix that. The only problem is that, as far as I know, it is impossible to
know which segments are code segments and which are data segments (there
are indeed solutions to this problem, like scanning the program on disk
or patch the LoadSeg functions, but they are rather complicated). The
solution I have chosen (see os_dep.c) is to test whether the program
counter is in the segment we are about to add to the root set, and if it
is, to skip the segment. The problems are that this solution is rather
awkward and that it works only for one code segment. This means that if
your program has more than one code segment, all of them but one will be
added to the root set. This isn't a big problem in fact, since the
collector will continue to work correctly, but it may be slower.
Anyway, the code which decides whether to skip a segment or not can be
removed simply by not defining AMIGA_SKIP_SEG. But notice that if you do
so, gctest will complain (it will say that "GC_is_visible produced wrong
failure indication"). However, it may be useful if you happen to have
pointers stored in a code segment (you really shouldn't).
If anyone has a good solution to the problem of finding, when a program
is loaded in memory, whether a segment is a code or a data segment,
please let me know.
PROBLEMS
If you have any problem with this version, please contact me at
schinz@alphanet.ch (but do *not* send long files, since we pay for
every mail!).
===========================================================================
Jesper Peterson's notes
===========================================================================
ADDITIONAL NOTES FOR AMIGA PORT
These notes assume some familiarity with Amiga internals.
WHY I PORTED TO THE AMIGA
The sole reason why I made this port was as a first step in getting
the Sather(*) language on the Amiga. A port of this language will
be done as soon as the Sather 1.0 sources are made available to me.
Given this motivation, the garbage collection (GC) port is rather
minimal.
(*) For information on Sather read the comp.lang.sather newsgroup.
LIMITATIONS
This port assumes that the startup code linked with target programs
is that supplied with SAS/C versions 6.0 or later. This allows
assumptions to be made about where to find the stack base pointer
and data segments when programs are run from WorkBench, as opposed
to running from the CLI. The compiler dependent code is all in the
GC_get_stack_base() and GC_register_data_segments() functions, but
may spread as I add Amiga specific features.
Given that SAS/C was assumed, the port is set up to be built with
"smake" using the "SMakefile". Compiler options in "SCoptions" can
be set with "scopts" program. Both "smake" and "scopts" are part of
the SAS/C commercial development system.
In keeping with the porting philosophy outlined above, this port
will not behave well with Amiga specific code. Especially not inter-
process comms via messages, and setting up public structures like
Intuition objects or anything else in the system lists. For the
time being the use of this library is limited to single threaded
ANSI/POSIX compliant or near-complient code. (ie. Stick to stdio
for now). Given this limitation there is currently no mechanism for
allocating "CHIP" or "PUBLIC" memory under the garbage collector.
I'll add this after giving it considerable thought. The major
problem is the entire physical address space may have to me scanned,
since there is no telling who we may have passed memory to.
If you allocate your own stack in client code, you will have to
assign the pointer plus stack size to GC_stackbottom.
The initial stack size of the target program can be compiled in by
setting the __stack symbol (see SAS documentaion). It can be over-
ridden from the CLI by running the AmigaDOS "stack" program, or from
the WorkBench by setting the stack size in the tool types window.
SAS/C COMPILER OPTIONS (SCoptions)
You may wish to check the "CPU" code option is appropriate for your
intended target system.
Under no circumstances set the "StackExtend" code option in either
compiling the library or *ANY* client code.
All benign compiler warnings have been suppressed. These mainly
involve lack of prototypes in the code, and dead assignments
detected by the optimizer.
THE GOOD NEWS
The library as it stands is compatible with the GigaMem commercial
virtual memory software, and probably similar PD software.
The performance of "gctest" on an Amiga 2630 (68030 @ 25Mhz)
compares favourably with an HP9000 with similar architecture (a 325
with a 68030 I think).
-----------------------------------------------------------------------
The Amiga port has been brought to you by:
Jesper Peterson.
jep@mtiame.mtia.oz.au (preferred, but 1 week turnaround)
jep@orca1.vic.design.telecom.au (that's orca<one>, 1 day turnaround)
At least one of these addresses should be around for a while, even
though I don't work for either of the companies involved.
Debugging suggestions:
****If you get a segmentation fault or bus error while debugging with a debugger:
If the fault occurred in GC_find_limit, or with incremental collection enabled, this is probably normal. The collector installs handlers to take care of these. You will not see these unless you are using a debugger. Your debugger should allow you to continue. It's preferable to tell the debugger to ignore SIGBUS and SIGSEGV ("handle" in gdb, "ignore" in most versions of dbx) and set a breakpoint in abort. The collector will call abort if the signal had another cause, and there was not other handler previously installed. I recommend debugging without incremental collection if possible. (This applies directly to UNIX systems. Debugging with incremental collection under win32 is worse. See README.win32.)
****If you get warning messages informing you that the collector needed to allocate blacklisted blocks:
0) Ignore these warnings while you are using GC_DEBUG. Some of the routines mentioned below don't have debugging equivalents. (Alternatively, write the missing routines and send them to me.)
1) Replace allocator calls that request large blocks with calls to GC_malloc_ignore_off_page or GC_malloc_atomic_ignore_off_page. You may want to set a breakpoint in GC_default_warn_proc to help you identify such calls. Make sure that a pointer to somewhere near the beginning of the resulting block is maintained in a (preferably volatile) variable as long as the block is needed.
2) If the large blocks are allocated with realloc, I suggest instead allocating them with something like the following. Note that the realloc size increment should be fairly large (e.g. a factor of 3/2) for this to exhibit reasonable performance. But we all know we should do that anyway.
void * big_realloc(void *p, size_t new_size)
{
size_t old_size = GC_size(p);
void * result;
if (new_size <= 10000) return(GC_realloc(p, new_size));
if (new_size <= old_size) return(p);
result = GC_malloc_ignore_off_page(new_size);
if (result == 0) return(0);
memcpy(result,p,old_size);
GC_free(p);
return(result);
}
3) In the unlikely case that even relatively small object (<20KB) allocations are triggering these warnings, then your address space contains lots of "bogus pointers", i.e. values that appear to be pointers but aren't. Usually this can be solved by using GC_malloc_atomic or the routines in gc_typed.h to allocate large pointerfree regions of bitmaps, etc. Sometimes the problem can be solved with trivial changes of encoding in certain values. It is possible, though not pleasant, to identify the source of the bogus pointers by setting a breakpoint in GC_add_to_black_list_stack, and looking at the value of current_p in the GC_mark_from_mark_stack frame. Current_p contains the address of the bogus pointer.
4) If you get only a fixed number of these warnings, you are probably only introducing a bounded leak by ignoring them. If the data structures being allocated are intended to be permanent, then it is also safe to ignore them. The warnings can be turned off by calling GC_set_warn_proc with a procedure that ignores these warnings (e.g. by doing absolutely nothing).
****If the collector dies in GC_malloc while trying to remove a free list element:
1) With > 99% probability, you wrote past the end of an allocated object. Try setting GC_DEBUG and using the debugging facilities in gc.h.
****If the heap grows too much:
1) Consider using GC_malloc_atomic for objects containing nonpointers. This is especially important for large arrays containg compressed data, pseudo-random numbers, and the like. (This isn't all that likely to solve your problem, but it's a useful and easy optimization anyway, and this is a good time to try it.) If you allocate large objects containg only one or two pointers at the beginning, either try the typed allocation primitives is gc.h, or separate out the pointerfree component.
2) If you are using the collector in its default mode, with interior pointer recognition enabled, consider using GC_malloc_ignore_off_page to allocate large objects. (See gc.h and above for details. Large means > 100K in most environments.)
3) GC_print_block_list() will print a list of all currently allocated heap blocks and what size objects they contain. GC_print_hblkfreelist() will print a list of free heap blocks, and whether they are blacklisted. GC_dump calls both of these, and also prints information about heap sections, and root segments.
4) Build the collector with -DKEEP_BACK_PTRS, and use the backptr.h
interface to determine why objects are being retained.
****If the collector appears to be losing objects:
1) Replace all calls to GC_malloc_atomic and typed allocation by GC_malloc calls. If this fixes the problem, gradually reinsert your optimizations.
2) You may also want to try the safe(r) pointer manipulation primitives in gc.h. But those are hard to use until the preprocessor becomes available.
3) Try using the GC_DEBUG facilities. This is less likely to be successful here than if the collector crashes.
[The rest of these are primarily for wizards. You shouldn't need them unless you're doing something really strange, or debugging a collector port.]
4) Don't turn on incremental collection. If that fixes the problem, suspect a bug in the dirty bit implementation. Try compiling with -DCHECKSUMS to check for modified, but supposedly clean, pages.
5) On a SPARC, in a single-threaded environment, GC_print_callers(GC_arrays._last_stack) prints a cryptic stack trace as of the time of the last collection. (You will need a debugger to decipher the result.) The question to ask then is "why should this object have been accessible at the time of the last collection? Where was a pointer to it stored?". This facility should be easy to add for some other collector ports (namely if it's easy to traverse stack frames), but will be hard for others.
6) "print *GC_find_header(p)" in dbx or gdb will print the garbage collector block header information associated with the object p (e.g. object size, etc.)
7) GC_is_marked(p) determines whether p is the base address of a marked object. Note that objects allocated since the last collection should not be marked, and that unmarked objects are reclaimed incrementally. It's usually most interesting to set a breakpoint in GC_finish_collection and then to determine how much of the damaged data structure is marked at that point.
8) Look at the tracing facility in mark.c. (Ignore this suggestion unless you are very familiar with collector internals.)
9) [From Melissa O'Neill:]
If you're using multiple threads, double check that all thread
creation goes through the GC_ wrapper functions rather than
calling the thread-creation functions themselves (e.g.,
GC_pthread_create rather than pthread_create). The gc.h header
file includes suitable preprocessor definitions to accomplish
this mapping transparently -- the question is: are you including
it in all the modules that create threads?
[Original version supplied by Xiaokun Zhu <xiaokun@aero.gla.ac.uk>]
[This version came mostly from Gary Leavens. ]
Look first at Makefile.dj, and possibly change the definitions of
RM and MV if you don't have rm and mv installed.
Then use Makefile.dj to compile the garbage collector.
For example, you can do:
make -f Makefile.dj test
All the tests should work fine.
Dynamic loading support requires that executables be linked with -ldld.
The alternative is to build the collector without defining DYNAMIC_LOADING
in gcconfig.h and ensuring that all garbage collectable objects are
accessible without considering statically allocated variables in dynamic
libraries.
The collector should compile with either plain cc or cc -Ae. CC -Aa
fails to define _HPUX_SOURCE and thus will not configure the collector
correctly.
Incremental collection support was reccently added, and should now work.
Thread support for HP/UX 11 Pthreads was also recently added. It is still
flakey in this release. (It has only been tested on a uniprocessor. Even
there some fraction of thread creation calls fail with a not-yet-understood
error return from sem_wait.)
See README.alpha for Linux on DEC AXP info.
This file applies mostly to Linux/Intel IA32. Ports to Linux on an M68K
and PowerPC are also integrated. They should behave similarly, except that
the PowerPC port lacks incremental GC support, and it is unknown to what
extent the Linux threads code is functional.
Incremental GC is supported on Intel IA32 and M68K.
Dynamic libraries are supported on an ELF system. A static executable
should be linked with the gcc option "-Wl,-defsym,_DYNAMIC=0".
The collector appears to work with Linux threads. We have seen
intermittent hangs in sem_wait. So far we have been unable to reproduce
these unless the process was being debugged or traced. Thus it's
possible that the only real issue is that the debugger loses
signals on rare occasions.
The garbage collector uses SIGPWR and SIGXCPU if it is used with
Linux threads. These should not be touched by the client program.
To use threads, you need to abide by the following requirements:
1) You need to use LinuxThreads (which are included in libc6).
The collector relies on some implementation details of the LinuxThreads
package. It is unlikely that this code will work on other
pthread implementations (in particular it will *not* work with
MIT pthreads).
2) You must compile the collector with -DLINUX_THREADS and -D_REENTRANT
specified in the Makefile.
3a) Every file that makes thread calls should define LINUX_THREADS and
_REENTRANT and then include gc.h. Gc.h redefines some of the
pthread primitives as macros which also provide the collector with
information it requires.
3b) A new alternative to (3a) is to build the collector with
-DUSE_LD_WRAP, and to link the final program with
(for ld) --wrap read --wrap dlopen --wrap pthread_create \
--wrap pthread_join --wrap pthread_sigmask
(for gcc) -Wl,--wrap -Wl,read -Wl,--wrap -Wl,dlopen -Wl,--wrap \
-Wl,pthread_create -Wl,--wrap -Wl,pthread_join -Wl,--wrap \
-Wl,pthread_sigmask
In any case, _REENTRANT should be defined during compilation.
4) Dlopen() disables collection during its execution. (It can't run
concurrently with the collector, since the collector looks at its
data structures. It can't acquire the allocator lock, since arbitrary
user startup code may run as part of dlopen().) Under unusual
conditions, this may cause unexpected heap growth.
5) The combination of LINUX_THREADS, REDIRECT_MALLOC, and incremental
collection fails in seemingly random places. This hasn't been tracked
down yet, but is perhaps not completely astonishing. The thread package
uses malloc, and thus can presumably get SIGSEGVs while inside the
package. There is no real guarantee that signals are handled properly
at that point.
6) Thread local storage may not be viewed as part of the root set by the
collector. This probably depends on the linuxthreads version. For the
time being, any collectable memory referenced by thread local storage should
also be referenced from elsewhere, or be allocated as uncollectable.
(This is really a bug that should be fixed somehow.)
We have so far failed to find a good way to determine the stack base.
It is highly recommended that GC_stackbottom be set explicitly on program
startup. The supplied value sometimes causes failure under AIX 4.1, though
it appears to work under 3.X. HEURISTIC2 seems to work under 4.1, but
involves a substantial performance penalty, and will fail if there is
no limit on stack size.
There is no thread support. (I assume recent versions of AIX provide
pthreads? I no longer have access to a machine ...)
Performance of the incremental collector can be greatly enhanced with
-DNO_EXECUTE_PERMISSION.
The collector should run with all of the -32, -n32 and -64 ABIs. Remember to
define the AS macro in the Makefile to be "as -64", or "as -n32".
If you use -DREDIRECT_MALLOC=GC_malloc with C++ code, your code should make
at least one explicit call to malloc instead of new to ensure that the proper
version of malloc is linked in.
Sproc threads are not supported in this version, though there may exist other
ports.
Pthreads support is provided. This requires that:
1) You compile the collector with -DIRIX_THREADS specified in the Makefile.
2) You have the latest pthreads patches installed.
(Though the collector makes only documented pthread calls,
it relies on signal/threads interactions working just right in ways
that are not required by the standard. It is unlikely that this code
will run on other pthreads platforms. But please tell me if it does.)
3) Every file that makes thread calls should define IRIX_THREADS and then
include gc.h. Gc.h redefines some of the pthread primitives as macros which
also provide the collector with information it requires.
4) pthread_cond_wait and pthread_cond_timed_wait should be prepared for
premature wakeups. (I believe the pthreads and realted standards require this
anyway. Irix pthreads often terminate a wait if a signal arrives.
The garbage collector uses signals to stop threads.)
5) It is expensive to stop a thread waiting in IO at the time the request is
initiated. Applications with many such threads may not exhibit acceptable
performance with the collector. (Increasing the heap size may help.)
6) The collector should not be compiled with -DREDIRECT_MALLOC. This
confuses some library calls made by the pthreads implementation, which
expect the standard malloc.
The collector supports both incremental collection and threads under
Solaris 2. The incremental collector normally retrieves page dirty information
through the appropriate /proc calls. But it can also be configured
(by defining MPROTECT_VDB instead of PROC_VDB in gcconfig.h) to use mprotect
and signals. This may result in shorter pause times, but it is no longer
safe to issue arbitrary system calls that write to the heap.
Under other UNIX versions,
the collector normally obtains memory through sbrk. There is some reason
to expect that this is not safe if the client program also calls the system
malloc, or especially realloc. The sbrk man page strongly suggests this is
not safe: "Many library routines use malloc() internally, so use brk()
and sbrk() only when you know that malloc() definitely will not be used by
any library routine." This doesn't make a lot of sense to me, since there
seems to be no documentation as to which routines can transitively call malloc.
Nonetheless, under Solaris2, the collector now (since 4.12) allocates
memory using mmap by default. (It defines USE_MMAP in gcconfig.h.)
You may want to reverse this decisions if you use -DREDIRECT_MALLOC=...
SOLARIS THREADS:
The collector must be compiled with -DSOLARIS_THREADS to be thread safe.
It is also essential that gc.h be included in files that call thr_create,
thr_join, thr_suspend, thr_continue, or dlopen. Gc.h macro defines
these to also do GC bookkeeping, etc. Gc.h must be included with
SOLARIS_THREADS defined, otherwise these replacements are not visible.
A collector built in this way way only be used by programs that are
linked with the threads library.
If you are using the Pthreads interface, also define _SOLARIS_PTHREADS.
In this mode, the collector contains various workarounds for older Solaris
bugs. Mostly, these should not be noticeable unless you look at system
call traces. However, it cannot protect a guard page at the end of
a thread stack. If you know that you will only be running Solaris2.5
or later, it should be possible to fix this by compiling the collector
with -DSOLARIS23_MPROTECT_BUG_FIXED.
Since 5.0 alpha5, dlopen disables collection temporarily,
unless USE_PROC_FOR_LIBRARIES is defined. In some unlikely cases, this
can result in unpleasant heap growth. But it seems better than the
race/deadlock issues we had before.
If solaris_threads are used on an X86 processor with malloc redirected to
GC_malloc, it is necessary to call GC_thr_init explicitly before forking the
first thread. (This avoids a deadlock arising from calling GC_thr_init
with the allocation lock held.)
It appears that there is a problem in using gc_cpp.h in conjunction with
Solaris threads and Sun's C++ runtime. Apparently the overloaded new operator
is invoked by some iostream initialization code before threads are correctly
initialized. As a result, call to thr_self() in garbage collector
initialization segfaults. Currently the only known workaround is to not
invoke the garbage collector from a user defined global operator new, or to
have it invoke the garbage-collector's allocators only after main has started.
(Note that the latter requires a moderately expensive test in operator
delete.)
Hans-J. Boehm
(The above contains my personal opinions, which are probably not shared
by anyone else.)
Alistair Crooks supplied the port. He used Lexa C version 2.1.3 with
-Xa to compile.
The collector has only been compiled under Windows NT, with the
original Microsoft SDK, with Visual C++ 2.0 and later, with
the GNU win32 environment, with Borland 4.5, and recently with
Watcom C.
It runs under both win32s and win32, but with different semantics.
Under win32, all writable pages outside of the heaps and stack are
scanned for roots. Thus the collector sees pointers in DLL data
segments. Under win32s, only the main data segment is scanned.
(The main data segment should always be scanned. Under some
versions of win32s, other regions may also be scanned.)
Thus all accessible objects should be accessible from local variables
or variables in the main data segment. Alternatively, other data
segments (e.g. in DLLs) may be registered with the collector by
calling GC_init() and then GC_register_root_section(a), where
a is the address of some variable inside the data segment. (Duplicate
registrations are ignored, but not terribly quickly.)
(There are two reasons for this. We didn't want to see many 16:16
pointers. And the VirtualQuery call has different semantics under
the two systems, and under different versions of win32s.)
The collector test program "gctest" is linked as a GUI application,
but does not open any windows. Its output appears in the file
"gc.log". It may be started from the file manager. The hour glass
cursor will appear as long as it's running. If it is started from the
command line, it will usually run in the background. Wait a few
minutes (a few seconds on a modern machine) before you check the output.
You should see either a failure indication or a "Collector appears to
work" message.
The cord test program has not been ported (but should port
easily). A toy editor (cord/de.exe) based on cords (heavyweight
strings represented as trees) has been ported and is included.
It runs fine under either win32 or win32S. It serves as an example
of a true Windows application, except that it was written by a
nonexpert Windows programmer. (There are some peculiarities
in the way files are displayed. The <cr> is displayed explicitly
for standard DOS text files. As in the UNIX version, control
characters are displayed explicitly, but in this case as red text.
This may be suboptimal for some tastes and/or sets of default
window colors.)
For Microsoft development tools, rename NT_MAKEFILE as
MAKEFILE. (Make sure that the CPU environment variable is defined
to be i386.)
For GNU-win32, use the regular makefile, possibly after uncommenting
the line "include Makefile.DLLs". The latter should be necessary only
if you want to package the collector as a DLL. The GNU-win32 port is
believed to work only for b18, not b19, probably dues to linker changes
in b19. This is probably fixable with a different definition of
DATASTART and DATAEND in gcconfig.h.
For Borland tools, use BCC_MAKEFILE. Note that
Borland's compiler defaults to 1 byte alignment in structures (-a1),
whereas Visual C++ appears to default to 8 byte alignment (/Zp8).
The garbage collector in its default configuration EXPECTS AT
LEAST 4 BYTE ALIGNMENT. Thus the BORLAND DEFAULT MUST
BE OVERRIDDEN. (In my opinion, it should usually be anyway.
I expect that -a1 introduces major performance penalties on a
486 or Pentium.) Note that this changes structure layouts. (As a last
resort, gcconfig.h can be changed to allow 1 byte alignment. But
this has significant negative performance implications.)
The Makefile is set up to assume Borland 4.5. If you have another
version, change the line near the top. By default, it does not
require the assembler. If you do have the assembler, I recommend
removing the -DUSE_GENERIC.
Incremental collection support was recently added. This is
currently pretty simpleminded. Pages are protected. Protection
faults are caught by a handler installed at the bottom of the handler
stack. This is both slow and interacts poorly with a debugger.
Whenever possible, I recommend adding a call to
GC_enable_incremental at the last possible moment, after most
debugging is complete. Unlike the UNIX versions, no system
calls are wrapped by the collector itself. It may be necessary
to wrap ReadFile calls that use a buffer in the heap, so that the
call does not encounter a protection fault while it's running.
(As usual, none of this is an issue unless GC_enable_incremental
is called.)
Note that incremental collection is disabled with -DSMALL_CONFIG,
which is the default for win32. If you need incremental collection,
undefine SMALL_CONFIG.
Incremental collection is not supported under win32s, and it may not
be possible to do so. However, win32 applications that attempt to use
incremental collection should continue to run, since the
collector detects if it's running under win32s and turns calls to
GC_enable_incremental() into noops.
James Clark has contributed the necessary code to support win32 threads.
This code is known to exhibit some problems with incremental collection
enabled. Use NT_THREADS_MAKEFILE (a.k.a gc.mak) instead of NT_MAKEFILE
to build this version. Note that this requires some files whose names
are more than 8 + 3 characters long. Thus you should unpack the tar file
so that long file names are preserved. To build the garbage collector
test with VC++ from the command line, use
nmake /F ".\gc.mak" CFG="gctest - Win32 Release"
This requires that the subdirectory gctest\Release exist.
The test program and DLL will reside in the Release directory.
This version relies on the collector residing in a dll.
This version currently supports incremental collection only if it is
enabled before any additional threads are created.
Version 4.13 attempts to fix some of the earlier problems, but there
may be other issues. If you need solid support for win32 threads, you
might check with Geodesic Systems. Their collector must be licensed,
but they have invested far more time in win32-specific issues.
Hans
Ivan V. Demakov's README for the Watcom port:
The collector has been compiled with Watcom C 10.6 and 11.0.
It runs under win32, win32s, and even under msdos with dos4gw
dos-extender. It should also run under OS/2, though this isn't
tested. Under win32 the collector can be built either as dll
or as static library.
Note that all compilations were done under Windows 95 or NT.
For unknown reason compiling under Windows 3.11 for NT (one
attempt has been made) leads to broken executables.
Incremental collection is not supported.
cord is not ported.
Before compiling you may need to edit WCC_MAKEFILE to set target
platform, library type (dynamic or static), calling conventions, and
optimization options.
To compile the collector and testing programs use the command:
wmake -f WCC_MAKEFILE
All programs using gc should be compiled with 4-byte alignment.
For further explanations on this see comments about Borland.
If gc compiled as dll, the macro ``GC_DLL'' should be defined before
including "gc.h" (for example, with -DGC_DLL compiler option). It's
important, otherwise resulting programs will not run.
Ivan Demakov (email: ivan@tgrad.nsk.su)
CPU=68030
NOSTACKCHECK
OPTIMIZE
VERBOSE
MAPHUNK
NOVERSION
NOICONS
OPTIMIZERTIME
DEFINE SILENT
DEFINE AMIGA_SKIP_SEG
IGNORE=85
IGNORE=154
IGNORE=161
IGNORE=100
OPTIMIZERCOMPLEXITY=4
OPTIMIZERDEPTH=3
OBJS= alloc.o reclaim.o allchblk.o misc.o mach_dep.o os_dep.o mark_rts.o headers.o mark.o obj_map.o blacklst.o finalize.o new_hblk.o real_malloc.o dyn_load.o dbg_mlc.o malloc.o stubborn.o checksums.o typd_mlc.o ptr_chck.o
INC= gc_private.h gc_hdrs.h gc.h gcconfig.h
# Rewritten smakefile for amiga / sas/c. -Kjetil M.
# Dont use the cord-package if you define parm=both or parm=reg.
#----------------TOOLS--------------------------------
CC=sc
LINKER=slink
LIBER=oml
#----------------CPU OPTIONS--------------------------
CPU=68060
#----------------FPU OPTIONS--------------------------
MATH=8
MATHLIB=LIB:scm881.lib
#----------------COMPILER OPTIONS---------------------
IGNORE= IGNORE=85 IGNORE=154 IGNORE=161 IGNORE=100
OPTIMIZE=optimize optimizetime optglobal optimizerdepth=100 optimizerpeephole optloop OPTSCHED optimizerinlocal optimizerrecurdepth=100
# optimizerinline optimizercomplexity=100
OPT= $(OPTIMIZE) CPU=$(CPU) math=$(MATH) NOSTACKCHECK VERBOSE \
MAPHUNK NOVERSION NOICONS nodebug \
DEFINE SILENT \
parm=reg \
DEFINE __USE_SYSBASE
SOPT= $(OPT) $(IGNORE) \
DEFINE AMIGA_SKIP_SEG \
DEFINE ATOMIC_UNCOLLECTABLE \
DEFINE GC_AMIGA_FASTALLOC \
DEFINE GC_AMIGA_RETRY \
DEFINE GC_AMIGA_PRINTSTATS \
DEFINE GC_AMIGA_GC
#DEFINE ALL_INTERIOR_POINTERS \
SCOPT= $(SOPT) define GC_AMIGA_MAKINGLIB
CSCOPT= $(OPT) DEFINE AMIGA IGNORE=100 IGNORE=161
#------------------LINKING----------------------------
all: gctest setjmp_t cord/cordtest
clean:
delete *.lib gctest setjmp_t *.o *.lnk cord/*.o cord/*.lib cord/*.lnk cord/cordtest
smake
test: setjmp_t gctest cord/cordtest
setjmp_t
gctest
cord/cordtest
gctest: gc$(CPU).lib GCAmigaOS$(CPU).lib test.o
$(LINKER) LIB:c.o test.o TO gctest LIB gc$(CPU).lib LIB:sc.lib $(MATHLIB)
setjmp_t: setjmp_t.o gc.h
$(LINKER) LIB:c.o setjmp_t.o to setjmp_t lib LIB:sc.lib
cord/cordtest: cord/cordtest.o cord/cord$(CPU).lib gc$(CPU).lib
slink LIB:c.o cord/cordtest.o LIB $(MATHLIB) gc$(CPU).lib cord/cord$(CPU).lib LIB:sc.lib TO cord/cordtest
#------------------LIBBING----------------------------
OBJS= alloc.o reclaim.o allchblk.o misc.o mach_dep.o os_dep.o mark_rts.o headers.o mark.o obj_map.o blacklst.o finalize.o new_hblk.o real_malloc.o dyn_load.o dbg_mlc.o malloc.o stubborn.o checksums.o typd_mlc.o ptr_chck.o mallocx.o
gc$(CPU).lib: $(OBJS)
$(LIBER) gc$(CPU).lib r $(OBJS)
COBJS = cord/cordbscs.o cord/cordprnt.o cord/cordxtra.o
all: gctest setjmp_t
cord/cord$(CPU).lib: $(COBJS)
oml cord/cord$(CPU).lib r $(COBJS)
#------------------COMPILING--------------------------
INC= gc_private.h gc_hdrs.h gc.h gcconfig.h
alloc.o : alloc.c $(INC)
$(CC) alloc.c $(SCOPT) ignore=7
reclaim.o : reclaim.c $(INC)
$(CC) reclaim.c $(SCOPT)
allchblk.o : allchblk.c $(INC)
$(CC) allchblk.c $(SCOPT)
misc.o : misc.c $(INC)
os_dep.o : os_dep.c $(INC)
$(CC) misc.c $(SCOPT)
os_dep.o : os_dep.c $(INC) AmigaOS.c
$(CC) os_dep.c $(SCOPT)
mark_rts.o : mark_rts.c $(INC)
$(CC) mark_rts.c $(SCOPT)
headers.o : headers.c $(INC)
$(CC) headers.c $(SCOPT)
mark.o : mark.c $(INC)
$(CC) mark.c $(SCOPT)
obj_map.o : obj_map.c $(INC)
$(CC) obj_map.c $(SCOPT)
blacklst.o : blacklst.c $(INC)
$(CC) blacklst.c $(SCOPT)
finalize.o : finalize.c $(INC)
sc noopt finalize.c # There seems to be a bug in the optimizer (V6.51).
# gctest won't work if you remove this...
$(CC) finalize.c $(SCOPT) noopt #Could sas/c still have problems with this one? Gctest sometimes fails to finalize all.
new_hblk.o : new_hblk.c $(INC)
$(CC) new_hblk.c $(SCOPT)
real_malloc.o : real_malloc.c $(INC)
$(CC) real_malloc.c $(SCOPT)
dyn_load.o : dyn_load.c $(INC)
$(CC) dyn_load.c $(SCOPT)
dbg_mlc.o : dbg_mlc.c $(INC)
$(CC) dbg_mlc.c $(SCOPT)
malloc.o : malloc.c $(INC)
mallocx.o : malloc.c $(INC)
$(CC) malloc.c $(SCOPT)
mallocx.o : mallocx.c $(INC)
$(CC) mallocx.c $(SCOPT)
stubborn.o : stubborn.c $(INC)
$(CC) stubborn.c $(SCOPT)
checksums.o : checksums.c $(INC)
$(CC) checksums.c $(SCOPT)
typd_mlc.o: typd_mlc.c $(INC)
$(CC) typd_mlc.c $(SCOPT)
mach_dep.o : mach_dep.c $(INC)
$(CC) mach_dep.c $(SCOPT)
ptr_chck.o: ptr_chck.c $(INC)
$(CC) ptr_chck.c $(SCOPT)
test.o : test.c $(INC)
$(CC) test.c $(SOPT)
gc.lib: $(OBJS)
oml gc.lib r $(OBJS)
setjmp_t: setjmp_t.c gc.h
$(CC) setjmp_t.c $(SOPT)
clean:
delete gc.lib gctest setjmp_t \#?.o
gctest: gc.lib test.o
slink LIB:c.o test.o to $@ lib gc.lib LIB:sc.lib LIB:scm.lib
# cords:
cord/cordbscs.o: cord/cordbscs.c
sc cord/cordbscs.c $(CSCOPT)
cord/cordprnt.o: cord/cordprnt.c
sc cord/cordprnt.c $(CSCOPT)
cord/cordxtra.o: cord/cordxtra.c
sc cord/cordxtra.c $(CSCOPT)
cord/cordtest.o: cord/cordtest.c
sc cord/cordtest.c $(CSCOPT)
setjmp_t: setjmp_t.c gc.h
sc setjmp_t.c
slink LIB:c.o $@.o to $@ lib LIB:sc.lib
test: setjmp_t gctest
setjmp_t
gctest
......@@ -169,9 +169,9 @@ test_cpp.exe: test_cpp.obj gc.lib
gc_cpp.obj: gc_cpp.cc .AUTODEPEND
$(CXX) $(TEST_CXXFLAGS) -iinclude $*.cc
test.obj: test.c .AUTODEPEND
test.obj: tests\test.c .AUTODEPEND
$(CC) $(TEST_CFLAGS) $*.c
test_cpp.obj: test_cpp.cc .AUTODEPEND
test_cpp.obj: tests\test_cpp.cc .AUTODEPEND
$(CXX) $(TEST_CXXFLAGS) -iinclude $*.cc
......
......@@ -43,7 +43,7 @@ AC_SUBST(boehm_gc_basedir)
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE(boehm-gc, 5.1, no-define)
AM_INIT_AUTOMAKE(boehm-gc, 6.0a7, no-define)
# FIXME: We temporarily define our own version of AC_PROG_CC. This is
# copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS. We
......
......@@ -14,10 +14,9 @@
* modified is included with the above copyright notice.
*/
#define DEBUG
#undef DEBUG
/* #define DEBUG */
#include <stdio.h>
#include "gc_priv.h"
#include "private/gc_priv.h"
GC_bool GC_use_entire_heap = 0;
......@@ -47,6 +46,35 @@ GC_bool GC_use_entire_heap = 0;
struct hblk * GC_hblkfreelist[N_HBLK_FLS+1] = { 0 };
#ifndef USE_MUNMAP
word GC_free_bytes[N_HBLK_FLS+1] = { 0 };
/* Number of free bytes on each list. */
/* Is bytes + the number of free bytes on lists n .. N_HBLK_FLS */
/* > GC_max_large_allocd_bytes? */
GC_bool GC_enough_large_bytes_left(bytes,n)
word bytes;
int n;
{
int i;
for (i = N_HBLK_FLS; i >= n; --i) {
bytes += GC_free_bytes[i];
if (bytes > GC_max_large_allocd_bytes) return TRUE;
}
return FALSE;
}
# define INCR_FREE_BYTES(n, b) GC_free_bytes[n] += (b);
# define FREE_ASSERT(e) GC_ASSERT(e)
#else /* USE_MUNMAP */
# define INCR_FREE_BYTES(n, b)
# define FREE_ASSERT(e)
#endif /* USE_MUNMAP */
/* Map a number of blocks to the appropriate large block free list index. */
int GC_hblk_fl_from_blocks(blocks_needed)
word blocks_needed;
......@@ -79,7 +107,14 @@ void GC_print_hblkfreelist()
for (i = 0; i <= N_HBLK_FLS; ++i) {
h = GC_hblkfreelist[i];
if (0 != h) GC_printf1("Free list %ld:\n", (unsigned long)i);
# ifdef USE_MUNMAP
if (0 != h) GC_printf1("Free list %ld (Total size %ld):\n",
(unsigned long)i);
# else
if (0 != h) GC_printf2("Free list %ld (Total size %ld):\n",
(unsigned long)i,
(unsigned long)GC_free_bytes[i]);
# endif
while (h != 0) {
hhdr = HDR(h);
sz = hhdr -> hb_sz;
......@@ -219,14 +254,25 @@ void GC_remove_from_fl(hhdr, n)
hdr * hhdr;
int n;
{
int index;
GC_ASSERT(((hhdr -> hb_sz) & (HBLKSIZE-1)) == 0);
# ifndef USE_MUNMAP
/* We always need index to mainatin free counts. */
if (FL_UNKNOWN == n) {
index = GC_hblk_fl_from_blocks(divHBLKSZ(hhdr -> hb_sz));
} else {
index = n;
}
# endif
if (hhdr -> hb_prev == 0) {
int index;
if (FL_UNKNOWN == n) {
# ifdef USE_MUNMAP
if (FL_UNKNOWN == n) {
index = GC_hblk_fl_from_blocks(divHBLKSZ(hhdr -> hb_sz));
} else {
} else {
index = n;
}
}
# endif
GC_ASSERT(HDR(GC_hblkfreelist[index]) == hhdr);
GC_hblkfreelist[index] = hhdr -> hb_next;
} else {
......@@ -234,6 +280,8 @@ int n;
GET_HDR(hhdr -> hb_prev, phdr);
phdr -> hb_next = hhdr -> hb_next;
}
INCR_FREE_BYTES(index, - (signed_word)(hhdr -> hb_sz));
FREE_ASSERT(GC_free_bytes[index] >= 0);
if (0 != hhdr -> hb_next) {
hdr * nhdr;
GC_ASSERT(!IS_FORWARDING_ADDR_OR_NIL(NHDR(hhdr)));
......@@ -294,6 +342,8 @@ hdr * hhdr;
# endif
GC_ASSERT(((hhdr -> hb_sz) & (HBLKSIZE-1)) == 0);
GC_hblkfreelist[index] = h;
INCR_FREE_BYTES(index, hhdr -> hb_sz);
FREE_ASSERT(GC_free_bytes[index] <= GC_large_free_bytes)
hhdr -> hb_next = second;
hhdr -> hb_prev = 0;
if (0 != second) {
......@@ -419,7 +469,7 @@ int index;
rest_hdr -> hb_sz = total_size - bytes;
rest_hdr -> hb_flags = 0;
# ifdef GC_ASSERTIONS
// Mark h not free, to avoid assertion about adjacent free blocks.
/* Mark h not free, to avoid assertion about adjacent free blocks. */
hhdr -> hb_map = 0;
# endif
GC_add_to_fl(rest, rest_hdr);
......@@ -463,6 +513,8 @@ int index; /* Index of free list */
if (0 != next) {
HDR(next) -> hb_prev = n;
}
INCR_FREE_BYTES(index, -(signed_word)h_size);
FREE_ASSERT(GC_free_bytes[index] > 0);
# ifdef GC_ASSERTIONS
nhdr -> hb_map = 0; /* Don't fail test for consecutive */
/* free blocks in GC_add_to_fl. */
......@@ -484,20 +536,23 @@ struct hblk * GC_allochblk_nth();
* NOTE: We set obj_map field in header correctly.
* Caller is responsible for building an object freelist in block.
*
* We clear the block if it is destined for large objects, and if
* kind requires that newly allocated objects be cleared.
* Unlike older versions of the collectors, the client is responsible
* for clearing the block, if necessary.
*/
struct hblk *
GC_allochblk(sz, kind, flags)
word sz;
int kind;
unsigned char flags; /* IGNORE_OFF_PAGE or 0 */
unsigned flags; /* IGNORE_OFF_PAGE or 0 */
{
int start_list = GC_hblk_fl_from_blocks(OBJ_SZ_TO_BLOCKS(sz));
word blocks = OBJ_SZ_TO_BLOCKS(sz);
int start_list = GC_hblk_fl_from_blocks(blocks);
int i;
for (i = start_list; i <= N_HBLK_FLS; ++i) {
struct hblk * result = GC_allochblk_nth(sz, kind, flags, i);
if (0 != result) return result;
if (0 != result) {
return result;
}
}
return 0;
}
......@@ -526,12 +581,22 @@ int n;
GET_HDR(hbp, hhdr);
size_avail = hhdr->hb_sz;
if (size_avail < size_needed) continue;
if (!GC_use_entire_heap) {
if (size_avail != size_needed
&& USED_HEAP_SIZE >= GC_requested_heapsize
&& !GC_incremental && GC_should_collect()) {
if (!GC_use_entire_heap
&& size_avail != size_needed
&& USED_HEAP_SIZE >= GC_requested_heapsize
&& !GC_incremental && GC_should_collect()) {
# ifdef USE_MUNMAP
continue;
}
# else
/* If we enough large blocks left to cover any */
/* previous request for large blocks, we go ahead */
/* and split. Assuming a steady state, that should */
/* be safe. It means that we can use the full */
/* heap if we allocate only small objects. */
if (!GC_enough_large_bytes_left(GC_large_allocd_bytes, n)) {
continue;
}
# endif /* !USE_MUNMAP */
}
/* If the next heap block is obviously better, go on. */
/* This prevents us from disassembling a single large block */
......@@ -573,7 +638,7 @@ int n;
/* Make sure it's mapped before we mangle it. */
# ifdef USE_MUNMAP
if (!IS_MAPPED(hhdr)) {
GC_remap((ptr_t)hbp, size_avail);
GC_remap((ptr_t)hbp, hhdr -> hb_sz);
hhdr -> hb_flags &= ~WAS_UNMAPPED;
}
# endif
......@@ -589,8 +654,10 @@ int n;
&& orig_avail - size_needed
> (signed_word)BL_LIMIT) {
/* Punt, since anything else risks unreasonable heap growth. */
WARN("Needed to allocate blacklisted block at 0x%lx\n",
(word)hbp);
if (0 != GETENV("GC_NO_BLACKLIST_WARNING")) {
WARN("Needed to allocate blacklisted block at 0x%lx\n",
(word)hbp);
}
size_avail = orig_avail;
} else if (size_avail == 0 && size_needed == HBLKSIZE
&& IS_MAPPED(hhdr)) {
......@@ -618,10 +685,10 @@ int n;
if (h == hbp || 0 != (hhdr = GC_install_header(h))) {
(void) setup_header(
hhdr,
BYTES_TO_WORDS(HBLKSIZE - HDR_BYTES),
BYTES_TO_WORDS(HBLKSIZE),
PTRFREE, 0); /* Cant fail */
if (GC_debugging_started) {
BZERO(h + HDR_BYTES, HBLKSIZE - HDR_BYTES);
BZERO(h, HBLKSIZE);
}
}
}
......@@ -638,7 +705,7 @@ int n;
if( size_avail >= size_needed ) {
# ifdef USE_MUNMAP
if (!IS_MAPPED(hhdr)) {
GC_remap((ptr_t)hbp, size_avail);
GC_remap((ptr_t)hbp, hhdr -> hb_sz);
hhdr -> hb_flags &= ~WAS_UNMAPPED;
}
# endif
......@@ -664,12 +731,6 @@ int n;
return(0); /* ditto */
}
/* Clear block if necessary */
if (GC_debugging_started
|| sz > MAXOBJSZ && GC_obj_kinds[kind].ok_init) {
BZERO(hbp + HDR_BYTES, size_needed - HDR_BYTES);
}
/* We just successfully allocated a block. Restart count of */
/* consecutive failures. */
{
......
......@@ -16,10 +16,10 @@
*/
# include "gc_priv.h"
# include "private/gc_priv.h"
# include <stdio.h>
# ifndef MACOS
# if !defined(MACOS) && !defined(MSWINCE)
# include <signal.h>
# include <sys/types.h>
# endif
......@@ -60,9 +60,11 @@ word GC_non_gc_bytes = 0; /* Number of bytes not intended to be collected */
word GC_gc_no = 0;
#ifndef SMALL_CONFIG
int GC_incremental = 0; /* By default, stop the world. */
int GC_incremental = 0; /* By default, stop the world. */
#endif
int GC_parallel = FALSE; /* By default, parallel GC is off. */
int GC_full_freq = 19; /* Every 20th collection is a full */
/* collection, whether we need it */
/* or not. */
......@@ -76,6 +78,7 @@ char * GC_copyright[] =
{"Copyright 1988,1989 Hans-J. Boehm and Alan J. Demers ",
"Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved. ",
"Copyright (c) 1996-1998 by Silicon Graphics. All rights reserved. ",
"Copyright (c) 1999-2000 by Hewlett-Packard Company. All rights reserved. ",
"THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY",
" EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.",
"See source code for details." };
......@@ -116,10 +119,12 @@ int GC_n_attempts = 0; /* Number of attempts at finishing */
GET_TIME(current_time);
time_diff = MS_TIME_DIFF(current_time,GC_start_time);
if (time_diff >= TIME_LIMIT) {
# ifdef PRINTSTATS
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf0("Abandoning stopped marking after ");
GC_printf1("%lu msecs", (unsigned long)time_diff);
GC_printf1("(attempt %d)\n", (unsigned long) GC_n_attempts);
}
# endif
return(1);
}
......@@ -222,7 +227,7 @@ GC_bool GC_should_collect()
void GC_notify_full_gc()
{
if (GC_start_call_back != (void (*)())0) {
if (GC_start_call_back != (void (*) GC_PROTO((void)))0) {
(*GC_start_call_back)();
}
}
......@@ -246,13 +251,18 @@ void GC_maybe_gc()
n_partial_gcs = 0;
return;
} else if (GC_need_full_gc || n_partial_gcs >= GC_full_freq) {
# ifdef PRINTSTATS
GC_printf2(
"***>Full mark for collection %lu after %ld allocd bytes\n",
(unsigned long) GC_gc_no+1,
(long)WORDS_TO_BYTES(GC_words_allocd));
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf2(
"***>Full mark for collection %lu after %ld allocd bytes\n",
(unsigned long) GC_gc_no+1,
(long)WORDS_TO_BYTES(GC_words_allocd));
}
# endif
GC_promote_black_lists();
# ifdef PARALLEL_MARK
GC_wait_for_reclaim();
# endif
(void)GC_reclaim_all((GC_stop_func)0, TRUE);
GC_clear_marks();
n_partial_gcs = 0;
......@@ -290,27 +300,36 @@ GC_bool GC_try_to_collect_inner(stop_func)
GC_stop_func stop_func;
{
if (GC_incremental && GC_collection_in_progress()) {
# ifdef PRINTSTATS
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf0(
"GC_try_to_collect_inner: finishing collection in progress\n");
# endif /* PRINTSTATS */
}
# endif /* CONDPRINT */
/* Just finish collection already in progress. */
while(GC_collection_in_progress()) {
if (stop_func()) return(FALSE);
GC_collect_a_little_inner(1);
}
}
# ifdef PRINTSTATS
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf2(
"Initiating full world-stop collection %lu after %ld allocd bytes\n",
(unsigned long) GC_gc_no+1,
(long)WORDS_TO_BYTES(GC_words_allocd));
}
# endif
GC_promote_black_lists();
/* Make sure all blocks have been reclaimed, so sweep routines */
/* don't see cleared mark bits. */
/* If we're guaranteed to finish, then this is unnecessary. */
if (stop_func != GC_never_stop_func
/* In the find_leak case, we have to finish to guarantee that */
/* previously unmarked objects are not reported as leaks. */
# ifdef PARALLEL_MARK
GC_wait_for_reclaim();
# endif
if ((GC_find_leak || stop_func != GC_never_stop_func)
&& !GC_reclaim_all(stop_func, FALSE)) {
/* Aborted. So far everything is still consistent. */
return(FALSE);
......@@ -412,18 +431,22 @@ GC_stop_func stop_func;
{
register int i;
int dummy;
# ifdef PRINTSTATS
# ifdef PRINTTIMES
CLOCK_TYPE start_time, current_time;
# endif
STOP_WORLD();
# ifdef PRINTSTATS
# ifdef PRINTTIMES
GET_TIME(start_time);
# endif
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf1("--> Marking for collection %lu ",
(unsigned long) GC_gc_no + 1);
GC_printf2("after %lu allocd bytes + %lu wasted bytes\n",
(unsigned long) WORDS_TO_BYTES(GC_words_allocd),
(unsigned long) WORDS_TO_BYTES(GC_words_wasted));
}
# endif
/* Mark from all roots. */
......@@ -433,10 +456,12 @@ GC_stop_func stop_func;
GC_initiate_gc();
for(i = 0;;i++) {
if ((*stop_func)()) {
# ifdef PRINTSTATS
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf0("Abandoned stopped marking after ");
GC_printf1("%lu iterations\n",
(unsigned long)i);
}
# endif
GC_deficit = i; /* Give the mutator a chance. */
START_WORLD();
......@@ -450,12 +475,22 @@ GC_stop_func stop_func;
GC_printf2("Collection %lu reclaimed %ld bytes",
(unsigned long) GC_gc_no - 1,
(long)WORDS_TO_BYTES(GC_mem_found));
GC_printf1(" ---> heapsize = %lu bytes\n",
(unsigned long) GC_heapsize);
/* Printf arguments may be pushed in funny places. Clear the */
/* space. */
GC_printf0("");
# endif
# else
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf1("Collection %lu finished", (unsigned long) GC_gc_no - 1);
}
# endif
# endif /* !PRINTSTATS */
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf1(" ---> heapsize = %lu bytes\n",
(unsigned long) GC_heapsize);
/* Printf arguments may be pushed in funny places. Clear the */
/* space. */
GC_printf0("");
}
# endif /* CONDPRINT */
/* Check all debugged objects for consistency */
if (GC_debugging_started) {
......@@ -488,6 +523,11 @@ void GC_finish_collection()
# ifdef GATHERSTATS
GC_mem_found = 0;
# endif
# if defined(LINUX) && defined(__ELF__) && !defined(SMALL_CONFIG)
if (getenv("GC_PRINT_ADDRESS_MAP") != 0) {
GC_print_address_map();
}
# endif
if (GC_find_leak) {
/* Mark all objects on the free list. All objects should be */
/* marked when we're done. */
......@@ -663,22 +703,22 @@ word bytes;
GC_heap_sects[GC_n_heap_sects].hs_start = (ptr_t)p;
GC_heap_sects[GC_n_heap_sects].hs_bytes = bytes;
GC_n_heap_sects++;
words = BYTES_TO_WORDS(bytes - HDR_BYTES);
words = BYTES_TO_WORDS(bytes);
phdr -> hb_sz = words;
phdr -> hb_map = (char *)1; /* A value != GC_invalid_map */
phdr -> hb_map = (unsigned char *)1; /* A value != GC_invalid_map */
phdr -> hb_flags = 0;
GC_freehblk(p);
GC_heapsize += bytes;
if ((ptr_t)p <= GC_least_plausible_heap_addr
if ((ptr_t)p <= (ptr_t)GC_least_plausible_heap_addr
|| GC_least_plausible_heap_addr == 0) {
GC_least_plausible_heap_addr = (ptr_t)p - sizeof(word);
GC_least_plausible_heap_addr = (GC_PTR)((ptr_t)p - sizeof(word));
/* Making it a little smaller than necessary prevents */
/* us from getting a false hit from the variable */
/* itself. There's some unintentional reflection */
/* here. */
}
if ((ptr_t)p + bytes >= GC_greatest_plausible_heap_addr) {
GC_greatest_plausible_heap_addr = (ptr_t)p + bytes;
if ((ptr_t)p + bytes >= (ptr_t)GC_greatest_plausible_heap_addr) {
GC_greatest_plausible_heap_addr = (GC_PTR)((ptr_t)p + bytes);
}
}
......@@ -705,8 +745,8 @@ void GC_print_heap_sects()
}
# endif
ptr_t GC_least_plausible_heap_addr = (ptr_t)ONES;
ptr_t GC_greatest_plausible_heap_addr = 0;
GC_PTR GC_least_plausible_heap_addr = (GC_PTR)ONES;
GC_PTR GC_greatest_plausible_heap_addr = 0;
ptr_t GC_max(x,y)
ptr_t x, y;
......@@ -762,9 +802,16 @@ word n;
}
space = GET_MEM(bytes);
if( space == 0 ) {
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf1("Failed to expand heap by %ld bytes\n",
(unsigned long)bytes);
}
# endif
return(FALSE);
}
# ifdef PRINTSTATS
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf2("Increasing heap size by %lu after %lu allocated bytes\n",
(unsigned long)bytes,
(unsigned long)WORDS_TO_BYTES(GC_words_allocd));
......@@ -773,6 +820,7 @@ word n;
GC_print_block_list(); GC_print_hblkfreelist();
GC_printf0("\n");
# endif
}
# endif
expansion_slop = 8 * WORDS_TO_BYTES(min_words_allocd());
if (5 * HBLKSIZE * MAXHINCR > expansion_slop) {
......@@ -856,12 +904,14 @@ GC_bool ignore_off_page;
GC_notify_full_gc();
GC_gcollect_inner();
} else {
WARN("Out of Memory! Returning NIL!\n", 0);
# if !defined(AMIGA) || !defined(GC_AMIGA_FASTALLOC)
WARN("Out of Memory! Returning NIL!\n", 0);
# endif
return(FALSE);
}
} else {
# ifdef PRINTSTATS
if (GC_fail_count) {
# ifdef CONDPRINT
if (GC_fail_count && GC_print_stats) {
GC_printf0("Memory available again ...\n");
}
# endif
......
/*
* This is a simple API to implement pointer back tracing, i.e.
* to answer questions such as "who is pointing to this" or
* "why is this object being retained by the collector"
*
* This API assumes that we have an ANSI C compiler.
*
* Most of these calls yield useful information on only after
* a garbage collection. Usually the client will first force
* a full collection and then gather information, preferably
* before much intervening allocation.
*
* The implementation of the interface is only about 99.9999%
* correct. It is intended to be good enough for profiling,
* but is not intended to be used with production code.
*
* Results are likely to be much more useful if all allocation is
* accomplished through the debugging allocators.
*
* The implementation idea is due to A. Demers.
*/
/* Store information about the object referencing dest in *base_p */
/* and *offset_p. */
/* If multiple objects or roots point to dest, the one reported */
/* will be the last on used by the garbage collector to trace the */
/* object. */
/* source is root ==> *base_p = address, *offset_p = 0 */
/* source is heap object ==> *base_p != 0, *offset_p = offset */
/* Returns 1 on success, 0 if source couldn't be determined. */
/* Dest can be any address within a heap object. */
typedef enum { GC_UNREFERENCED, /* No reference info available. */
GC_NO_SPACE, /* Dest not allocated with debug alloc */
GC_REFD_FROM_ROOT, /* Referenced directly by root *base_p */
GC_REFD_FROM_REG, /* Referenced from a register, i.e. */
/* a root without an address. */
GC_REFD_FROM_HEAP, /* Referenced from another heap obj. */
GC_FINALIZER_REFD /* Finalizable and hence accessible. */
} GC_ref_kind;
GC_ref_kind GC_get_back_ptr_info(void *dest, void **base_p, size_t *offset_p);
/* Generate a random heap address. */
/* The resulting address is in the heap, but */
/* not necessarily inside a valid object. */
void * GC_generate_random_heap_address(void);
/* Generate a random address inside a valid marked heap object. */
void * GC_generate_random_valid_address(void);
/* Force a garbage collection and generate a backtrace from a */
/* random heap address. */
/* This uses the GC logging mechanism (GC_printf) to produce */
/* output. It can often be called from a debugger. The */
/* source in dbg_mlc.c also serves as a sample client. */
void GC_generate_random_backtrace(void);
/* Print a backtrace from a specific address. Used by the */
/* above. The client should call GC_gcollect() immediately */
/* before invocation. */
void GC_print_backtrace(void *);
This is an ASCII diagram of the data structure used to check pointer
validity. It was provided by Dave Barrett <barrett@asgard.cs.colorado.edu>,
and should be of use to others attempting to understand the code.
The data structure in GC4.X is essentially the same. -HB
Data Structure used by GC_base in gc3.7:
21-Apr-94
63 LOG_TOP_SZ[11] LOG_BOTTOM_SZ[10] LOG_HBLKSIZE[13]
+------------------+----------------+------------------+------------------+
p:| | TL_HASH(hi) | | HBLKDISPL(p) |
+------------------+----------------+------------------+------------------+
\-----------------------HBLKPTR(p)-------------------/
\------------hi-------------------/
\______ ________/ \________ _______/ \________ _______/
V V V
| | |
GC_top_index[] | | |
--- +--------------+ | | |
^ | | | | |
| | | | | |
TOP +--------------+<--+ | |
_SZ +-<| [] | * | |
(items)| +--------------+ if 0 < bi< HBLKSIZE | |
| | | | then large object | |
| | | | starts at the bi'th | |
v | | | HBLK before p. | i |
--- | +--------------+ | (word- |
v | aligned) |
bi= |GET_BI(p){->hash_link}->key==hi | |
v | |
| (bottom_index) \ scratch_alloc'd | |
| ( struct bi ) / by get_index() | |
--- +->+--------------+ | |
^ | | | |
^ | | | |
BOTTOM | | ha=GET_HDR_ADDR(p) | |
_SZ(items)+--------------+<----------------------+ +-------+
| +--<| index[] | |
| | +--------------+ GC_obj_map: v
| | | | from / +-+-+-----+-+-+-+-+ ---
v | | | GC_add < 0| | | | | | | | ^
--- | +--------------+ _map_entry \ +-+-+-----+-+-+-+-+ |
| | asc_link | +-+-+-----+-+-+-+-+ MAXOBJSZ
| +--------------+ +-->| | | j | | | | | +1
| | key | | +-+-+-----+-+-+-+-+ |
| +--------------+ | +-+-+-----+-+-+-+-+ |
| | hash_link | | | | | | | | | | v
| +--------------+ | +-+-+-----+-+-+-+-+ ---
| | |<--MAX_OFFSET--->|
| | (bytes)
HDR(p)| GC_find_header(p) | |<--MAP_ENTRIES-->|
| \ from | =HBLKSIZE/WORDSZ
| (hdr) (struct hblkhdr) / alloc_hdr() | (1024 on Alpha)
+-->+----------------------+ | (8/16 bits each)
GET_HDR(p)| word hb_sz (words) | |
+----------------------+ |
| struct hblk *hb_next | |
+----------------------+ |
|mark_proc hb_mark_proc| |
+----------------------+ |
| char * hb_map |>-------------+
+----------------------+
| ushort hb_obj_kind |
+----------------------+
| hb_last_reclaimed |
--- +----------------------+
^ | |
MARK_BITS| hb_marks[] | *if hdr is free, hb_sz + DISCARD_WORDS
_SZ(words)| | is the size of a heap chunk (struct hblk)
v | | of at least MININCR*HBLKSIZE bytes (below),
--- +----------------------+ otherwise, size of each object in chunk.
Dynamic data structures above are interleaved throughout the heap in blocks of
size MININCR * HBLKSIZE bytes as done by gc_scratch_alloc which cannot be
freed; free lists are used (e.g. alloc_hdr). HBLKs's below are collected.
(struct hblk)
--- +----------------------+ < HBLKSIZE --- --- DISCARD_
^ |garbage[DISCARD_WORDS]| aligned ^ ^ HDR_BYTES WORDS
| | | | v (bytes) (words)
| +-----hb_body----------+ < WORDSZ | --- ---
| | | aligned | ^ ^
| | Object 0 | | hb_sz |
| | | i |(word- (words)|
| | | (bytes)|aligned) v |
| + - - - - - - - - - - -+ --- | --- |
| | | ^ | ^ |
n * | | j (words) | hb_sz BODY_SZ
HBLKSIZE | Object 1 | v v | (words)
(bytes) | |--------------- v MAX_OFFSET
| + - - - - - - - - - - -+ --- (bytes)
| | | !All_INTERIOR_PTRS ^ |
| | | sets j only for hb_sz |
| | Object N | valid object offsets. | |
v | | All objects WORDSZ v v
--- +----------------------+ aligned. --- ---
DISCARD_WORDS is normally zero. Indeed the collector has not been tested
with another value in ages.
......@@ -12,7 +12,7 @@
* modified is included with the above copyright notice.
*/
/* Boehm, August 9, 1995 6:09 pm PDT */
# include "gc_priv.h"
# include "private/gc_priv.h"
/*
* We maintain several hash tables of hblks that have had false hits.
......@@ -52,15 +52,19 @@ word GC_black_list_spacing = MINHINCR*HBLKSIZE; /* Initial rough guess */
void GC_clear_bl();
void GC_default_print_heap_obj_proc(p)
ptr_t p;
# if defined(__STDC__) || defined(__cplusplus)
void GC_default_print_heap_obj_proc(ptr_t p)
# else
void GC_default_print_heap_obj_proc(p)
ptr_t p;
# endif
{
ptr_t base = GC_base(p);
GC_err_printf2("start: 0x%lx, appr. length: %ld", base, GC_size(base));
}
void (*GC_print_heap_obj)(/* char * s, ptr_t p */) =
void (*GC_print_heap_obj) GC_PROTO((ptr_t p)) =
GC_default_print_heap_obj_proc;
void GC_print_source_ptr(p)
......@@ -81,18 +85,18 @@ ptr_t p;
void GC_bl_init()
{
# ifndef ALL_INTERIOR_POINTERS
GC_old_normal_bl = (word *)
if (!GC_all_interior_pointers) {
GC_old_normal_bl = (word *)
GC_scratch_alloc((word)(sizeof (page_hash_table)));
GC_incomplete_normal_bl = (word *)GC_scratch_alloc
GC_incomplete_normal_bl = (word *)GC_scratch_alloc
((word)(sizeof(page_hash_table)));
if (GC_old_normal_bl == 0 || GC_incomplete_normal_bl == 0) {
if (GC_old_normal_bl == 0 || GC_incomplete_normal_bl == 0) {
GC_err_printf0("Insufficient memory for black list\n");
EXIT();
}
GC_clear_bl(GC_old_normal_bl);
GC_clear_bl(GC_incomplete_normal_bl);
}
GC_clear_bl(GC_old_normal_bl);
GC_clear_bl(GC_incomplete_normal_bl);
# endif
GC_old_stack_bl = (word *)GC_scratch_alloc((word)(sizeof(page_hash_table)));
GC_incomplete_stack_bl = (word *)GC_scratch_alloc
((word)(sizeof(page_hash_table)));
......@@ -127,9 +131,9 @@ void GC_promote_black_lists()
GC_old_normal_bl = GC_incomplete_normal_bl;
GC_old_stack_bl = GC_incomplete_stack_bl;
# ifndef ALL_INTERIOR_POINTERS
if (!GC_all_interior_pointers) {
GC_clear_bl(very_old_normal_bl);
# endif
}
GC_clear_bl(very_old_stack_bl);
GC_incomplete_normal_bl = very_old_normal_bl;
GC_incomplete_stack_bl = very_old_stack_bl;
......@@ -156,13 +160,12 @@ void GC_promote_black_lists()
void GC_unpromote_black_lists()
{
# ifndef ALL_INTERIOR_POINTERS
if (!GC_all_interior_pointers) {
GC_copy_bl(GC_old_normal_bl, GC_incomplete_normal_bl);
# endif
}
GC_copy_bl(GC_old_stack_bl, GC_incomplete_stack_bl);
}
# ifndef ALL_INTERIOR_POINTERS
/* P is not a valid pointer reference, but it falls inside */
/* the plausible heap bounds. */
/* Add it to the normal incomplete black list if appropriate. */
......@@ -193,7 +196,6 @@ word p;
/* object, and isn't worth black listing. */
}
}
# endif
/* And the same for false pointers from the stack. */
#ifdef PRINT_BLACK_LIST
......@@ -236,12 +238,12 @@ word len;
register word i;
word nblocks = divHBLKSZ(len);
# ifndef ALL_INTERIOR_POINTERS
if (!GC_all_interior_pointers) {
if (get_pht_entry_from_index(GC_old_normal_bl, index)
|| get_pht_entry_from_index(GC_incomplete_normal_bl, index)) {
return(h+1);
}
# endif
}
for (i = 0; ; ) {
if (GC_old_stack_bl[divWORDSZ(index)] == 0
......
......@@ -80,7 +80,7 @@ int index;
if (pe -> block != 0 && pe -> block != h + OFFSET) ABORT("goofed");
pe -> old_sum = pe -> new_sum;
pe -> new_sum = GC_checksum(h);
# ifndef MSWIN32
# if !defined(MSWIN32) && !defined(MSWINCE)
if (pe -> new_sum != 0 && !GC_page_was_ever_dirty(h)) {
GC_printf1("GC_page_was_ever_dirty(0x%lx) is wrong\n",
(unsigned long)h);
......
dnl Process this file with autoconf to produce configure.
AC_INIT(gc_mark.h)
AC_INIT(gcj_mlc.c)
dnl Can't be done in BOEHM_CONFIGURE because that confuses automake.
AC_CONFIG_AUX_DIR(..)
......@@ -30,7 +30,7 @@ AC_MSG_CHECKING([for thread model used by GCC])
THREADS=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
AC_MSG_RESULT([$THREADS])
INCLUDES=
INCLUDES=-I${srcdir}/include
THREADLIBS=
case "$THREADS" in
no | none | single)
......@@ -47,7 +47,7 @@ case "$THREADS" in
*-*-freebsd*)
AC_MSG_WARN("FreeBSD does not yet fully support threads with Boehm GC.")
AC_DEFINE(FREEBSD_THREADS)
INCLUDES=-pthread
INCLUDES="$INCLUDES -pthread"
THREADLIBS=-pthread
;;
*-*-solaris*)
......
Copyright (c) 1993-1994 by Xerox Corporation. All rights reserved.
THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
Permission is hereby granted to use or copy this program
for any purpose, provided the above notices are retained on all copies.
Permission to modify the code and to distribute modified code is granted,
provided the above notices are retained, and a notice that the code was
modified is included with the above copyright notice.
Please send bug reports to Hans-J. Boehm (boehm@sgi.com).
This is a string packages that uses a tree-based representation.
See cord.h for a description of the functions provided. Ec.h describes
"extensible cords", which are essentially output streams that write
to a cord. These allow for efficient construction of cords without
requiring a bound on the size of a cord.
de.c is a very dumb text editor that illustrates the use of cords.
It maintains a list of file versions. Each version is simply a
cord representing the file contents. Nonetheless, standard
editing operations are efficient, even on very large files.
(Its 3 line "user manual" can be obtained by invoking it without
arguments. Note that ^R^N and ^R^P move the cursor by
almost a screen. It does not understand tabs, which will show
up as highlighred "I"s. Use the UNIX "expand" program first.)
To build the editor, type "make cord/de" in the gc directory.
This package assumes an ANSI C compiler such as gcc. It will
not compile with an old-style K&R compiler.
MATH=STANDARD
CPU=68030
NOSTACKCHECK
OPTIMIZE
VERBOSE
NOVERSION
NOICONS
OPTIMIZERTIME
INCLUDEDIR=/
DEFINE AMIGA
LIBRARY=cord.lib
LIBRARY=/gc.lib
IGNORE=100
IGNORE=161
# Makefile for cord.lib
# Michel Schinz 1994/07/20
OBJS = cordbscs.o cordprnt.o cordxtra.o
all: cord.lib cordtest
cordbscs.o: cordbscs.c
cordprnt.o: cordprnt.c
cordxtra.o: cordxtra.c
cordtest.o: cordtest.c
cord.lib: $(OBJS)
oml cord.lib r $(OBJS)
cordtest: cordtest.o cord.lib
sc cordtest.o link
clean:
delete cord.lib cordtest \#?.o \#?.lnk
# ifndef EC_H
# define EC_H
# ifndef CORD_H
# include "cord.h"
# endif
/* Extensible cords are strings that may be destructively appended to. */
/* They allow fast construction of cords from characters that are */
/* being read from a stream. */
/*
* A client might look like:
*
* {
* CORD_ec x;
* CORD result;
* char c;
* FILE *f;
*
* ...
* CORD_ec_init(x);
* while(...) {
* c = getc(f);
* ...
* CORD_ec_append(x, c);
* }
* result = CORD_balance(CORD_ec_to_cord(x));
*
* If a C string is desired as the final result, the call to CORD_balance
* may be replaced by a call to CORD_to_char_star.
*/
# ifndef CORD_BUFSZ
# define CORD_BUFSZ 128
# endif
typedef struct CORD_ec_struct {
CORD ec_cord;
char * ec_bufptr;
char ec_buf[CORD_BUFSZ+1];
} CORD_ec[1];
/* This structure represents the concatenation of ec_cord with */
/* ec_buf[0 ... (ec_bufptr-ec_buf-1)] */
/* Flush the buffer part of the extended chord into ec_cord. */
/* Note that this is almost the only real function, and it is */
/* implemented in 6 lines in cordxtra.c */
void CORD_ec_flush_buf(CORD_ec x);
/* Convert an extensible cord to a cord. */
# define CORD_ec_to_cord(x) (CORD_ec_flush_buf(x), (x)[0].ec_cord)
/* Initialize an extensible cord. */
# define CORD_ec_init(x) ((x)[0].ec_cord = 0, (x)[0].ec_bufptr = (x)[0].ec_buf)
/* Append a character to an extensible cord. */
# define CORD_ec_append(x, c) \
{ \
if ((x)[0].ec_bufptr == (x)[0].ec_buf + CORD_BUFSZ) { \
CORD_ec_flush_buf(x); \
} \
*((x)[0].ec_bufptr)++ = (c); \
}
/* Append a cord to an extensible cord. Structure remains shared with */
/* original. */
void CORD_ec_append_cord(CORD_ec x, CORD s);
# endif /* EC_H */
/*
* Copyright (c) 1993-1994 by Xerox Corporation. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* Boehm, May 19, 1994 2:23 pm PDT */
# ifndef CORD_POSITION_H
/* The representation of CORD_position. This is private to the */
/* implementation, but the size is known to clients. Also */
/* the implementation of some exported macros relies on it. */
/* Don't use anything defined here and not in cord.h. */
# define MAX_DEPTH 48
/* The maximum depth of a balanced cord + 1. */
/* We don't let cords get deeper than MAX_DEPTH. */
struct CORD_pe {
CORD pe_cord;
size_t pe_start_pos;
};
/* A structure describing an entry on the path from the root */
/* to current position. */
typedef struct CORD_Pos {
size_t cur_pos;
int path_len;
# define CORD_POS_INVALID (0x55555555)
/* path_len == INVALID <==> position invalid */
const char *cur_leaf; /* Current leaf, if it is a string. */
/* If the current leaf is a function, */
/* then this may point to function_buf */
/* containing the next few characters. */
/* Always points to a valid string */
/* containing the current character */
/* unless cur_end is 0. */
size_t cur_start; /* Start position of cur_leaf */
size_t cur_end; /* Ending position of cur_leaf */
/* 0 if cur_leaf is invalid. */
struct CORD_pe path[MAX_DEPTH + 1];
/* path[path_len] is the leaf corresponding to cur_pos */
/* path[0].pe_cord is the cord we point to. */
# define FUNCTION_BUF_SZ 8
char function_buf[FUNCTION_BUF_SZ]; /* Space for next few chars */
/* from function node. */
} CORD_pos[1];
/* Extract the cord from a position: */
CORD CORD_pos_to_cord(CORD_pos p);
/* Extract the current index from a position: */
size_t CORD_pos_to_index(CORD_pos p);
/* Fetch the character located at the given position: */
char CORD_pos_fetch(CORD_pos p);
/* Initialize the position to refer to the give cord and index. */
/* Note that this is the most expensive function on positions: */
void CORD_set_pos(CORD_pos p, CORD x, size_t i);
/* Advance the position to the next character. */
/* P must be initialized and valid. */
/* Invalidates p if past end: */
void CORD_next(CORD_pos p);
/* Move the position to the preceding character. */
/* P must be initialized and valid. */
/* Invalidates p if past beginning: */
void CORD_prev(CORD_pos p);
/* Is the position valid, i.e. inside the cord? */
int CORD_pos_valid(CORD_pos p);
char CORD__pos_fetch(CORD_pos);
void CORD__next(CORD_pos);
void CORD__prev(CORD_pos);
#define CORD_pos_fetch(p) \
(((p)[0].cur_end != 0)? \
(p)[0].cur_leaf[(p)[0].cur_pos - (p)[0].cur_start] \
: CORD__pos_fetch(p))
#define CORD_next(p) \
(((p)[0].cur_pos + 1 < (p)[0].cur_end)? \
(p)[0].cur_pos++ \
: (CORD__next(p), 0))
#define CORD_prev(p) \
(((p)[0].cur_end != 0 && (p)[0].cur_pos > (p)[0].cur_start)? \
(p)[0].cur_pos-- \
: (CORD__prev(p), 0))
#define CORD_pos_to_index(p) ((p)[0].cur_pos)
#define CORD_pos_to_cord(p) ((p)[0].path[0].pe_cord)
#define CORD_pos_valid(p) ((p)[0].path_len != CORD_POS_INVALID)
/* Some grubby stuff for performance-critical friends: */
#define CORD_pos_chars_left(p) ((long)((p)[0].cur_end) - (long)((p)[0].cur_pos))
/* Number of characters in cache. <= 0 ==> none */
#define CORD_pos_advance(p,n) ((p)[0].cur_pos += (n) - 1, CORD_next(p))
/* Advance position by n characters */
/* 0 < n < CORD_pos_chars_left(p) */
#define CORD_pos_cur_char_addr(p) \
(p)[0].cur_leaf + ((p)[0].cur_pos - (p)[0].cur_start)
/* address of current character in cache. */
#endif
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
* Copyright (c) 1997 by Silicon Graphics. All rights reserved.
* Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/*
* This is mostly an internal header file. Typical clients should
* not use it. Clients that define their own object kinds with
* debugging allocators will probably want to include this, however.
* No attempt is made to keep the namespace clean. This should not be
* included from header filrd that are frequently included by clients.
*/
#ifndef _DBG_MLC_H
#define _DBG_MLC_H
# define I_HIDE_POINTERS
# include "gc_priv.h"
# ifdef KEEP_BACK_PTRS
# include "backptr.h"
# endif
# define START_FLAG ((word)0xfedcedcb)
# define END_FLAG ((word)0xbcdecdef)
/* Stored both one past the end of user object, and one before */
/* the end of the object as seen by the allocator. */
/* Object header */
typedef struct {
# ifdef KEEP_BACK_PTRS
ptr_t oh_back_ptr;
# define MARKED_FOR_FINALIZATION (ptr_t)(-1)
/* Object was marked because it is finalizable. */
# define MARKED_FROM_REGISTER (ptr_t)(-2)
/* Object was marked from a rgister. Hence the */
/* source of the reference doesn't have an address. */
# ifdef ALIGN_DOUBLE
word oh_dummy;
# endif
# endif
char * oh_string; /* object descriptor string */
word oh_int; /* object descriptor integers */
# ifdef NEED_CALLINFO
struct callinfo oh_ci[NFRAMES];
# endif
word oh_sz; /* Original malloc arg. */
word oh_sf; /* start flag */
} oh;
/* The size of the above structure is assumed not to dealign things, */
/* and to be a multiple of the word length. */
#define DEBUG_BYTES (sizeof (oh) + sizeof (word))
#define USR_PTR_FROM_BASE(p) ((ptr_t)(p) + sizeof(oh))
/* There is no reason to ever add a byte at the end explicitly, since we */
/* already add a guard word. */
#undef ROUNDED_UP_WORDS
#define ROUNDED_UP_WORDS(n) BYTES_TO_WORDS((n) + WORDS_TO_BYTES(1) - 1)
#ifdef SAVE_CALL_CHAIN
# define ADD_CALL_CHAIN(base, ra) GC_save_callers(((oh *)(base)) -> oh_ci)
# define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
#else
# ifdef GC_ADD_CALLER
# define ADD_CALL_CHAIN(base, ra) ((oh *)(base)) -> oh_ci[0].ci_pc = (ra)
# define PRINT_CALL_CHAIN(base) GC_print_callers(((oh *)(base)) -> oh_ci)
# else
# define ADD_CALL_CHAIN(base, ra)
# define PRINT_CALL_CHAIN(base)
# endif
#endif
# ifdef GC_ADD_CALLER
# define OPT_RA ra,
# else
# define OPT_RA
# endif
/* Check whether object with base pointer p has debugging info */
/* p is assumed to point to a legitimate object in our part */
/* of the heap. */
GC_bool GC_has_debug_info(/* p */);
/* Store debugging info into p. Return displaced pointer. */
/* Assumes we don't hold allocation lock. */
ptr_t GC_store_debug_info(/* p, sz, string, integer */);
#endif /* _DBG_MLC_H */
......@@ -14,8 +14,7 @@
*/
/* Boehm, February 1, 1996 1:19 pm PST */
# define I_HIDE_POINTERS
# include "gc_priv.h"
# include "gc_mark.h"
# include "private/gc_pmark.h"
# ifdef FINALIZE_ON_DEMAND
int GC_finalize_on_demand = 1;
......@@ -86,13 +85,13 @@ static signed_word log_fo_table_size = -1;
word GC_fo_entries = 0;
# ifdef SRC_M3
void GC_push_finalizer_structures()
void GC_push_finalizer_structures GC_PROTO((void))
{
GC_push_all((ptr_t)(&dl_head), (ptr_t)(&dl_head) + sizeof(word));
GC_push_all((ptr_t)(&fo_head), (ptr_t)(&fo_head) + sizeof(word));
GC_push_all((ptr_t)(&GC_finalize_now),
(ptr_t)(&GC_finalize_now) + sizeof(word));
}
# endif
/* Double the size of a hash table. *size_ptr is the log of its current */
/* size. May be a noop. */
......@@ -110,7 +109,7 @@ signed_word * log_size_ptr;
word old_size = ((log_old_size == -1)? 0: (1 << log_old_size));
register word new_size = 1 << log_new_size;
struct hash_chain_entry **new_table = (struct hash_chain_entry **)
GC_generic_malloc_inner_ignore_off_page(
GC_INTERNAL_MALLOC_IGNORE_OFF_PAGE(
(size_t)new_size * sizeof(struct hash_chain_entry *), NORMAL);
if (new_table == 0) {
......@@ -179,9 +178,11 @@ signed_word * log_size_ptr;
# endif
GC_grow_table((struct hash_chain_entry ***)(&dl_head),
&log_dl_table_size);
# ifdef PRINTSTATS
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf1("Grew dl table to %lu entries\n",
(unsigned long)(1 << log_dl_table_size));
}
# endif
# ifndef THREADS
ENABLE_SIGNALS();
......@@ -199,13 +200,8 @@ signed_word * log_size_ptr;
return(1);
}
}
# ifdef THREADS
new_dl = (struct disappearing_link *)
GC_generic_malloc_inner(sizeof(struct disappearing_link),NORMAL);
# else
new_dl = (struct disappearing_link *)
GC_malloc(sizeof(struct disappearing_link));
# endif
new_dl = (struct disappearing_link *)
GC_INTERNAL_MALLOC(sizeof(struct disappearing_link),NORMAL);
if (new_dl != 0) {
new_dl -> dl_hidden_obj = HIDE_POINTER(obj);
new_dl -> dl_hidden_link = HIDE_POINTER(link);
......@@ -248,7 +244,11 @@ signed_word * log_size_ptr;
GC_dl_entries--;
UNLOCK();
ENABLE_SIGNALS();
GC_free((GC_PTR)curr_dl);
# ifdef DBG_HDRS_ALL
dl_next(curr_dl) = 0;
# else
GC_free((GC_PTR)curr_dl);
# endif
return(1);
}
prev_dl = curr_dl;
......@@ -283,7 +283,7 @@ ptr_t p;
ptr_t scan_limit;
ptr_t target_limit = p + WORDS_TO_BYTES(hhdr -> hb_sz) - 1;
if ((descr & DS_TAGS) == DS_LENGTH) {
if ((descr & GC_DS_TAGS) == GC_DS_LENGTH) {
scan_limit = p + descr - sizeof(word);
} else {
scan_limit = target_limit + 1 - sizeof(word);
......@@ -338,9 +338,11 @@ finalization_mark_proc * mp;
# endif
GC_grow_table((struct hash_chain_entry ***)(&fo_head),
&log_fo_table_size);
# ifdef PRINTSTATS
# ifdef CONDPRINT
if (GC_print_stats) {
GC_printf1("Grew fo table to %lu entries\n",
(unsigned long)(1 << log_fo_table_size));
}
# endif
# ifndef THREADS
ENABLE_SIGNALS();
......@@ -370,7 +372,7 @@ finalization_mark_proc * mp;
/* May not happen if we get a signal. But a high */
/* estimate will only make the table larger than */
/* necessary. */
# ifndef THREADS
# if !defined(THREADS) && !defined(DBG_HDRS_ALL)
GC_free((GC_PTR)curr_fo);
# endif
} else {
......@@ -406,23 +408,14 @@ finalization_mark_proc * mp;
GET_HDR(base, hhdr);
if (0 == hhdr) {
/* We won't collect it, hence finalizer wouldn't be run. */
/* This is changed for gcj, but it will be in version 6.0 of the */
/* standard collector distribution. It costs virtually nothing */
/* here, but it's expensive to check in the hash synchronization */
/* code, where it matters. -HB */
# ifdef THREADS
UNLOCK();
ENABLE_SIGNALS();
# endif
return;
}
# ifdef THREADS
new_fo = (struct finalizable_object *)
GC_generic_malloc_inner(sizeof(struct finalizable_object),NORMAL);
# else
new_fo = (struct finalizable_object *)
GC_malloc(sizeof(struct finalizable_object));
# endif
new_fo = (struct finalizable_object *)
GC_INTERNAL_MALLOC(sizeof(struct finalizable_object),NORMAL);
if (new_fo != 0) {
new_fo -> fo_hidden_base = (word)HIDE_POINTER(base);
new_fo -> fo_fn = fn;
......@@ -492,6 +485,34 @@ finalization_mark_proc * mp;
ocd, GC_null_finalize_mark_proc);
}
#ifndef NO_DEBUGGING
void GC_dump_finalization()
{
struct disappearing_link * curr_dl;
struct finalizable_object * curr_fo;
ptr_t real_ptr, real_link;
int dl_size = (log_dl_table_size == -1 ) ? 0 : (1 << log_dl_table_size);
int fo_size = (log_fo_table_size == -1 ) ? 0 : (1 << log_fo_table_size);
int i;
GC_printf0("Disappearing links:\n");
for (i = 0; i < dl_size; i++) {
for (curr_dl = dl_head[i]; curr_dl != 0; curr_dl = dl_next(curr_dl)) {
real_ptr = (ptr_t)REVEAL_POINTER(curr_dl -> dl_hidden_obj);
real_link = (ptr_t)REVEAL_POINTER(curr_dl -> dl_hidden_link);
GC_printf2("Object: 0x%lx, Link:0x%lx\n", real_ptr, real_link);
}
}
GC_printf0("Finalizers:\n");
for (i = 0; i < fo_size; i++) {
for (curr_fo = fo_head[i]; curr_fo != 0; curr_fo = fo_next(curr_fo)) {
real_ptr = (ptr_t)REVEAL_POINTER(curr_fo -> fo_hidden_base);
GC_printf1("Finalizable object: 0x%lx\n", real_ptr);
}
}
}
#endif
/* Called with world stopped. Cause disappearing links to disappear, */
/* and invoke finalizers. */
void GC_finalize()
......@@ -529,9 +550,7 @@ void GC_finalize()
}
/* Mark all objects reachable via chains of 1 or more pointers */
/* from finalizable objects. */
# ifdef PRINTSTATS
if (GC_mark_state != MS_NONE) ABORT("Bad mark state");
# endif
GC_ASSERT(GC_mark_state == MS_NONE);
for (i = 0; i < fo_size; i++) {
for (curr_fo = fo_head[i]; curr_fo != 0; curr_fo = fo_next(curr_fo)) {
real_ptr = (ptr_t)REVEAL_POINTER(curr_fo -> fo_hidden_base);
......@@ -574,11 +593,7 @@ void GC_finalize()
GC_words_finalized +=
ALIGNED_WORDS(curr_fo -> fo_object_size)
+ ALIGNED_WORDS(sizeof(struct finalizable_object));
# ifdef PRINTSTATS
if (!GC_is_marked((ptr_t)curr_fo)) {
ABORT("GC_finalize: found accessible unmarked object\n");
}
# endif
GC_ASSERT(GC_is_marked((ptr_t)curr_fo));
curr_fo = next_fo;
} else {
prev_fo = curr_fo;
......@@ -753,6 +768,25 @@ int GC_invoke_finalizers()
return count;
}
void (* GC_finalizer_notifier)() = (void (*) GC_PROTO((void)))0;
static GC_word last_finalizer_notification = 0;
void GC_notify_or_invoke_finalizers GC_PROTO((void))
{
if (GC_finalize_now == 0) return;
if (!GC_finalize_on_demand) {
(void) GC_invoke_finalizers();
GC_ASSERT(GC_finalize_now == 0);
return;
}
if (GC_finalizer_notifier != (void (*) GC_PROTO((void)))0
&& last_finalizer_notification != GC_gc_no) {
last_finalizer_notification = GC_gc_no;
GC_finalizer_notifier();
}
}
# ifdef __STDC__
GC_PTR GC_call_with_alloc_lock(GC_fn_type fn,
GC_PTR client_data)
......@@ -772,7 +806,9 @@ int GC_invoke_finalizers()
# endif
result = (*fn)(client_data);
# ifdef THREADS
UNSET_LOCK_HOLDER();
# ifndef GC_ASSERTIONS
UNSET_LOCK_HOLDER();
# endif /* o.w. UNLOCK() does it implicitly */
UNLOCK();
ENABLE_SIGNALS();
# endif
......
.TH GC_MALLOC 1L "12 February 1996"
.SH NAME
GC_malloc, GC_malloc_atomic, GC_free, GC_realloc, GC_enable_incremental, GC_register_finalizer, GC_malloc_ignore_off_page, GC_malloc_atomic_ignore_off_page, GC_set_warn_proc \- Garbage collecting malloc replacement
.SH SYNOPSIS
#include "gc.h"
.br
# define malloc(n) GC_malloc(n)
.br
... malloc(...) ...
.br
.sp
cc ... gc.a
.LP
.SH DESCRIPTION
.I GC_malloc
and
.I GC_free
are plug-in replacements for standard malloc and free. However,
.I
GC_malloc
will attempt to reclaim inaccessible space automatically by invoking a conservative garbage collector at appropriate points. The collector traverses all data structures accessible by following pointers from the machines registers, stack(s), data, and bss segments. Inaccessible structures will be reclaimed. A machine word is considered to be a valid pointer if it is an address inside an object allocated by
.I
GC_malloc
or friends.
.LP
See the documentation in the include file gc_cpp.h for an alternate, C++ specific interface to the garbage collector.
.LP
Unlike the standard implementations of malloc,
.I
GC_malloc
clears the newly allocated storage.
.I
GC_malloc_atomic
does not. Furthermore, it informs the collector that the resulting object will never contain any pointers, and should therefore not be scanned by the collector.
.LP
.I
GC_free
can be used to deallocate objects, but its use is optional, and generally discouraged.
.I
GC_realloc
has the standard realloc semantics. It preserves pointer-free-ness.
.I
GC_register_finalizer
allows for registration of functions that are invoked when an object becomes inaccessible.
.LP
The garbage collector tries to avoid allocating memory at locations that already appear to be referenced before allocation. (Such apparent ``pointers'' are usually large integers and the like that just happen to look like an address.) This may make it hard to allocate very large objects. An attempt to do so may generate a warning.
.LP
.I
GC_malloc_ignore_off_page
and
.I
GC_malloc_atomic_ignore_off_page
inform the collector that the client code will always maintain a pointer to near the beginning of the object (within the first 512 bytes), and that pointers beyond that can be ignored by the collector. This makes it much easier for the collector to place large objects. These are recommended for large object allocation. (Objects expected to be larger than about 100KBytes should be allocated this way.)
.LP
It is also possible to use the collector to find storage leaks in programs destined to be run with standard malloc/free. The collector can be compiled for thread-safe operation. Unlike standard malloc, it is safe to call malloc after a previous malloc call was interrupted by a signal, provided the original malloc call is not resumed.
.LP
The collector may, on rare occasion produce warning messages. On UNIX machines these appear on stderr. Warning messages can be filtered, redirected, or ignored with
.I
GC_set_warn_proc.
This is recommended for production code. See gc.h for details.
.LP
Debugging versions of many of the above routines are provided as macros. Their names are identical to the above, but consist of all capital letters. If GC_DEBUG is defined before gc.h is included, these routines do additional checking, and allow the leak detecting version of the collector to produce slightly more useful output. Without GC_DEBUG defined, they behave exactly like the lower-case versions.
.LP
On some machines, collection will be performed incrementally after a call to
.I
GC_enable_incremental.
This may temporarily write protect pages in the heap. See the README file for more information on how this interacts with system calls that write to the heap.
.LP
Other facilities not discussed here include limited facilities to support incremental collection on machines without appropriate VM support, provisions for providing more explicit object layout information to the garbage collector, more direct support for ``weak'' pointers, support for ``abortable'' garbage collections during idle time, etc.
.LP
.SH "SEE ALSO"
The README and gc.h files in the distribution. More detailed definitions of the functions exported by the collector are given there. (The above list is not complete.)
.LP
Boehm, H., and M. Weiser, "Garbage Collection in an Uncooperative Environment",
\fISoftware Practice & Experience\fP, September 1988, pp. 807-820.
.LP
The malloc(3) man page.
.LP
.SH AUTHOR
Hans-J. Boehm (boehm@parc.xerox.com). Some of the code was written by others, most notably Alan Demers.
......@@ -26,27 +26,14 @@ Authors: John R. Ellis and Jesse Hull
#include "gc_cpp.h"
#ifndef _MSC_VER
/* In the Visual C++ case, we moved this into the header. */
void* operator new( size_t size ) {
return GC_MALLOC_UNCOLLECTABLE( size );}
void operator delete( void* obj ) {
GC_FREE( obj );}
#ifdef _MSC_VER
// This new operator is used by VC++ in case of Debug builds !
void* operator new( size_t size,
int ,//nBlockUse,
const char * szFileName,
int nLine
) {
# ifndef GC_DEBUG
return GC_malloc_uncollectable( size );
# else
return GC_debug_malloc_uncollectable(size, szFileName, nLine);
# endif
}
#endif
#ifdef OPERATOR_NEW_ARRAY
void* operator new[]( size_t size ) {
......@@ -57,4 +44,6 @@ void operator delete[]( void* obj ) {
#endif /* OPERATOR_NEW_ARRAY */
#endif /* _MSC_VER */
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* Boehm, July 11, 1995 11:54 am PDT */
# ifndef GC_HEADERS_H
# define GC_HEADERS_H
typedef struct hblkhdr hdr;
# if CPP_WORDSZ != 32 && CPP_WORDSZ < 36
--> Get a real machine.
# endif
/*
* The 2 level tree data structure that is used to find block headers.
* If there are more than 32 bits in a pointer, the top level is a hash
* table.
*
* This defines HDR, GET_HDR, and SET_HDR, the main macros used to
* retrieve and set object headers. We also define some variants to
* retrieve 2 unrelated headers in interleaved fashion. This
* slightly improves scheduling.
*
* Since 5.0 alpha 5, we can also take advantage of a header lookup
* cache. This is a locally declared direct mapped cache, used inside
* the marker. The HC_GET_HDR and HC_GET_HDR2 macros use and maintain this
* cache. Assuming we get reasonable hit rates, this shaves a few
* memory references from each pointer validation.
*/
# if CPP_WORDSZ > 32
# define HASH_TL
# endif
/* Define appropriate out-degrees for each of the two tree levels */
# ifdef SMALL_CONFIG
# define LOG_BOTTOM_SZ 11
/* Keep top index size reasonable with smaller blocks. */
# else
# define LOG_BOTTOM_SZ 10
# endif
# ifndef HASH_TL
# define LOG_TOP_SZ (WORDSZ - LOG_BOTTOM_SZ - LOG_HBLKSIZE)
# else
# define LOG_TOP_SZ 11
# endif
# define TOP_SZ (1 << LOG_TOP_SZ)
# define BOTTOM_SZ (1 << LOG_BOTTOM_SZ)
#ifndef SMALL_CONFIG
# define USE_HDR_CACHE
#endif
/* #define COUNT_HDR_CACHE_HITS */
extern hdr * GC_invalid_header; /* header for an imaginary block */
/* containing no objects. */
/* Check whether p and corresponding hhdr point to long or invalid */
/* object. If so, advance them to */
/* beginning of block, or set hhdr to GC_invalid_header. */
#define ADVANCE(p, hhdr, source) \
if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { \
p = GC_FIND_START(p, hhdr, (word)source); \
if (p == 0) { \
hhdr = GC_invalid_header; \
} else { \
hhdr = GC_find_header(p); \
} \
}
#ifdef USE_HDR_CACHE
# ifdef COUNT_HDR_CACHE_HITS
extern word GC_hdr_cache_hits;
extern word GC_hdr_cache_misses;
# define HC_HIT() ++GC_hdr_cache_hits
# define HC_MISS() ++GC_hdr_cache_misses
# else
# define HC_HIT()
# define HC_MISS()
# endif
typedef struct hce {
word block_addr; /* right shifted by LOG_HBLKSIZE */
hdr * hce_hdr;
} hdr_cache_entry;
# define HDR_CACHE_SIZE 8 /* power of 2 */
# define DECLARE_HDR_CACHE \
hdr_cache_entry hdr_cache[HDR_CACHE_SIZE]
# define INIT_HDR_CACHE BZERO(hdr_cache, sizeof(hdr_cache));
# define HCE(h) hdr_cache + (((word)(h) >> LOG_HBLKSIZE) & (HDR_CACHE_SIZE-1))
# define HCE_VALID_FOR(hce,h) ((hce) -> block_addr == \
((word)(h) >> LOG_HBLKSIZE))
# define HCE_HDR(h) ((hce) -> hce_hdr)
/* Analogous to GET_HDR, except that in the case of large objects, it */
/* Returns the header for the object beginning, and updates p. */
/* Returns &GC_bad_header instead of 0. All of this saves a branch */
/* in the fast path. */
# define HC_GET_HDR(p, hhdr, source) \
{ \
hdr_cache_entry * hce = HCE(p); \
if (HCE_VALID_FOR(hce, p)) { \
HC_HIT(); \
hhdr = hce -> hce_hdr; \
} else { \
HC_MISS(); \
GET_HDR(p, hhdr); \
ADVANCE(p, hhdr, source); \
hce -> block_addr = (word)(p) >> LOG_HBLKSIZE; \
hce -> hce_hdr = hhdr; \
} \
}
# define HC_GET_HDR2(p1, hhdr1, source1, p2, hhdr2, source2) \
{ \
hdr_cache_entry * hce1 = HCE(p1); \
hdr_cache_entry * hce2 = HCE(p2); \
if (HCE_VALID_FOR(hce1, p1)) { \
HC_HIT(); \
hhdr1 = hce1 -> hce_hdr; \
} else { \
HC_MISS(); \
GET_HDR(p1, hhdr1); \
ADVANCE(p1, hhdr1, source1); \
hce1 -> block_addr = (word)(p1) >> LOG_HBLKSIZE; \
hce1 -> hce_hdr = hhdr1; \
} \
if (HCE_VALID_FOR(hce2, p2)) { \
HC_HIT(); \
hhdr2 = hce2 -> hce_hdr; \
} else { \
HC_MISS(); \
GET_HDR(p2, hhdr2); \
ADVANCE(p2, hhdr2, source2); \
hce2 -> block_addr = (word)(p2) >> LOG_HBLKSIZE; \
hce2 -> hce_hdr = hhdr2; \
} \
}
#else /* !USE_HDR_CACHE */
# define DECLARE_HDR_CACHE
# define INIT_HDR_CACHE
# define HC_GET_HDR(p, hhdr, source) \
{ \
GET_HDR(p, hhdr); \
ADVANCE(p, hhdr, source); \
}
# define HC_GET_HDR2(p1, hhdr1, source1, p2, hhdr2, source2) \
{ \
GET_HDR2(p1, hhdr1, p2, hhdr2); \
ADVANCE(p1, hhdr1, source1); \
ADVANCE(p2, hhdr2, source2); \
}
#endif
typedef struct bi {
hdr * index[BOTTOM_SZ];
/*
* The bottom level index contains one of three kinds of values:
* 0 means we're not responsible for this block,
* or this is a block other than the first one in a free block.
* 1 < (long)X <= MAX_JUMP means the block starts at least
* X * HBLKSIZE bytes before the current address.
* A valid pointer points to a hdr structure. (The above can't be
* valid pointers due to the GET_MEM return convention.)
*/
struct bi * asc_link; /* All indices are linked in */
/* ascending order... */
struct bi * desc_link; /* ... and in descending order. */
word key; /* high order address bits. */
# ifdef HASH_TL
struct bi * hash_link; /* Hash chain link. */
# endif
} bottom_index;
/* extern bottom_index GC_all_nils; - really part of GC_arrays */
/* extern bottom_index * GC_top_index []; - really part of GC_arrays */
/* Each entry points to a bottom_index. */
/* On a 32 bit machine, it points to */
/* the index for a set of high order */
/* bits equal to the index. For longer */
/* addresses, we hash the high order */
/* bits to compute the index in */
/* GC_top_index, and each entry points */
/* to a hash chain. */
/* The last entry in each chain is */
/* GC_all_nils. */
# define MAX_JUMP (HBLKSIZE - 1)
# define HDR_FROM_BI(bi, p) \
((bi)->index[((word)(p) >> LOG_HBLKSIZE) & (BOTTOM_SZ - 1)])
# ifndef HASH_TL
# define BI(p) (GC_top_index \
[(word)(p) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE)])
# define HDR_INNER(p) HDR_FROM_BI(BI(p),p)
# ifdef SMALL_CONFIG
# define HDR(p) GC_find_header((ptr_t)(p))
# else
# define HDR(p) HDR_INNER(p)
# endif
# define GET_BI(p, bottom_indx) (bottom_indx) = BI(p)
# define GET_HDR(p, hhdr) (hhdr) = HDR(p)
# define SET_HDR(p, hhdr) HDR_INNER(p) = (hhdr)
# define GET_HDR_ADDR(p, ha) (ha) = &(HDR_INNER(p))
# define GET_HDR2(p1, hhdr1, p2, hhdr2) \
{ GET_HDR(p1, hhdr1); GET_HDR(p2, hhdr2); }
# else /* hash */
/* Hash function for tree top level */
# define TL_HASH(hi) ((hi) & (TOP_SZ - 1))
/* Set bottom_indx to point to the bottom index for address p */
# define GET_BI(p, bottom_indx) \
{ \
register word hi = \
(word)(p) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE); \
register bottom_index * _bi = GC_top_index[TL_HASH(hi)]; \
\
while (_bi -> key != hi && _bi != GC_all_nils) \
_bi = _bi -> hash_link; \
(bottom_indx) = _bi; \
}
# define GET_HDR_ADDR(p, ha) \
{ \
register bottom_index * bi; \
\
GET_BI(p, bi); \
(ha) = &(HDR_FROM_BI(bi, p)); \
}
# define GET_HDR(p, hhdr) { register hdr ** _ha; GET_HDR_ADDR(p, _ha); \
(hhdr) = *_ha; }
# define SET_HDR(p, hhdr) { register hdr ** _ha; GET_HDR_ADDR(p, _ha); \
*_ha = (hhdr); }
# define HDR(p) GC_find_header((ptr_t)(p))
/* And some interleaved versions for two pointers at once. */
/* This hopefully helps scheduling on processors like IA64. */
# define GET_BI2(p1, bottom_indx1, p2, bottom_indx2) \
{ \
register word hi1 = \
(word)(p1) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE); \
register word hi2 = \
(word)(p2) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE); \
register bottom_index * _bi1 = GC_top_index[TL_HASH(hi1)]; \
register bottom_index * _bi2 = GC_top_index[TL_HASH(hi2)]; \
\
while (_bi1 -> key != hi1 && _bi1 != GC_all_nils) \
_bi1 = _bi1 -> hash_link; \
while (_bi2 -> key != hi2 && _bi2 != GC_all_nils) \
_bi2 = _bi2 -> hash_link; \
(bottom_indx1) = _bi1; \
(bottom_indx2) = _bi2; \
}
# define GET_HDR_ADDR2(p1, ha1, p2, ha2) \
{ \
register bottom_index * bi1; \
register bottom_index * bi2; \
\
GET_BI2(p1, bi1, p2, bi2); \
(ha1) = &(HDR_FROM_BI(bi1, p1)); \
(ha2) = &(HDR_FROM_BI(bi2, p2)); \
}
# define GET_HDR2(p1, hhdr1, p2, hhdr2) \
{ register hdr ** _ha1; \
register hdr ** _ha2; \
GET_HDR_ADDR2(p1, _ha1, p2, _ha2); \
(hhdr1) = *_ha1; \
(hhdr2) = *_ha2; \
}
# endif
/* Is the result a forwarding address to someplace closer to the */
/* beginning of the block or NIL? */
# define IS_FORWARDING_ADDR_OR_NIL(hhdr) ((unsigned long) (hhdr) <= MAX_JUMP)
/* Get an HBLKSIZE aligned address closer to the beginning of the block */
/* h. Assumes hhdr == HDR(h) and IS_FORWARDING_ADDR(hhdr). */
# define FORWARDED_ADDR(h, hhdr) ((struct hblk *)(h) - (unsigned long)(hhdr))
# endif /* GC_HEADERS_H */
# include "gc_priv.h"
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright 1996 Silicon Graphics. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/*
* Some simple primitives for allocation with explicit type information.
* Facilities for dynamic type inference may be added later.
* Should be used only for extremely performance critical applications,
* or if conservative collector leakage is otherwise a problem (unlikely).
* Note that this is implemented completely separately from the rest
* of the collector, and is not linked in unless referenced.
* This does not currently support GC_DEBUG in any interesting way.
*/
/* Boehm, May 19, 1994 2:13 pm PDT */
#ifndef _GC_TYPED_H
# define _GC_TYPED_H
# ifndef _GC_H
# include "gc.h"
# endif
typedef GC_word * GC_bitmap;
/* The least significant bit of the first word is one if */
/* the first word in the object may be a pointer. */
# define GC_get_bit(bm, index) \
(((bm)[divWORDSZ(index)] >> modWORDSZ(index)) & 1)
# define GC_set_bit(bm, index) \
(bm)[divWORDSZ(index)] |= (word)1 << modWORDSZ(index)
typedef GC_word GC_descr;
GC_API GC_descr GC_make_descriptor GC_PROTO((GC_bitmap bm, size_t len));
/* Return a type descriptor for the object whose layout */
/* is described by the argument. */
/* The least significant bit of the first word is one */
/* if the first word in the object may be a pointer. */
/* The second argument specifies the number of */
/* meaningful bits in the bitmap. The actual object */
/* may be larger (but not smaller). Any additional */
/* words in the object are assumed not to contain */
/* pointers. */
/* Returns a conservative approximation in the */
/* (unlikely) case of insufficient memory to build */
/* the descriptor. Calls to GC_make_descriptor */
/* may consume some amount of a finite resource. This */
/* is intended to be called once per type, not once */
/* per allocation. */
GC_API GC_PTR GC_malloc_explicitly_typed
GC_PROTO((size_t size_in_bytes, GC_descr d));
/* Allocate an object whose layout is described by d. */
/* The resulting object MAY NOT BE PASSED TO REALLOC. */
/* The returned object is cleared. */
GC_API GC_PTR GC_malloc_explicitly_typed_ignore_off_page
GC_PROTO((size_t size_in_bytes, GC_descr d));
GC_API GC_PTR GC_calloc_explicitly_typed
GC_PROTO((size_t nelements,
size_t element_size_in_bytes,
GC_descr d));
/* Allocate an array of nelements elements, each of the */
/* given size, and with the given descriptor. */
/* The elemnt size must be a multiple of the byte */
/* alignment required for pointers. E.g. on a 32-bit */
/* machine with 16-bit aligned pointers, size_in_bytes */
/* must be a multiple of 2. */
/* Returned object is cleared. */
#ifdef GC_DEBUG
# define GC_MALLOC_EXPLICTLY_TYPED(bytes, d) GC_MALLOC(bytes)
# define GC_CALLOC_EXPLICTLY_TYPED(n, bytes, d) GC_MALLOC(n*bytes)
#else
# define GC_MALLOC_EXPLICTLY_TYPED(bytes, d) \
GC_malloc_explicitly_typed(bytes, d)
# define GC_CALLOC_EXPLICTLY_TYPED(n, bytes, d) \
GC_calloc_explicitly_typed(n, bytes, d)
#endif /* !GC_DEBUG */
#endif /* _GC_TYPED_H */
......@@ -17,13 +17,13 @@
#ifdef GC_GCJ_SUPPORT
/*
* This is an allocator interface tuned for gcj (the GNU/Cygnus static
* This is an allocator interface tuned for gcj (the GNU static
* java compiler).
*
* Each allocated object has a pointer in its first word to a vtable,
* which for our purposes is simply a structure describing the type of
* the object.
* This descriptor structur contains a GC marking descriptor at offset
* This descriptor structure contains a GC marking descriptor at offset
* MARK_DESCR_OFFSET.
*
* It is hoped that this interface may also be useful for other systems,
......@@ -36,10 +36,10 @@
* 3) FASTLOCK is not a significant win.
*/
#include "gc_priv.h"
#include "gc_mark.h"
#include "include/gc_gcj.h"
#include "dbg_mlc.h"
#include "private/gc_priv.h"
#include "private/gc_pmark.h"
#include "gc_gcj.h"
#include "private/dbg_mlc.h"
GC_bool GC_gcj_malloc_initialized = FALSE;
......@@ -51,12 +51,8 @@ int GC_gcj_debug_kind; /* The kind of objects that is always marked */
ptr_t * GC_gcjobjfreelist;
ptr_t * GC_gcjdebugobjfreelist;
void * GC_default_oom_action(void) { return 0; }
void * (*GC_oom_action)(void) = GC_default_oom_action;
/* Caller does not hold allocation lock. */
void GC_init_gcj_malloc(int mp_index, void * /* really mark_proc */mp)
void GC_init_gcj_malloc(int mp_index, void * /* really GC_mark_proc */mp)
{
register int i;
DCL_LOCK_STATE;
......@@ -70,23 +66,23 @@ void GC_init_gcj_malloc(int mp_index, void * /* really mark_proc */mp)
return;
}
GC_gcj_malloc_initialized = TRUE;
GC_mark_procs[mp_index] = (mark_proc)mp;
GC_mark_procs[mp_index] = (GC_mark_proc)mp;
if (mp_index >= GC_n_mark_procs) ABORT("GC_init_gcj_malloc: bad index");
/* Set up object kind gcj-style indirect descriptor. */
GC_gcjobjfreelist = (ptr_t *)
GC_generic_malloc_inner((MAXOBJSZ+1)*sizeof(ptr_t), PTRFREE);
GC_INTERNAL_MALLOC((MAXOBJSZ+1)*sizeof(ptr_t), PTRFREE);
if (GC_gcjobjfreelist == 0) ABORT("Couldn't allocate GC_gcjobjfreelist");
BZERO(GC_gcjobjfreelist, (MAXOBJSZ+1)*sizeof(ptr_t));
GC_gcj_kind = GC_n_kinds++;
GC_obj_kinds[GC_gcj_kind].ok_freelist = GC_gcjobjfreelist;
GC_obj_kinds[GC_gcj_kind].ok_reclaim_list = 0;
GC_obj_kinds[GC_gcj_kind].ok_descriptor =
(((word)(-MARK_DESCR_OFFSET - INDIR_PER_OBJ_BIAS)) | DS_PER_OBJECT);
(((word)(-MARK_DESCR_OFFSET - GC_INDIR_PER_OBJ_BIAS)) | GC_DS_PER_OBJECT);
GC_obj_kinds[GC_gcj_kind].ok_relocate_descr = FALSE;
GC_obj_kinds[GC_gcj_kind].ok_init = TRUE;
/* Set up object kind for objects that require mark proc call. */
GC_gcjdebugobjfreelist = (ptr_t *)
GC_generic_malloc_inner((MAXOBJSZ+1)*sizeof(ptr_t), PTRFREE);
GC_INTERNAL_MALLOC((MAXOBJSZ+1)*sizeof(ptr_t), PTRFREE);
if (GC_gcjdebugobjfreelist == 0)
ABORT("Couldn't allocate GC_gcjdebugobjfreelist");
BZERO(GC_gcjdebugobjfreelist, (MAXOBJSZ+1)*sizeof(ptr_t));
......@@ -94,7 +90,7 @@ void GC_init_gcj_malloc(int mp_index, void * /* really mark_proc */mp)
GC_obj_kinds[GC_gcj_debug_kind].ok_freelist = GC_gcjdebugobjfreelist;
GC_obj_kinds[GC_gcj_debug_kind].ok_reclaim_list = 0;
GC_obj_kinds[GC_gcj_debug_kind].ok_descriptor =
MAKE_PROC(mp_index, 1 /* allocated with debug info */);
GC_MAKE_PROC(mp_index, 1 /* allocated with debug info */);
GC_obj_kinds[GC_gcj_debug_kind].ok_relocate_descr = FALSE;
GC_obj_kinds[GC_gcj_debug_kind].ok_init = TRUE;
UNLOCK();
......@@ -119,7 +115,7 @@ register ptr_t * opp;
register word lw;
DCL_LOCK_STATE;
if( SMALL_OBJ(lb) ) {
if( EXPECT(SMALL_OBJ(lb), 1) ) {
# ifdef MERGE_SIZES
lw = GC_size_map[lb];
# else
......@@ -127,11 +123,12 @@ DCL_LOCK_STATE;
# endif
opp = &(GC_gcjobjfreelist[lw]);
LOCK();
if( (op = *opp) == 0 ) {
op = *opp;
if( EXPECT(op == 0, 0)) {
op = (ptr_t)GENERAL_MALLOC((word)lb, GC_gcj_kind);
if (0 == op) {
UNLOCK();
return(GC_oom_action());
return(GC_oom_fn(lb));
}
# ifdef MERGE_SIZES
lw = GC_size_map[lb]; /* May have been uninitialized. */
......@@ -147,7 +144,7 @@ DCL_LOCK_STATE;
op = (ptr_t)GENERAL_MALLOC((word)lb, GC_gcj_kind);
if (0 == op) {
UNLOCK();
return(GC_oom_action());
return(GC_oom_fn(lb));
}
*(void **)op = ptr_to_struct_containing_descr;
UNLOCK();
......@@ -174,7 +171,7 @@ GC_PTR GC_debug_gcj_malloc(size_t lb, void * ptr_to_struct_containing_descr,
(unsigned long) ptr_to_struct_containing_descr);
GC_err_puts(s);
GC_err_printf1(":%ld)\n", (unsigned long)i);
return(GC_oom_action());
return(GC_oom_fn(lb));
}
*((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr;
UNLOCK();
......@@ -196,12 +193,13 @@ DCL_LOCK_STATE;
opp = &(GC_gcjobjfreelist[lw]);
LOCK();
if( (op = *opp) == 0 ) {
op = *opp;
if( EXPECT(op == 0, 0) ) {
op = (ptr_t)GC_clear_stack(
GC_generic_malloc_words_small_inner(lw, GC_gcj_kind));
if (0 == op) {
UNLOCK();
return(GC_oom_action());
return GC_oom_fn(WORDS_TO_BYTES(lw));
}
} else {
*opp = obj_link(op);
......@@ -232,7 +230,7 @@ void * GC_debug_gcj_fast_malloc(size_t lw,
(unsigned long) ptr_to_struct_containing_descr);
GC_err_puts(s);
GC_err_printf1(":%ld)\n", (unsigned long)i);
return(GC_oom_action());
return GC_oom_fn(WORDS_TO_BYTES(lw));
}
*((void **)((ptr_t)result + sizeof(oh))) = ptr_to_struct_containing_descr;
UNLOCK();
......
......@@ -22,7 +22,7 @@
* level tree.
*/
# include "gc_priv.h"
# include "private/gc_priv.h"
bottom_index * GC_all_bottom_indices = 0;
/* Pointer to first (lowest addr) */
......@@ -260,7 +260,7 @@ register word sz; /* bytes */
/* Apply fn to all allocated blocks */
/*VARARGS1*/
void GC_apply_to_all_blocks(fn, client_data)
void (*fn)(/* struct hblk *h, word client_data */);
void (*fn) GC_PROTO((struct hblk *h, word client_data));
word client_data;
{
register int j;
......
/* Conditionally execute a command based on machine and OS from gcconfig.h */
# include "gcconfig.h"
# include "private/gcconfig.h"
# include <stdio.h>
# include <string.h>
# include <unistd.h>
int main(argc, argv, envp)
int argc;
......@@ -13,6 +15,7 @@ char ** envp;
if (strcmp(OS_TYPE, "") != 0 && strcmp(argv[2], "") != 0
&& strcmp(OS_TYPE, argv[2]) != 0) return(0);
printf("^^^^Starting command^^^^\n");
fflush(stdout);
execvp(argv[3], argv+3);
perror("Couldn't execute");
......
/* Conditionally execute a command based if the file argv[1] doesn't exist */
/* Except for execvp, we stick to ANSI C. */
# include "gcconfig.h"
# include "private/gcconfig.h"
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
int main(argc, argv, envp)
int argc;
......@@ -16,6 +18,7 @@ char ** envp;
return(0);
}
printf("^^^^Starting command^^^^\n");
fflush(stdout);
execvp(argv[2], argv+2);
exit(1);
......
/*
* This is a simple API to implement pointer back tracing, i.e.
* to answer questions such as "who is pointing to this" or
* "why is this object being retained by the collector"
*
* This API assumes that we have an ANSI C compiler.
*
* Most of these calls yield useful information on only after
* a garbage collection. Usually the client will first force
* a full collection and then gather information, preferably
* before much intervening allocation.
*
* The implementation of the interface is only about 99.9999%
* correct. It is intended to be good enough for profiling,
* but is not intended to be used with production code.
*
* Results are likely to be much more useful if all allocation is
* accomplished through the debugging allocators.
*
* The implementation idea is due to A. Demers.
*/
/* Store information about the object referencing dest in *base_p */
/* and *offset_p. */
/* If multiple objects or roots point to dest, the one reported */
/* will be the last on used by the garbage collector to trace the */
/* object. */
/* source is root ==> *base_p = address, *offset_p = 0 */
/* source is heap object ==> *base_p != 0, *offset_p = offset */
/* Returns 1 on success, 0 if source couldn't be determined. */
/* Dest can be any address within a heap object. */
typedef enum { GC_UNREFERENCED, /* No reference info available. */
GC_NO_SPACE, /* Dest not allocated with debug alloc */
GC_REFD_FROM_ROOT, /* Referenced directly by root *base_p */
GC_REFD_FROM_REG, /* Referenced from a register, i.e. */
/* a root without an address. */
GC_REFD_FROM_HEAP, /* Referenced from another heap obj. */
GC_FINALIZER_REFD /* Finalizable and hence accessible. */
} GC_ref_kind;
GC_ref_kind GC_get_back_ptr_info(void *dest, void **base_p, size_t *offset_p);
/* Generate a random heap address. */
/* The resulting address is in the heap, but */
/* not necessarily inside a valid object. */
void * GC_generate_random_heap_address(void);
/* Generate a random address inside a valid marked heap object. */
void * GC_generate_random_valid_address(void);
/* Force a garbage collection and generate a backtrace from a */
/* random heap address. */
/* This uses the GC logging mechanism (GC_printf) to produce */
/* output. It can often be called from a debugger. The */
/* source in dbg_mlc.c also serves as a sample client. */
void GC_generate_random_backtrace(void);
/* Print a backtrace from a specific address. Used by the */
/* above. The client should call GC_gcollect() immediately */
/* before invocation. */
void GC_print_backtrace(void *);
/*
* Copyright (c) 1999 by Silicon Graphics. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* Descriptor for allocation request. May be redefined by client. */
typedef struct {
GC_word bitmap; /* Bitmap describing pointer locations. */
/* High order bit correspond to 0th */
/* word. 2 lsbs must be 0. */
size_t length; /* In bytes, must be multiple of word */
/* size. Must be >0, <= 512 */
} * GC_copy_descriptor;
/* The collector accesses descriptors only through these two macros. */
#define GC_SIZE_FROM_DESCRIPTOR(d) ((d) -> length)
#define GC_BIT_MAP_FROM_DESCRIPTOR(d) ((d) -> bitmap)
/*
* Copyright (c) 1999 by Silicon Graphics. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/*
* THIS IMPLEMENTATION FOR THIS INTERFACE IS INCOMPLETE.
* NONE OF THIS HAS BEEN TESTED. DO NOT USE.
*
* Comments on the interface are appreciated, especially from
* potential users of the interface.
*
* This is a Bartlett style copying collector for young objects.
* We assume for now that all objects allocated through this
* mechanism have pointers only in the first BITMAP_BITS words.
* (On a 32-bit machine, BITMAP_BITS is 30.)
* Objects allocated in this manner should be rarely referenced
* by objects not allocated either through this interface, or through
* the typed allocation interface.
* If this interface is used, we assume that type information provided
* through either this or the typed allocation interface is valid
* in a stronger sense:
*
* 1) No pointers are stored in fields not marked as such.
* (Otherwise it is only necessary that objects referenced by
* fields marked as nonpointers are also reachable via another
* path.)
* 2) Values stored in pointer fields are either not addresses in
* the heap, or they really are pointers. In the latter case, it
* is acceptable to move the object they refer to, and to update
* the pointer.
*
* GC_free may not be invoked on objects allocated with GC_copying_malloc.
*
* No extra space is added to the end of objects allocated through this
* interface. If the client needs to maintain pointers past the
* end, the size should be explicitly padded.
*
* We assume that calls to this will usually be compiler generated.
* Hence the interface is allowed to be a bit ugly in return for speed.
*/
#include "gc_copy_descr.h"
/* GC_copy_descr.h must define */
/* GC_SIZE_FROM_DESCRIPTOR(descr) and */
/* GC_BIT_MAP_FROM_DESCRIPTOR(descr). */
/* It may either be the GC supplied version of the header file, or a */
/* client specific one that derives the information from a client- */
/* specific type descriptor. */
typedef GC_PTR GC_copy_alloc_state;
/* Current allocator state. */
/* Multiple allocation states */
/* may be used for concurrent */
/* allocation, or to enhance */
/* locality. */
/* Should be treated as opaque. */
/* Allocate a memory block of size given in the descriptor, and with */
/* pointer layout given by the descriptor. The resulting block may not */
/* be cleared, and should immediately be initialized by the client. */
/* (A concurrent GC may see an uninitialized pointer field. If it */
/* points outside the nursery, that's fine. If it points inside, it */
/* may retain an object, and be relocated. But that's also fine, since */
/* the new value will be immediately overwritten. */
/* This variant acquires the allocation lock, and uses a default */
/* global allocation state. */
GC_PTR GC_copying_malloc(GC_copy_descriptor);
/* A variant of the above that does no locking on the fast path, */
/* and passes an explicit pointer to an allocation state. */
/* The allocation state is updated. */
/* There will eventually need to be a macro or inline function version */
/* of this. */
GC_PTR GC_copying_malloc2(GC_copy_descriptor, GC_copy_alloc_state *);
/* Initialize an allocation state so that it can be used for */
/* allocation. This implicitly reserves a small section of the */
/* nursery for use with this allocator. */
void GC_init_copy_alloc_state(GC_copy_alloc_state *);
......@@ -132,9 +132,14 @@ extern mse * GC_mark_stack;
*/
#endif /* PARALLEL_MARK */
ptr_t GC_find_start();
# ifdef PRINT_BLACK_LIST
ptr_t GC_find_start(ptr_t current, hdr *hhdr, word source);
# else
ptr_t GC_find_start(ptr_t current, hdr *hhdr);
# define source 0
# endif
mse * GC_signal_mark_stack_overflow();
mse *GC_signal_mark_stack_overflow(mse *msp);
# ifdef GATHERSTATS
# define ADD_TO_ATOMIC(sz) GC_atomic_in_use += (sz)
......@@ -245,7 +250,6 @@ exit_label2: ; \
# define SET_MARK_BIT_EXIT_IF_SET(hhdr,displ,exit_label) \
{ \
register word * mark_word_addr = hhdr -> hb_marks + divWORDSZ(displ); \
register word mark_word = *mark_word_addr; \
\
OR_WORD_EXIT_IF_SET(mark_word_addr, (word)1 << modWORDSZ(displ), \
exit_label); \
......
......@@ -25,13 +25,9 @@
* there too.
*/
# if defined(IRIX_THREADS) || defined(HPUX_THREADS)
# if defined(GC_IRIX_THREADS) || defined(IRIX_THREADS)
# if defined(HPUX_THREADS)
# include <sys/semaphore.h>
# endif
# include "gc_priv.h"
# include "private/gc_priv.h"
# include <pthread.h>
# include <semaphore.h>
# include <time.h>
......@@ -43,6 +39,7 @@
#undef pthread_create
#undef pthread_sigmask
#undef pthread_join
#undef pthread_detach
void GC_thr_init();
......@@ -208,6 +205,11 @@ void GC_stack_free(ptr_t stack, size_t size)
# define THREAD_TABLE_SZ 128 /* Must be power of 2 */
volatile GC_thread GC_threads[THREAD_TABLE_SZ];
void GC_push_thread_structures GC_PROTO((void))
{
GC_push_all((ptr_t)(GC_threads), (ptr_t)(GC_threads)+sizeof(GC_threads));
}
/* Add a thread to GC_threads. We assume it wasn't already there. */
/* Caller holds allocation lock. */
GC_thread GC_new_thread(pthread_t id)
......@@ -223,7 +225,7 @@ GC_thread GC_new_thread(pthread_t id)
/* Dont acquire allocation lock, since we may already hold it. */
} else {
result = (struct GC_Thread_Rep *)
GC_generic_malloc_inner(sizeof(struct GC_Thread_Rep), NORMAL);
GC_INTERNAL_MALLOC(sizeof(struct GC_Thread_Rep), NORMAL);
}
if (result == 0) return(0);
result -> id = id;
......@@ -503,10 +505,33 @@ int GC_pthread_join(pthread_t thread, void **retval)
/* Some versions of the Irix pthreads library can erroneously */
/* return EINTR when the call succeeds. */
if (EINTR == result) result = 0;
if (result == 0) {
LOCK();
/* Here the pthread thread id may have been recycled. */
GC_delete_gc_thread(thread, thread_gc_id);
UNLOCK();
}
return result;
}
int GC_pthread_detach(pthread_t thread)
{
int result;
GC_thread thread_gc_id;
LOCK();
/* Here the pthread thread id may have been recycled. */
GC_delete_gc_thread(thread, thread_gc_id);
thread_gc_id = GC_lookup_thread(thread);
UNLOCK();
result = REAL_FUNC(pthread_detach)(thread);
if (result == 0) {
LOCK();
thread_gc_id -> flags |= DETACHED;
/* Here the pthread thread id may have been recycled. */
if (thread_gc_id -> flags & FINISHED) {
GC_delete_gc_thread(thread, thread_gc_id);
}
UNLOCK();
}
return result;
}
......@@ -552,39 +577,7 @@ void * GC_start_routine(void * arg)
return(result);
}
# ifdef HPUX_THREADS
/* pthread_attr_t is not a structure, thus a simple structure copy */
/* won't work. */
static void copy_attr(pthread_attr_t * pa_ptr,
const pthread_attr_t * source) {
int tmp;
size_t stmp;
void * vtmp;
struct sched_param sp_tmp;
pthread_spu_t ps_tmp;
(void) pthread_attr_init(pa_ptr);
(void) pthread_attr_getdetachstate(source, &tmp);
(void) pthread_attr_setdetachstate(pa_ptr, tmp);
(void) pthread_attr_getinheritsched(source, &tmp);
(void) pthread_attr_setinheritsched(pa_ptr, tmp);
(void) pthread_attr_getschedpolicy(source, &tmp);
(void) pthread_attr_setschedpolicy(pa_ptr, tmp);
(void) pthread_attr_getstacksize(source, &stmp);
(void) pthread_attr_setstacksize(pa_ptr, stmp);
(void) pthread_attr_getguardsize(source, &stmp);
(void) pthread_attr_setguardsize(pa_ptr, stmp);
(void) pthread_attr_getstackaddr(source, &vtmp);
(void) pthread_attr_setstackaddr(pa_ptr, vtmp);
(void) pthread_attr_getscope(source, &tmp);
(void) pthread_attr_setscope(pa_ptr, tmp);
(void) pthread_attr_getschedparam(source, &sp_tmp);
(void) pthread_attr_setschedparam(pa_ptr, &sp_tmp);
(void) pthread_attr_getprocessor_np(source, &ps_tmp, &tmp);
(void) pthread_attr_setprocessor_np(pa_ptr, ps_tmp, tmp);
}
# else
# define copy_attr(pa_ptr, source) *(pa_ptr) = *(source)
# endif
# define copy_attr(pa_ptr, source) *(pa_ptr) = *(source)
int
GC_pthread_create(pthread_t *new_thread,
......@@ -650,14 +643,12 @@ GC_pthread_create(pthread_t *new_thread,
}
}
sem_destroy(&(si -> registered));
pthread_attr_destroy(&new_attr); /* Not a no-op under HPUX */
pthread_attr_destroy(&new_attr); /* Probably unnecessary under Irix */
return(result);
}
#ifndef HPUX_THREADS
/* For now we use the pthreads locking primitives on HP/UX */
GC_bool GC_collecting = 0; /* A hint that we're in the collector and */
VOLATILE GC_bool GC_collecting = 0;
/* A hint that we're in the collector and */
/* holding the allocation lock for an */
/* extended period. */
......@@ -666,15 +657,9 @@ GC_bool GC_collecting = 0; /* A hint that we're in the collector and */
#define SLEEP_THRESHOLD 3
#ifdef HPUX
unsigned long GC_allocate_lock = 1;
# define GC_TRY_LOCK() GC_test_and_clear(&GC_allocate_lock)
# define GC_LOCK_TAKEN !GC_allocate_lock
#else
unsigned long GC_allocate_lock = 0;
# define GC_TRY_LOCK() !GC_test_and_set(&GC_allocate_lock,1)
# define GC_LOCK_TAKEN GC_allocate_lock
#endif
unsigned long GC_allocate_lock = 0;
# define GC_TRY_LOCK() !GC_test_and_set(&GC_allocate_lock,1)
# define GC_LOCK_TAKEN GC_allocate_lock
void GC_lock()
{
......@@ -734,8 +719,6 @@ yield:
}
}
#endif /* !HPUX_THREADS */
# else
#ifndef LINT
......
......@@ -12,7 +12,7 @@
* modified is included with the above copyright notice.
*/
/* Boehm, November 17, 1995 12:13 pm PST */
# include "gc_priv.h"
# include "private/gc_priv.h"
# include <stdio.h>
# include <setjmp.h>
# if defined(OS2) || defined(CX_UX)
......@@ -21,7 +21,7 @@
# endif
# ifdef AMIGA
# ifndef __GNUC__
# include <dos/dos.h>
# include <dos.h>
# else
# include <machine/reg.h>
# endif
......@@ -178,7 +178,10 @@ void GC_push_regs()
# else /* !__GNUC__ */
GC_push_one(getreg(REG_A2));
GC_push_one(getreg(REG_A3));
GC_push_one(getreg(REG_A4));
# ifndef __SASC
/* Can probably be changed to #if 0 -Kjetil M. (a4=globals)*/
GC_push_one(getreg(REG_A4));
# endif
GC_push_one(getreg(REG_A5));
GC_push_one(getreg(REG_A6));
/* Skip stack pointer */
......@@ -220,8 +223,11 @@ void GC_push_regs()
# if defined(I386) &&!defined(OS2) &&!defined(SVR4) \
&& (defined(__MINGW32__) || !defined(MSWIN32)) \
&& !defined(SCO) && !defined(SCO_ELF) \
&& !(defined(LINUX) && defined(__ELF__)) \
&& !(defined(LINUX) && defined(__ELF__)) \
&& !(defined(FREEBSD) && defined(__ELF__)) \
&& !(defined(NETBSD) && defined(__ELF__)) \
&& !(defined(OPENBSD) && defined(__ELF__)) \
&& !(defined(BEOS) && defined(__ELF__)) \
&& !defined(DOS4GW)
/* I386 code, generic code does not appear to work */
/* It does appear to work under OS2, and asms dont */
......@@ -236,7 +242,9 @@ void GC_push_regs()
# endif
# if ( defined(I386) && defined(LINUX) && defined(__ELF__) ) \
|| ( defined(I386) && defined(FREEBSD) && defined(__ELF__) )
|| ( defined(I386) && defined(FREEBSD) && defined(__ELF__) ) \
|| ( defined(I386) && defined(NETBSD) && defined(__ELF__) ) \
|| ( defined(I386) && defined(OPENBSD) && defined(__ELF__) )
/* This is modified for Linux with ELF (Note: _ELF_ only) */
/* This section handles FreeBSD with ELF. */
......@@ -253,6 +261,17 @@ void GC_push_regs()
asm("pushl %ebx; call GC_push_one; addl $4,%esp");
# endif
# if ( defined(I386) && defined(BEOS) && defined(__ELF__) )
/* As far as I can understand from */
/* http://www.beunited.org/articles/jbq/nasm.shtml, */
/* only ebp, esi, edi and ebx are not scratch. How MMX */
/* etc. registers should be treated, I have no idea. */
asm("pushl %ebp; call GC_push_one; addl $4,%esp");
asm("pushl %esi; call GC_push_one; addl $4,%esp");
asm("pushl %edi; call GC_push_one; addl $4,%esp");
asm("pushl %ebx; call GC_push_one; addl $4,%esp");
# endif
# if defined(I386) && defined(MSWIN32) && !defined(__MINGW32__) \
&& !defined(USE_GENERIC)
/* I386 code, Microsoft variant */
......@@ -402,7 +421,8 @@ ptr_t cold_gc_frame;
for (; (char *)i < lim; i++) {
*i = 0;
}
# if defined(POWERPC) || defined(MSWIN32) || defined(UTS4) || defined(LINUX)
# if defined(POWERPC) || defined(MSWIN32) || defined(MSWINCE) \
|| defined(UTS4) || defined(LINUX)
(void) setjmp(regs);
# else
(void) _setjmp(regs);
......@@ -438,15 +458,15 @@ ptr_t cold_gc_frame;
asm("_GC_save_regs_in_stack:");
# endif
# if defined(__arch64__) || defined(__sparcv9)
asm(" save %sp,-128,%sp");
asm(" flushw");
asm(" ret");
asm(" restore %sp,2047+128,%o0");
asm(" save %sp,-128,%sp");
asm(" flushw");
asm(" ret");
asm(" restore %sp,2047+128,%o0");
# else
asm(" ta 0x3 ! ST_FLUSH_WINDOWS");
asm(" retl");
asm(" mov %sp,%o0");
#endif
asm(" ta 0x3 ! ST_FLUSH_WINDOWS");
asm(" retl");
asm(" mov %sp,%o0");
# endif
# ifdef SVR4
asm(" .GC_save_regs_in_stack_end:");
asm(" .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack");
......@@ -460,6 +480,7 @@ ptr_t cold_gc_frame;
/* up on the other side of the stack segment. */
/* Returns the backing store pointer for the register stack. */
# ifdef IA64
# ifdef __GNUC__
asm(" .text");
asm(" .psr abi64");
asm(" .psr lsb");
......@@ -476,6 +497,14 @@ ptr_t cold_gc_frame;
asm(" mov r8=ar.bsp");
asm(" br.ret.sptk.few rp");
asm(" .endp GC_save_regs_in_stack");
# else
void GC_save_regs_in_stack() {
asm(" flushrs");
asm(" ;;");
asm(" mov r8=ar.bsp");
asm(" br.ret.sptk.few rp");
}
# endif
# endif
/* GC_clear_stack_inner(arg, limit) clears stack area up to limit and */
......@@ -523,7 +552,7 @@ ptr_t cold_gc_frame;
asm("add %o3,-8,%o3"); /* p -= 8 (delay slot) */
asm("retl");
asm("mov %o2,%sp"); /* Restore sp., delay slot */
#endif
#endif /* old SPARC */
/* First argument = %o0 = return value */
# ifdef SVR4
asm(" .GC_clear_stack_inner_end:");
......
......@@ -11,9 +11,8 @@
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* Boehm, October 9, 1995 1:06 pm PDT */
# include <stdio.h>
# include "gc_priv.h"
# include "private/gc_priv.h"
/* Data structure for list of root sets. */
/* We keep a hash table, so that we can filter out duplicate additions. */
......@@ -23,7 +22,7 @@
struct roots {
ptr_t r_start;
ptr_t r_end;
# ifndef MSWIN32
# if !defined(MSWIN32) && !defined(MSWINCE)
struct roots * r_next;
# endif
GC_bool r_tmp;
......@@ -33,6 +32,8 @@ struct roots {
struct roots GC_static_roots[MAX_ROOT_SETS];
*/
int GC_no_dls = 0; /* Register dynamic library data segments. */
static int n_root_sets = 0;
/* GC_static_roots[0..n_root_sets) contains the valid root sets. */
......@@ -69,11 +70,12 @@ void GC_print_static_roots()
GC_bool GC_is_static_root(p)
ptr_t p;
{
static int last_root_set = 0;
static int last_root_set = MAX_ROOT_SETS;
register int i;
if (p >= GC_static_roots[last_root_set].r_start
if (last_root_set < n_root_sets
&& p >= GC_static_roots[last_root_set].r_start
&& p < GC_static_roots[last_root_set].r_end) return(TRUE);
for (i = 0; i < n_root_sets; i++) {
if (p >= GC_static_roots[i].r_start
......@@ -85,7 +87,7 @@ ptr_t p;
return(FALSE);
}
#ifndef MSWIN32
#if !defined(MSWIN32) && !defined(MSWINCE)
/*
# define LOG_RT_SIZE 6
# define RT_SIZE (1 << LOG_RT_SIZE) -- Power of 2, may be != MAX_ROOT_SETS
......@@ -137,7 +139,7 @@ struct roots *p;
GC_root_index[h] = p;
}
# else /* MSWIN32 */
# else /* MSWIN32 || MSWINCE */
# define add_roots_to_index(p)
......@@ -173,7 +175,7 @@ GC_bool tmp;
{
struct roots * old;
# ifdef MSWIN32
# if defined(MSWIN32) || defined(MSWINCE)
/* Spend the time to ensure that there are no overlapping */
/* or adjacent intervals. */
/* This could be done faster with e.g. a */
......@@ -242,7 +244,7 @@ GC_bool tmp;
GC_static_roots[n_root_sets].r_start = (ptr_t)b;
GC_static_roots[n_root_sets].r_end = (ptr_t)e;
GC_static_roots[n_root_sets].r_tmp = tmp;
# ifndef MSWIN32
# if !defined(MSWIN32) && !defined(MSWINCE)
GC_static_roots[n_root_sets].r_next = 0;
# endif
add_roots_to_index(GC_static_roots + n_root_sets);
......@@ -250,15 +252,18 @@ GC_bool tmp;
n_root_sets++;
}
static roots_were_cleared = FALSE;
void GC_clear_roots GC_PROTO((void))
{
DCL_LOCK_STATE;
DISABLE_SIGNALS();
LOCK();
roots_were_cleared = TRUE;
n_root_sets = 0;
GC_root_size = 0;
# ifndef MSWIN32
# if !defined(MSWIN32) && !defined(MSWINCE)
{
register int i;
......@@ -286,7 +291,7 @@ void GC_remove_tmp_roots()
i++;
}
}
# ifndef MSWIN32
# if !defined(MSWIN32) && !defined(MSWINCE)
{
register int i;
......@@ -298,11 +303,41 @@ void GC_remove_tmp_roots()
}
#if defined(MSWIN32) || defined(_WIN32_WCE_EMULATION)
/* Workaround for the OS mapping and unmapping behind our back: */
/* Is the address p in one of the temporary static root sections? */
GC_bool GC_is_tmp_root(p)
ptr_t p;
{
static int last_root_set = MAX_ROOT_SETS;
register int i;
if (last_root_set < n_root_sets
&& p >= GC_static_roots[last_root_set].r_start
&& p < GC_static_roots[last_root_set].r_end)
return GC_static_roots[last_root_set].r_tmp;
for (i = 0; i < n_root_sets; i++) {
if (p >= GC_static_roots[i].r_start
&& p < GC_static_roots[i].r_end) {
last_root_set = i;
return GC_static_roots[i].r_tmp;
}
}
return(FALSE);
}
#endif /* MSWIN32 || _WIN32_WCE_EMULATION */
ptr_t GC_approx_sp()
{
word dummy;
# ifdef _MSC_VER
# pragma warning(disable:4172)
# endif
return((ptr_t)(&dummy));
# ifdef _MSC_VER
# pragma warning(default:4172)
# endif
}
/*
......@@ -432,15 +467,15 @@ ptr_t cold_gc_frame;
/* Previously set to backing store pointer. */
ptr_t bsp = (ptr_t) GC_save_regs_ret_val;
ptr_t cold_gc_bs_pointer;
# ifdef ALL_INTERIOR_POINTERS
if (GC_all_interior_pointers) {
cold_gc_bs_pointer = bsp - 2048;
if (cold_gc_bs_pointer < BACKING_STORE_BASE) {
cold_gc_bs_pointer = BACKING_STORE_BASE;
}
GC_push_all(BACKING_STORE_BASE, cold_gc_bs_pointer);
# else
GC_push_all_stack(BACKING_STORE_BASE, cold_gc_bs_pointer);
} else {
cold_gc_bs_pointer = BACKING_STORE_BASE;
# endif
}
GC_push_all_eager(cold_gc_bs_pointer, bsp);
/* All values should be sufficiently aligned that we */
/* dont have to worry about the boundary. */
......@@ -454,6 +489,19 @@ ptr_t cold_gc_frame;
}
/*
* Push GC internal roots. Only called if there is some reason to believe
* these would not otherwise get registered.
*/
void GC_push_gc_structures GC_PROTO((void))
{
GC_push_finalizer_structures();
GC_push_stubborn_structures();
# if defined(THREADS)
GC_push_thread_structures();
# endif
}
/*
* Call the mark routines (GC_tl_push for a single pointer, GC_push_conditional
* on groups of pointers) on every top level accessible pointer.
* If all is FALSE, arrange to push only possibly altered values.
......@@ -483,11 +531,14 @@ ptr_t cold_gc_frame;
* not robust against mark stack overflow.
*/
/* Reregister dynamic libraries, in case one got added. */
# if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(PCR)) \
&& !defined(SRC_M3)
# if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(MSWINCE) \
|| defined(PCR)) && !defined(SRC_M3)
GC_remove_tmp_roots();
GC_register_dynamic_libraries();
if (!GC_no_dls) GC_register_dynamic_libraries();
# else
GC_no_dls = TRUE;
# endif
/* Mark everything in static data areas */
for (i = 0; i < n_root_sets; i++) {
GC_push_conditional_with_exclusions(
......@@ -495,6 +546,12 @@ ptr_t cold_gc_frame;
GC_static_roots[i].r_end, all);
}
/* Mark from GC internal roots if those might otherwise have */
/* been excluded. */
if (GC_no_dls || roots_were_cleared) {
GC_push_gc_structures();
}
/*
* Now traverse stacks.
*/
......
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 2000 by Hewlett-Packard Company. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
......@@ -19,7 +20,7 @@
# include <stdio.h>
# include "gc_priv.h"
# include "private/gc_priv.h"
#ifndef SMALL_CONFIG
/*
......@@ -30,7 +31,7 @@ ptr_t GC_build_fl1(h, ofl)
struct hblk *h;
ptr_t ofl;
{
register word * p = (word *)h;
register word * p = h -> hb_body;
register word * lim = (word *)(h + 1);
p[0] = (word)ofl;
......@@ -52,7 +53,7 @@ ptr_t GC_build_fl_clear2(h, ofl)
struct hblk *h;
ptr_t ofl;
{
register word * p = (word *)h;
register word * p = h -> hb_body;
register word * lim = (word *)(h + 1);
p[0] = (word)ofl;
......@@ -74,7 +75,7 @@ ptr_t GC_build_fl_clear3(h, ofl)
struct hblk *h;
ptr_t ofl;
{
register word * p = (word *)h;
register word * p = h -> hb_body;
register word * lim = (word *)(h + 1) - 2;
p[0] = (word)ofl;
......@@ -94,7 +95,7 @@ ptr_t GC_build_fl_clear4(h, ofl)
struct hblk *h;
ptr_t ofl;
{
register word * p = (word *)h;
register word * p = h -> hb_body;
register word * lim = (word *)(h + 1);
p[0] = (word)ofl;
......@@ -116,7 +117,7 @@ ptr_t GC_build_fl2(h, ofl)
struct hblk *h;
ptr_t ofl;
{
register word * p = (word *)h;
register word * p = h -> hb_body;
register word * lim = (word *)(h + 1);
p[0] = (word)ofl;
......@@ -134,7 +135,7 @@ ptr_t GC_build_fl4(h, ofl)
struct hblk *h;
ptr_t ofl;
{
register word * p = (word *)h;
register word * p = h -> hb_body;
register word * lim = (word *)(h + 1);
p[0] = (word)ofl;
......@@ -150,71 +151,51 @@ ptr_t ofl;
#endif /* !SMALL_CONFIG */
/*
* Allocate a new heapblock for small objects of size n.
* Add all of the heapblock's objects to the free list for objects
* of that size.
* Set all mark bits if objects are uncollectable.
* Will fail to do anything if we are out of memory.
*/
void GC_new_hblk(sz, kind)
register word sz;
int kind;
{
register word *p,
*prev;
word *last_object; /* points to last object in new hblk */
register struct hblk *h; /* the new heap block */
register GC_bool clear = GC_obj_kinds[kind].ok_init;
# ifdef PRINTSTATS
if ((sizeof (struct hblk)) > HBLKSIZE) {
ABORT("HBLK SZ inconsistency");
}
# endif
/* Allocate a new heap block */
h = GC_allochblk(sz, kind, 0);
if (h == 0) return;
/* Mark all objects if appropriate. */
if (IS_UNCOLLECTABLE(kind)) GC_set_hdr_marks(HDR(h));
/* Build a free list for objects of size sz inside heap block h. */
/* Clear objects inside h if clear is set. Add list to the end of */
/* the free list we build. Return the new free list. */
/* This could be called without the main GC lock, if we ensure that */
/* there is no concurrent collection which might reclaim objects that */
/* we have not yet allocated. */
ptr_t GC_build_fl(h, sz, clear, list)
struct hblk *h;
word sz;
GC_bool clear;
ptr_t list;
{
word *p, *prev;
word *last_object; /* points to last object in new hblk */
PREFETCH_FOR_WRITE((char *)h);
PREFETCH_FOR_WRITE((char *)h + 128);
PREFETCH_FOR_WRITE((char *)h + 256);
PREFETCH_FOR_WRITE((char *)h + 378);
/* Do a few prefetches here, just because its cheap. */
/* If we were more serious about it, these should go inside */
/* the loops. But write prefetches usually don't seem to */
/* matter much. */
PREFETCH_FOR_WRITE((char *)h);
PREFETCH_FOR_WRITE((char *)h + 128);
PREFETCH_FOR_WRITE((char *)h + 256);
PREFETCH_FOR_WRITE((char *)h + 378);
/* Handle small objects sizes more efficiently. For larger objects */
/* the difference is less significant. */
# ifndef SMALL_CONFIG
switch (sz) {
case 1: GC_obj_kinds[kind].ok_freelist[1] =
GC_build_fl1(h, GC_obj_kinds[kind].ok_freelist[1]);
return;
case 1: return GC_build_fl1(h, list);
case 2: if (clear) {
GC_obj_kinds[kind].ok_freelist[2] =
GC_build_fl_clear2(h, GC_obj_kinds[kind].ok_freelist[2]);
return GC_build_fl_clear2(h, list);
} else {
GC_obj_kinds[kind].ok_freelist[2] =
GC_build_fl2(h, GC_obj_kinds[kind].ok_freelist[2]);
return GC_build_fl2(h, list);
}
return;
case 3: if (clear) {
GC_obj_kinds[kind].ok_freelist[3] =
GC_build_fl_clear3(h, GC_obj_kinds[kind].ok_freelist[3]);
return;
return GC_build_fl_clear3(h, list);
} else {
/* It's messy to do better than the default here. */
break;
}
case 4: if (clear) {
GC_obj_kinds[kind].ok_freelist[4] =
GC_build_fl_clear4(h, GC_obj_kinds[kind].ok_freelist[4]);
return GC_build_fl_clear4(h, list);
} else {
GC_obj_kinds[kind].ok_freelist[4] =
GC_build_fl4(h, GC_obj_kinds[kind].ok_freelist[4]);
return GC_build_fl4(h, list);
}
return;
default:
break;
}
......@@ -243,7 +224,39 @@ int kind;
* put p (which is now head of list of objects in *h) as first
* pointer in the appropriate free list for this size.
*/
obj_link(h -> hb_body) = GC_obj_kinds[kind].ok_freelist[sz];
GC_obj_kinds[kind].ok_freelist[sz] = ((ptr_t)p);
obj_link(h -> hb_body) = list;
return ((ptr_t)p);
}
/*
* Allocate a new heapblock for small objects of size n.
* Add all of the heapblock's objects to the free list for objects
* of that size.
* Set all mark bits if objects are uncollectable.
* Will fail to do anything if we are out of memory.
*/
void GC_new_hblk(sz, kind)
register word sz;
int kind;
{
register struct hblk *h; /* the new heap block */
register GC_bool clear = GC_obj_kinds[kind].ok_init;
# ifdef PRINTSTATS
if ((sizeof (struct hblk)) > HBLKSIZE) {
ABORT("HBLK SZ inconsistency");
}
# endif
/* Allocate a new heap block */
h = GC_allochblk(sz, kind, 0);
if (h == 0) return;
/* Mark all objects if appropriate. */
if (IS_UNCOLLECTABLE(kind)) GC_set_hdr_marks(HDR(h));
/* Build the free list */
GC_obj_kinds[kind].ok_freelist[sz] =
GC_build_fl(h, sz, clear, GC_obj_kinds[kind].ok_freelist[sz]);
}
/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991, 1992 by Xerox Corporation. All rights reserved.
* Copyright (c) 1999-2001 by Hewlett-Packard Company. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
......@@ -11,7 +12,6 @@
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* Boehm, October 9, 1995 1:09 pm PDT */
/* Routines for maintaining maps describing heap block
* layouts for various object sizes. Allows fast pointer validity checks
......@@ -19,9 +19,9 @@
* with slow division.
*/
# include "gc_priv.h"
# include "private/gc_priv.h"
char * GC_invalid_map = 0;
map_entry_type * GC_invalid_map = 0;
/* Invalidate the object map associated with a block. Free blocks */
/* are identified by invalid maps. */
......@@ -31,7 +31,7 @@ hdr *hhdr;
register int displ;
if (GC_invalid_map == 0) {
GC_invalid_map = GC_scratch_alloc(MAP_SIZE);
GC_invalid_map = (map_entry_type *)GC_scratch_alloc(MAP_SIZE);
if (GC_invalid_map == 0) {
GC_err_printf0(
"Cant initialize GC_invalid_map: insufficient memory\n");
......@@ -54,7 +54,6 @@ hdr *hhdr;
GC_word offset;
# endif
{
# ifndef ALL_INTERIOR_POINTERS
DCL_LOCK_STATE;
DISABLE_SIGNALS();
......@@ -62,39 +61,40 @@ hdr *hhdr;
GC_register_displacement_inner(offset);
UNLOCK();
ENABLE_SIGNALS();
# endif
}
void GC_register_displacement_inner(offset)
word offset;
{
# ifndef ALL_INTERIOR_POINTERS
register unsigned i;
word map_entry = BYTES_TO_WORDS(offset);
if (offset > MAX_OFFSET) {
if (offset >= VALID_OFFSET_SZ) {
ABORT("Bad argument to GC_register_displacement");
}
if (map_entry > MAX_OFFSET) map_entry = OFFSET_TOO_BIG;
if (!GC_valid_offsets[offset]) {
GC_valid_offsets[offset] = TRUE;
GC_modws_valid_offsets[offset % sizeof(word)] = TRUE;
for (i = 0; i <= MAXOBJSZ; i++) {
if (!GC_all_interior_pointers) {
for (i = 0; i <= MAXOBJSZ; i++) {
if (GC_obj_map[i] != 0) {
if (i == 0) {
GC_obj_map[i][offset + HDR_BYTES] = (char)BYTES_TO_WORDS(offset);
GC_obj_map[i][offset] = (map_entry_type)map_entry;
} else {
register unsigned j;
register unsigned lb = WORDS_TO_BYTES(i);
if (offset < lb) {
for (j = offset + HDR_BYTES; j < HBLKSIZE; j += lb) {
GC_obj_map[i][j] = (char)BYTES_TO_WORDS(offset);
for (j = offset; j < HBLKSIZE; j += lb) {
GC_obj_map[i][j] = (map_entry_type)map_entry;
}
}
}
}
}
}
}
# endif
}
......@@ -105,13 +105,14 @@ word sz;
{
register unsigned obj_start;
register unsigned displ;
register char * new_map;
register map_entry_type * new_map;
word map_entry;
if (sz > MAXOBJSZ) sz = 0;
if (GC_obj_map[sz] != 0) {
return(TRUE);
}
new_map = GC_scratch_alloc(MAP_SIZE);
new_map = (map_entry_type *)GC_scratch_alloc(MAP_SIZE);
if (new_map == 0) return(FALSE);
# ifdef PRINTSTATS
GC_printf1("Adding block map for size %lu\n", (unsigned long)sz);
......@@ -120,19 +121,23 @@ word sz;
MAP_ENTRY(new_map,displ) = OBJ_INVALID;
}
if (sz == 0) {
for(displ = 0; displ <= MAX_OFFSET; displ++) {
for(displ = 0; displ <= HBLKSIZE; displ++) {
if (OFFSET_VALID(displ)) {
MAP_ENTRY(new_map,displ+HDR_BYTES) = BYTES_TO_WORDS(displ);
map_entry = BYTES_TO_WORDS(displ);
if (map_entry > MAX_OFFSET) map_entry = OFFSET_TOO_BIG;
MAP_ENTRY(new_map,displ) = (map_entry_type)map_entry;
}
}
} else {
for (obj_start = HDR_BYTES;
for (obj_start = 0;
obj_start + WORDS_TO_BYTES(sz) <= HBLKSIZE;
obj_start += WORDS_TO_BYTES(sz)) {
for (displ = 0; displ < WORDS_TO_BYTES(sz); displ++) {
if (OFFSET_VALID(displ)) {
map_entry = BYTES_TO_WORDS(displ);
if (map_entry > MAX_OFFSET) map_entry = OFFSET_TOO_BIG;
MAP_ENTRY(new_map, obj_start + displ) =
BYTES_TO_WORDS(displ);
(map_entry_type)map_entry;
}
}
}
......
solaris_threads.c
solaris_pthreads.c
irix_threads.c
pcr_interface.c
real_malloc.c
mips_mach_dep.s
......@@ -8,8 +10,12 @@ sparc_mach_dep.s
PCR-Makefile
setjmp_t.c
callprocs
gc.man
doc/gc.man
pc_excludes
barrett_diagram
include/gc_c++.h
include/gc_inline.h
\ No newline at end of file
include/gc_inline.h
doc/README.hp
doc/README.rs6000
doc/README.sgi
......@@ -10,8 +10,7 @@
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* Boehm, February 7, 1996 11:09 am PST */
# include "gc_priv.h"
# include "private/gc_priv.h"
# ifdef PCR
/*
......@@ -170,4 +169,10 @@ PCR_GC_Run(void)
return PCR_ERes_okay;
}
void GC_push_thread_structures(void)
{
/* PCR doesn't work unless static roots are pushed. Can't get here. */
ABORT("In GC_push_thread_structures()");
}
# endif
......@@ -10,10 +10,13 @@
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* Boehm, September 19, 1995 1:26 pm PDT */
#include "gc_priv.h"
#include "gc_mark.h"
/*
* These are checking routines calls to which could be inserted by a
* preprocessor to validate C pointer arithmetic.
*/
#include "private/gc_pmark.h"
#ifdef __STDC__
void GC_default_same_obj_print_proc(GC_PTR p, GC_PTR q)
......@@ -69,7 +72,7 @@ void (*GC_same_obj_print_proc) GC_PROTO((GC_PTR, GC_PTR))
h = FORWARDED_ADDR(h, hhdr);
hhdr = HDR(h);
}
limit = (ptr_t)((word *)h + HDR_WORDS + hhdr -> hb_sz);
limit = (ptr_t)((word *)h + hhdr -> hb_sz);
if ((ptr_t)p >= limit || (ptr_t)q >= limit || (ptr_t)q < (ptr_t)h ) {
goto fail;
}
......@@ -83,28 +86,19 @@ void (*GC_same_obj_print_proc) GC_PROTO((GC_PTR, GC_PTR))
goto fail;
}
} else {
# ifdef ALL_INTERIOR_POINTERS
register map_entry_type map_entry;
register int pdispl;
pdispl = HBLKDISPL(p);
map_entry = MAP_ENTRY((hhdr -> hb_map), pdispl);
if (map_entry == OBJ_INVALID) {
goto fail;
} else {
base = (char *)((word)p & ~(WORDS_TO_BYTES(1) - 1));
base -= WORDS_TO_BYTES(map_entry);
}
# else
register int offset = HBLKDISPL(p) - HDR_BYTES;
register word correction = offset % sz;
if (HBLKPTR(p) != HBLKPTR(q)) {
/* The following computation otherwise fails in this case */
goto fail;
}
base = (ptr_t)p - correction;
# endif
register int map_entry;
register int pdispl = HBLKDISPL(p);
map_entry = MAP_ENTRY((hhdr -> hb_map), pdispl);
if (map_entry > CPP_MAX_OFFSET) {
map_entry = BYTES_TO_WORDS(pdispl) % BYTES_TO_WORDS(sz);
if (HBLKPTR(p) != HBLKPTR(q)) goto fail;
/* W/o this check, we might miss an error if */
/* q points to the first object on a page, and */
/* points just before the page. */
}
base = (char *)((word)p & ~(WORDS_TO_BYTES(1) - 1));
base -= WORDS_TO_BYTES(map_entry);
limit = base + sz;
}
/* [base, limit) delimits the object containing p, if any. */
......@@ -137,7 +131,7 @@ void (*GC_is_valid_displacement_print_proc) GC_PROTO((GC_PTR)) =
/* Check that if p is a pointer to a heap page, then it points to */
/* a valid displacement within a heap object. */
/* Uninteresting with ALL_INTERIOR_POINTERS. */
/* Uninteresting with GC_all_interior_pointers. */
/* Always returns its argument. */
/* Note that we don't lock, since nothing relevant about the header */
/* should change while we have a valid object pointer to the block. */
......@@ -158,12 +152,12 @@ void (*GC_is_valid_displacement_print_proc) GC_PROTO((GC_PTR)) =
hhdr = HDR((word)p);
if (hhdr == 0) return(p);
h = HBLKPTR(p);
# ifdef ALL_INTERIOR_POINTERS
if (GC_all_interior_pointers) {
while (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
h = FORWARDED_ADDR(h, hhdr);
hhdr = HDR(h);
}
# endif
}
if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
goto fail;
}
......@@ -252,7 +246,8 @@ ptr_t p;
if (GC_is_static_root(p)) return(p);
/* Else do it again correctly: */
# if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || defined(PCR)) \
# if (defined(DYNAMIC_LOADING) || defined(MSWIN32) || \
defined(MSWINCE) || defined(PCR)) \
&& !defined(SRC_M3)
DISABLE_SIGNALS();
GC_register_dynamic_libraries();
......@@ -270,23 +265,30 @@ ptr_t p;
if (HBLKPTR(base) != HBLKPTR(p)) hhdr = HDR((word)p);
descr = hhdr -> hb_descr;
retry:
switch(descr & DS_TAGS) {
case DS_LENGTH:
switch(descr & GC_DS_TAGS) {
case GC_DS_LENGTH:
if ((word)((ptr_t)p - (ptr_t)base) > (word)descr) goto fail;
break;
case DS_BITMAP:
case GC_DS_BITMAP:
if ((ptr_t)p - (ptr_t)base
>= WORDS_TO_BYTES(BITMAP_BITS)
|| ((word)p & (sizeof(word) - 1))) goto fail;
if (!((1 << (WORDSZ - ((ptr_t)p - (ptr_t)base) - 1))
& descr)) goto fail;
break;
case DS_PROC:
case GC_DS_PROC:
/* We could try to decipher this partially. */
/* For now we just punt. */
break;
case DS_PER_OBJECT:
descr = *(word *)((ptr_t)base + (descr & ~DS_TAGS));
case GC_DS_PER_OBJECT:
if ((signed_word)descr >= 0) {
descr = *(word *)((ptr_t)base + (descr & ~GC_DS_TAGS));
} else {
ptr_t type_descr = *(ptr_t *)base;
descr = *(word *)(type_descr
- (descr - (GC_DS_PER_OBJECT
- GC_INDIR_PER_OBJ_BIAS)));
}
goto retry;
}
return(p);
......@@ -305,9 +307,9 @@ size_t how_much;
GC_PTR initial = *p;
GC_PTR result = GC_same_obj((GC_PTR)((word)initial + how_much), initial);
# ifndef ALL_INTERIOR_POINTERS
if (!GC_all_interior_pointers) {
(void) GC_is_valid_displacement(result);
# endif
}
return (*p = result);
}
......@@ -318,9 +320,9 @@ size_t how_much;
GC_PTR initial = *p;
GC_PTR result = GC_same_obj((GC_PTR)((word)initial + how_much), initial);
# ifndef ALL_INTERIOR_POINTERS
if (!GC_all_interior_pointers) {
(void) GC_is_valid_displacement(result);
# endif
}
*p = result;
return(initial);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment