summaryrefslogtreecommitdiff
path: root/runtime/indirect_reference_table.h
AgeCommit message (Collapse)Author
2024-01-24Add visibility attributes in runtime/i* Dmitrii Ishcheikin
Bug: 260881207 Test: presubmit Test: abtd app_compat_drm Test: abtd app_compat_top_100 Test: abtd app_compat_banking Change-Id: I017173510501982607b7688b55ee27a0389abb3d
2023-04-04JNI: Fast-path for decoding returned jobject. Vladimir Marko
Results for the timeGetBytesAscii#EMPTY benchmark from the libcore's StringToBytesBenchmark suite on blueline-userdebug with the cpu frequencies fixed at 1420800 (cpus 0-3; little) and 1459200 (cpus 4-7; big): 32-bit little: ~415 -> ~390 64-bit little: ~415 -> ~390 32-bit big: ~180 -> ~170 64-bit big: ~180 -> ~170 Test: m test-art-host-gtest Test: testrunner.py --host --optimizing --debug --ndebug Test: run-gtests.sh Test: testrunner.py --target --optimizing --debug --ndebug Bug: 172332525 Change-Id: I0e19d583e5141e99a8b8c6fd9ae125fe7c9e02e7
2023-03-31Reland "Rewrite `LocalReferenceTable`." Vladimír Marko
This reverts commit 7911b464894dbfc580e5a8920a4d98eddb832e9e. Reason for revert: Reland with a fix and a regression test. Test: m test-art-host-gtest Test: testrunner.py --host Bug: 172332525 Bug: 276210372 Change-Id: I8109c8f3d13735606999859b82339c3513b0da9f
2023-03-30Revert "Rewrite `LocalReferenceTable`." Vladimír Marko
This reverts commit db18e88d8a9e2a45639c6fd25e91341dd3f32f07. Reason for revert: Crashes seen on virtual x86_64 devices. Bug: 172332525 Bug: 276210372 Change-Id: I50e47f45f60253a31d246e9f38e65ebf82da7765
2023-03-29Rewrite `LocalReferenceTable`. Vladimir Marko
Change `jobject` for local references to a `GcRoot<>*` with a `kLocal` tag, so that decoding can be done by clearing the tag and dereferencing. Optimize operations with CheckJNI disabled and small local reference table. Results for the timeGetBytesAscii#EMPTY benchmark from the libcore's StringToBytesBenchmark suite on blueline-userdebug with the cpu frequencies fixed at 1420800 (cpus 0-3; little) and 1459200 (cpus 4-7; big): 32-bit little: ~450 -> ~415 64-bit little: ~455 -> ~415 32-bit big: ~200 -> ~180 64-bit big: ~200 -> ~180 This CL also opens an opportunity for inlining a fast-path for local reference decoding to compiled JNI stubs for methods that return a reference. Test: m test-art-host-gtest Test: testrunner.py --host Bug: 172332525 Change-Id: Id6f2955419b966fd1ad860bace9c23947080f8ed
2022-12-08Split local reference table out of `IndirectReferenceTable`. Vladimir Marko
In preparation for rewriting the representation of local JNI references, split their implementation out of the shared `IndirectReferenceTable` which shall be used only for global and weak global references going forward. Make the new `LocalReferenceTable` always resizable (remove the enum `ResizableCapacity`) and rename the memory mappings for LRT to "local ref table". Remove `IndirectReferenceTable` code that was needed only for local references, make these tables non-resizable. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 172332525 Change-Id: I87f02c93694577d1b577c4114fa86c2cd23b4c97
2022-11-22Rename `kJniTransitionOrInvalid` to `kJniTransition`. Vladimir Marko
And remove `IndirectReferenceTable::SynchronizedGet()`. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 172332525 Change-Id: Ice599b33f4d494fccc0efd3b3a3574e930088f89
2022-11-21Clean up `IndirectReferenceTable` visiting. Vladimir Marko
Move weak global sweeping to the IRT class and clean up the entry visiting to avoid the need for the `IrtIterator`. Move `JNIEnvExt::UpdateLocal` to the `jni_env_ext-inl.h` because it requires `indirect_reference_table-inl.h`. Test: m test-art-host-gtest Test: tesrunner.py --host --optimizing Bug: 172332525 Change-Id: Ia96d31e0d8d701c93d7752bf76f633719a836f3f
2022-11-21Clean up `IndirectReferenceTable` construction. Vladimir Marko
Split the parts that can fail to a separate function. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Bug: 172332525 Change-Id: I95200a31cc757e4593d9cc7f956dd4d5ef624f92
2022-05-03Avoid PushLocalFrame(0) CHECK failure Hans Boehm
This makes EnsureLocalCapacity(0) and PushLocalFrame(0) correct, which we believe is the spec intent. Also simplify test for ridiculously large argument. Bug: 230854166 Test: Build and boot AOSP Change-Id: Id4bb3b6bb2f52ff0c3e78f13326405dac06de730
2021-11-01Assign lower level to Small IRT table lock Hans Boehm
It can be acquired after Class loader classes lock. Jvmti GetLoadedClasses traverses classes with a visitor that may need to allocate a LocalRef. Bug: 184847225 Test: Build and boot AOSP Change-Id: Ic19b2a3238321bc21440064f0d1b531ed254ea35
2021-10-27Initially allocate smaller local IRT Hans Boehm
Introduce a separate small object allocator to allocate tables for the initial local indirect reference tables, so they don't each occupy a full page. This seemed to be easier than using linear_alloc, since these allocations are done from multiple threads. This also has the advantage that GC roots are concentrated on separate pages, that could be protected as before, but there are many fewer of then than before. As discussed with Lokesh, it might eventually be better to allocate these in the Java heap. But doing that cleanly seems to require a major refactoring to split IrtEntrys into two separate components, which complicates iteration, etc. And that has locality disadvantages during lookup. Or we need to either drop the serial number of merge it into the GcRoot, neither of which is ideal either. Drive-by-fix: When trimming, don't call madvise on empty address ranges. Test: Build and boot AOSP. Test: art/test/testrunner/testrunner.py --host -b --64 Bug: 184847225 Change-Id: I297646acbdd9dbeab4af47461849fffa2fee23b1
2021-09-24Simplify IRTEntry Hans Boehm
We previously stored the last several object references associated with indirect reference table entry. The old entries might once have been used to provide more informatio about stale entries. But with a copying collector, they were not even getting updated during GCs, and we could not identify any purpose for them. Keep just the current entry instead. We keep the serial number from before to continue to check for stale references. This should save nearly half the space (both used and reserved) in indirect reference tables, while slightly speeding up accesses. It implements the most basic option suggested in the bug. If this pays off in a noticable way, we should do more here. Test: Build and boot AOSP Bug: 184847225 Change-Id: If563bcfcf7a01e4551326f06a2894bd906947025
2021-07-14Modernize typedefs with `using`. Vladimir Marko
Replace many occurences of `typedef` with `using`. For now, do not update typedefs for function types and aligned types and do not touch some parts such as jvmti or dmtracedump. Test: m Change-Id: Ie97ecbc5abf7e7109ef4b01f208752e2dc26c36d
2021-07-08Add JNI globals tracing Hans Boehm
Add separate tracing for global and weak global JNI references. We only add an entry for every Nth addition or removal of a reference. Currently N = 17 to minimize danger of getting in sync with some application code pattern. Bug: 189738006 Bug: 192318532 Test: Build boot and look at trace in S build. Change-Id: I2f223c2a07932f97f89ff87d57f4379c1396ef9e
2021-02-23Do not create HandleScope for JNI transitions. Vladimir Marko
We previously crated a HandleScope in the JNI transition frame to hold references passed as jobject (jclass, etc.) to the native function and these references were actually spilled twice during the transition. We now construct the jobject as a pointer to the reference spilled in the reserved out vreg area in the caller's frame. And the jclass for static methods is just a pointer to the method's declaring class. This reduces the amount of work required in the JNI transition, both on entry (in compiled stubs) and exit (in JniMethodEnd*). Some additional work is required when GC visits references of a native method as we need to walk over the method's shorty which was unnecessary for a HandleScope. Also fix Thread::InitStackHwm() to calculate correct stack size needed by the new Thread::IsJniTransitionReference(). The results for StringToBytesBenchmark on blueline little cores running at fixed frequency 1420800 are approximately arm64 (medians from 3 runs) before after timeGetBytesAscii EMPTY 447.33 436.86 timeGetBytesIso88591 EMPTY 440.52 431.13 timeGetBytesUtf8 EMPTY 432.31 409.82 arm (medians from 3 runs) before after timeGetBytesAscii EMPTY 500.53 490.87 timeGetBytesIso88591 EMPTY 496.45 495.30 timeGetBytesUtf8 EMPTY 488.84 472.68 Test: m test-art-host-gtest Test: testrunner.py --host Test: testrunner.py --host --gcstress Test: testrunner.py --host --jit-on-first-use Test: testrunner.py --host --jit-on-first-use --gcstress Test: run-gtests.sh Test: testrunner.py --target --optimizing Test: boots. Bug: 172332525 Change-Id: I658f9d87071587b3e89f31c65feca976a11e9cc2
2020-12-09JNI: Faster jobject decoding by avoiding checks. Vladimir Marko
Avoid costly runtime checks in Thread::DecodeJObject() and IndirectReferenceTable::Get() that it calls and replace them with DCHECK()s and checks in CheckJNI. This improves the performance of JNI interface in release mode for processes that do not use CheckJNI (default for non-debuggable apps). The results for StringToBytesBenchmark on blueline little cores running at fixed frequency 1420800 are approximately (medians from 3 runs) before after timeGetBytesAscii EMPTY 477.70 408.18 timeGetBytesIso88591 EMPTY 473.00 412.15 timeGetBytesUtf8 EMPTY 468.96 402.78 Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: blueline-userdebug boots. Bug: 172332525 Change-Id: Ibea788bb54879d1fca0608c30fde008063aaafcc
2020-09-14Prevent IndirectReferenceTable from being outside of kPageAlignment Alex Light
Due to how we resized the IndirectReferenceTable it could end up being an unaligned size. On some architectures, this could sometimes cause issues we would try to madvise a negative length region, causing crashes. To fix this we changed the IRT to avoid ever having non-page aligned lengths and changed how we calculate what to madvise slightly. Test: ./test.py --host Test: ./test.py --host --debuggable --64 --with-agent $ANDROID_HOST_OUT/lib64/libtifastd.so=ClassFileLoadHook Test: Manual checks on emulator Bug: 152421535 Change-Id: I9eb99c750e6b6230998bf8ba314be426ad8c228c
2020-06-11Clean up generated operator<<(os, enum). Vladimir Marko
Pass enums by value instead of const reference. Do not generate operator<< sources for headers that have no enums or no declarations of operator<<. Do not define the operator<< for flag enums; these were unused anyway. Add generated operator<< for some enums in nodes.h . Change the operator<< for ComparisonBias so that the graph visualizer can use it but do not use the generated operator<< yet as that would require changing checker tests. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: Ifd4c455c2fa921a9668c966a13068d43b9c6e173
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-08-21Remove unnecessary indirection from MemMap. Vladimir Marko
Avoid plain MemMap pointers being passed around by changing the MemMap to moveable and return MemMap objects by value. Previously we could have a valid zero-size MemMap but this is now forbidden. MemMap::RemapAtEnd() is changed to avoid the explicit call to munmap(); mmap() with MAP_FIXED automatically removes old mappings for overlapping regions. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: Pixel 2 XL boots. Test: m test-art-target-gtest Test: testrunner.py --target --optimizing Change-Id: I12bd453c26a396edc20eb141bfd4dad20923f170
2018-02-08Suppress clang 7.0 warnings. Chih-Hung Hsieh
capacity_ is used in some build target, and not in others. clang compiler gives warning on unused case, and also on used case if declared as unused. Test: make checkbuild Change-Id: I1800d02129a7587096b6de19dd791d2af44596d4
2017-12-07ART: Replace base/logging with android-base/logging Andreas Gampe
Replace wherever possible. ART's base/logging is now mainly VLOG and initialization code that is unnecessary to pull in and makes changes to verbose logging more painful than they have to be. Test: m test-art-host Change-Id: I3e3a4672ba5b621e57590a526c7d1c8b749e4f6e
2017-10-04ART: Add allocation tracking to JNI global refs Andreas Gampe
Add allocation tracking to global references. When the reference table's free capacity falls under an adjustable value, enable tracking so as to help tracking down possibly-leaky allocations. Bug: 67044702 Test: m test-art-host Change-Id: Ic17d6ebbad895b54c5ac63558027e04aef2b14c1
2017-10-02ART: Dump allocation stacks in reference table dumps Andreas Gampe
When allocation tracking is enabled and allocation stacks are available, print the stack traces of the objects in a reference table dumps, to aid tracking table overflows. Extend reference_table_test. Bug: 67044702 Test: m test-art-host Change-Id: I0118ba095f08dc66739707cd6a184487974b1570
2017-09-25ART: Refactor IRT:Add Andreas Gampe
Do not abort on overflow. Return null and an error message. The caller is responsible for handling this, e.g., by aborting. In a future CL, this may be used for driving additional GCs. Additional side effect is the removal of a frame from an abortion stack trace. Test: m Test: m test-art-host Change-Id: I80b1e0ee396fc69906d051f1b661d7dba222fc6f
2017-06-05ART: Remove old object_callbacks.h includes Andreas Gampe
Remove unused includes. Test: m Change-Id: I70c227d32c6900904e186b975d1f2131b718d93d
2017-06-01ART: Allow unlimited PushLocalFrame Andreas Gampe
The local reference table is resizable. Allow arbitrary capacity requests and only fail when the request cannot be satisfied. Bug: 62223672 Test: m test-art-host Change-Id: I05183098359c5a33473701e9a0d2a4d6c81bde58
2016-10-24ART: Make IndirectReferenceTable resizable Andreas Gampe
Allow backing table to be resized. This can be used for the local reference table, where synchronization is not an issue. Bug: 32125344 Test: m test-art-host Change-Id: Iae3a933e330026231b17fdde44bcdd99c235dff1
2016-10-24ART: Change IndirectReferenceTable Andreas Gampe
Change cookie structure to allow for more entries. Use a local hole-count caching scheme. The design is driven by two considerations. For one, the change is small and mostly local. The other point is to still allow inlining of functions involved with JNI transitions. This change is in preparation for a resizable backing table for "unlimite" local references. micro_native tests show changes are in the noise. Bug: 32125344 Test: m test-art-host Change-Id: I08ff5d6eaed75d13ec88f469fb0d18328a0eeb70
2016-10-24ART: Clean up IndirectReferenceTable Andreas Gampe
Introduce constants and move some functions into the IndirectReferenceTable class. Slightly change IndirectRef encoding to be more obvious (and slighly more optimized when decoding). Bug: 32125344 Test: m test-art-host Change-Id: I05819eccb733b611de582fb8d7151f1a110c305a
2016-10-19Return error message if IndirectReferenceTable construction fails. Richard Uhler
Previously if there was an error when constructing the IndirectReferenceTable, the error message was lost. Now expose and include the error message when throwing an exception related to failures to construct the IndirectReferenceTable. The error message is propagated through JVMEnvExt, JavaVMExt, and Runtime::Init as well. Bug: 32013594 Test: Added new 151-OpenFileLimit runtest. Test: m test-art-host, m test-art-target Change-Id: I3692f6928c9570358571bce634569d6f14cdeb05
2016-10-17ART: Remove IRT cruft Andreas Gampe
Remove dead code for initial vs maximum table size. Bug: 32125344 Test: m test-art-host Change-Id: Ie5806da7f5f3238483da918deca5982f01764466
2016-10-05Change indirect reference table to use ObjPtr Mathieu Chartier
Bug: 31113334 Test: test-art-host Change-Id: I340fdf430897ebd790ea4e35f94bcee776e98445
2016-10-03ART: Clean up IRT-related abort messaging Andreas Gampe
Change AbortIfNoCheckJNI to take the abort message as a parameter. This way it can be passed down. Bug: 31893081 Test: m test-art-host Change-Id: Ib24c7060f1b32c9613ab84e6c1966082c866bc14
2016-08-30ART: SHARED_REQUIRES to REQUIRES_SHARED Andreas Gampe
This coincides with the actual attribute name and upstream usage. Preparation for deferring to libbase. Test: m Test: m test-art-host Change-Id: Ia8986b5dfd926ba772bf00b0a35eaf83596d8518
2015-12-09ART: Make trampoline compiler pointer-size-safe Andreas Gampe
The trampoline compiler uses offsets of runtime structures which may change with the pointer size. Add offset tests to jni_internal_test. Bug: 26071368 (cherry picked from commit da9b763abc712fd6d1e24170a194abfbe795b8cd) Change-Id: I01d1a3727f46b3015ac677afb5427337c3093402
2015-09-01Enable lockless decoding of weak globals Mathieu Chartier
Will help speed up decoding weak DexCache roots. Change-Id: I9a68beb4106cbd383111a30e249c9b0149064e78
2015-08-12Remove unnecessary `explicit` qualifiers on constructors. Roland Levillain
Change-Id: Id12e392ad50f66a6e2251a68662b7959315dc567
2015-07-22Move to newer clang annotations Mathieu Chartier
Also enable -Wthread-safety-negative. Changes: Switch to capabilities and negative capabilities. Future work: Use capabilities to implement uninterruptible annotations to work with AssertNoThreadSuspension. Bug: 20072211 Change-Id: I42fcbe0300d98a831c89d1eff3ecd5a7e99ebf33
2015-05-20Intercept JNI invocation of String.<init> methods. Jeff Hao
libmono uses JNI AllocObject and CallNonvirtualVoidMethod to create and initialize a string instead of using the recommended NewObject. This change adds an intercept to change the String.<init> call to a StringFactory call instead. Then, it uses the object id of the original string object referrer and maps it to the result of the StringFactory. Bug: 21288130 (cherry picked from commit 15e9ad1d028d7f12cb598b075453173532a00d91) Change-Id: I3421c43722c07397da4a398c2ca9110e1d40bcfa
2015-04-22Replace NULL with nullptr Mathieu Chartier
Also fixed some lines that were too long, and a few other minor details. Change-Id: I6efba5fb6e03eb5d0a300fddb2a75bf8e2f175cb
2015-04-09ART: IRT refactor Andreas Gampe
IRT creation might fail. Add a path that allows to bypass the aborts and instead signal validity. Hide this path with a private constructor, rewrite users to use a static Create method. Bug: 20110201 Change-Id: I440499c3372cd7557eb970b70ce2c4543da520e4
2015-04-06Refactor and improve GC root handling Mathieu Chartier
Changed GcRoot to use compressed references. Changed root visiting to use virtual functions instead of function pointers. Changed root visting interface to be an array of roots instead of a single root at a time. Added buffered root marking helper to avoid dispatch overhead. Root marking seems a bit faster on EvaluateAndApplyChanges due to batch marking. Pause times unaffected. Mips64 is untested but might work, maybe. Before: MarkConcurrentRoots: Sum: 67.678ms 99% C.I. 2us-664.999us Avg: 161.138us Max: 671us After: MarkConcurrentRoots: Sum: 54.806ms 99% C.I. 2us-499.986us Avg: 136.333us Max: 602us Bug: 19264997 Change-Id: I0a71ebb5928f205b9b3f7945b25db6489d5657ca
2015-02-23Avoid unaligned accesses (SIGBUG/BUS_ADRALN) in IRT. Hiroshi Yamauchi
Pointers in IrtEntry aren't currently aligned under 64 bit builds. But unaligned atomic stores (store exclusive) do not work on arm64 (causes SIGBUG/BUS_ADRALN). Fix CC collector crashes caused by this. Bug: 12687968 Change-Id: I1d2f5376778a9a1e5cfea876f1f57d7a88ad5445
2015-01-15Print more info in MarkSweep::VerifyRoot Mathieu Chartier
Refactored old root callback to use a new class called RootInfo. RootInfo contains all the relevant info related to the root associated with the callback. The MarkSweep::VerifyRoot function now uses this info to print the StackVisitor's described location if the GC root is of the type kRootJavaFrame. Some other cleanup. Example output: E/art (12167): Tried to mark 0x123 not contained by any spaces E/art (12167): Attempting see if it's a bad root E/art (12167): Found invalid root: 0x123 with type RootJavaFrame E/art (12167): Location=Visiting method 'void java.lang.Runtime.gc()' at dex PC 0xffffffff (native PC 0x0) vreg=0 (cherry picked from commit 12f7423a2bb4bfab76700d84eb6d4338d211983a) Bug: 18588862 Change-Id: Ic5a2781f704e931265ffb3621c2eab4b2e25f60f
2014-11-26Trim reference tables when we trim the heap Mathieu Chartier
Before: System server: virtual shared shared private private size RSS PSS clean dirty clean dirty # object 2200 300 229 0 80 0 220 77 /dev/ashmem/dalvik-indirect ref table (deleted) Location: 1896 128 102 0 28 0 100 39 /dev/ashmem/dalvik-indirect ref table (deleted) After: virtual shared shared private private size RSS PSS clean dirty clean dirty # object System server: 2216 64 64 0 0 0 64 79 /dev/ashmem/dalvik-indirect ref table (deleted) Location: 2120 48 48 0 0 0 48 67 /dev/ashmem/dalvik-indirect ref table (deleted) No pause time regression measured in memalloc test. (cherry picked from commit 84dc99d2fa67e5dff018685661cb2bff62132989) Change-Id: I80d9bd3b98e888fa8f77d03df69f8479ed209986
2014-09-25Reduce IndirectReferenceTable memory usage Mathieu Chartier
Changed the slot side table and the main table to be a single table, reduced number of slots per reference from 4 to 3 to make the IrtEntry a power of 2 size. Before: 20848 kB: Dalvik Other After: 16760 kB: Dalvik Other Bug: 17643507 (cherry picked from commit a1de6b93426cfc66a64eb1b57303348aab5e766d) Change-Id: I362475235a887c60eff6870bb10051a6be3d5814
2014-09-09Address read barrier issue with cl/106467 Hiroshi Yamauchi
And tidy/add a check. Bug: 12687968 Change-Id: If63dc0d9d0a0ce5f2eeb81734ff8f4307865f67d
2014-09-03Remove abuse of mirror::Object* to reference special values. Ian Rogers
Remove kInvalidIndirectRefObject, kClearedJniWeakGlobal and ObjectRegistry::kInvalidObject. Handle error conditions by passing in or returning an error value. GetObjectRefType is simplified to be faster and not return invalid references that are not expected according to the spec. Adjust check JNI and jni_internal_test appropriately. Fix cases in the debugger/JDWP of out arguments being passed by reference. Bug: 17376993 Change-Id: I3ce8a28c01827e163f4dc288449959464da788b1