Charles Manning <[EMAIL PROTECTED]> wrote:
> On Wednesday 17 January 2007 10:15, Juergen Stuber wrote:
> > Hallo Arne,
> >
> > Arne Limburg <[EMAIL PROTECTED]> wrote:
> > > I took a look at the source code quite a while ago to implement a garbage
> > > collector for the RCX version of lejos. I ended up with that it would not
> > > be difficult to implement, but that there was not enough memory in the
> > > RCX.
> >
> > me too.
> >
> > I figured out some years ago that fully real-time GC could be done
> > with an overhead of two pointers per object and a kB or two of code,
> > but that the RCX had too little memory to make it worthwhile.
> 
> I think I have a basic grip of the idea here: Instead of pointers we have a 
> table of pointers accessed via handles. Thus the pointers in the table can be 
> fiddled with without hurting the objects.
> 
> That is pretty straight forward I think, except for one scenario.
> 
> Do we ever pass pointers into the VM that get used a synchronously? If so 
> then 
> the pointers cannot be gc'd while they are in use.
> 
> For example:
> 
>   sensor = new I2CSensor(); // Has an internal buffer
>   sensor.startRead();
>   ......       // gc happens here
>   if(sensor.done())
>   ...
> 
> If the gc shift the sensor and the low level C code has a pointer into the 
> buffer, then chaos will happen.

That's pretty much it. The tricky situation is something like this:

1. An object A is created. This object contains a reference to another object 
B, but is currently null.

2. Object B is created.

3. Object A is updated to refer to object B.

There is some time between 2 and 3 where object B is not referred to by any 
other object, and an over-zealous garbage collector may sweep it up.

I recall that the way lejos works with its memory management is that every 
thread has a stack and a set of stack frames (for context). When an object is 
created (local to a function) a reference to it will immediately get put on the 
stack. So the reference isn't ever in a state where it can be erroneously 
collected, as long as you scan every stack for references. There are things you 
can do in the GC like making new objects immune from collection for a short 
while.

Speaking of the stack, it's a bit problematic because primitives are also 
stored there. It's hard to determine what is a primitive and what isn't, as 
they aren't wrapped by objects. A primitive could easily look like a reference. 
That was one of the biggest problems I came across.

-----------------------------------------
Email sent from www.ntlworld.com
Virus-checked using McAfee(R) Software 
Visit www.ntlworld.com/security for more information


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Lejos-discussion mailing list
Lejos-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lejos-discussion

Reply via email to