summaryrefslogtreecommitdiff
path: root/runtime/class_linker.cc
AgeCommit message (Collapse)Author
2025-03-20Allow APEX versions in the OAT header to be overriden. Jiakai Zhang
APEX versions are stringified mtime's of the APEXes installed on device, for detecting samegrade placebos (go/samegrade-placebos). In the case of Cloud Compilation, we cannot put the APEX versions in the OAT header because the OAT file is generated on the server. Instead, we put the APEX versions in a separate file (SDC file) when the SDM file is being installed on device. Therefore, we need a way to override the APEX versions in the OAT header. This is a no-op change. Bug: 377474232 Test: m test-art-host-gtest-art_runtime_tests Change-Id: I69658b61942979ff7f56e4908ce3204bd0a2116e
2025-03-20Revert^2 "Call target method in accessor MHs when it is set." Almaz Mingaleev
Previous LUCI crashes were due to b/404465902, which was fixed in aosp/3551420. Bug: 297147201 Test: ART_HEAP_POISONING=true art/test/testrunner/testrunner.py -b \ --host --baseline --debug --gcstress --64 Test: art/test/testrunner/testrunner.py -b \ --host --baseline --debug --gcstress --64 Change-Id: If93b9c6559ac8ddbc3211df1cbc4dec192cb054a
2025-03-10Revert "Call target method in accessor MHs when it is set." Almaz Mingaleev
Revert submission 3382609-target-accessors Reason for revert: x86.poison.64 failures on LUCI Reverted changes: /q/submissionid:3382609-target-accessors Change-Id: I384945809bc18ac4dfc937af088c7dbe30ac5c5c
2025-03-06Call target method in accessor MHs when it is set. Almaz Mingaleev
Bug: 297147201 Test: ./art/tools/run-libcore-tests.sh --mode host --variant X64 Test: ./art/test/testrunner/testrunner.py -b --host --64 Test: ./art/test/testrunner/testrunner.py -b --target --64 Change-Id: I5f8dc0761abbc1f5bb4f5727ae1e6966a4ebaf8a
2025-03-03Flag classes that have unresolved type checks. Nicolas Geoffray
This allows skipping resolving the field type when setting a field. Test: test.py Change-Id: I1945deca5fdcccca7e67297eca8765b1f2f516f3
2025-02-21Support loading an ART file from a zip file. Jiakai Zhang
Bug: 377474232 Test: art/test.py --host -g Change-Id: I1f8acd1d6eeff96cf83af8fcd5111865e114bcef
2025-02-17Refactor `ArtMethod` entrypoint initialization. Vladimir Marko
Introduce `Instrumentation::ReinitializeMethodsCode()` for the cases where we want to reset the entrypoint after the method has already been initialized. Keep the old function `Instrumentation::InitializeMethodsCode()` exclusively for the initialization of a newly loaded method's entrypoint, split out the work that can be done in suspended state and remove any unnecessary work. For example, we do not use the Nterp entrypoint until the class has been verified, so all the Nterp checks can be removed. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 329196666 Change-Id: I1d0c195b0118fe50434d496f56346a9f744fbaf7
2025-02-17Do most of `ClassLinker::LoadClass()` in native state. Vladimir Marko
Load class data to temporary storage without holding the mutator lock to avoid holding up any checkpoints. Then copy the data to the actual `Class` structures. For abstract methods, use the "quick to interpreter bridge" directly instead of going through the boot image trampoline. Note: The `ArtMethod::{hotness_count_,imt_index_}` was previously documented as unused and zero-initialized for abstract class (non-interface) methods in https://android-review.googlesource.com/3477431 . This unused value was actually initialized to the initial hotness threshold but we're making it zero-initialized now. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 329196666 Change-Id: I07a040944e9137481897b5d9313d56e623a3894f
2025-02-07Remove cdex support from `ArtMethod`... Vladimir Marko
... and a few other places in `runtime/`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 325430813 Change-Id: Ied837bffed78b1fe4c4d381772b8c1933b76f6c0
2025-02-05Refactor `ImTable::GetImtIndex()`. Vladimir Marko
Make it easier to calculate the IMT index without an actual `ArtMethod` in preparation for a significant refactoring of `ClassLinker::LoadClass()`. Update documentation of `ArtMethod::imt_index_` which is actually unused for abstract non-interface methods. Also reorder code in `ClassLinker` without any modification to make it easier to compare the differences in the upcoming refactoring. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 329196666 Change-Id: Ic71ff323ea92325958d59536e83ab70d057b94df
2025-01-28Fix missing logging of core platform API violations in just-warn mode. Martin Stjernholm
In one case a hiddenapi access check was done with hiddenapi::AccessMethod::kNone for an app access, with the intention of following it up with another "real" check that does log and applies the enforcement policy. However, hiddenapi::AccessMethod::kNone applied the current enforcement policy, so the second check would always get skipped if the policy isn't hiddenapi::EnforcementPolicy::kEnabled. That's a problem when it's kJustWarn, because the first check won't log, and the second - which would - is skipped. Fix that by returning an access failure for the first check, regardless of the policy, so that the second doesn't get skipped. The behaviour doesn't change if the policy is kEnabled, and the second check won't do anything if it's kDisabled, so this change only has effect when it's kJustWarn. Also rename kNone to the more apt kCheck. For compatibility in other places where access checks with kNone aren't used like above, introduce a new access method kCheckWithPolicy, which keeps the behaviour of kNone (but with a more descriptive name). Some of those code paths should perhaps be changed to kCheck as well, but that's for another time. Test: Boot and check logcat with planted API violations in system_server. Test: 674-hiddenapi 690-hiddenapi-same-name-methods 691-hiddenapi-proxy 817-hiddenapi 822-hiddenapi-future 999-redefine-hiddenapi 2038-hiddenapi-jvmti-ext 2270-mh-internal-hiddenapi-use on host and target Bug: 377676642 Change-Id: I4ca70c229bd6261a78dcd68990708a318b0e7588
2025-01-21Add new WellKnownClasses fields to avoid harcoded constants. Nicolas Geoffray
Test: test.py Change-Id: I3a065dd5582269792032df0c6446c3c4b6cd72be
2025-01-16Merge sFields and iFields. Nicolas Geoffray
Test: test.py Change-Id: Ib97fca637a8866a41a4389b150c6000d9fb6d99b
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-12-02Only constructor names can start with `<`. Vladimir Marko
`DexFileVerifier::CheckClassDataItemMethod()` rejects method names starting with '<' other than "<init>" and "<clinit>". Therefore `ClassLinker::LoadMethod()` does not need to check the whole method name when checking for constructors without the `kAccConstructor` flag. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I41dbedc1b6dd2e26444a2198a82ab65b6ab4a43e
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-20Revert "Always use an array in the DexCache for ArtField and ArtMethod." Nicolas Geoffray
This reverts commit 1f9c184392020cb5c4bdf453f4c8847ca389614b. Reason for revert: Memory regressions. Change-Id: I85357603c31aa7dbde92aea5958167ea8f0fd481
2024-11-12Add an extra bit for intrinsics in ArtMethod Santiago Aboy Solanes
This increases the number of intrinsics from 255 to 511. Bug: 370367478 Test: art/test/testrunner/testrunner.py --host --64 -b --optimizing Change-Id: I9104dab59b06f4fb72c44ec9e004566cc28e668f
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-11-05Use `std::string_view` for `ClassTable` operations. Vladimir Marko
Use `std::string_view` instead of `const char*` descriptor. This uses faster `memcmp` instead of the slower`strcmp` for descriptor comparison. Note that the `ScopedTrace` passes `const char*` across the `libartpalette` boundary, so we cannot easily replace the `const char* descriptor` with `std::string_view descriptor` in certain `ClassLinker` functions because we actually need to pass a null-terminated string and the `string_view` API does not technically guarantee null-terminated data. Therefore we resort to explicitly passing around the descriptor and its length as separate arguments. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 181943478 Bug: 338123769 Change-Id: Ie3fa251390acc582c54b4686d18696eb89b32361
2024-11-05Rename ResolveMethodWithoutInvokeType and use it more. Nicolas Geoffray
Rename it to ResolveMethodId as a more precise name, and use it in places where that's the thing we need. Test: test.py Change-Id: I906371585e9fa208093eed9affba552fd135a184
2024-11-04Remove `ClassLinker::LookupClasses()`. Vladimir Marko
This has been dead code since https://android-review.googlesource.com/1216803 . Test: m Change-Id: I1bc84b8c85f88a50071e50b58ed2efb2177633d3
2024-10-28Always use an array in the DexCache for ArtField and ArtMethod. Nicolas Geoffray
The lookup success rate is too low (<1%) during app startup where the cache is most stressed. So always use an array for them. To avoid memory regression, madvise away the arrays at every GC. go/art-benchmark-service reports ~3% improvement in app startup with no statistically significant memory regression. Test: test.py Change-Id: Id13612054943ed7770c9e96756f391eed2352d79
2024-10-17Separate kRuntimeISA/kRuntimeQuickCodeISA Chris Jones
Currently ART has an implicit assumption that the ISA of the quick code (e.g.: app code) that is targeted to be run by ART will be the same as the machine that runs ART itself (e.g.: runtime code). This assumption is made by having a single value (kRuntimeISA) representing both of these types of code. Instead kRuntimeISA is split into two values so that it is possible to target the case where these two ISAs don't match, for example: in simulator mode. The two values are as follows. - kRuntimeISA: - Must match the ISA of the machine that ART will be run on. This ISA will be used for the native context, native stack frame and native ABI. - kRuntimeQuickCodeISA: - The ISA that ART will generate quick code for, i.e.: that java code will be compiled to. This ISA will be used for the quick context, quick stack frame and quick ABI. Therefore replace kRuntimeISA with kRuntimeQuickCodeISA where the semantics of quick code ISA is expected, not the ISA of the machine the code is running on. Also hardcode ISA for ISA specific QuickArgumentFrameInfo classes. Authors: Artem Serov <artem.serov@linaro.org> Artem Serov <artem.serov@arm.com> Chris Jones <christopher.jones@arm.com> Test: test.py --host --target Change-Id: Ibe6f3e27179f3baa49a8de89686341df0dcf16f5
2024-10-07Fix `VerificationResults` use in `OatWriter`. Vladimir Marko
Since https://android-review.googlesource.com/2236075 the `OatWriter` has been using a null `VerificationResults` because `CreateOatWriters()` is called before initializing the `verification_results_` in `Dex2Oat`. As the `OatWriter` is using it only to select between two `ClassStatus` values that currently lead to the very same behavior in the `ClassLinker::VerifyClassUsingOatFile()` (but with different comments and therefore prone to diverging), this did not yet lead to any observable difference in behavior. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing. Change-Id: I3f0b67497358ac98b4980691f80044a5b0f0fc17
2024-09-27Fix spacing in verbose logging Santiago Aboy Solanes
It used to print things like `: 0( NotReady)` and now it will print them, like `: 0 (NotReady)` which is more readable. Change-Id: I81773bd64d56444be4efd984ce3eb752bdd2df84
2024-09-24Add more validation for const-method-handle. Almaz Mingaleev
Making it closer to JVMS 4.4.8 and 5.4.3.5. The RI rejects certain constructions at the class verification stage, hence there are separate classes for MethodHandle-s targeting <init> and <clinit> methods. In these cases The RI throws ClassFormatError during class load, but currently we do validations only when actual MethodHandle object is constructed, that's is the reason why test code has ICCE | CFE in catch blocks. That will be addressed in the upcoming CLs. This should not cause any compat issues as even if some of these MethodHandle were constructed successfully, their invocation leads to runtime crashes. Bug: 297147201 Test: ./art/test/testrunner/testrunner.py --host --64 --jvm -b Change-Id: I551b04e3c00ffc8bcdeac4760d9ac4b3bb7b2aff
2024-09-17Consider MethodType/Handle annotations in VisitClassAnnotations Santiago Aboy Solanes
These annotations are possible (due to the DEX spec) but unexpected in this scenario. Update dexdump to dump those annotations too. Update the gtest to not dereference h_klass until we know it's safe. Bug: 365807384 Fixes: 365807384 Test: m test-art-host-gtest-art_runtime_tests64 Change-Id: I7fc8ff2bc60f0b7e6af3047ab721b18427ee5f96
2024-08-08Use variable sized ref-offset bitmap for fast VisitReferences() Lokesh Gidra
Bug: 304325190 Test: art/test/testrunner/testrunner.py --host Change-Id: I6e25143b827acaa12ff5bd94e6196faaed461f4a
2024-07-22Embed component-size shift in class-flags Lokesh Gidra
This helps by eliminating the need to dereference component_type_ reference in Class each time we need to compute the array's size. Bug: 304325190 Test: art/test/testrunner/testrunner.py --host Change-Id: I745b794066fa24787800f0e0baaf5c4188842bc1
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-06-25Remove a failing DCHECK for IAE in an edge case. Vladimir Marko
Also address some other late comments on https://android-review.googlesource.com/2146626 . Test: m test-art-host-gtest Test: testrunnerpy.py --host --optimizing Change-Id: Ib43ff9b959431e74a6ada6213780b400bbf265a2
2024-06-20Move some classes from `runtime/` to `dex2oat/`. Vladimir Marko
Move the transactional interpreter, `AotClassLinker`, `Transaction` and `SdkChecker`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: If001e06711ee345ce5b937ed764e66b26a0abcd6
2024-06-20Replace `ScopedAssertNoNewTransactionRecords`... Vladimir Marko
... with `ScopedAssertNoTransactionChecks`. The new check is stronger than the old one but does not work during early setup when we do not have a `Thread` object yet. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: Iba5a5cda0d97993ff324b4d11de02cb07f770699
2024-06-18Move `jni_stub_hash_map_test.cc` to `compiler/`. Vladimir Marko
The test is using `Compiler`, so it belongs to `compiler/`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 288983053 Change-Id: Id1d5aef67a694a8b610d390c4e40e74d9d788ca9
2024-06-13Use C++20 `string{,_view}::{starts,ends}_with()`, part 1. Vladimir Marko
Remove the header file `string_view_cpp20.h` and update all source files that previously used this header file. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: Iafcdfc838a97deed7fb3a37cc8afe1f7ee78306b
2024-05-31Faster `ArtMethod` fixup in `ImageWriter`. Vladimir Marko
Calculate the access flags in a local variable to avoid unnecessary atomic operations. Clean up the code to avoid some unnecessary branching. Avoid nterp flag recalculation when the target ISA is the same as `kRuntimeISA`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 181943478 Change-Id: I2486d54f4b4cf73f9b8e94b366ee9db3085e5fa7
2024-05-21Further refactor transaction checks in interpreter. Vladimir Marko
Reverse the relationship between `ActiveTransactionChecker` and `AotClassLinker` by moving the checks to the latter. Move `{Active,Inactive}TransactionChecker` and functions `DoField{Get,Put}()` to the `interpreter_switch_impl*`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing --interp-ac Change-Id: I509083b4ee77a69a3ba7e0d277b0e9e5fb7e32c8
2024-05-17Move transaction records from `Runtime` to `AotClassLinker`. Vladimir Marko
Keep a simple flag for active transaction in `Runtime` but move all other transaction data to `AotClassLinker`. Make `IsActiveTransaction()` a pre-requisite for calling `IsTransactionAborted()`. Eliminate `AbortTransactionAndThrowAbortError()` by inlining into `AbortTransactionV()` and rewriting other callers to use `AbortTransactionF()` instead. Separate transaction-related test code to its own files. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: Ie6ee421fcfed1599049ab50ca692f19c71f395ce
2024-05-14Faster `DexFile::FindTypeId()`. Vladimir Marko
Work with `std::string_view::compare()` instead of slower `CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues()`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 338123769 Change-Id: I4c3cc131da457c0a73f83fa2f864491eb2bc7a03
2024-05-13Faster `ClassTable::UpdateClass()`. Vladimir Marko
In the `ClassTable::UpdateClass()`, both the old and the new `Class` objects reference the same dex file and type index. Therefore it's better to do the lookup with the new `Class` object as the `Class:DescriptorEquals(ObjPtr<Class>)` can avoid the string comparison for the descriptor match in this case and we compare descriptors only for hash conflicts. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 338123769 Change-Id: I23960c9c3b34b7f7fdd2fce6b191fd9c4efe7320
2024-05-03Refactor transaction checks in switch interpreter. Vladimir Marko
Prepare for moving the transactional interpreter from `runtime/` to `dex2oat/` by moving transaction checking code to a new file `active_transaction_checker.h`, and breaking unstarted runtime dependency on transaction code by adding an indirection with a virtual call through `ClassLinker`. Consistently return the same value from contraint checks. Previously we were returning the negated result from the `CheckWrite{,Value}Constraint()` compared to the value we received from `Transaction::Write{,Value}Constraint()`. Test: m test-art-host-gtest Test: testrunner.py --host --interp-ac Change-Id: I88a168b6c770932d014e3a40486480590cef0401
2024-04-30Do not return an abstract class as IMT owner. Nicolas Geoffray
Abstract classes don't have an IMT and therefore cannot own one. Test: 141-class-unload Bug: 322253629 Change-Id: Ic6bb498d83ec66252710af384c24963be2287055
2024-04-16Rename `.data.bimg.rel.ro` to `.data.img.rel.ro`. Vladimir Marko
Prepare for adding app image patches to the same section. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 38313278 Change-Id: Ib552f005b3a2859152d0de9fa6b2fcd48a0f3feb
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-04-11Fetch class loaders and wait for GC in JitCodeCache::GetProfiledMethods. Nicolas Geoffray
Otherwise, we could be looking at ArtMethods whose class loader is being deleted. Test: test.py Bug: 331427447 Change-Id: I3a1d052216c7691d98576ab912e8af96de65a77b
2024-04-08ART Faster `LinkCode()` in `ClassLinker`. Vladimir Marko
Make `LinkCode()` a member of `ClassLinker` and speed it up by avoiding a linear (but fast) method code lookup using the `BitVector::NumSetBits()`, avoiding related function call overhead as well as pulling some invariant checks out of the calling loops and eliminating redundant checks. For a test class with 1000 unannotated static methods and 400 @NeverCompile static methods, this change reduces the time needed by `ClassLinker::LoadClass()` by roughly 25%. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 329196666 Change-Id: Ifeae520113594acae2e5c19ba746f11ede2dfac2
2024-04-05Faster annotations processing in `ClassLinker::LoadClass()`. Vladimir Marko
Iterate annotations alongside other method data, using the fact that both are ordered by method index. We use separate iterators for loading direct and virtual methods. For a test class with 500 unannotated static methods and 200 @NeverCompile static methods, this change reduces the time needed by `ClassLinker::LoadClass` approximately 2x. For a test class with twice that many methods, the time without this change increases by ~3x but with this change the time increases by ~2x, showing nice linear scaling. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 329196666 Change-Id: I800b8e8e9f9e5a4fbfbda1361f99feb8c43ff1d5
2024-03-28Simplify finalizer check in `ClassLinker::LoadMethod()`. Vladimir Marko
Move the special handling for `Object` and `Enum` to the `ClassLinker::InitWithoutImage()` to simplify the function used for loading methods for all classes. Test: test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 329196666 Change-Id: I81057802dfa6406045deea53c8029de3622a9ef8
2024-03-26Rename enums.h/.cc to pointer_size.h/.cc. Santiago Aboy Solanes
It was the only enum in the file Bug: 329378408 Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Change-Id: If0e385324afa3685f648135ba9b60e6bc79ba0ed