Commit Graph

652 Commits

Author SHA1 Message Date
Troels Bjerre Lund ec891474b0 [K/N] custom-alloc: AtomicStack avoid loop on move ^KT-55364
This change avoids looping through the source stack, looking for the
last element, in the case where the target stack is empty. This could
matter in two places:

* when merging ready_ and used_ into unswept_ in PrepareForGC. The first
  of these will be faster with this change.
* when merging finalizer queues (in CR-592, not merged yet), where we
  expect the target queue to be empty.

Since we can expect used_ to be larger than ready_, since we are about
to do a GC, the order of these two has also been reversed.


Co-authored-by: Troels Lund <troels@google.com>

Merge-request: KOTLIN-MR-599
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2023-01-06 12:44:28 +00:00
Troels Bjerre Lund e04c6220ff [K/N] custom-alloc: free largepages on sweep ^KT-55364
The default behavior on a sweep is to push empty pages into a separate
stack, which will be freed if not used before the next GC starts. This
serves two purposes: it reduces the number of system allocations, and it
avoids a race condition inside AtomicStack::Pop.

Neither of these are relevant for LargePages, since LargePages are never
reused and it is only the GC thread that calls
AtomicStack<LargePage>::Pop. The change is to free LargePages
immediately instead of waiting for the next GC cycle.


Co-authored-by: Troels Lund <troels@google.com>

