How the Nasal GC works: Difference between revisions

Jump to navigation Jump to search
Line 53: Line 53:
}}
}}


= Status (09/2012) =
= Status (02/2016) =
<!--
As of 06/2012, a new incremental Nasal GC is being worked on [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg37579.html]:
 
<pre>
I have been working on a 4-color incremental mark/sweep collector with
the intention of merging it into the Nasal interpreter.
The work so far can be found at http://github.com/chrisforbes/incgc;
There's still quite a lot to do, but the path is clear.
</pre>
-->
 
The main Nasal repository (maintained by Andy Ross) can also be found at github: https://github.com/andyross/nasal
 
The latest version in FlightGear is maintained in the SimGear repository which is to be found at gitorious: https://gitorious.org/fg/simgear/trees/next/simgear/nasal
 
The garbage collector in Nasal is pretty self-contained and entirely implemented in the file [https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/gc.c gc.c].
 
{{FGCquote
  |Nasal's garbage collector requires that no other Nasal threads are <br/>
running, and achieves this by keeping a count of active Nasal threads <br/>
(nThreads, simgear/nasal/code.h), and having the thread that needs GC <br/>
ask all other threads to stop and wait until nThreads-1 say they have <br/>
(bottleneck(), simgear/nasal/gc.c).  This will hang if there are any <br/>
threads that Nasal thinks are active but actually aren't, as they will <br/>
never reply to the stop request.
  |{{cite web |url=http://sourceforge.net/p/flightgear/mailman/message/32969200/
    |title=<nowiki>[Flightgear-devel] Nasal threading, naCall() vs naCallMethodCtx()</nowiki>
    |author=<nowiki>Rebecca N. Palmer</nowiki>
    |date=<nowiki>2014-10-25</nowiki>
  }}
}}
 
 
 
 
{{FGCquote
{{FGCquote
|1= Such things may look simple at first. Easy to convert a simple "hello world". But it's very complex when supporting all the features of an interpreted script language. And the funny thing is: you'd still need to worry about automatic garbage collection and count references (though that'd be a lesser issue compared to many others then). So, time wake up...
|1= Such things may look simple at first. Easy to convert a simple "hello world". But it's very complex when supporting all the features of an interpreted script language. And the funny thing is: you'd still need to worry about automatic garbage collection and count references (though that'd be a lesser issue compared to many others then). So, time wake up...
Line 62: Line 98:
   | date  = Mar 26th, 2011
   | date  = Mar 26th, 2011
   | added  = Mar 26th, 2011
   | added  = Mar 26th, 2011
  | script_version = 0.23
  }}
}}
=== Patches ===
{{FGCquote
|1= there is still the issue that you can't execute Nasal while the GC is running (for that you'd need a concurrent GC which is most likely not so easily implemented). The implication is that if the time required for a collection exceeds the frame dealy you'll still notice it even when the GC runs in a different thread. I have updated my experimental patch from last year, which should also work on Windows now (and it has even been tested there):
* http://sleipner.gidenstam.org/users/anders/FlightGear/sg-gc-4.diff
* http://sleipner.gidenstam.org/users/anders/FlightGear/fg-gc-3.diff
Again: It doesn't solve the bigger problem of the current Nasal GC needing to run uninterrupted and in mutual exclusion - but I see very few GC runs in the main loop here (the patch prints "** Nasal GC in main thread **" in the console when that happens) except a few during startup.
|2= {{cite web
  | url    = http://sourceforge.net/p/flightgear/mailman/message/29306592/
  | title  = <nowiki>Re: [Flightgear-devel] Nasal performance</nowiki>
  | author = <nowiki>Anders Gidenstam</nowiki>
  | date  = May 23rd, 2012
  | added  = May 23rd, 2012
  | script_version = 0.23
  }}
}}
{{FGCquote
|1= There are algorithms for incremental and/or concurrent and/or parallel garbage collection out there. They most likely not easy to implement and as far as I have seen so far would require (at least for concurrent and /or parallel GC) all writes of pointers to the Nasal heap (and possibly reads) to be redirected via wrapper functions (also known as (GC) read/write barriers). This will not be an easy task but in my opinion it would be a promising option. It might be possible to use a GC module from a GPL:d Java vm or similar. Btw, just running the normal (mutually exclusive) Nasal GC in another thread than the main loop is not hard - but since it is mutually exclusive to executing Nasal functions it doesn't help much when it comes to reducing the worst case latency. The small changes needed to add a separate GC thread are available here:
* http://www.gidenstam.org/FlightGear/misc/test/sg-gc-2.diff
* http://www.gidenstam.org/FlightGear/misc/test/fg-gc-1.diff
|2= {{cite web
  | url    = http://sourceforge.net/p/flightgear/mailman/message/27338998/
  | title  = <nowiki>Re: [Flightgear-devel] Nasal Garbage Collector (was Stuttering at 1
Hz rate)</nowiki>
  | author = <nowiki>Anders Gidenstam</nowiki>
  | date  = Apr 10th, 2011
  | added  = Apr 10th, 2011
   | script_version = 0.23
   | script_version = 0.23
   }}
   }}
Line 92: Line 161:
   | script_version = 0.23
   | script_version = 0.23
   }}
   }}
}}
As of 06/2012, a new incremental Nasal GC is being worked on [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg37579.html]:
I have been working on a 4-color incremental mark/sweep collector with
the intention of merging it into the Nasal interpreter.
The work so far can be found at http://github.com/chrisforbes/incgc;
There's still quite a lot to do, but the path is clear.
The main Nasal repository (maintained by Andy Ross) can also be found at github: https://github.com/andyross/nasal
The latest version in FlightGear is maintained in the SimGear repository which is to be found at gitorious: https://gitorious.org/fg/simgear/trees/next/simgear/nasal
The garbage collector in Nasal is pretty self-contained and entirely implemented in the file [https://gitorious.org/fg/simgear/blobs/next/simgear/nasal/gc.c gc.c].
{{FGCquote
  |Nasal's garbage collector requires that no other Nasal threads are <br/>
running, and achieves this by keeping a count of active Nasal threads <br/>
(nThreads, simgear/nasal/code.h), and having the thread that needs GC <br/>
ask all other threads to stop and wait until nThreads-1 say they have <br/>
(bottleneck(), simgear/nasal/gc.c).  This will hang if there are any <br/>
threads that Nasal thinks are active but actually aren't, as they will <br/>
never reply to the stop request.
  |{{cite web |url=http://sourceforge.net/p/flightgear/mailman/message/32969200/
    |title=<nowiki>[Flightgear-devel] Nasal threading, naCall() vs naCallMethodCtx()</nowiki>
    |author=<nowiki>Rebecca N. Palmer</nowiki>
    |date=<nowiki>2014-10-25</nowiki>
  }}
}}
}}


Navigation menu