Re: Fat references

Paul Biggar <paul.biggar@gmail.com>
Wed, 30 Dec 2009 13:32:22 +0000

          From comp.compilers

Related articles
Fat references jon@ffconsultancy.com (Jon Harrop) (2009-12-29)
Re: Fat references paul.biggar@gmail.com (Paul Biggar) (2009-12-30)
Re: Fat references bobduff@shell01.TheWorld.com (Robert A Duff) (2009-12-30)
Re: Fat references cr88192@hotmail.com (BGB / cr88192) (2009-12-30)
Re: Fat references gah@ugcs.caltech.edu (glen herrmannsfeldt) (2009-12-30)
Re: Fat references jon@ffconsultancy.com (Jon Harrop) (2009-12-30)
Re: Fat references kkylheku@gmail.com (Kaz Kylheku) (2009-12-30)
Re: Fat references jon@ffconsultancy.com (Jon Harrop) (2009-12-30)
[27 later articles]
| List of all articles for this month |
From: Paul Biggar <paul.biggar@gmail.com>
Newsgroups: comp.compilers
Date: Wed, 30 Dec 2009 13:32:22 +0000
Organization: Compilers Central
References: 09-12-045
Keywords: storage, GC
Posted-Date: 30 Dec 2009 12:27:44 EST

Hi John,


On Tue, Dec 29, 2009 at 5:55 PM, Jon Harrop <jon@ffconsultancy.com> wrote:
> One goal was to have fast interop with C, so I didn't want to copy the
> traditional style of placing a header with GC metadata before every value
> in the heap because that would require C arrays to be copied just to add
> this header. I couldn't be bothered to allocate a separate header so,
> instead, I pulled the GC metadata into the reference. So my references are
> now "fat": a quadword of pointer to run-time type, array length or union
> type tag, pointer to mark state and pointer to the actual data itself.


This strongly resembles how values are represented in modern scripting
language implementations, including the canonical implementations of
Lua, PHP, Perl, Python and Ruby. In PHP, each value is a struct
containing:


- a reference count
- a union of primitive values/object pointer/array pointer/resource
- a type byte (indicates object/array/string/int/float/bool/null/resource)
- a flag indicating whether the value is a reference (we can ignore
this, I just added it for completeness)


The "resource" mentioned above is a C pointer (void*) used as part of
a foreign function interface. C data is typically referred to by the
pointer, rather than copied into some PHP representation.


> This actually works rather well except I sacrificed atomic read/write of
> references. Has it been done before?


All in all, the PHP approach seems to be very similar to what you're
doing. All the other scripting languages have a variation on this
theme.


One difference might be that in the PHP implementation, a pointer to
the struct is passed around. I get the impression your "fat
references" are passed by copy instead, but I'm not sure? If you did,
and found that was faster due to less indirection, that would be
interesting.




Paul




--
Paul Biggar
paul.biggar@gmail.com



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.