[erlang-questions] Deforesting tuple updates

Richard Carlsson richardc@REDACTED
Thu Feb 22 10:14:51 CET 2007


Joel Reymont wrote:
> On Feb 22, 2007, at 7:09 AM, Bjorn Gustavsson wrote:
> 
>> Do you also plan to implement a write barrier in the garbage collector
>> at the same time? If not, you are likely to get some nasty emulator  
>> crashes.
> 
> Could you expand on this?
> 
> I understand that the optimization is performed if a fixnum is used  
> to index the tuple and if the updates are done within the same  
> function. This is what I remember form your previous explanation. Is  
> this correct?

The point is that it is not only within the same function - it can only
be done between points where no garbage collection can be triggered
(since, as Björn said, there are no write barriers). If GC happens -
and it can happen at any point where an instruction needs to allocate
some memory, or call out to other code which might allocate memory -
you are likely to end up with some pointers from the old generation into
the new generation, and this breaks the main invariant that the GC is
based on. The result will be an emulator crash.

But, if you're still curious to see if you can improve on the current
implementation, check out the file lib/compiler/src/sys_core_dsetel.erl.

     /Richard

PS. We _would_ like to have write barriers, but for historical reasons,
the GC implementation in Erlang/OTP is very resistant to change.




More information about the erlang-questions mailing list