summaryrefslogtreecommitdiff
path: root/runtime/class_linker-inl.h
AgeCommit message (Collapse)Author
2025-01-15Make ResolveField respect the is_static parameter. Santiago Aboy Solanes
Also fixes some logic and a DCHECK in the presence of duplicate fields. Bug: 364876321 Test: 734-duplicate-fields Change-Id: Ice510db35853e6a3383e30393f616c839faca75d
2024-11-28Refactor ResolveMethod. Nicolas Geoffray
Introduce ResolveMethodId and ResolveMethodWithChecks to make it more explicit at the call site. This also simplifies the implementation of ResolveMethodWithChecks. Also avoid creating handles in ResolveField when the dex cache already contains the field. Test: test.py Change-Id: Ie722c6d7ecadf7c6dbd780f0fc58dfae89140a01
2024-11-11Avoid `strlen()` for `ClassLinker::FindClass()`... Vladimir Marko
... and related functions in most cases. Note that the `CompilerDriver` previously resolved the `ClassLoader` and `TransactionAbortError` using the provided class loaders. We're now using the `ClassLoader` from the class roots and resolving the `TransactionAbortError` in the BCP class loader. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 181943478 Bug: 338123769 Change-Id: I38e480cdcdb8bf02c958e4d0773437f5766f6be0
2024-07-10Use atomics for find_array_class_cache_ Mythri Alle
find_array_class_cache_ is used to cache the array classes. This is accessed concurrently by mutator threads that are looking for an array class. These threads both read entries and update the cache with the new array class if it wasn't found in the cache. GC also accesses this cache to clear it when visiting the roots of class linker. GC uses std::fill_n to clear the cache. Under ideal circumstances these operations could work as expected and the updates to each entry could be atomic. Though some valid compiler optimizations could break this and it is possible we see a partially initialized / cleared entry. To prevent these we use atomics to make it safe to access concurrently. Bug: 330843930 Test: art/test.py Change-Id: I493e0b0d47bf03603a4970855608cbe82a87c1a4
2024-05-10Revert "Workaround for b/336842546" Nicolas Geoffray
This reverts commit a4ac01044c50f4da02c40b8da5520d2eb65b41d9. Bug: 336842546 Bug: 73760543 Reason for revert: Fix for the bug has been submitted. CL also has an issue with thread suspension. Change-Id: I06785d58f3e473a13e18876e481fff9118851f53
2024-05-03Workaround for b/336842546 Santiago Aboy Solanes
Resolve the type if it hasn't been resolved before. Also, change to use Handles instead of ObjPtr since ResolveType can potentially suspend. Bug: 336842546 Bug: 73760543 Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Change-Id: I8ad77e63d6d9cc76fee8aac88742d4a4b678abf5
2024-04-11Clean up string data access in `DexFile`. Vladimir Marko
The `*ByIdx()` and `*ByTypeIdx()` functions were doing validity checks that were needed only for processing the debug data, so move the checks to these callers. Replace these functions with new overloads of other functions to provide consistent naming. In a few cases, rewrite calls to these functions to fetch and work with a `string_view` instead. Rename `GetStringLength()` to `GetStringUtf16Length()` and change its return type to `uint32_t`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I561899606f6e5ec5f23aa4be617349dacdb376e3
2024-01-24Add visibility attributes in runtime/c* Dmitrii Ishcheikin
Bug: 260881207 Test: presubmit Test: abtd app_compat_drm Test: abtd app_compat_top_100 Test: abtd app_compat_banking Change-Id: Id729aca1d8b6d003ff3e9755112f3283e9f2b507
2023-11-15Remove some unnecessary WellKnownClasses #includes. Vladimir Marko
Remove unnecesary includes from .h files and add an include that becomes necessary in a .cc file. Test: m Change-Id: I08237f612b366dedc2f2dce7c936d62de95089f5
2023-03-07Use a read barrier when getting the dex cache for lookups. Nicolas Geoffray
The previous assumption that the arrays were the same doesn't hold anymore since https://android-review.googlesource.com/2273646. Test: test.py Bug: 260557058 Change-Id: I681438c63036c43fe0c68d97d81d33047f019a9e
2023-01-16Refactor code aroud method resolution. Nicolas Geoffray
- Make unresolved AOT entrypoints use the tls cache - Remove duplicate code - Inline method access checks logic in its only use. - Fix in ClassLinker::ResolveMethodWithoutInvokeType() by calling shared helper. Test: test.py Change-Id: I1f42b5d0ac1dcd9c5eb483db9c5c5eefc9b2f4d1
2022-11-03Optimistically update field and method cache on type update. Nicolas Geoffray
To save on future lookups, update the method and field caches as soon as we update the type cache, when the type has the same dex cache, and the dex cache is using full arrays. This saves the number of lookup of maps startup by ~30% (2100 -> 1500). Test: test.py Change-Id: I4cb708a04fb491fe65a75412bb2a8b9306e81f78
2022-08-10Update native gc-roots separately in compaction pause Lokesh Gidra
The concurrent compaction algorithm requires all GC roots to be updated to post-compact addresses before resuming mutators for concurrent compaction. Therefore, unlike CC, we cannot update native roots in classes/dex-caches/class-loaders while visiting references (VisitReferences) on heap objects. This CL separates the two and updates all the gc-roots in the compaction pause. Bug: 160737021 Test: art/test/testrunner/testrunner.py Change-Id: I8a57472ba49b9dc30bc0f41a7db3f5efa7eafd9a
2022-02-25Update runtime/ implications to use (D)CHECK_IMPLIES Santiago Aboy Solanes
Follow-up to aosp/1988868 in which we added the (D)CHECK_IMPLIES macro. This CL uses it on compiler/ occurrences found by a regex. Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Change-Id: Id4ee45b41bad85a1f0d98c1e88af6baa3e34a662
2021-11-09Modified revert of "Add couple DexCache read-barriers." David Srbecky
Remove the DexCache read-barriers again (the revert) since there is measurable performance difference in app startup (~1%). It turns out they are on very hot path in the interpreter. The lazy array initialization made the DexCache fields mutable. However, instead of the read-barriers, we can just ensure we get the right to-space object on the array-initialization slow path. Test: test.py -b -r --host Change-Id: I3f0123141e9a7875a26f088bff68d50641b66883
2021-11-02Inline ResolveMethod and ResolveField in nterp David Srbecky
They are on very hot path (field and method opcodes). This makes up startup ~1% faster with interpreter. The methods are fairly big and spill most registers, but the DexCache-hit fastpath requires no spills. Rather than refactoring the methods, it is easier to just inline them, since the caller already spills. Test: test.py -b --host Change-Id: I60221e3aa819378ed2f353044cfdfe6cbc51237d
2021-10-05Change ClassLinker::dex_caches_ from list to unordered_map. David Srbecky
Move the DexFile* pointer from struct field out to map key. This makes it easy and fast to find DexCache from DexFile. Add check that given DexFile* is registered only once. Test: test.py -b -r --host --64 Test: generated images are identical as before Change-Id: I84a6d6cbf963af2408abe5bb5e4c99d0ca11df78
2021-09-21Add couple DexCache read-barriers. David Srbecky
I intend to make some of the fields mutable in the next CL, which means we cannot skip the read-barrier any more. Split this into own CL to make it easier to check if there are any significant performance changes. Bug: 182072259 Test: test.py -b -r --host --64 Change-Id: Ia20a3ba8285eb56ae6ff9e7fa5c0a62b14d88b65
2021-09-14Address review comments on method resolution. Nicolas Geoffray
Follow-up after: https://android-review.googlesource.com/c/platform/art/+/1825135 Test: 827-resolve-method Bug: 199246839 Change-Id: I085348040308d70730bd7f90bd3aa8ded5113087
2021-09-13Add a test and consistency checks in method / field resolution. Nicolas Geoffray
Always use the associated class loader of a dex cache. Test: test.py Bug: 199246839 Change-Id: Ib512126915cac4af229a5a206a8b4d9d73bdf02a
2021-03-31Workaround for b/145491866 Nicolas Geoffray
Check if the type is resolved before invoking CheckInvokeClassMismatch. Test: test.py Bug: 145491866 Bug: 73760543 Change-Id: I02714480cef2eece614ef487af60d257f070f46b
2021-02-25Revert "Lazily allocate DexCache arrays." Orion Hodson
This reverts commit 1214319d27e7fb4c4ff00b39799df6f15288098a. Reason for revert: Post-submit fails Bug: b/181097963 Test: TH Change-Id: I9fd21140f1703d0020458b786f48bd39889a9948
2021-02-23Lazily allocate DexCache arrays. David Srbecky
We rarely need the DexCache for compiled code. Delay the allocation in hope we never need it. This reduces DexCache memory usage by ~25% at startup. Test: m test-art-host-gtest Test: test.py -r -b --host Change-Id: I680a59c905c2b821ee954e4b32abd5d24876bd11
2021-02-18Remove pointer-size arguments from DexCache. David Srbecky
The DexCache is always allocated at runtime now and thus it always has runtime pointer-size. Remove the dead code. Test: m test-art-host-gtest Change-Id: Ic21dc20649e1fd70f8981602d75b5690065aec20
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
2020-07-07Workaround for b/160292234. Nicolas Geoffray
Resolve the type if not found before invoking CheckInvokeClassMismatch. Test: test.py Bug: 160292234 Bug: 73760543 Change-Id: Ia8ae4c2fff19af758b5bb7586a13b76972f50711
2020-07-03Add some logging for diagnosing a crash. Nicolas Geoffray
Test: m Bug: 160292234 Change-Id: I578f7b64b4f78ff32d1a4e17ea0570d351ff4980
2019-12-10Proactively dequicken on debuggable switch. Alex Light
Previously we would generally not really consider dex2dex quickening with debuggable processes. This could cause problems for structural redefinition since the -quick opcodes are incompatible with the types of changes structural redefinition allows. Furthermore this can cause some unexpected behavior where (for example) check-casts might appear to pass even if debugger activity should cause it to fail. In order to fix these issues we make the runtime more proactively dequicken dex-files when we start or switch to JAVA_DEBUGGABLE mode. Test: ./test.py --target --host Test: adb install -t ~/misc/Bandhook-Kotlin/app/build/outputs/apk/debug/app-debug.apk && adb shell monkey -p com.antonioleiva.bandhookkotlin -c android.intent.category.LAUNCHER 1 Bug: 134162467 Bug: 144168550 Change-Id: I2673c91b72ae7048d2ff71a1cf68cf552d4e8004
2019-01-02ART: Move dex structs into own header Andreas Gampe
Separating out the structs from DexFile allows them to be forward- declared, which reduces the need to include the dex_file header. Bug: 119869270 Test: m Change-Id: I32dde5a632884bca7435cd584b4a81883de2e7b4
2018-12-06ART: Move to using locks.h instead of mutex.h Andreas Gampe
When only annotating lock requirements, use locks.h. Bug: 119869270 Test: mmma art Change-Id: I1608b03254712feff0072ebad012c3af0cc3dda4
2018-11-21ART: Fix ResolveType with ArtMethod Andreas Gampe
ArtMethods may be obsolete. In that case, the dex cache of the declaring class is not correct. Refactor the code to avoid issues. Partially reverts commit 09c5ca40635faee00f40f6ca0581dd475efd545e. Bug: 119830111 Test: m test-art-host Change-Id: Ibf89af48e6384569c2abd6d5846cf05c929679d0
2018-10-25ART: Do some include-what-you-use Andreas Gampe
Help with transitive includes. In preparation for new specialized headers reducing transitivity. Bug: 118385392 Test: mmma art Change-Id: Ib465ecceec3331ea81588fb4a43eb65e766b6904
2018-10-23ART: Refactor for bugprone-argument-comment Andreas Gampe
Handles runtime. Bug: 116054210 Test: WITH_TIDY=1 mmma art Change-Id: Ibc0d5086809d647f0ce4df5452eb84442d27ecf0
2018-06-04Refactor String resolution. Vladimir Marko
Use the same pattern as type resolution and avoid some unnecessary read barriers in the fast path. Consolidate naming between ArtField and ArtMethod. Test: m test-art-host-gtest Test: testrunner.py --host Change-Id: Iea69129085f61f04a4add09edd0eadbb7ac9ecb2
2018-06-01ObjPtr<>-ify array allocations. Vladimir Marko
And remove some unnecessary calls to ObjPtr<>::Ptr(). Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 31113334 Change-Id: Ie313980f7f23b33b0ccea4fa8d5131d643c59080
2018-06-01Clean up class resolution and lookup. Vladimir Marko
Simplify the code and avoid read barriers when appropriate. Relax class status check in ArtField::GetDeclaringClass() because we can see ClassStatus::kIdx from the from-space class object for kReadBarrierOption=kWithoutReadBarrier. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I83886a64fe5a99a1c3c30eab3b35dae449e6b4bc
2018-05-31ObjPtr<>-ify ClassLinker::FindClass(), fix 1 stale reference use. Vladimir Marko
Thread::CreateAnnotatedStackTrace() was using a stale reference `aste_array_class`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 31113334 Change-Id: I191907c0053456bb57de425aa6ccd9668df818a2
2018-05-25Refactor ClassRoot/GetClassRoot(). Vladimir Marko
Move it outside the ClassLinker, into its own header file, and add retrieval based on a mirror class template argument. Keep the SetClassRoot() as a private member of ClassLinker. Make the new GetClassRoot()s return ObjPtr<>. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 31113334 Change-Id: Icbc6b62b41f6ffd65b437297a21eadbb0454e2b7
2018-02-15Refactor method resolution in class linker. Nicolas Geoffray
Rewrite all runtime callers of DexCache::SetResolvedMethod to call a shared method that will do the dex cache update. bug: 64759619 Test: test-art-host Test: device boots, runs Change-Id: Icc1aca121030e2864de09667bdbc793b502e3802
2018-01-02Fix default method verifier check for compact dex Mathieu Chartier
Add a feature flag and mark if the compact dex file was generated from a dex file that supported default methods or not. This is done to maintain the existing verifier behavior differences for dex files that do and don't support default methods. Fixed callers to use a virtual function instead of always checking the dex file version. Re-enabled run-test 975. Bug: 70930171 Bug: 63756964 Test: test-art-host Change-Id: I46ac5d3cde0d0c9f41cbc68cccaf954b531e0edf
2017-12-12Do not pass DexFile to ClassLinker::Lookup/ResolveType(). Vladimir Marko
The DexFile can be easily retrieved from the DexCache, so reduce the number of arguments that need to be passed. Also refactor the code to avoid doing the DexCache lookup twice and avoid unnecessary read barriers in the initial DexCache lookup (also for Lookup/ResolveField()). Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: Idea9aa42b6a5bade947e93e330b1abdb9d11b2da
2017-12-11Do not pass DexFile to ClassLinker::Lookup/ResolveMethod(). Vladimir Marko
The DexFile can be easily retrieved from the DexCache, so reduce the number of arguments that need to be passed. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I2e47280e7cb8b84595130c4abfb5ece18d7f5c75
2017-12-08Do not pass DexFile to ClassLinker::ResolveField*(). Vladimir Marko
The DexFile can be easily retrieved from the DexCache, so reduce the number of arguments that need to be passed. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I0579db64c63afea789c7c9ad8db81e37c9248e97
2017-12-08Determine HLoadClass/String load kind early. Vladimir Marko
This helps save memory by avoiding the allocation of HEnvironment and related objects for AOT references to boot image strings and classes (kBootImage* load kinds) and also for JIT references (kJitTableAddress). Compiling aosp_taimen-userdebug boot image, the most memory hungry method BatteryStats.dumpLocked() needs - before: Used 55105384 bytes of arena memory... ... UseListNode 10009704 Environment 423248 EnvVRegs 20676560 ... - after: Used 50559176 bytes of arena memory... ... UseListNode 8568936 Environment 365680 EnvVRegs 17628704 ... Test: m test-art-host-gtest Test: testrunner.py --host --optimizing --jit Bug: 34053922 Change-Id: I68e73a438e6ac8e8908e6fccf53bbeea8a64a077
2017-08-29ART: Remove ArtMethod::dex_cache_resolved_methods_. Vladimir Marko
Test: m test-art-host-gtest Test: testrunner.py --host Test: testrunner.py --target on Nexus 6P Test: Repeat the above tests with ART_HEAP_POISONING=true Test: Build aosp_mips64-eng Change-Id: I9cd0b8aa5001542b0863cccfca4f9c1cd4d25396
2017-07-28Use class unloading in dex2oat for verify and extract Mathieu Chartier
Unload the main classloader in between each dex file compilation to reduce RAM. This frees the whole java heap and associated linear allocs. This is only used for quickening since filters that do compilation may require loaded classes in the compiler and oat writer. This reduces dex2oat peak PSS for compiling a large app from 196MB to 135MB. Only works for verify and extract since the current approach is incompatible with oat writer patching. b/63911263 Added a verification override that reads the compiled class status to avoid ever verifying classes that were quickened (since this is not supported and causes failures). There is still some duplicated verification for some class with superclasses in other dex files. Support for quicken will be added in a follow up CL. Bug: 63467744 Test: test-art-host Test: test/testrunner/testrunner.py --interpreter --host -j40 Change-Id: Id0e4f84eb5db91d6143f752b498f4832a5b25b6e
2017-07-24ART: Include cleanup Andreas Gampe
Let clang-format reorder the header includes. Derived with: * .clang-format: BasedOnStyle: Google IncludeIsMainRegex: '(_test|-inl)?$' * Steps: find . -name '*.cc' -o -name '*.h' | xargs sed -i.bak -e 's/^#include/ #include/' ; git commit -a -m 'ART: Include cleanup' git-clang-format -style=file HEAD^ manual inspection git commit -a --amend Test: mmma art Change-Id: Ia963a8ce3ce5f96b5e78acd587e26908c7a70d02
2017-07-20Hash-based DexCache methods array. Vladimir Marko
Total boot*.art size for aosp_angler-userdebug: - arm64: - before: 11603968 - after: 10129408 (-1.4MiB, -12.7%) - arm: - before: 8626176 - after: 7888896 (-0.7MiB, -8.5%) Test: m test-art-host-gtest Test: testrunner.py --host Test: Nexus 6P boots. Test: testrunner.py --target Test: Build aosp_mips64-eng Bug: 30627598 Change-Id: I7f858605de5f074cbd7f0d9c4c072fbd44aee28f
2017-07-20ART: Change method lookup to be more consistent to JLS and the RI. Vladimir Marko
The method lookup for different invoke types was previously widely different and didn't work well with the dex cache method array where we have only a single slot for each MethodId. The new behavior is to perform the same lookup for all cases, distinguishing only between interface and non-interface referencing class, and to further align the behavior with the JLS and the RI. Where the JLS conflicts with the RI, we follow the JLS semantics. The new lookup for class methods first searches the methods declared in the superclass chain (ignoring "copied" methods) and only then looks in the "copied" methods. If the search in the superclass chain finds a method that has not been inherited (i.e. either a private method or a package-access method where one of the classes in the chain does not belong to the same package, see JLS 8.4.8), we still search the "copied" methods as there may actually be a method inherited from an interface. This follows the JLS semantics where inherited methods are included in the search (JLS 15.12.2.1) but conflicts with the RI where the private or package-access method takes precedence over methods inherited from interfaces. Note that this search can find an accessible method that is not inherited by the qualifying type, either for a package access method when the referrer is in the same package but the qualifying type is in another package, or for a private method where the referrer is in the same class but the qualifying type is actually a subclass. For the moment we allow such calls and we shall consider whether to throw an IncompatibleClassChangeError in this situation in future to comply with JLS 15.12.4.3. The new lookup for interface methods searches the interface class, then all the superinterfaces and then the java.lang.Object class, see implicitly declared methods in interfaces, JLS 9.2. The search for the maximally-specific non-abstract superinterface method is not yet implemented, but the difference should be difficult to observe as the usual subsequent call to FindVirtualMethodForInterface() should yield the same result for any matching method. The new test 162-method-idx-clash exposes several cases where we previously completely messed up due to the effects of the DexCache, or where we were out of line with the RI. It also tests a case where the JLS and the RI disagree and we follow the JLS. Test: art/test/run-test --host --jvm 162-method-resolution Test: m test-art-host-gtest Test: testrunner.py --host Test: testrunner.py --host --interp-ac Test: Nexus 6P boots. Test: testrunner.py --target Bug: 62855082 Bug: 30627598 Change-Id: If450c8cff2751369011d649c25d28a482a2c61a3
2017-04-21ART: Add object-readbarrier-inl.h Andreas Gampe
Move some read-barrier code into a new header. This prunes the include tree for the concurrent-copying collector. Clean up other related includes. Test: mmma art Change-Id: I40ce4e74f2e5d4c692529ffb4df933230b6fd73e