summaryrefslogtreecommitdiff
path: root/compiler/optimizing/intrinsics.h
AgeCommit message (Collapse)Author
2025-01-02Rename `GetBootImageVarHandleField()`, drop "Boot". Vladimir Marko
This is a minor cleanup after https://android-review.googlesource.com/3048514 . Test: m test-art-host-gtest Test: testrunner.py --host --optimizing --speed-profile Bug: 38313278 Change-Id: Ic47063231fd48656b612ede3ec100ceb8a379050
2024-04-22Optimizing: Treat app image objects as non-movable. Vladimir Marko
Treat app image objects similar to boot image objects and avoid unnecessary read barriers for app image `HLoadClass` and `HInstanceOf` checks with app image `HLoadClass` input. Extend other optimizations to treat app image classes the same way as boot image classes even though this remains mostly dormant because we currently do not initialize app image classes with class initializers; the experimental flag `--initialize-app-image-classes` is false by default. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing --speed-profile Bug: 38313278 Change-Id: I359dd8897f6d128213602f5731d40edace298ab8
2024-01-23Fix crash when inlining intrinsics with specialized HIR Santiago Aboy Solanes
During the inliner phase if we recognize an intrinsic, we insert it. This is problematic since there are some intrinsics which we only expect during the instruction builder phase. This CL skips inlining those intrinsics. Potentially, we could generate the graphs for those intrinsics and inline it, but it needs refactoring of inliner.cc. Bug: 319045458 Fixes: 319045458 Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Test: Locally compiling the app in the bug Change-Id: Ied3ec87e5655cec3bdfd978eb5c7411ddb102360
2024-01-22Create list of intrinsics with specialized HIR. Vladimir Marko
Split the intrinsics list to differentiate intrinsics with and without HIR. Eliminate unreachable intrinsic functions for intrinsics with HIR. Test: m test-art-host-gtest Test: restrunner.py --host --optimizing Bug: 319045458 Change-Id: I6144ef6b6ec547c30f2911c41125a1f07f6f6d50
2023-12-13riscv64: Clean up the `SystemArrayCopy` intrinsic. Vladimir Marko
Define a new optimization flag for source and destination position match. Use it to avoid the forward-copy check (where the assembler optimized away a BLT instruction, so we had just a useless BNE to the next instruction) and one position sign check. Avoid checking that the position is inside the array. The subsequent subtraction cannot underflow an `int32_t` and the following BLT shall go to the slow path for negative values anyway. Rewrite the array type check to avoid unnecessary checks and read barriers. Use an allocated temporary instead of scratch register for the marking in the read barrier slow path. Simplify the gray bit check and the fake dependency. Use constant position and length locations for small constant values. (It was probably an oversight that we used it only for large constant values.) Emit threshold check when the length equals source or destination length. The old code allowed the intrinsic to process array copy of an arbirary length. Use `ShNAdd()` for faster array address calculations. Use helper functions and lambdas to simplify the code. Pass registers and locations by value. Prefer load/store macro instructions over raw load/store instructions. Use a bare conditional branch to assert the `TMP` shall not be clobbered. Test: testrunner.py --target --64 --ndebug --optimizing Bug: 283082089 Change-Id: I3f697b4a74497d6d712a92450a6a45e772430662
2023-11-22Address review comments. Nicolas Geoffray
For https://android-review.googlesource.com/2835572 Test: test.py Change-Id: Ia1584de58fe945a46b8f49548e062ce212be0a23
2023-11-21Implement Short/Byte/Character.valueOf intrinsics. Nicolas Geoffray
Also remove now obsolete IntegerCache checks - we can rely on the checks done when generating the boot image. Test: test.py Change-Id: Ia8dfa97498e7aaefd4493e8ed67fa62874fe78c3
2023-11-16Harcode IntegerCache range. Nicolas Geoffray
Let JIT assume these ranges. They are checked at AOT time when generating the boot image and when compiling applications. Test: test.py Change-Id: Ib2240d150bab366a3c17e0015503f728a98ae2ea
2023-10-30Replace `gUseReadBarrier` with compiler option in compiler. Vladimir Marko
Leave a few `gUseReadBarrier` uses in JNI macro assemblers. We shall deaal with these later. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: run-gtests.sh Test: testrunner.py --target --optimizing Bug: 289805127 Change-Id: I9d2aa245cee4c650129f169a82beda7dc0dd6a35
2023-10-17riscv64: Implement `CriticalNativeAbiFixupRiscv64`. Vladimir Marko
And pass integral stack args sign-extended to 64 bits for direct @CriticalNative calls. Enable direct @CriticalNative call codegen unconditionally and also enable `HClinitCheck` codegen and extend the 178-app-image-native-method run-test to properly test these use cases. Test: # Edit `run-test` to disable checker, then testrunner.py --target --64 --ndebug --optimizing # Ignore 6 pre-existing failures (down from 7). Bug: 283082089 Change-Id: Ia514c62006c7079b04182cc39e413eb2deb089c1
2023-07-14Clean up ART intrinsics. Vladimir Marko
Change `intrinsics_list.h` to a normal include file instead of the weird include-use-and-undef pattern. Prefix macros defined in that file with `ART_`. And also remove blank lines at end of some files and address some comments on merged changes. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 283082089 Change-Id: I9c462f973c0c4bb53eff39fbe191014f6321d7c5
2023-05-22Use C++17's [[maybe_unused]] attribute in ART Stefano Cianciulli
Bug: 169680875 Test: mmm art Change-Id: Ic0cc320891c42b07a2b5520a584d2b62052e7235
2023-04-27Optimizing: Add `HInstruction::As##type()`. Vladimir Marko
After the old implementation was renamed in https://android-review.googlesource.com/2526708 , we introduce a new function with the old name but new behavior, just `DCHECK()`-ing the instruction kind before casting down the pointer. We change appropriate calls from `As##type##OrNull()` to `As##type()` to avoid unncessary run-time checks and reduce the size of libart-compiler.so. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: run-gtests.sh Test: testrunner.py --target --optimizing Bug: 181943478 Change-Id: I025681612a77ca2157fed4886ca47f2053975d4e
2023-04-27Optimizing: Rename `As##type` to `As##type##OrNull`. Vladimir Marko
The null type check in the current implementation of `HInstruction::As##type()` often cannot be optimized away by clang++. It is therefore beneficial to have two functions HInstruction::As##type() HInstruction::As##type##OrNull() where the first function never returns null but the second one can return null. The additional text "OrNull" shall also flag the possibility of yielding null to the developer which may help avoid bugs similar to what we have seen previously. This requires renaming the existing function that can return null and introducing new function that cannot. However, defining the new function `HInstruction::As##type()` in the same change as renaming the old one would risk introducing bugs by missing a rename. Therefore we simply rename the old function here and the new function shall be introduced in a separate change with all behavioral changes being explicit. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: buildbot-build.sh --target Bug: 181943478 Change-Id: I4defd85038e28fe3506903ba3f33f723682b3298
2022-11-07Reland "Make compiler/optimizing/ symbols hidden." VladimĂ­r Marko
This reverts commit 0a51605ddd81635135463dab08b6f7c21b58ffb0. Reason for revert: Reland after some of the required work was merged in other CLs. Also address a TODO from the original CL to mark required symbols with EXPORT in `intrinsic_objects.h`. Also mark symbols in new files as HIDDEN. Bug: 186902856 Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I936d448983928af23614ca82c2d0bf9a645e2c52
2022-04-21Avoid VarHandle checks for boot image field VarHandles. Vladimir Marko
And use the field offset as seen at compile time. Implemented for x86-64, arm and arm64 but not for x86 with incomplete set of `VarHandle` intrinsics. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: run-gtests.sh Test: testrunner.py --target --optimizing Bug: 191765508 Change-Id: If68b0287c8823e69c493dcefb7e61dc34d69fb4f
2021-09-24Copying sun.misc.Unsafe to jdk.internal.misc Sorin Basca
From OpenJDK 10 onward, sun.misc.Unsafe has been moved to jdk.internal.misc. Trying to merge in changes from OpenJDK 11 depends on having jdk.internal.misc.Unsafe available. As sun.misc.Unsafe is still used throughout libcore code, it cannot be changed yet, so a copy is made to jdk.internal.misc.Unsafe for now. As OpenJDK 11 is merged in and sun.misc.Unsafe references will disappear, it can be deprecated and eventually made to call into jdk.internal.misc.Unsafe. Test: m Test: art/test/testrunner/testrunner.py -t 004-UnsafeTest Test: art/test/testrunner/testrunner.py -t 2235-JdkUnsafeTest Bug: 190470684 Change-Id: I472a9778a1001fbd7c3ecce0dfa58ea6d632f158
2021-08-31Revert^2 "Compile time null checks for VarHandle intrinsics." Ulyana Trafimovich
This reverts commit 4a889b7f1e58368f0ffd795eaa24f2f493ccab8d. Reason for revert: relanding the original change after fixing the baseline compiler. Static checks for VarHandle intrinsics are now done in two places: 1) Simple static checks are done for both baseline and optimizing compilers in `HInstructionBuilder::BuildInvokePolymorphic`. 2) More complex checks are done in instruction simplifier only for the optimizing compiler. They can use information provided by preceding optimization passes. Bug: 191765508 Test: art/test.py --host -r Change-Id: I92932f6fcf408c700e6db0101fe2fb1e8300a54a
2021-07-21Revert "Compile time null checks for VarHandle intrinsics." Vladimir Marko
This reverts commit b3a7a6a72d7b91ee5507bd7314a3aae3948e6f29. Reason for revert: Breaks ART baseline compiler. Bug: 191765508 Change-Id: Ida63660e0149c4847f015950f95282e61add7204
2021-07-21Compile time null checks for VarHandle intrinsics. Vladimir Marko
Create a `VarHandleOptimizations` helper class holding the optimization flags for VarHandle intrinsics. Add a flag to avoid emitting the intrinsic implementation and move shared checks previously duplicated in intrinsic codegens helpers `HasVarHandleIntrinsicImplementation()` to the instruction simplifier. Individual intrinsic codegens perform additional checks as needed. Add the first optimization flag to avoid null check on the holder object if it cannot be null. And do not emit the intrinsic implementation if the holder object is null. Test: testrunner.py --host --optimizing Test: testrunner.py --target --optimizing Bug: 191765508 Change-Id: I53b1b57c327f02a9913f22885c1ce663cd9c3d44
2021-02-05Implement Reference.refersTo() intrinsic. Vladimir Marko
Test: Added tests to 122-npe and 160-read-barrier-stress Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: run-gtests.sh Test: testrunner.py --target --optimizing Bug: 172573708 Change-Id: I8342510565289058df218d3249ffac1eb993ca4f
2020-11-11Move VarHandle fences to unreachable intrinsics. Vladimir Marko
These were erroneously moved to unimplemented intrinsics in https://android-review.googlesource.com/1372099 . Test: m Bug: 71781600 Change-Id: Ic348ec1be92e7db8722575dd44f22826e770cc75
2020-11-06Remove NeedsDexCache logic from the compiler. Nicolas Geoffray
The compiled code and runtime stubs don't need to have direct access to the dex cache anymore. Test: test.py Change-Id: Id3aab9b10445ba2599e1a9ffd8e36506a745bfec
2020-11-04Implement Reference.getReferent() intrinsic. Vladimir Marko
Test: m test-art-host-gtest Test: testrunner.py --host --optimizing --jit Test: aosp_blueline-userdebug boots. Test: run-gtests.sh Test: testrunner.py --target --optimizing --jit Bug: 170286013 Change-Id: I4762f7c1cf3d61de2215ec8f1d14be80289c2372
2020-10-29Refactor Integer.valueOf() intrinsic implementation. Vladimir Marko
Prepare for Reference.getReferent() intrinsic implementation by a refactoring to separate the retrieval of an intrinsic method's declaring class to its own helper function, rather than being a part of a larger one. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing --jit Test: aosp_blueline-userdebug boots. Test: run-gtests.sh Test: testrunner.py --target --optimizing --jit Bug: 170286013 Change-Id: Ib6c0e55d0c6fcc932999428f21c51afe32ab7ef2
2020-07-24Prepare compiler for adding VarHandle support. Andra Danciu
This commit prepares the ground for adding VarHandle support in the compiler. The intrinsic locations builder and code generator are now triggered for HInvokePolymorphic nodes. VarHandle and MethodHandle intrinsics are marked as unimplemented rather than unreachable. Since the Varhandle intrinsics are not implemented yet, the functionality is not changed (i.e. the intrinsics are evaluated at runtime and not compiled). I manually tested that the intrinsic Visit* methods are triggered for the VarHandle methods. Bug: b/65872996 Test: art/test.py --host -r -t 713-varhandle-invokers Test: art/test.py --host --all-compiler -r Change-Id: I3333728c5f16d8dc4f92ceae2738ed59b3e31e6a
2019-10-14Revert "Make compiler/optimizing/ symbols hidden." Vladimir Marko
This reverts commit e2727154f25e0db9a5bb92af494d8e47b181dfcf. Reason for revert: Breaks ASAN tests (ODR violation). Bug: 142365358 Change-Id: I38103d74a1297256c81d90872b6902ff1e9ef7a4
2019-10-14Make compiler/optimizing/ symbols hidden. Vladimir Marko
Make symbols in compiler/optimizing hidden by a namespace attribute. The unit intrinsic_objects.{h,cc} is excluded as it is needed by dex2oat. As the symbols are no longer exported, gtests are now linked with the static version of the libartd-compiler library. libart-compiler.so size: - before: arm: 2396152 arm64: 3345280 - after: arm: 2016176 (-371KiB, -15.9%) arm64: 2874480 (-460KiB, -14.1%) Test: m test-art-host-gtest Test: testrunner.py --host --optimizing --jit Bug: 142365358 Change-Id: I1fb04a33351f53f00b389a1642e81a68e40912a8
2019-02-05Merge "Check that the String class is not movable in String.equals intrinsics." Roland Levillain
2018-12-14Revert "Revert "Add a baseline flag to JIT compile."" Nicolas Geoffray
This reverts commit 344b0d18eb9f9f2f2ef704acadc510a6dd56a282. Reason for revert: Not the CL that broke the tests. Change-Id: I38221d1ac723e5ea71cb398401e2fda8dd2d7db9
2018-12-13Revert "Add a baseline flag to JIT compile." Andreas Gampe
This reverts commit e734fe8d4aa5f70a5798363774a4ed63357ebe20. Reason for revert: May be breaking tests. Change-Id: I6c0c04a60c1b4f329c472d28a3c2666526bd6383
2018-12-12Add a baseline flag to JIT compile. Nicolas Geoffray
bug: 111397239 bug: 119800099 Test: m Change-Id: Id831b641e18a8497435839e2fbcfee1f6d60a56d
2018-11-01Do not cache RequiresConstructorBarrier() results. Vladimir Marko
Avoid caching the results. Caching was broken for JIT in the presence of class unloading; entries for unloaded dex files were leaked and potentially used erroneously with a newly loaded dex file. Test: m test-art-host-gtest Test: testrunner.py --host Test: Pixel 2 XL boots. Test: m test-art-target-gtest Test: testrunner.py --target Bug: 118808764 Change-Id: Ic1163601170364e060c2e3009752f543c9bb37b7
2018-10-10Introduce a 'baseline' variant for the compiler. Nicolas Geoffray
Implemented as a stripped down version of the optimizing compiler, not running any optimization. Adjust code to still work with expectations in code generators. bug: 111397239 Test: test.py --baseline Change-Id: I4328283825f9a890616e7496ed4c1e77d6bcc5dd
2018-09-28Remove need for intrinsic recognizer to be a pass. Nicolas Geoffray
Instead just recognize the intrinsic when creating an invoke instruction. Also remove some old code related to compiler driver sharpening. Test: test.py Change-Id: Iecb668f30e95034970fcf57160ca12092c9c610d
2018-09-07Check that the String class is not movable in String.equals intrinsics. Roland Levillain
Test: art/test.py Bug: 68181300 Bug: 67628039 Change-Id: I66afa3ea010f758125f8aec79509f0255cb5ea03
2018-09-06Revert "Fix String.equals() for moveable String.class." Roland Levillain
This reverts commit da283050a1a3ddbb7cefae3f36e8c8c1a6acedb7. Reason for revert: This CL is no longer needed with https://android-review.googlesource.com/737437 which makes the String class non-movable in all cases. Test: art/test.py Bug: 68181300 Bug: 67628039 Change-Id: I414abd79de1e1b0fc43dc3be412fc70598ef3044
2018-08-28Use 'final' and 'override' specifiers directly in ART. Roland Levillain
Remove all uses of macros 'FINAL' and 'OVERRIDE' and replace them with 'final' and 'override' specifiers. Remove all definitions of these macros as well, which were located in these files: - libartbase/base/macros.h - test/913-heaps/heaps.cc - test/ti-agent/ti_macros.h ART is now using C++14; the 'final' and 'override' specifiers have been introduced in C++11. Test: mmma art Change-Id: I256c7758155a71a2940ef2574925a44076feeebf
2018-06-29Implement Integer.valueOf() intrinsic for boot image. Vladimir Marko
And generate only one "boot image live objects" array rather than one per boot*.art file. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: Pixel 2 XL boots. Test: testrunner.py --target --optimizing Bug: 71526895 Change-Id: I23af7f47fea5150805f801cd2512f2d152ee5b73
2018-06-21Implement Integer.valueOf() intrinsic for PIC. Vladimir Marko
And fix the intrinsic for JIT even in case when someone messes up the IntegerCache using reflection. Two cases are exposed with a regression test (one that previously failed randomly and one that failed 100%) but other crashes were possible; for example, we would need a read barrier for array reads when elements are not guaranteed to be in the boot image. The new approach loads references only from the boot image live objects array which cannot be touched by reflection. The referenced objects and IntegerCache.cache are exposed and can lead to weird behavior but not crashes. On x86, the pc_relative_fixups_86 actually checks the cache an additional time but discrepancies between this check and the location building at the beginning of codegen should be OK as the HIsX86ComputeBaseMethodAddress should be added for PIC regardless of whether pc_relative_fixups_86 thinks the method is intrinsified or not. Test: 717-integer-value-of Test: Pixel 2 XL boots. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing --pictest --npictest Test: testrunner.py --host --jit Test: testrunner.py --target --optimizing --pictest --npictest Test: testrunner.py --target --jit Bug: 71526895 Change-Id: I89b3245a62aba22980c86a99e2af480bfa250af1
2018-04-26Step 1 of 2: conditional passes. Aart Bik
Rationale: The change adds a return value to Run() in preparation of conditional pass execution. The value returned by Run() is best effort, returning false means no optimizations were applied or no useful information was obtained. I filled in a few cases with more exact information, others still just return true. In addition, it integrates inlining as a regular pass, avoiding the ugly "break" into optimizations1 and optimziations2. Bug: b/78171933, b/74026074 Test: test-art-host,target Change-Id: Ia39c5c83c01dcd79841e4b623917d61c754cf075
2018-03-07Introduce MIN/MAX/ABS as HIR nodes. Aart Bik
Rationale: Having explicit MIN/MAX/ABS operations (in contrast with intrinsics) simplifies recognition and optimization of these common operations (e.g. constant folding, hoisting, detection of saturation arithmetic). Furthermore, mapping conditionals, selectors, intrinsics, etc. (some still TBD) onto these operations generalizes the way they are optimized downstream substantially. Bug: b/65164101 Test: test-art-host,target Change-Id: I69240683339356e5a012802f179298f0b04c6726
2018-03-01Introduce ABS as HIR nodes. Aart Bik
NOTE: step 1 of 2 for "Introduce MIN/MAX/ABS as HIR nodes." Rationale: Having explicit MIN/MAX/ABS operations (in contrast with intrinsics) simplifies recognition and optimization of these common operations (e.g. constant folding, hoisting, detection of saturation arithmetic). Furthermore, mapping conditionals, selectors, intrinsics, etc. (some still TBD) onto these operations generalizes the way they are optimized downstream substantially. Bug: b/65164101 Test: test-art-host,target Change-Id: I9c93987197216158ba02c8aca2385086adedabc4
2017-12-01Allow devirtualized method to be intrinsified. Mingyao Yang
For a invocation that's devirtualized to a different method, try to give intrinsics matching an opportunity before trying to inline it. Test: run-test on host. 638-checker-inline-cache-intrinsic. Change-Id: I51f70835db4c07575c58872a64a603a38dbcb89c
2017-11-29ART: Remove nested SOA in intrinsics code Orion Hodson
Removes a couple of unnecessary SOA instances. Bug: 69622155 Test: m -j32 Change-Id: I92e194096faeb4a83e4972d745bd8182ce8f820c
2017-11-24Apply individual intrinsic recognition during inliner. Aart Bik
Rationale: Inliner could introduce new method calls, in particular it could change invoke-interface to invoke-virtual, which could expose new intrinsics. This situation happens, for example, in Kotlin generated code where String operations first go through the CharSequence interface. Rather than running a full new phase, we just recognize intrinsics when interface calls are replaced by virtual calls. This optimization boosts KotlinMicroItems by 100% Test: test-art-host test-art-target Change-Id: Ibd0519283d67ed6997b056e34b4eafdd49fcbc2d
2017-11-20Refactored optimization passes setup. Aart Bik
Rationale: Refactors the way we set up optimization passes in the compiler into a more centralized approach. The refactoring also found some "holes" in the existing mechanism (missing string lookup in the debugging mechanism, or inablity to set alternative name for optimizations that may repeat). Bug: 64538565 Test: test-art-host test-art-target Change-Id: Ie5e0b70f67ac5acc706db91f64612dff0e561f83
2017-11-08Fix String.equals() for moveable String.class. Vladimir Marko
If the String.class is moveable (i.e. running without boot image), the instanceof check emitted by the JIT in the String.equals() intrinsic would require read barriers. As we do not really care about the performance of running without the boot image, disable the intrinsic in this case. Test: 669-moveable-string-class-equals (--jit) Bug: 68181300 Change-Id: I39c9f9935e0482b3b30f1ae5cd23515cbda0603b
2017-11-01ART: Intrinsify polymorphic signature methods Orion Hodson
Adds VarHandle accessor method to list of intrinsics. Adds code to interpreter to ensure intrinsics with polymorphic signatures are initialized. Rename most uses of InvokePolymorphic to InvokeMethodHandle (and similar changes) to be clear that the particular code path applies to MethodHandle instances rather than VarHandle. Change-Id: Ib74865124a1e986badc0a7c4bb3d782af07225d4 Bug: 65872996 Test: art/test.py --host
2017-10-06ART: Use ScopedArenaAllocator for pass-local data. Vladimir Marko
Passes using local ArenaAllocator were hiding their memory usage from the allocation counting, making it difficult to track down where memory was used. Using ScopedArenaAllocator reveals the memory usage. This changes the HGraph constructor which requires a lot of changes in tests. Refactor these tests to limit the amount of work needed the next time we change that constructor. Test: m test-art-host-gtest Test: testrunner.py --host Test: Build with kArenaAllocatorCountAllocations = true. Bug: 64312607 Change-Id: I34939e4086b500d6e827ff3ef2211d1a421ac91a