Commit Graph

514 Commits

Author SHA1 Message Date
Pavel Kunyavskiy 00c900cb49 [K/N] Optimize code generation for function references
In before, each function reference created 5 functions needed only
for equals/hashcode properties. It contributed arround 3.5% of code size
on several sample projects. This is now replaced by passing constant
object to base class constructor.
2023-02-14 13:00:47 +00:00
Igor Chevdar 707fbe7a6c [K/N] Follow-up for the fix for #KT-55869 2023-02-03 11:14:54 +00:00
Jake Wharton e821523b90 Implement RandomAccess on NS(Mutable)Array bridges
This communicates to runtime tests that calls to `get` are O(1).
2023-02-01 18:39:53 +02:00
Troels Bjerre Lund 73e420d69d [K/N] custom-alloc: Fix off-by-one in threshold
The existing threshold for determining between medium and large page
does not take the dummy block into account, meaning that an allocation
on the threshold will lead to a loop that only terminates when the
process goes out of memory.


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

Merge-request: KOTLIN-MR-618
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2023-01-27 14:03:55 +00:00
Alexander Shabalin dd9b0f9fa5 [K/N] Fix custom allocator ^KT-55364
* Make CustomFinalizerProcessor mirror the existing FinalizerProcessor
* Fix Heap::PrepareForGC in custom allocator

Merge-request: KOTLIN-MR-616
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2023-01-26 14:03:30 +00:00
Igor Chevdar 9d911247fa [K/N] Wrap continuation with ContinuationImpl on callable references
#KT-55869
2023-01-25 15:55:16 +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 6ab00a65dd [K/N] Support volatile intrinsics on globals
Also, make intrinsics signature more consistent with other intrinsics,
e.g. with isInitialized on lateinit field.

^KT-54944
2023-01-16 08:34:24 +00:00
Pavel Kunyavskiy a11f6fd9cb [K/N] Support of aligned fields
For now only alignment by at most 8 is supported for instance fields.

^KT-54944
2023-01-16 08:34:21 +00:00
Pavel Kunyavskiy 6da66649e7 [K/N] Hack for make 64-bit atomics working on mips
^KT-54944
2023-01-16 08:34:21 +00:00
Pavel Kunyavskiy 9dea349752 [K/N] Support of @Volatile annotation
^KT-54944
2023-01-16 08:34:20 +00:00
Aleksei.Glushko 20e80401b2 [K/N] Hide throwable constructor frames from stack traces.
Merge-request: KT-MR-8242
Merged-by: Alexey Glushko <aleksei.glushko@jetbrains.com>
2023-01-13 14:14:40 +00:00
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