GC pointer alignment bug fix

Matthias Hopf (@Home) mshopf at ftpamiga.dialin.rrze.uni-erlangen.de
Tue May 27 01:28:13 PDT 1997


Hihi!

While trying to find out what was wrong with the GC (see my last mail) I
happened to find out that on m68k/amigaos regulary pointers on the stack were
not properly aligned (e.g. p%-4 = 2). I have added an aligment test to
configure.in and changed the scanner to use ALIGNMENTOF_VOIDP instead of
sizeof(void*) as stepping width.

I guess there are more CPUs which could benefit from this patch. If you would
like to know whether there are misalignments on your CPU, too, enable the
alignment test in kaffevm/gc-incremental.c (#define ALDBG(s) s) and wait for
any output of the form <x>, x being a digit, specifying the misalignment.

Note that *some* 'pointers' with misalignment showing up doesn't say anything
- they can well be integer values that were misinterpreted as pointers.
But if you happen to get for instance 20 misaligned pointers per garbage
collection, you should now have a problem less than before ;)

And please tell me when you have found another CPU that shared this problem.


Find the patch enclosed. Note that you will have to run autoconf first! I did
not include patches for 'configure', because the amigaos autoconf adds some
additional lines that don't make sense for other computers.


BTW - the patch also corrects the generation of the CLASSPATH settings in
the ENVIRONMENT file.

CU

Matthias

-- 
    //             |   Matthias Hopf - "Hoeppel"   |    _      __
\\ //    Amiga     |  student of computer science  |  _|cience |-iction
 \X/ by conviction |      in Erlangen/Germany      | by belief in Future

 EMail:  mshopf at informatik.uni-erlangen.de
 Aminet: ftpamiga at epix.rrze.uni-erlangen.de
 WWW:    http://wwwcip.informatik.uni-erlangen.de/user/mshopf/

-------------- next part --------------
diff -bcrN gc_kaffe-0.9.0/config/config.h.in kaffe-0.9.0/config/config.h.in
*** gc_kaffe-0.9.0/config/config.h.in	Mon May 12 19:16:38 1997
--- kaffe-0.9.0/config/config.h.in	Sat May 24 19:04:14 1997
***************
*** 259,264 ****
--- 259,267 ----
  /* How big are pointers */
  #undef	SIZEOF_VOIDP
  
+ /* How are pointers aligned */
+ #undef	ALIGNMENTOF_VOIDP
+ 
  /* Do we have sigcontext */
  #undef	HAVE_STRUCT_SIGCONTEXT
  
diff -bcrN gc_kaffe-0.9.0/configure.in kaffe-0.9.0/configure.in
*** gc_kaffe-0.9.0/configure.in	Mon May 12 19:16:23 1997
--- kaffe-0.9.0/configure.in	Sat May 24 19:22:31 1997
***************
*** 617,622 ****
--- 617,641 ----
  AC_CHECK_SIZEOF(long long,0)
  AC_CHECK_SIZEOF(__int64,0)
  AC_CHECK_SIZEOF(void*,0)
+ 
+ dnl =========================================================================
+ dnl Checks for alignments
+ dnl -------------------------------------------------------------------------
+ 
+ AC_CACHE_CHECK(alignment of void*, ac_cv_alignmentof_voidp,
+ AC_TRY_RUN([#include <stdio.h>
+ main() { struct { char c; void *p; } t; FILE *f;
+   if ((char*) &t.c != (char*) &t)  exit (1);
+   f=fopen ("conftestdata", "w");
+   if (! f)                         exit (1);
+   fprintf (f, "%d", ((char*) &t.p)-((char*) &t));
+   fclose(f); exit (0); }],
+ ac_cv_alignmentof_voidp=$(<conftestdata), ac_cv_alignmentof_voidp=1,
+ ac_cv_alignmentof_voidp=1))
+ AC_DEFINE_UNQUOTED(ALIGNMENTOF_VOIDP,$ac_cv_alignmentof_voidp)
+ 
+ dnl -------------------------------------------------------------------------
+ 
  AC_TYPE_SIGNAL
  AC_TYPE_SIZE_T
  AC_CHECK_TYPE(ssize_t,int)
***************
*** 958,966 ****
  
  if test "$SYSTEM" = "unix" ; then
  	if test "$awt_toolkit" != "none" ; then
! 		echo CLASSPATH=.:$datadir/kaffe/classes.zip:$datadir/kaffe/$awt_toolkit.zip > ENVIRONMENT
  	else
