[M3devel] Using REFANYs to store integers?

Tony Hosking hosking at cs.purdue.edu
Mon Dec 10 15:08:39 CET 2007


Yikes.  The current collector will expect to find an aligned  
reference in any global variable or heap field declared as a subtype  
of REFANY.  It will break if it does not find one.  You cannot  
reliably use the technique you describe with Modula-3 as it is  
currently defined, nor for that matter with any safe language.  To do  
what you want in Modula-3 you would need to use ADDRESS and  
explicitly test for low bits when using ADDRESS values.  Of course,  
then you'd need to write your own GC for your interpreter (probably  
not a bad idea anyway, given that you are in much more control).

On Dec 10, 2007, at 6:38 AM, Mika Nystrom wrote:

> Hello Modula-3ers...
>
> I have a question about garbage collecting, pointers, and dirty
> tricks that I'm curious if anyone (Tony??) can answer.
>
> Here it is.  I am considering writing a bytecode interpreter that
> is to run mixed into a Modula-3 environment, that is, it will be
> able to deal with bytecodes as well as Modula-3 objects.  There is
> no problem with that of course, as bytecodes are "code" and Modula-3
> objects are "objects" and can live on separate stacks.  However,
> as an optimization (not an uncommon one in these types of systems),
> I'd like a space and time efficient representation for "small
> integers".  A tried-and-true method (it goes back at least to the
> Smalltalk-80 runtime) is to realize that pointers (in my case
> REFANYs) always point to word-aligned addresses.  We can then use
> integers that are congruent to 1, 2, and 3 (mod 4) to represent
> other types of data.
>
> What will happen if I LOOPHOLE such integers back and forth to
> REFANY?  Will the garbage collector just ignore them?  I wrote a
> test program that does it and it doesn't crash... except when you
> hit ctrl-C, it often dies with an assertion failure in
> RTCollector.m3.. (This both with my ancient PM3 on FreeBSD and a
> relatively recent update of CM3 on PPC_DARWIN.)  If the garbage
> collector somehow disapproves of these integers, is there any
> conceivable thing that would be broken by making necessary adjustments
> to the garbage collector such that it would just ignore them?
> Or is there a better way of solving my problem?
>
>       Best regards,
>         Mika




More information about the M3devel mailing list