Merge-request: KOTLIN-MR-598
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2023-01-06 12:43:46 +00:00
Ilya Gorbunov e2d96da396 Introduce experimental kotlin.concurrent.Volatile annotation KT-55268, KT-55609
Use this annotation in tests to ensure it works the same at least on JVM
2022-12-23 19:07:30 +01:00
Alexander Shabalin ff2f163ac9 [K/N] Extract Module in CompileToBitcodePlugin ^KT-53776
Merge-request: KT-MR-7960
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-12-21 22:30:25 +00:00
Pavel Kunyavskiy 4f8dad3e4b [K/N] Fix notification order in finalizers
In before thread waiting for finalizers done could be unsuspended
before statistics about finalization is written.
Probably it doesn't affect real code, but it can lead to test failures.
2022-12-20 21:44:38 +00:00
Igor Chevdar c88ac7cc86 [K/N][IR][codegen] Build per-file dependencies for caches 2022-12-20 14:24:54 +00:00
Igor Chevdar a058fcb628 [K/N][runtime] Do not export ImmutableBlob type info
It's not used by the native runtime
2022-12-20 14:24:54 +00:00
Shahlin Ibrahim 65f71cccc9 Fix several typos in docs of K/N runtime (#5054) 2022-12-16 19:05:08 +03:00
Alexander Shabalin f2835f3534 [K/N] Use Gradle configurations for CompileToBitcode modules ^KT-53776 2022-12-16 13:48:30 +00:00
Aleksei.Glushko c6d8af003d [K/N] Don't get out of bound during SSE hashCode calculation
Use loadl_epi64 to read vectors of u16x4.

Merge-request: KT-MR-7964
Merged-by: Alexey Glushko <aleksei.glushko@jetbrains.com>
2022-12-13 10:44:52 +00:00
Troels Bjerre Lund bb1acf729b [K/N] Add custom allocator prototype ^KT-55364
Enable custom allocator with -Xallocator=custom.

If the gc is cms (default):
 * a patched version of the memory manager is used that does not build a
   list of allocated objects.
 * a patched version of the cms is used that defers to the allocator for
   sweeping.

Otherwise, a warning is printed, and the allocator is used using the
standard api.

Design doc:
https://docs.google.com/document/d/15xMp-nE-DWL8OrtOc8DoXB80AHUphFICEGjj5K0aNFc

Co-authored-by: Troels Lund <troels@google.com>

Merge-request: KOTLIN-MR-546
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2022-12-08 17:22:04 +00:00
Ilya Gorbunov 77e03bb769 Minor fixes in math docs 2022-11-25 14:09:09 +00:00
Pavel Kunyavskiy 0be789e9e3 [K/N] Add API for garbage collection statistics
^KT-53064
2022-11-24 13:14:37 +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 cf80a86855 [K/N] Some strange fix to make wasm target happy 2022-11-22 13:51:20 +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 5ef9a5a240 [K/N] Crash with OOM on large array allocations ^KT-54659
Merge-request: KT-MR-7507
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-11-01 11:00:23 +00:00
Troels Bjerre Lund c6e4d034cb [K/N] Fix large array allocations ^KT-54659
If the count argument is above 2**29, then memberSize does not fit in
uint32_t.

Co-authored-by: Troels Lund <troels@google.com>

Merge-request: KOTLIN-MR-533
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2022-10-25 19:18:54 +00:00
Sergey Bogolepov c6bbce986d [K/N] Fix KT-54498
Forward users to kotlinlang.org instead of new_mm.md because the latter
is obsolete now.
2022-10-17 14:36:59 +00:00
Alexander Shabalin 5c9802ae84 [K/N] Optimize intrusive_forward_list usage in GCs ^KT-54163
* Add fallible push to intrusive_forward_list.
* Add fallible pop to intrusive_forward_list.
* Get rid of size_ member in intrusive_forward_list.
* Force all intrusive_forward_list items to have non-null next().
* Get rid of explicit colors in STMS and CMS.
* Do not queue weak reference for later processing in Mark.

Merge-request: KT-MR-7263
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-10-06 20:16:53 +00:00
Pavel Kunyavskiy 0959255379 [K/N] Refactor GC logging and statistics
Same code is now used for GC logging in all gc versions.

^KT-53064
2022-10-04 18:44:58 +00:00
Pavel Kunyavskiy c4e2901a1d [K/N] Avoid inlining of ignored check on external call 2022-10-04 18:44:58 +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
Ilya Gorbunov 607f15b55b Sycnhronize docs of primitives in JS-IR, Wasm, Native sources 2022-10-02 19:04:37 +00:00
Pavel Kunyavskiy 817dba8564 [K/N] Use suspend function desugaring lowerings. 2022-09-30 08:48:58 +00:00
Alexander Shabalin c561b1a861 [K/N] Manually compact mimalloc heap with stms ^KT-53182
Merge-request: KT-MR-7222
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-09-27 17:25:18 +00:00
Alexander Shabalin 822e341d76 [K/N] Remove marker check from mark phase ^KT-54163
Markers can't appear in object fields.

Merge-request: KT-MR-7201
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-09-27 09:08:29 +00:00
Alexander Shabalin f009d9b633 [K/N] Manually compact mimalloc heap ^KT-53182
Merge-request: KT-MR-7111
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-09-23 15:07:16 +00:00
Svyatoslav Scherbina 39c73e25a4 Native: improve thread state switches for NSSet/NSDictionary adapters
^KT-54119
2022-09-22 07:37:44 +00:00
Nikolay Krasko 1630386712 Move to JDK_X_Y variables 2022-09-21 22:53:19 +00:00
Ilya Gorbunov 57c9d61291 ComparableTimeMark and specialized TimeSource KT-54082
- Introduce ComparableTimeMark interface extending TimeMark,
and TimeSource.WithComparableMarks - a time source that returns such time marks.
- Implement ComparableTimeMark in ValueTimeMark and AbstractLong/DoubleTimeMark classes.
2022-09-19 19:16:40 +00:00
Alexander Shabalin 529a29ae52 [K/N] Use TargetDomainObjectContainer ^KT-53776
Merge-request: KT-MR-7110
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-09-17 08:40:09 +00:00
Sergey Bogolepov 5f847ac40d [K/N] Add workaround for NS_FORMAT_ARGUMENT(A)
See KT-48807 for explanation
2022-09-17 07:51:34 +03:00
Johan Bay 4b92d2e76c Add OnSuspendForGC hook to GCImpl::ThreadData
Co-authored-by: Johan Bay <jobay@google.com>

Merge-request: KOTLIN-MR-506
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2022-09-16 14:43:54 +00:00
Pavel Kunyavskiy 7293dd6d65 [K/N] Require small binaries for all watchos targets 2022-09-16 12:24:11 +00:00
Svyatoslav Scherbina 1b17dbff09 Native: compile runtime/src/cpp/math code only for wasm32 2022-09-15 09:32:32 +00:00
Alexander Shabalin e6e7feb985 [K/N] Do not check for external calls in SpinLock<Ignore>
Merge-request: KT-MR-7099
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-09-13 13:37:12 +00:00
Abduqodiri Qurbonzoda 73a65c1bb1 Promote top-level kotlin.math.cbrt() to stable #KT-53277 2022-09-08 12:00:58 +00:00
Igor Chevdar 44010a04b1 [K/N][runtime] Extracted compiler interface from native runtime 2022-09-06 14:03:41 +00:00
Svyatoslav Scherbina 728fe918fe Native: don't expect that startCoroutineUninterceptedOrReturn receiver is FunctionN+1
Previous implementation of startCoroutineUninterceptedOrReturn expected
that the receiver (i.e. the suspend function object to start) of type
SuspendFunctionN (i.e. suspend function type with arity = N) is also an
instance of FunctionN+1 (i.e. regular function type with arity = N + 1)
with proper convention.

While compiler tries to achieve that (for better compatibility with
Kotlin/JVM, by generating additional supertypes and methods for classes
implementing suspend function types), this doesn't work e.g. for
implementations defined in Swift.

Fix this by adding fallbacks for cases when the receiver is not
a FunctionN+1, while keeping the fastpath for default FunctionN+1
cases.

^KT-51043 Fixed
2022-09-01 09:35:22 +00:00
Svyatoslav Scherbina 15fe2c2c5c Native: remove code duplication in coroutine intrinsics implementation
Make `createCoroutineUnintercepted` invoke
`startCoroutineUninterceptedOrReturn` when suspend function object is
not a `BaseContinuationImpl` (e.g. for a custom suspend function type
subclass), instead of using the copy of its implementation.
2022-09-01 09:35:22 +00:00
Johan Bay f71931d04b [K/N] Parallelize marking in CMS GC
This change parallelizes marking by making each non-native Kotlin thread
mark its own view of the heap. To make this safe, we make flipping the
marking bit atomic which ensures that threads do not try to trace the
same objects.

Co-authored-by: Johan Bay <jobay@google.com>

Merge-request: KOTLIN-MR-423
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2022-09-01 09:07:54 +00:00
Alexander Shabalin 0734456a87 [K/N] Enable extra option for mimalloc ^KT-53182
Merge-request: KT-MR-6952
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-09-01 09:02:23 +00:00
Sergey Bogolepov f946496979 [K/N] Deprecate obsolete GC handles. 2022-08-26 14:35:08 +00:00
Sergey Bogolepov 8010203ee5 [K/N] Update Throwable.kt documentation for the new MM 2022-08-26 14:35:08 +00:00
Sergey Bogolepov aaf24c897f [K/N] Update ObjectTransfer.kt documentation for the new MM 2022-08-26 14:35:08 +00:00
Sergey Bogolepov 122f3033f2 [K/N] Update Atomics.kt documentation for the new MM 2022-08-26 14:35:07 +00:00
Sergey Bogolepov 5d11e0d408 [K/N] Update Worker.kt documentation for the new MM 2022-08-26 14:35:06 +00:00