summaryrefslogtreecommitdiff
path: root/core/java/android/util/ArrayMap.java
Commit message (Collapse)AuthorAgeFilesLines
* Merge "Redact key value from log when DEBUG is false" am: 17a7d79ff4 am: ↵Suprabh Shukla2021-09-301-1/+1
|\ | | | | | | | | | | | | | | 694cf0f6af am: 23315f8003 am: fefc7f08be am: 0708411189 Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1458401 Change-Id: I1a937222e7f92e2db0ca183f14f08aa05d7e295b
| * Merge "Redact key value from log when DEBUG is false" am: 17a7d79ff4Suprabh Shukla2021-09-291-1/+1
| |\ | | | | | | | | | | | | | | | Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1458401 Change-Id: Iea902e93f038cd3a06d63cf6c6cdd149c873df79
| | * Redact key value from log when DEBUG is falseEdward Savage-Jones2021-09-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | See bug for details Bug: 170653379 Test: see bug Change-Id: I713fd8c03444167faf35a170b885c38af5482e31
* | | Improve replaceAll.Kweku Adams2021-09-101-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default implementation of Map.replaceAll() iterates through the entrySet. Switch to a simple for loop iterating through the array since the iterator is an inefficient way to access the array contents. Benchmark results: Before: android.util.ArrayMapPerfTest#testReplaceAll_Large: replaceAll_Large_min (ns): 888977 replaceAll_Large_median (ns): 904642 replaceAll_Large_mean (ns): 914596 replaceAll_Large_standardDeviation: 23960 android.util.ArrayMapPerfTest#testReplaceAll_Small: replaceAll_Small_min (ns): 177767 replaceAll_Small_median (ns): 179955 replaceAll_Small_mean (ns): 180331 replaceAll_Small_standardDeviation: 2865 After: android.util.ArrayMapPerfTest#testReplaceAll_Large: replaceAll_Large_min (ns): 557385 replaceAll_Large_median (ns): 586495 replaceAll_Large_mean (ns): 583712 replaceAll_Large_standardDeviation: 20356 android.util.ArrayMapPerfTest#testReplaceAll_Small: replaceAll_Small_min (ns): 108051 replaceAll_Small_median (ns): 110802 replaceAll_Small_mean (ns): 109987 replaceAll_Small_standardDeviation: 1334 Bug: 194098491 Test: atest CorePerfTests:ArrayMapPerfTest (see results above) Test: atest CtsUtilTestCases:ArrayMapTest Test: atest FrameworksCoreTests:ArrayMapTest Change-Id: If87ae5f3aa4b184b95c16aed5f2fb6f31d11668a
* | | Improve forEach.Kweku Adams2021-08-111-0/+23
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default implementation of Collection.forEach() uses the iterator(). Switch to a simple for loop iterating through the array since the iterator is an inefficient way to access the array contents. Benchmark results: Before: android.util.ArrayMapPerfTest#testForEach_Large: forEach_Large_min (ns): 599759 forEach_Large_median (ns): 655845 forEach_Large_mean (ns): 636927 forEach_Large_standardDeviation: 34373 android.util.ArrayMapPerfTest#testForEach_Small: forEach_Small_min (ns): 118822 forEach_Small_median (ns): 121422 forEach_Small_mean (ns): 121695 forEach_Small_standardDeviation: 2079 After: android.util.ArrayMapPerfTest#testForEach_Large: forEach_Large_min (ns): 403562 forEach_Large_median (ns): 441364 forEach_Large_mean (ns): 442301 forEach_Large_standardDeviation: 24917 android.util.ArrayMapPerfTest#testForEach_Small: forEach_Small_min (ns): 81889 forEach_Small_median (ns): 87889 forEach_Small_mean (ns): 86905 forEach_Small_standardDeviation: 2880 Bug: 194098491 Test: atest CorePerfTests:ArrayMapPerfTest (see results above) Test: atest CtsUtilTestCases:ArrayMapTest Test: atest FrameworksCoreTests:ArrayMapTest Change-Id: Id528fe24f1d17af01a2d639753d42e2ad21144d2
* / Add @Nullable annotation to the parameter of Object.equals() methods.Roman Kalukiewicz2020-10-151-1/+2
|/ | | | | | | | | | | | | | | | | | Those annotations could be inferred by some tools (like Kotlin), but the https://checkerframework.org/ doesn't check inherited annotations complaining about all equals() invocations that get nullable argument. The change was generated by running find . -name \*.java | xargs sed -i 's/public boolean equals(Object /public boolean equals(@Nullable Object /' in the frameworks/base directory and by automatically adding and formatting required imports if needed. No manual edits. Bug: 170883422 Test: Annotation change only. Should have not impact. Exempt-From-Owner-Approval: Mechanical change not specific to any component. Change-Id: I5eedb571c9d78862115dfdc5dae1cf2a35343580
* Use new UnsupportedAppUsage annotation.Artur Satayev2020-01-071-1/+1
| | | | | | | | Existing annotations in libcore/ and frameworks/ will deleted after the migration. This also means that any java library that compiles @UnsupportedAppUsage requires a direct dependency on "unsupportedappusage" java_library. Bug: 145132366 Test: m && diff unsupportedappusage_index.csv Change-Id: I288969b0c22fa3a63bc2e71bb5009fe4a927e154
* Address static cache access issues.Kweku Adams2019-08-201-20/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | ArrayMap and ArraySet are not thread safe, so callers are expected to lock around their instances before calling any methods. However, if a caller fails to lock, there can be races that end up corrupting the cache pool (despite having the class level lock held). A corrupted pool causes issues for other ArrayMap/Set instances, even if those instances are properly used under locks. There's no way to guard against cache pool corruption without making ArrayMap/Set fully thread-safe, changing the pool structure, or appropriately locking around each ArrayMap/Set instance. For now, we make ArraySet throw ConcurrentModificationException on a best effort basis to provide better awareness when an ArraySet is accessed concurrently without any locks and try to detect when the cache is corrupted. Bug: 62282384 Bug: 73549921 Bug: 122969275 Bug: 139015193 Bug: 139401479 Test: atest CtsUtilTestCases:ArrayMapTest Test: atest CtsUtilTestCases:ArraySetTest Test: atest FrameworksCoreTests:ArrayMapTest Test: atest FrameworksCoreTests:ArraySetTest Change-Id: Icd76630b25afd9f3627239301ffa5c37da25ea18
* Add extra comment for implementation.Kweku Adams2019-04-291-0/+4
| | | | | | | | | Add a comment noting that the check to throw the exception is intentionally second so that it's out of the critical path. Bug: 118339123 Test: N/A Change-Id: I36c5ea67579bcd7906f711530392110d9987ffb4
* Gating OutOfBoundsException on targetSdkVersion.Kweku Adams2019-04-261-4/+28
| | | | | | | | | Apps targeting Pie or older will get the old undefined behavior. Apps targeting Q or newer will get the OutOfBoundsException. Bug: 118339123 Test: atest CtsUtilTestCases Change-Id: Ibf5467aadec4a2f76ee180e963afeaf5a8a013a2
* Revert "Revert "Checkng upper bound in *Array classes.""Kweku Adams2019-03-301-2/+19
| | | | | | | | This reverts commit 91ec97056451753d6db55d310fc93fbd93c61cb3. Reason for revert: b/128433495 Change-Id: I4aac43f6aacd594f9c2bf58db9fbc4a1395d8888
* Revert "Checkng upper bound in *Array classes."Paul Scovanner2019-03-121-19/+2
| | | | | | | | This reverts commit 17d453ea85703a5bc26c0669231be4d6f0d8bbac. Reason for revert: b/127750694 Change-Id: I0ffbf0e64109b3ec724e0687a27b231e335f76b4
* Checkng upper bound in *Array classes.Kweku Adams2019-03-051-2/+19
| | | | | | | | | | *Array classes will now throw an IndexOutOfBoundsException if a caller tries to get or set a value for an index that's invalid based on the current size. Bug: 118339123 Test: atest CtsUtilTestCases Change-Id: Iddc9a0c7c89e0ac743b0380049527a1b2dfb434f
* Translate selection arguments that are paths.Jeff Sharkey2019-02-281-1/+4
| | | | | | | | | | Also migrate MediaProvider logging to more general-purpose location on the ContentProvider.Transport, where we can log exact input/output values to aid debugging. Bug: 124347872 Test: manual Change-Id: I6aba60879ded4e0892d2d1cdd717c23cebaaabd8
* Expose a few APIs in util collections.Jake Wharton2018-09-291-17/+24
| | | | | | | | | | These are either already exposed on other specialized collection variants or are exposed as public API on the androidx versions, or both. With these APIs exposed, all of the unsupported app usage can be done through public API. As a result, all unsupported app usage is now locked to apps targeting API 28 or earlier. Bug: 116877302 Test: none, no implementation change Change-Id: I548d71319bffb0a6b529e380ea936df674dbf515
* Add @UnsupportedAppUsage annotationsMathew Inwood2018-08-141-0/+17
| | | | | | | | | | | | | | | | | | | For packages: android.util.proto android.util.jar android.util.apk android.util This is an automatically generated CL. See go/UnsupportedAppUsage for more details. Exempted-From-Owner-Approval: Mechanical changes to the codebase which have been approved by Android API council and announced on android-eng@ Bug: 110868826 Test: m Change-Id: Ia0f48c244b0fbe33d40d797702a82303648196ed
* Mitigating cache corruption in ArrayMapSuprabh Shukla2018-05-141-1/+3
| | | | | | | | | | | | | Before calling freeArrays, storing the array reference into a temporary pointer so that the main pointer doesn't end up corrupting the static pool of arrays on concurrent access. An earlier change missed a rare case when removeAt was called for the last element in the map. Test: atest android.util.ArrayMapTest atest android.util.cts.ArrayMapTest Bug: 78898947 Change-Id: I454c5b1600eb0a6c690e746df10f6a0ebcd8aa1d
* Avoid ClassCastException in ArrayMap.Dan Sandler2017-04-261-30/+84
| | | | | | | | | | | | | | | | Only happens if you're put()ing and clear()ing the map from different threads, and Dianne told you not to do that. In addition to avoiding the cache poisoning that results from concurrent access, ArrayMap now attempts to throw ConcurrentModificationException if clear() or ensureCapacity() or put() notices you've modified the map elsewhere. Bug: 32994281 Test: runtest -x frameworks/base/core/tests/coretests/src/android/util/ArrayMapTest.java runtest -x cts/tests/tests/util/src/android/util/cts/ArrayMapTest.java Change-Id: Ia75970aa9e2b2b65692179f51243584b9773797f
* Utility to detect lock inversions in system.Jeff Sharkey2016-02-271-17/+22
| | | | | | | | | | | | | | | | | This change adds a new LockGuard utility class that can be used to detect lock inversions across the system server. For example, if a thread is trying to acquire the ActivityManager lock while holding the PackageManager lock, it will yell. This class requires no prior knowledge of locks or their ordering; it derives all of this data at runtime. However, this means the overhead is substantial and it should not be enabled by default. Adds overrides to ArrayMap and ArraySet to use identityHashCode() instead of the hashCode() provided by the object. Bug: 27336728 Change-Id: I26c31bc99fe8d61ff13c3455aaeddd5517e44433
* Fix issue #25656837: Static initialization order bug in ArrayMap leading to NPEsDianne Hackborn2015-12-041-5/+5
| | | | Change-Id: Iec3532ba167b5a09a5e505997e9e6035033f713f
* Add ArraySet to the SDK.Dianne Hackborn2015-06-111-4/+7
| | | | | | Also fix some documentation. Change-Id: I46025c3b5450e7cd671135b99ff3b298e223651d
* Make ArrayMap.EMPTY immutableAdam Lesinski2015-02-051-1/+4
| | | | | | | This is a regression from KitKat. Bug:19271657 Change-Id: I11b8e4dd50f6a8d2b15fef66b44aa2d72b1f0349
* Add indexOf method to ArrayMap & ArraySetAdam Lesinski2014-08-261-4/+14
| | | | | | | | | | | | | | Getting the indexOf is useful for doing compound operations like: int i = set.indexOf(key); if (i >= 0) { Object o = set.valueAt(i); o.blah(); set.removeAt(i); } Change-Id: I3d4b77d1461ba969fc6b4d332d52d4d084b5b53c
* Fix issue #16794553: Duplicate ArrayMap entries in Bundle...Dianne Hackborn2014-08-131-0/+38
| | | | | | | | | | | | | | | ...can lead to launching of un-exported activities We now validate the array map after unparcelling to make sure there are no duplicate keys. And to make up for the performance overhead this introduces, I switched the parcelling/unparcelling code to write keys as explicit string objects rather than generic values. There was no reason to use generic values since the write method itself only accepts an array map with String keys. Change-Id: I57bda9eb79ceaaa9c1b94ad49d9e462b52102149
* Add 560dpi, and some other stuff.Dianne Hackborn2014-08-121-1/+1
| | | | | | | | | | Like new settings actions for some of the new settings panels. And fix voice interaction services so they require a recognizer. And tweak array map doc to be correct. Blah blah blah. Change-Id: Ib5e66b574b10e7b3fa39723b21046a74e6ead204
* Uses VMRuntime.newUnpaddedArray for ideal array sizesAdam Lesinski2014-03-271-10/+12
| | | | | | Bug:13028925 Change-Id: I0a9301248b10a339afbdc5e4ffe3310ac4fa1fb7
* Fix issue #10921903: CTS: android.os.cts.ParcelTest#testReadBundle...Dianne Hackborn2013-10-031-0/+1
| | | | | | | | | | ...fails from KRS84 across all platforms My fix for issue #10807048 was wrong, wrong, wrong. The problem was actually just a stupid mistake in ArrayMap.erase(). This makes it all right. Change-Id: I762f7a2d5100bceb86a091ab3d6368edc21b4266
* Okay, I give in, add null key support to ArrayMap and ArraySet.Dianne Hackborn2013-07-251-17/+59
| | | | Change-Id: Iac5035f9c5884a9f9d5acb38132bb128d7a55249
* Fix issue #9940105: IllegalArgumentException in ArrayMapDianne Hackborn2013-07-191-2/+21
| | | | | | | | Try to deal with unmarshalling old parcels. Turns out someone was writing a parcel to disk storing a Bundle. Naughty, naughty. This helps us not completely keel over. Change-Id: Id343da2690b7bab89f6c3cb6fad1b92f270dad03
* Switch Bundle's implementation over to ArrayMap.Dianne Hackborn2013-07-181-1/+42
| | | | | | That was... um... easier than I thought it was going to be. Change-Id: Id8f2211c1d5f8145e0bb009dca0f62a590f2b860
* Make ArrayMap public! :)Dianne Hackborn2013-07-161-11/+9
| | | | | | | | | | Also do some tweaking of the various container classes to synchronize them with the support lib and make it easier to copy code between the two. And update activity/fragment to use ArrayMap. Change-Id: I3cfe82392a17119dfc72c3d9961f64e1914f42be
* Update SparseArray docs to be more informative.Dianne Hackborn2013-07-121-3/+2
| | | | Change-Id: I5d8d17d46a69ccdcf6b29f93be3d44addd80ab61
* More procstats work: separate global proc account, more dumping.Dianne Hackborn2013-06-211-0/+37
| | | | | | | | | | | | | | We now keep track of the time actually process run independently of the time packages run in process, so we can give an accurate summary of how long each physical process runs. New command line options can be supplied to restrict printing to a specific package, dump in a new csv format, control what is printed in the csv format, and print a checkin report. Add toString methods to ArrayMap and ArraySet. Change-Id: I47b8f68472592ecc0088c5286d3564aa615f4e0a
* ArrayMap is great, so how about ArraySet!Dianne Hackborn2013-06-111-63/+60
| | | | | | | | | | | | Also a few little tweaks to the ArrayMap implementation. Note that these are fairly parallel implementations; I looked at what I could abstract out as a base class, but there isn't really all that much without making the resulting code more general and thus slower. If we kept the data structure for ArraySet the same as map, where the array has two values per entry, then they could probably share a lot of code. I couldn't really bring myself to do that at this point, though... Change-Id: I9e0dd8baa8e1febcc1033ecef61623ad59ce4aae
* Additional functionality and performance for ArrayMapChet Haase2013-06-061-4/+72
| | | | | | | | | | | | | | | Added equals() and hashCode() to ArrayMap to allow equals() tests of maps with the same key/value pairs to return true. Changed putAll() to handle the case of an empty map faster, just copying the arrays instead of adding elements one by one. Added to ArrayMapTests to test new equals() and copy constructor functionality. Issue #9299310 Optimize ArrayMap copy constructor Change-Id: I1186a0eddd1fd53a0f380c2f3972fc1942cdf879
* Use ArrayMap instead of HashMap in transitionsChet Haase2013-06-041-0/+10
| | | | | | | | | | | | The new ArrayMap class is more efficient for small collections. Transitions use maps all over the place to collect/use property values in setting up the transition animations. Changing to ArrayMap should be more efficient, especially in terms of memory allocations and GCs. Issue #9276256 Transitions: Reduce memory allocations Change-Id: I07b7d4ba68d5a207808eca11943aa3578fa90e3e
* Clean up some temporary allocations.Dianne Hackborn2013-05-301-7/+9
| | | | | | | | | | | | Yay to ArrayMap, letting me get rid of a bunch of temporary iterators in core code paths like updateOomAdj. (Now I definitely need an ArraySet to finish that up.) Also clean up various other things that are doing unnecessary allocations, clean up some debug output, make more of the debug output respect package filtering. Change-Id: Ib4979faf4de8c7912739bc0937c3fa9e7bfcde67
* New ArrayMap class.Dianne Hackborn2013-05-241-0/+615
This is a new kind of key/value mapping that stores its data as an array, so it doesn't need to create an extra Entry object for every mapping placed in to it. It is also optimized to reduce memory overhead in other ways, by keeping the base object small, being fairly aggressive about keeping the array data structures small, etc. There are some unit and performance tests dropped in to some random places; they will need to be put somewhere else once I decided what we are going to do with this for the next release (for example if we make it public the unit tests should go in to CTS). Switch IntentResolver to using ArrayMap instead of HashMap. Also get rid of a bunch of duplicate implementations of binarySearch, and add an optimization to the various sparse arrays where you can supply an explicit 0 capacity to prevent it from doing an initial array allocation; use this new optimization in a few places where it makes sense. Change-Id: I01ef2764680f8ae49938e2a2ed40dc01606a056b