Commit Graph

66 Commits

Author SHA1 Message Date
Igor Chevdar 55632f5df2 [K/N][runtime] Used internal isInstance 2023-05-22 12:49:58 +00:00
Troels Bjerre Lund 918a247bcc [K/N] custom_alloc: sweep extraobjects outside stw ^KT-55364
Co-authored-by: Troels Lund <troels@google.com>

Merge-request: KOTLIN-MR-677
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2023-05-09 16:37:58 +00:00
Alexander Shabalin 82f94015f1 [K/N] Dispose ObjC objects from main thread on main thread. ^KT-56402
Merge-request: KT-MR-9515
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2023-04-26 07:35:44 +00:00
Alexander Shabalin 4cd1f2ff82 [K/N] Fix a race in MemorySharedRefs ^KT-56233 2023-04-06 11:40:47 +00:00
Alexander Shabalin 1f1b26f2a5 [K/N] Split Weak and MemorySharedRefs between mm implementations ^KT-56233
* 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.
2023-04-06 11:40:45 +00:00
Troels Bjerre Lund 7854b01473 [K/N] custom-alloc: handle finalizers
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>
2023-01-20 16:47:06 +00:00
Pavel Kunyavskiy 9dea349752 [K/N] Support of @Volatile annotation
^KT-54944
2023-01-16 08:34:20 +00:00
Pavel Kunyavskiy d3adfec2fb [K/N] Rework object and enum classes initialization
Now it works with common logic for all static scope not with custom one.
2022-11-22 13:51:22 +00:00
Pavel Kunyavskiy c04e1b6ce7 [K/N] Better fix for calls checker use-after-free in main thread deinit 2022-11-16 15:15:07 +00:00
Alexander Shabalin a31c3f979b [K/N] Benchmarks on weak references
Merge-request: KT-MR-7575
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-11-15 13:22:15 +00:00
Pavel Kunyavskiy ef54a6d7cb [K/N] Fix calls checker use-after-free in main thread deinit
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.
2022-11-14 14:25:01 +00:00
Alexander Shabalin 98251f42f2 [K/N] Specialize marking call for objects ^KT-54163
Merge-request: KT-MR-7232
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-10-04 09:51:08 +00:00
Pavel Kunyavskiy 18cda8844d [K/N] Fix possible data races found by thread sanitizer 2022-08-10 08:36:07 +00:00
Pavel Kunyavskiy f4ea929d8e [K/N] Better removing of extra safepoints 2022-06-17 06:42:28 +00:00
Alexander Shabalin ac395b21ea [K/N] Fix state switch in CAdapterGenerator ^KT-52692
Merge-request: KT-MR-6429
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-06-09 13:01:17 +00:00
Sergey Bogolepov 77c04e7d71 [K/N] Do not inline runtime functions in case of armv7 darwin targets
^KT-51649 fixed
2022-03-21 09:11:13 +00:00
Pavel Kunyavskiy 85633771da [K/N] Replace escape analysis correctness check to RuntimeAssert to avoid checks in release mode 2022-02-03 08:08:21 +00:00
Pavel Kunyavskiy 3798920183 [K/N] Any.isFrozen is now always false when freezing is disabled 2022-01-24 13:38:30 +00:00
Alexander Shabalin 69bb2587eb [K/N] Make GC scheduler less aggressive
^KT-48537

Merge-request: KT-MR-5319
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-01-19 19:11:15 +00:00
Alexander Shabalin 65fdfffeb4 [K/N] Make GC.collect wait for finalizers being run
^KT-50713

Merge-request: KT-MR-5404
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-01-11 11:39:22 +00:00
Alexander Shabalin 43b8683b9c [K/N] Separate MM from GC implementations
^KT-50291

