We want to make sure people are only adding valid handles to the list of global handles. This means that the VALUE pointer in the CAPI needs to point to a proper CAPI handle and not point to some random memory location that can cause things such as GC crashes later on. Should help in debugging stuff like therubyracer to see earlier where extensions such as that register invalid handles.
By default, CAPI methods are not subject to a single lock, meaning that extensions that are not thread safe can crash. As a workaround, a user can set -Xcapi.lock to activate the lock. Extensions that use a non-threadsafe C library should use a ruby Mutex class internally.
Introduce AuxiliaryThreads to manage the AuxiliaryThread instances.
This reduces memory usage and allows for using indexes to handles instead of needing a full pointer.
We want to be sure that the QueryAgent shuts down properly also makes sure the shared state doesn't reference it anymore.
Previously there were cases where we weren't properly removing the thread from the threads list. This happened for example for the SignalHandler thread and QueryAgent thread. By always removing it from the threads list from VM::discard, we make sure it's always remove and does not cause a crash when the GC tries to scan a thread that was not running anymore.
…orld This greatly improves performance of the gc_dependent / gc_independent barrier. This barrier is often crossed for potentially blocking and GC indepedenent functions such as FFI and IO calls. This makes these calls a lot cheaper because in the common case of not needing to GC they only have to automatically increase and decrease the pending_threads_ counter instead of doing a full lock / unlock.