Debian Codegraph @

gc/doc/README.amiga

raw
1 Kjetil S. Matheussen's notes (28-11-2000)
2
3 Compiles under SAS/C again. Should also still compile under other
4 Amiga compilers without big changes. I haven't checked if it still
5 works under gcc, because I don't have gcc for Amiga. But I have
6 updated 'Makefile', and hope it compiles fine.
7
8
9 WHATS NEW:
10
11 1.
12 Made a pretty big effort in preventing GC allocating-functions from
13 returning chip-mem.
14
15 The lower part of the new file AmigaOS.c does this in various ways, mainly by
16 wrapping GC_malloc, GC_malloc_atomic, GC_malloc_uncollectable,
17 GC_malloc_atomic_uncollectable, GC_malloc_ignore_off_page
18 and GC_malloc_atomic_ignore_off_page. GC_realloc is also wrapped, but
19 doesn't do the same effort in preventing to return chip-mem.
20 Other allocating-functions (e.g., GC_*_typed) can probably be
21 used without any problems, but beware that the warn hook will not be called.
22 In case of problems, don't define GC_AMIGA_FASTALLOC.
23
24 Programs using more time actually using the memory allocated
25 (instead of just allocate and free rapidly) have
26 the most to earn on this, but even gctest now normally runs twice
27 as fast and uses less memory, on my poor 8 MB machine.
28
29 The changes have only effect when there is no more
30 fast-mem left. But with the way GC works, it
31 could happen quite often. Beware that an atexit handler had to be added,
32 so using the abort() function will make a big memory-loss.
33 If you absolutely must call abort() instead of exit(), try calling
34 the GC_amiga_free_all_mem function before abort().
35
36 New Amiga-specific compilation flags:
37
38 GC_AMIGA_FASTALLOC - By NOT defining this option, GC will work like before,
39 it will not try to force fast-mem out of the OS, and
40 it will use normal calloc for allocation, and the rest
41 of the following flags will have no effect.
42
43 GC_AMIGA_ONLYFAST - Makes GC never to return chip-mem. GC_AMIGA_RETRY have
44 no effect if this flag is set.
45
46 GC_AMIGA_GC - If gc returns NULL, do a GC_gcollect, and try again. This
47 usually is a success with the standard GC configuration.
48 It is also the most important flag to set to prevent
49 GC from returning chip-mem. Beware that it slows down a lot
50 when a program is rapidly allocating/deallocating when
51 there's either very little fast-memory left or very little
52 chip-memory left. It's not a very common situation, but gctest
53 sometimes (very rare) use many minutes because of this.
54
55 GC_AMIGA_RETRY - If gc succeed allocating memory, but it is chip-mem,
56 try again and see if it is fast-mem. Most of the time,
57 it will actually return fast-mem for the second try.
58 I have set max number of retries to 9 or size/5000. You
59 can change this if you like. (see GC_amiga_rec_alloc())
60
61 GC_AMIGA_PRINTSTATS - Gather some statistics during the execution of a
62 program, and prints out the info when the atexit-handler
63 is called.
64
65 My recommendation is to set all this flags, except GC_AMIGA_PRINTSTATS and
66 GC_AMIGA_ONLYFAST.
67
68 If your program demands high response-time, you should
69 not define GC_AMIGA_GC, and possible also define GC_AMIGA_ONLYFAST.
70 GC_AMIGA_RETRY does not seem to slow down much.
71
72 Also, when compiling up programs, and GC_AMIGA_FASTALLOC was not defined when
73 compiling gc, you can define GC_AMIGA_MAKINGLIB to avoid having these allocation-
74 functions wrapped. (see gc.h)
75
76 Note that GC_realloc must not be called before any of
77 the other above mentioned allocating-functions have been called. (shouldn't be
78 any programs doing so either, I hope).
79
80 Another note. The allocation-function is wrapped when defining
81 GC_AMIGA_FASTALLOC by letting the function go thru the new
82 GC_amiga_allocwrapper_do function-pointer (see gc.h). Means that
83 sending function-pointers, such as GC_malloc, GC_malloc_atomic, etc.,
84 for later to be called, e.g., like this, (*GC_malloc_function_pointer)(size),
85 will not wrap the function. This is normally not a big problem, unless
86 all allocation function is called like this, which will cause the
87 atexit un-allocating function never to be called. Then you either
88 have to manually add the atexit handler, or call the allocation-
89 functions function-pointer functions like this;
90 (*GC_amiga_allocwrapper_do)(size,GC_malloc_function_pointer).
91 There are probably better ways this problem could be handled, unfortunately,
92 I didn't find any without rewriting or replacing a lot of the GC-code, which
93 I really didn't want to. (Making new GC_malloc_* functions, and just
94 defining, e.g., GC_malloc as GC_amiga_malloc should work too).
95
96
97 New Amiga-specific function:
98
99 void GC_amiga_set_toany(void (*func)(void));
100
101 'func' is a function that will be called right before gc has to change
102 allocation-method from MEMF_FAST to MEMF_ANY. I.e., when it is likely
103 it will return chip-mem.
104
105
106 2. A few small compiler-specific additions to make it compile with SAS/C again.
107
108 3. Updated and rewritten the SMakefile.amiga, so that it works again and that
109 the "unnecessary" 'SCOPTIONS' files could be removed. Also included
110 the cord-smakefile stuff in the main smakefile, so that the cord smakefile
111 could be removed too. By typing "smake -f SMakefile.amiga", both gc.lib and
112 cord.lib will be made.
113
114
115
116 STILL MISSING:
117
118 Programs can not be started from workbench, at least not for SAS/C. (Martin
119 Tauchmanns note about that it now works with workbench is definitely wrong
120 when concerning SAS/C). An iconx-script solves this problem.
121
122
123 BEWARE!
124
125 -To run gctest, set the stack to around 200000 bytes first.
126 -SAS/C-specific: cord will crash if you compile gc.lib with
127 either parm=reg or parm=both. (missing legal prototypes for
128 function-pointers someplace is the reason I guess.).
129
130
131 tested with software: Radium, http://www.stud.ifi.uio.no/~ksvalast/radium/
132 tested with hardware: MC68060
133
134
135 Martin Tauchmann's notes (1-Apr-99)
136
137 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/>
138 Modify the `Makefile`
139 CC=cc $(ABI_FLAG)
140 to
141 CC=gcc $(ABI_FLAG)
142
143 TECHNICAL NOTES
144
145 - `GC_get_stack_base()`, `GC_register_data_segments()` works now with every
146 C compiler; also Workbench.
147
148 - Removed AMIGA_SKIP_SEG, but the Code-Segment must not be scanned by GC.
149
150
151 PROBLEMS
152 - When the Linker, does`t merge all Code-Segments to an single one. LD of GCC
153 do it always.
154
155 - With ixemul.library V47.3, when an GC program launched from another program
156 (example: `Make` or `if_mach M68K AMIGA gctest`), `GC_register_data_segments()`
157 found the Segment-List of the caller program.
158 Can be fixed, if the run-time initialization code (for C programs, usually *crt0*)
159 support `__data` and `__bss`.
160
161 - PowerPC Amiga currently not supported.
162
163 - Dynamic libraries (dyn_load.c) not supported.
164
165
166 TESTED WITH SOFTWARE
167
168 `Optimized Oberon 2 C` (oo2c) <http://cognac.informatik.uni-kl.de/download/index.html>
169
170
171 TESTED WITH HARDWARE
172
173 MC68030
174
175
176 Michel Schinz's notes
177
178 WHO DID WHAT
179
180 The original Amiga port was made by Jesper Peterson. I (Michel Schinz)
181 modified it slightly to reflect the changes made in the new official
182 distributions, and to take advantage of the new SAS/C 6.x features. I also
183 created a makefile to compile the "cord" package (see the cord
184 subdirectory).
185
186 TECHNICAL NOTES
187
188 In addition to Jesper's notes, I have the following to say:
189
190 - gctest checks to see if the code segment is added to the root set or not,
191 and complains if it is. The only problem is that, as far as I know, it is
192 impossible to know which segments are code segments and which are data
193 segments (there are indeed solutions to this problem, like scanning the
194 program on disk or patch the LoadSeg functions, but they are rather
195 complicated). The solution I have chosen (see os_dep.c) is to test whether
196 the program counter is in the segment we are about to add to the root set,
197 and if it is, to skip the segment. The problems are that this solution is
198 rather awkward and that it works only for one code segment. This means that
199 if your program has more than one code segment, all of them but one will be
200 added to the root set. This isn't a big problem in fact, since the
201 collector will continue to work correctly, but it may be slower.
202
203 Anyway, the code which decides whether to skip a segment or not can be
204 removed simply by not defining AMIGA_SKIP_SEG. But notice that if you do
205 so, gctest will complain (it will say that "GC_is_visible produced wrong
206 failure indication"). However, it may be useful if you happen to have
207 pointers stored in a code segment (you really shouldn't).
208
209 If anyone has a good solution to the problem of finding, when a program
210 is loaded in memory, whether a segment is a code or a data segment,
211 please let me know.
212
213
214 Jesper Peterson's notes
215
216 ADDITIONAL NOTES FOR AMIGA PORT
217
218 These notes assume some familiarity with Amiga internals.
219
220 WHY I PORTED TO THE AMIGA
221
222 The sole reason why I made this port was as a first step in getting
223 the Sather(*) language on the Amiga. A port of this language will
224 be done as soon as the Sather 1.0 sources are made available to me.
225 Given this motivation, the garbage collection (GC) port is rather
226 minimal.
227
228 (*) For information on Sather read the comp.lang.sather newsgroup.
229
230 LIMITATIONS
231
232 This port assumes that the startup code linked with target programs
233 is that supplied with SAS/C versions 6.0 or later. This allows
234 assumptions to be made about where to find the stack base pointer
235 and data segments when programs are run from WorkBench, as opposed
236 to running from the CLI. The compiler dependent code is all in the
237 GC_get_stack_base() and GC_register_data_segments() functions, but
238 may spread as I add Amiga specific features.
239
240 Given that SAS/C was assumed, the port is set up to be built with
241 "smake" using the "SMakefile". Compiler options in "SCoptions" can
242 be set with "scopts" program. Both "smake" and "scopts" are part of
243 the SAS/C commercial development system.
244
245 In keeping with the porting philosophy outlined above, this port
246 will not behave well with Amiga specific code. Especially not inter-
247 process communications via messages, and setting up public structures like
248 Intuition objects or anything else in the system lists. For the
249 time being the use of this library is limited to single threaded
250 ANSI/POSIX compliant or near-compliant code. (i.e., stick to stdio
251 for now). Given this limitation there is currently no mechanism for
252 allocating "CHIP" or "PUBLIC" memory under the garbage collector.
253 I'll add this after giving it considerable thought. The major
254 problem is the entire physical address space may have to me scanned,
255 since there is no telling who we may have passed memory to.
256
257 If you allocate your own stack in client code, you will have to
258 assign the pointer plus stack size to GC_stackbottom.
259
260 The initial stack size of the target program can be compiled in by
261 setting the __stack symbol (see SAS documentation). It can be over-
262 ridden from the CLI by running the AmigaDOS "stack" program, or from
263 the WorkBench by setting the stack size in the tool types window.
264
265 SAS/C COMPILER OPTIONS (SCoptions)
266
267 You may wish to check the "CPU" code option is appropriate for your
268 intended target system.
269
270 Under no circumstances set the "StackExtend" code option in either
271 compiling the library or *ANY* client code.
272
273 All benign compiler warnings have been suppressed. These mainly
274 involve lack of prototypes in the code, and dead assignments
275 detected by the optimizer.
276
277 THE GOOD NEWS
278
279 The library as it stands is compatible with the GigaMem commercial
280 virtual memory software, and probably similar PD software.
281
282 The performance of "gctest" on an Amiga 2630 (68030 @ 25 MHz)
283 compares favorably with an HP9000 with similar architecture (a 325
284 with a 68030 I think).