Merge-request: KT-MR-5191
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2021-12-21 08:33:51 +00:00
Pavel Kunyavskiy ebca4d793f [K/N] Implement non-blocking approach for sweep 2021-12-13 05:32:10 +00:00
Pavel Kunyavskiy b22dec062c [K/N] Optimize finalizing of simple extra objects
There is no need to delay ExtraObject deletion when it doesn't have
associated object. We can just remove it while iterating on them.
2021-12-13 05:32:08 +00:00
Elena Lepilkina f67941e244 [K/N] Replaced safe points to prologue 2021-11-02 12:04:45 +00:00
Elena Lepilkina 2d72f4d5a9 [K/N] Added checks for tests that current frame after catch is right 2021-11-02 12:04:40 +00:00
Elena Lepilkina cde51ecc3a [K/N] Added function SetCurrentFrame to use in unwind block 2021-11-02 12:04:37 +00:00
Pavel Kunyavskiy ae64af09fb [K/N] Add ability to get base object from extra data
^KT-49325
2021-10-27 12:11:16 +00:00
Alexander Shabalin 84e7b53926 [K/N] Rework GCScheduler to schedule GC on its own. 2021-09-27 08:03:55 +00:00
Ilya Matveev bfc4ff6343 [K/N][New MM] Disallow getting thread data for detached threads
This patch fixes a performance degradation introduced by
99bd26c2ef (Switch thread states
in termination handlers).
2021-09-20 07:28:57 +00:00
Alexander Shabalin d03a7993ed [K/N] Implement GCScheduler 2021-09-14 13:53:36 +00:00
Ilya Matveev 99bd26c2ef [K/N][Runtime] Switch thread states in termination handlers 2021-08-26 14:46:07 +00:00
Pavel Kunyavskiy fc75486611 [K/N] Debug tool for checking state at call points of unknown functions
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.
2021-07-05 08:35:23 +00:00
Alexander Shabalin 28b6427d3e Make FreezableAtomicReference atomic when unfrozen for the new MM. 2021-06-25 21:18:37 +00:00
Ilya Matveev cece652412 [K/N][Runtime] Separate thread registering and making it 'Runnable'
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.
2021-06-18 12:20:03 +00:00
Svyatoslav Scherbina 85ab4f68df Native: support reentrant mode for CalledFromNativeGuard 2021-06-11 07:35:48 +00:00
Svyatoslav Scherbina fa36ccedeb Native: improve ObjCExport thread state switching 2021-06-04 16:58:26 +00:00
Alexander Shabalin af1f57007a https://channel9.msdn.com/Shows/Going+Deep/Cpp-and-Beyond-2012-Herb-Sutter-atomic-Weapons-2-of-2 2021-05-27 17:18:55 +00:00
Alexander Shabalin 73533e4b19 Make NoOp GC support multiple mutators 2021-05-21 06:31:09 +00:00
Alexander Shabalin eac3f507b6 Make Kotlin_initRuntimeIfNeeded switch to native state 2021-05-20 13:48:49 +00:00
Alexander Shabalin 3388ca2536 Support ObjC blocks in the new MM 2021-05-19 07:31:12 +00:00
Alexander Shabalin 94076300ec Implement a bit more of GC object interface 2021-05-19 07:29:27 +00:00
Ilya Matveev 4d346d3735 [K/N][New MM] Support thread state switching
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
2021-05-06 14:10:21 +00:00
Ilya Matveev 0b46ed3cde [K/N][New MM] Add thread state asserts to reference updates 2021-05-06 14:10:20 +00:00
Alexander Shabalin 71397a06fb Add Stop-the-World Mark & Sweep GC for single-threaded programs.
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.
2021-04-02 12:13:44 +00:00
Alexander Shabalin 770401801b Implement freezing in the new MM
Currently, it uses suboptimal storage for the freeze bit. This'll be revised later when we finalize stack objects handling in the new MM.
2021-03-26 15:00:14 +00:00
Ilya Matveev 6643119f08 [K/N][New MM] Move ThreadStateGuard to the main Memory.h
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.
2021-03-16 17:04:26 +03:00
Ilya Matveev 482305cfb2 [K/N][New MM] Move RunInNewThread to the main ThreadSupport.hpp
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.
2021-03-16 17:04:25 +03:00
Ilya Matveev fc43fbf578 [K/N][New MM] Move MemoryState conversions to separate header 2021-03-16 17:04:23 +03:00
Alexander Shabalin f51c85a63f Add test support for types and objects creation
* 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*.
2021-03-15 11:25:04 +00:00
LepilkinaElena fcbb921194 [LEGACY MM] Escape making extra increments and decrements during coping to the same array (#4731)
(cherry picked from commit 8b601d8e2c6bc772386ebd88d303a032a6f54237)
2021-03-09 20:19:34 +00:00