README.amiga 12 KB

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