* A separate RegularWeakReferenceImpl for the new mm. Name is chosen for
better consistency with other WeakReferenceImpl implementations.
* KRefSharedHolder and BackRefFromAssociatedObject implementations are
independent between the legacy and the new mm.
* Better support for WeakReference in runtime unit tests.
This commit adds finalizers to the custom allocator. Compared to the
existing solution:
* The finalizer queue is replaced by an AtomicStack<ExtraObjectData>.
* All objects with finalizers get meta objects attached. This was not
previously the case for CleanerImpl, but is now needed to link objects
together in the finalization queue.
* The finalizer queue is built during SweepExtraObjects, instead of
during regular sweeping.
* Cleaners are executed by the finalizer thread, and no longer by a
separate worker thread.
Co-authored-by: Troels Lund <troels@google.com>
Merge-request: KOTLIN-MR-592
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
Calls checker was trying to read thread state while unlocking mutex in
unregister thread function. At this point thread is already
unregistered and reference to current thread node is dangling.
To avoid this, we nullify this reference in advance, as its anyway
explicitly passed to unregister function, not read from global.
After linking runtime, llvm-ir is modified to add checker function
call at all points where unknown function, which can possibly run long
is called. This function checks Native state is set, to avoid long locks
at gc.
The new GC will require threads to suspend right after registering
if Stop-The-World is requested. This patch changes the initial
thread state to kNative and adds a separate state switch right
after thread registering. This switch suspends if it is necessary.
Including
* Support thread state switching in codegen
* Introduce and use GCUnsafeCall annotation
* Switch thread state in C++ runtime code
Also
* Register current thread in Mark&Sweep tests
* Store MemoryState in Worker instance
* Set worker tid in WorkerInit
GC implementation for testing purposes
* Only works for a single mutator
* Runs on the same thread as the mutator
* Runs every nth checkpoint and after every m bytes are allocated
* Runs finalizers after sweeping on the mutator thread.
Integrating the stdlib with the thread states machinery requires
accessing to some parts of the new MM. This patch provides this
access by moving these parts to the main Memory.h header.
Some of unit-tests for the C++ part of the stdlib will require
thread state switching. In the new MM, we already have a helper
function that allows us to scopely initialize the memory subsystem
for a separate thread. This patch makes this helper available
for tests in the main runtime module by moving it to the main
ThreadSupport.hpp.
* test_support::TypeInfoHolder to create TypeInfo given payload description
* test_support::Object<Payload> to create objects with Payload and to get them from ObjHeader* after checking that their type_info are layout compatible.
* test_support::*Array<Count> to create various arrays with given length and similarly get them from ArrayHeader*.