! 		echo CLASSPATH=.:$datadir/kaffe/classes.zip > ENVIRONMENT
  	fi
  	echo KAFFEHOME=$datadir/kaffe >> ENVIRONMENT
  	if test "$dynamic_libraries" = "yes" ; then
--- 977,985 ----
  
  if test "$SYSTEM" = "unix" ; then
  	if test "$awt_toolkit" != "none" ; then
! 		echo CLASSPATH=.:$datadir/kaffe/classes/classes.zip:$datadir/kaffe/$awt_toolkit.zip > ENVIRONMENT
  	else
! 		echo CLASSPATH=.:$datadir/kaffe/classes/classes.zip > ENVIRONMENT
  	fi
  	echo KAFFEHOME=$datadir/kaffe >> ENVIRONMENT
  	if test "$dynamic_libraries" = "yes" ; then
***************
*** 971,979 ****
  elif test "$SYSTEM" = "win32" ; then
  	echo @echo off > ENVIRONMENT.BAT
  	if test "$awt_toolkit" != "none" ; then
! 		echo set CLASSPATH=.\;$datadir/kaffe/classes.zip\;$datadir/kaffe/$awt_toolkit >> ENVIRONMENT.BAT
  	else
! 		echo set CLASSPATH=.\;$datadir/kaffe/classes.zip >> ENVIRONMENT.BAT
  	fi
  	echo set KAFFEHOME=$datadir/kaffe >> ENVIRONMENT.BAT
  	echo set PATH=%PATH%\;$bindir >> ENVIRONMENT.BAT
--- 990,998 ----
  elif test "$SYSTEM" = "win32" ; then
  	echo @echo off > ENVIRONMENT.BAT
  	if test "$awt_toolkit" != "none" ; then
! 		echo set CLASSPATH=.\;$datadir/kaffe/classes/classes.zip\;$datadir/kaffe/$awt_toolkit >> ENVIRONMENT.BAT
  	else
! 		echo set CLASSPATH=.\;$datadir/kaffe/classes/classes.zip >> ENVIRONMENT.BAT
  	fi
  	echo set KAFFEHOME=$datadir/kaffe >> ENVIRONMENT.BAT
  	echo set PATH=%PATH%\;$bindir >> ENVIRONMENT.BAT
diff -bcrN gc_kaffe-0.9.0/kaffe/kaffevm/gc-incremental.c kaffe-0.9.0/kaffe/kaffevm/gc-incremental.c
*** gc_kaffe-0.9.0/kaffe/kaffevm/gc-incremental.c	Tue May 27 00:04:39 1997
--- kaffe-0.9.0/kaffe/kaffevm/gc-incremental.c	Mon May 26 20:31:58 1997
***************
*** 13,18 ****
--- 13,19 ----
  #define FDBG(s)
  #define FTDBG(s)
  #define ADBG(s)
+ #define ALDBG(s)
  
  #include "config.h"
  #include "config-std.h"
***************
*** 152,167 ****
  }
  
  void
! scanConservative(void* base, size_t size)
  {
! 	void** mem;
! 	int32 i;
  
  	gcStats.markedmem += size;
  
! 	mem = base;
! 	for (i = (size / sizeof(void*)) - 1; i >= 0; i--) {
! 		markObject(mem[i]);
  	}
  }
  
--- 153,170 ----
  }
  
  void
! scanConservative(void *base, size_t size)
  {
! 	int8  *mem;
  
  	gcStats.markedmem += size;
  
! 	mem = ((int8 *) base) + (size & -ALIGNMENTOF_VOIDP) - sizeof (void *);
! 	while ((void *) mem >= base) {
! ALDBG(          if (gc_heap_isobject (* (void **) mem) && ((long)mem & (sizeof(void*)-1)))
! 			fprintf (stderr, "<%d>", (long)mem & (sizeof(void*)-1));             )
! 		markObject(* (void **) mem);
! 		mem -= ALIGNMENTOF_VOIDP;
  	}
  }
  
-------------- next part --------------
Tue May 27 01:05:42 MET1 1997   Matthias Hopf   <mshopf at informatik.uni-erlangen.de>

	* config/config.h.in: Added ALIGNMENTOF_VOIDP.
	* configure.in: Added Alignment test for void*.
	* configure.in: Fixed CLASSPATH settings in ENVIRONMENT file.
	* kaffevm/gc-incremental.c(scanConservative): Scaning memory in steps
	  of ALIGNEMNTOF_VOIDP instead of sizeof(void*).



More information about the kaffe mailing list