|
Packit |
d28291 |
The collector has at various times been compiled under Windows 95 & later, NT,
|
|
Packit |
d28291 |
and XP, with the original Microsoft SDK, with Visual C++ 2.0, 4.0, and 6, with
|
|
Packit |
d28291 |
the GNU win32 tools, with Borland 4.5, with Watcom C, and recently
|
|
Packit |
d28291 |
with the Digital Mars compiler. It is likely that some of these have been
|
|
Packit |
d28291 |
broken in the meantime. Patches are appreciated.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
For historical reasons,
|
|
Packit |
d28291 |
the collector test program "gctest" is linked as a GUI application,
|
|
Packit |
d28291 |
but does not open any windows. Its output normally appears in the file
|
|
Packit |
d28291 |
"gctest.gc.log". It may be started from the file manager. The hour glass
|
|
Packit |
d28291 |
cursor may appear as long as it's running. If it is started from the
|
|
Packit |
d28291 |
command line, it will usually run in the background. Wait a few
|
|
Packit |
d28291 |
minutes (a few seconds on a modern machine) before you check the output.
|
|
Packit |
d28291 |
You should see either a failure indication or a "Collector appears to
|
|
Packit |
d28291 |
work" message.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
The cord test program has not been ported (but should port
|
|
Packit |
d28291 |
easily). A toy editor (cord/de.exe) based on cords (heavyweight
|
|
Packit |
d28291 |
strings represented as trees) has been ported and is included.
|
|
Packit |
d28291 |
It runs fine under either win32 or win32S. It serves as an example
|
|
Packit |
d28291 |
of a true Windows application, except that it was written by a
|
|
Packit |
d28291 |
nonexpert Windows programmer. (There are some peculiarities
|
|
Packit |
d28291 |
in the way files are displayed. The <cr> is displayed explicitly
|
|
Packit |
d28291 |
for standard DOS text files. As in the UNIX version, control
|
|
Packit |
d28291 |
characters are displayed explicitly, but in this case as red text.
|
|
Packit |
d28291 |
This may be suboptimal for some tastes and/or sets of default
|
|
Packit |
d28291 |
window colors.)
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
In general -DREDIRECT_MALLOC is unlikely to work unless the
|
|
Packit |
d28291 |
application is completely statically linked.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
The collector normally allocates memory from the OS with VirtualAlloc.
|
|
Packit |
d28291 |
This appears to cause problems under Windows NT and Windows 2000 (but
|
|
Packit |
d28291 |
not Windows 95/98) if the memory is later passed to CreateDIBitmap.
|
|
Packit |
d28291 |
To work around this problem, build the collector with -DUSE_GLOBAL_ALLOC.
|
|
Packit |
d28291 |
This is currently incompatible with -DUSE_MUNMAP. (Thanks to Jonathan
|
|
Packit |
d28291 |
Clark for tracking this down. There's some chance this may be fixed
|
|
Packit |
d28291 |
in 6.1alpha4, since we now separate heap sections with an unused page.)
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
[Threads and incremental collection are discussed near the end, below.]
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Microsoft Tools
|
|
Packit |
d28291 |
---------------
|
|
Packit |
d28291 |
For Microsoft development tools, rename NT_MAKEFILE as
|
|
Packit |
d28291 |
MAKEFILE. (Make sure that the CPU environment variable is defined
|
|
Packit |
d28291 |
to be i386.) In order to use the gc_cpp.h C++ interface, all
|
|
Packit |
d28291 |
client code should include gc_cpp.h.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
For historical reasons,
|
|
Packit |
d28291 |
the collector test program "gctest" is linked as a GUI application,
|
|
Packit |
d28291 |
but does not open any windows. Its output appears in the file
|
|
Packit |
d28291 |
"gctest.gc.log". It may be started from the file manager. The hour glass
|
|
Packit |
d28291 |
cursor may appear as long as it's running. If it is started from the
|
|
Packit |
d28291 |
command line, it will usually run in the background. Wait a few
|
|
Packit |
d28291 |
minutes (a few seconds on a modern machine) before you check the output.
|
|
Packit |
d28291 |
You should see either a failure indication or a "Collector appears to
|
|
Packit |
d28291 |
work" message.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
If you would prefer a VC++ .NET project file, ask Hans Boehm. One has
|
|
Packit |
d28291 |
been contributed, but it seems to contain some absolute paths etc., so
|
|
Packit |
d28291 |
it can presumably only be a starting point, and is not in the standard
|
|
Packit |
d28291 |
distribution. It is unclear (to me, Hans Boehm) whether it is feasible to
|
|
Packit |
d28291 |
change that.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Clients may need to define GC_NOT_DLL before including gc.h, if the
|
|
Packit |
d28291 |
collector was built as a static library (as it normally is in the
|
|
Packit |
d28291 |
absence of thread support).
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
GNU Tools
|
|
Packit |
d28291 |
---------
|
|
Packit |
d28291 |
The collector should be buildable under Cygwin with the
|
|
Packit |
d28291 |
"./configure; make check" machinery.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
MinGW builds (including for x86_64) are available via cross-compilation, e.g.
|
|
Packit |
d28291 |
"./configure --host=i686-pc-mingw32; make check"
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
To build the collector as a DLL, pass "--enable-shared --disable-static" to
|
|
Packit |
d28291 |
configure (this will instruct make compile with -D GC_DLL).
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Parallel marker could be enabled via "--enable-parallel-mark".
|
|
Packit |
d28291 |
Memory unmapping could be enabled via "--enable-munmap".
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Borland Tools
|
|
Packit |
d28291 |
-------------
|
|
Packit |
d28291 |
[Rarely tested.]
|
|
Packit |
d28291 |
For Borland tools, use BCC_MAKEFILE. Note that
|
|
Packit |
d28291 |
Borland's compiler defaults to 1 byte alignment in structures (-a1),
|
|
Packit |
d28291 |
whereas Visual C++ appears to default to 8 byte alignment (/Zp8).
|
|
Packit |
d28291 |
The garbage collector in its default configuration EXPECTS AT
|
|
Packit |
d28291 |
LEAST 4 BYTE ALIGNMENT. Thus the BORLAND DEFAULT MUST
|
|
Packit |
d28291 |
BE OVERRIDDEN. (In my opinion, it should usually be anyway.
|
|
Packit |
d28291 |
I expect that -a1 introduces major performance penalties on a
|
|
Packit |
d28291 |
486 or Pentium.) Note that this changes structure layouts. (As a last
|
|
Packit |
d28291 |
resort, gcconfig.h can be changed to allow 1 byte alignment. But
|
|
Packit |
d28291 |
this has significant negative performance implications.)
|
|
Packit |
d28291 |
The Makefile is set up to assume Borland 4.5. If you have another
|
|
Packit |
d28291 |
version, change the line near the top. By default, it does not
|
|
Packit |
d28291 |
require the assembler. If you do have the assembler, I recommend
|
|
Packit |
d28291 |
removing the -DUSE_GENERIC.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Digital Mars compiler
|
|
Packit |
d28291 |
---------------------
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Same as MS Visual C++ but might require
|
|
Packit |
d28291 |
-DAO_OLD_STYLE_INTERLOCKED_COMPARE_EXCHANGE option to compile with the
|
|
Packit |
d28291 |
parallel marker enabled.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Watcom compiler
|
|
Packit |
d28291 |
---------------
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Ivan V. Demakov's README for the Watcom port:
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
The collector has been compiled with Watcom C 10.6 and 11.0.
|
|
Packit |
d28291 |
It runs under win32, win32s, and even under msdos with dos4gw
|
|
Packit |
d28291 |
dos-extender. It should also run under OS/2, though this isn't
|
|
Packit |
d28291 |
tested. Under win32 the collector can be built either as dll
|
|
Packit |
d28291 |
or as static library.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Note that all compilations were done under Windows 95 or NT.
|
|
Packit |
d28291 |
For unknown reason compiling under Windows 3.11 for NT (one
|
|
Packit |
d28291 |
attempt has been made) leads to broken executables.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Incremental collection is not supported.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
cord is not ported.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Before compiling you may need to edit WCC_MAKEFILE to set target
|
|
Packit |
d28291 |
platform, library type (dynamic or static), calling conventions, and
|
|
Packit |
d28291 |
optimization options.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
To compile the collector and testing programs use the command:
|
|
Packit |
d28291 |
wmake -f WCC_MAKEFILE
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
All programs using gc should be compiled with 4-byte alignment.
|
|
Packit |
d28291 |
For further explanations on this see comments about Borland.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
If the gc is compiled as dll, the macro "GC_DLL" should be defined before
|
|
Packit |
d28291 |
including "gc.h" (for example, with -DGC_DLL compiler option). It's
|
|
Packit |
d28291 |
important, otherwise resulting programs will not run.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Special note for OpenWatcom users: the C (unlike the C++) compiler (of the
|
|
Packit |
d28291 |
latest stable release, not sure for older ones) doesn't force pointer global
|
|
Packit |
d28291 |
variables (i.e. not struct fields, not sure for locals) to be aligned unless
|
|
Packit |
d28291 |
optimizing for speed (e.g., "-ot" option is set); the "-zp" option (or align
|
|
Packit |
d28291 |
pragma) only controls alignment for structs; I don't know whether it's a bug or
|
|
Packit |
d28291 |
a feature (see an old report of same kind -
|
|
Packit |
d28291 |
http://bugzilla.openwatcom.org/show_bug.cgi?id=664), so You are warned.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Incremental Collection
|
|
Packit |
d28291 |
----------------------
|
|
Packit |
d28291 |
There is some support for incremental collection. By default, the
|
|
Packit |
d28291 |
collector chooses between explicit page protection, and GetWriteWatch-based
|
|
Packit |
d28291 |
write tracking automatically, depending on the platform.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
The former is slow and interacts poorly with a debugger.
|
|
Packit |
d28291 |
Pages are protected. Protection faults are caught by a handler
|
|
Packit |
d28291 |
installed at the bottom of the handler
|
|
Packit |
d28291 |
stack. Whenever possible, I recommend adding a call to
|
|
Packit |
d28291 |
GC_enable_incremental at the last possible moment, after most
|
|
Packit |
d28291 |
debugging is complete. No system
|
|
Packit |
d28291 |
calls are wrapped by the collector itself. It may be necessary
|
|
Packit |
d28291 |
to wrap ReadFile calls that use a buffer in the heap, so that the
|
|
Packit |
d28291 |
call does not encounter a protection fault while it's running.
|
|
Packit |
d28291 |
(As usual, none of this is an issue unless GC_enable_incremental
|
|
Packit |
d28291 |
is called.)
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Note that incremental collection is disabled with -DSMALL_CONFIG.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Threads
|
|
Packit |
d28291 |
-------
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
This version of the collector by default handles threads similarly
|
|
Packit |
d28291 |
to other platforms. James Clark's code which tracks threads attached
|
|
Packit |
d28291 |
to the collector DLL still exists, but requires that both
|
|
Packit |
d28291 |
- the collector is built in a DLL with GC_DLL defined, and
|
|
Packit |
d28291 |
- GC_use_threads_discovery() is called before GC initialization, which
|
|
Packit |
d28291 |
in turn must happen before creating additional threads.
|
|
Packit |
d28291 |
We generally recommend avoiding this if possible, since it seems to
|
|
Packit |
d28291 |
be less than 100% reliable.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Use gc.mak (a.k.a NT_THREADS_MAKEFILE) instead of NT_MAKEFILE
|
|
Packit |
d28291 |
to build a version that supports both kinds of thread tracking.
|
|
Packit |
d28291 |
To build the garbage collector
|
|
Packit |
d28291 |
test with VC++ from the command line, use
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
nmake /F ".\gc.mak" CFG="gctest - Win32 Release"
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
This requires that the subdirectory gctest\Release exist.
|
|
Packit |
d28291 |
The test program and DLL will reside in the Release directory.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
This version currently supports incremental collection only if it is
|
|
Packit |
d28291 |
enabled before any additional threads are created.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Since 6.3alpha2, threads are also better supported in static library builds
|
|
Packit |
d28291 |
with Microsoft tools (use NT_STATIC_THREADS_MAKEFILE) and with the GNU
|
|
Packit |
d28291 |
tools. The collector must be built with GC_THREADS defined.
|
|
Packit |
d28291 |
(NT_STATIC_THREADS_MAKEFILE does this implicitly. Under Cygwin,
|
|
Packit |
d28291 |
./configure --enable-threads=posix should be used.)
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
For the normal, non-dll-based thread tracking to work properly,
|
|
Packit |
d28291 |
threads should be created with GC_CreateThread or GC_beginthreadex,
|
|
Packit |
d28291 |
and exit normally or call GC_endthreadex or GC_ExitThread. (For
|
|
Packit |
d28291 |
Cygwin, use standard pthread calls instead.) As in the pthread
|
|
Packit |
d28291 |
case, including gc.h will redefine CreateThread, _beginthreadex,
|
|
Packit |
d28291 |
_endthreadex, and ExitThread to call the GC_ versions instead.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
Note that, as usual, GC_CreateThread tends to introduce resource leaks
|
|
Packit |
d28291 |
that are avoided by GC_beginthreadex. There is currently no equivalent of
|
|
Packit |
d28291 |
_beginthread, and it should not be used.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
GC_INIT should be called from the main executable before other GC calls.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
We strongly advise against using the TerminateThread() win32 API call,
|
|
Packit |
d28291 |
especially with the garbage collector. Any use is likely to provoke a
|
|
Packit |
d28291 |
crash in the GC, since it makes it impossible for the collector to
|
|
Packit |
d28291 |
correctly track threads.
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
To build the collector for MinGW pthreads-win32 (or other non-Cygwin pthreads
|
|
Packit |
d28291 |
implementation for Windows), use Makefile.direct and explicitly set
|
|
Packit |
d28291 |
GC_WIN32_PTHREADS (or pass --enable-threads=pthreads to configure).
|
|
Packit |
d28291 |
Use -DPTW32_STATIC_LIB for the static threads library.
|