summaryrefslogtreecommitdiff
path: root/core/java/android/util/ArraySet.java
Commit message (Collapse)AuthorAgeFilesLines
* Improve forEach.Kweku Adams2021-07-191-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default implementation of Collection.forEach() uses the iterator(). Switch to straight iterating through the array since the iterator is an inefficient way to access the array contents. Benchmark results: Before: android.util.ArraySetPerfTest#testForEach_Large: forEach_Large_median (ns): 398480 forEach_Large_min (ns): 395758 forEach_Large_mean (ns): 400957 forEach_Large_standardDeviation: 5457 android.util.ArraySetPerfTest#testForEach_Small: forEach_Small_min (ns): 82768 forEach_Small_median (ns): 83884 forEach_Small_standardDeviation: 896 forEach_Small_mean (ns): 83724 After: android.util.ArraySetPerfTest#testForEach_Large: forEach_Large_median (ns): 319481 forEach_Large_min (ns): 316166 forEach_Large_mean (ns): 339865 forEach_Large_standardDeviation: 44201 android.util.ArraySetPerfTest#testForEach_Small: forEach_Small_min (ns): 58736 forEach_Small_median (ns): 60648 forEach_Small_standardDeviation: 1375 forEach_Small_mean (ns): 60622 Bug: 194098491 Test: atest CorePerfTests:ArraySetPerfTest (see results above) Test: atest CtsUtilTestCases:ArraySetTest Test: atest FrameworksCoreTests:ArraySetTest Change-Id: Ib14b96f095203e1f5811132f2a21be0452645f7e
* Add @Nullable annotation to the parameter of Object.equals() methods.Roman Kalukiewicz2020-10-151-1/+1
| | | | | | | | | | | | | | | | | | 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
* resolve merge conflicts of 484e166df3c21712c7dfa687d10c91bb0e007397 to masterValentin Iftime2019-10-081-0/+13
|\ | | | | | | | | | | Test: I solemnly swear I tested this conflict resolution. Bug: None Change-Id: Ia9db1400207d9196012362c480ede059e94184af
| * API to detect which network interfaces support wake-on-lanValentin Iftime2019-10-081-0/+13
| | | | | | | | | | | | | | | | | | | | Add a new method in LinkProperties, isWakeOnLanEnabled() which returns true if network interface is defined in config_wakeonlan_enabled_interfaces string-array (config.xml) Bug: 132705025 Test: atest LinkPropertiesTest & atest ConnectivityServiceTest Change-Id: I3f7803aafd2f8eaf8aa18419b21339e15d4b7a0b
* | Address static cache access issues.Kweku Adams2019-08-201-45/+101
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/+2
| | | | | | | | | 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-2/+14
| | | | | | | | | 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
* Slight improvements to ArraySet.Kweku Adams2018-11-011-10/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. There are cases where valueAt could return null even though the given index was out of bounds. I've added a check for that in the code. 2. The default implementation of Collection.removeIf() uses the iterator(). This change avoids that since the iterator is an inefficient way to access the array contents. Benchmark tests. Note that these times are in nanoseconds: Before: INSTRUMENTATION_STATUS: removeIf_Small_Base_mean=163679 INSTRUMENTATION_STATUS: removeIf_Small_Base_median=158215 INSTRUMENTATION_STATUS: removeIf_Small_Base_min=129564 INSTRUMENTATION_STATUS: removeIf_Small_Base_standardDeviation=24779 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: valueAt_OutOfBounds_Negative_mean=5645195 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_Negative_median=5584964 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_Negative_min=5448560 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_Negative_standardDeviation=206915 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Large_RemoveHalf_mean=1316514 INSTRUMENTATION_STATUS: removeIf_Large_RemoveHalf_median=1282442 INSTRUMENTATION_STATUS: removeIf_Large_RemoveHalf_min=1216533 INSTRUMENTATION_STATUS: removeIf_Large_RemoveHalf_standardDeviation=109087 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Large_Base_mean=571712 INSTRUMENTATION_STATUS: removeIf_Large_Base_median=566500 INSTRUMENTATION_STATUS: removeIf_Large_Base_min=535726 INSTRUMENTATION_STATUS: removeIf_Large_Base_standardDeviation=26374 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: valueAt_OutOfBounds_EdgeCase_mean=946 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_EdgeCase_median=896 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_EdgeCase_min=841 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_EdgeCase_standardDeviation=106 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Large_RemoveAll_mean=2196954 INSTRUMENTATION_STATUS: removeIf_Large_RemoveAll_median=2163910 INSTRUMENTATION_STATUS: removeIf_Large_RemoveAll_min=2136283 INSTRUMENTATION_STATUS: removeIf_Large_RemoveAll_standardDeviation=91149 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Small_RemoveHalf_mean=356644 INSTRUMENTATION_STATUS: removeIf_Small_RemoveHalf_median=350376 INSTRUMENTATION_STATUS: removeIf_Small_RemoveHalf_min=337067 INSTRUMENTATION_STATUS: removeIf_Small_RemoveHalf_standardDeviation=17354 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Large_RemoveNothing_mean=1044645 INSTRUMENTATION_STATUS: removeIf_Large_RemoveNothing_median=1040981 INSTRUMENTATION_STATUS: removeIf_Large_RemoveNothing_min=1010144 INSTRUMENTATION_STATUS: removeIf_Large_RemoveNothing_standardDeviation=35016 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Small_RemoveAll_mean=507561 INSTRUMENTATION_STATUS: removeIf_Small_RemoveAll_median=503419 INSTRUMENTATION_STATUS: removeIf_Small_RemoveAll_min=471564 INSTRUMENTATION_STATUS: removeIf_Small_RemoveAll_standardDeviation=33141 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Small_RemoveNothing_mean=300889 INSTRUMENTATION_STATUS: removeIf_Small_RemoveNothing_median=295486 INSTRUMENTATION_STATUS: removeIf_Small_RemoveNothing_min=282948 INSTRUMENTATION_STATUS: removeIf_Small_RemoveNothing_standardDeviation=19869 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: valueAt_InBounds_mean=644 INSTRUMENTATION_STATUS: valueAt_InBounds_median=584 INSTRUMENTATION_STATUS: valueAt_InBounds_min=528 INSTRUMENTATION_STATUS: valueAt_InBounds_standardDeviation=141 INSTRUMENTATION_STATUS_CODE: -1 After: INSTRUMENTATION_STATUS: removeIf_Small_Base_mean=143926 INSTRUMENTATION_STATUS: removeIf_Small_Base_median=145985 INSTRUMENTATION_STATUS: removeIf_Small_Base_min=125700 INSTRUMENTATION_STATUS: removeIf_Small_Base_standardDeviation=11112 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: valueAt_OutOfBounds_Negative_mean=5173581 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_Negative_median=5168995 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_Negative_min=5108405 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_Negative_standardDeviation=45739 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Large_RemoveHalf_mean=695812 INSTRUMENTATION_STATUS: removeIf_Large_RemoveHalf_median=690070 INSTRUMENTATION_STATUS: removeIf_Large_RemoveHalf_min=679793 INSTRUMENTATION_STATUS: removeIf_Large_RemoveHalf_standardDeviation=17959 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Large_Base_mean=591815 INSTRUMENTATION_STATUS: removeIf_Large_Base_median=588499 INSTRUMENTATION_STATUS: removeIf_Large_Base_min=573707 INSTRUMENTATION_STATUS: removeIf_Large_Base_standardDeviation=14348 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: valueAt_OutOfBounds_EdgeCase_mean=4010666 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_EdgeCase_median=4017245 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_EdgeCase_min=3970170 INSTRUMENTATION_STATUS: valueAt_OutOfBounds_EdgeCase_standardDeviation=28577 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Large_RemoveAll_mean=734297 INSTRUMENTATION_STATUS: removeIf_Large_RemoveAll_median=732576 INSTRUMENTATION_STATUS: removeIf_Large_RemoveAll_min=720065 INSTRUMENTATION_STATUS: removeIf_Large_RemoveAll_standardDeviation=14906 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Small_RemoveHalf_mean=195026 INSTRUMENTATION_STATUS: removeIf_Small_RemoveHalf_median=194430 INSTRUMENTATION_STATUS: removeIf_Small_RemoveHalf_min=190400 INSTRUMENTATION_STATUS: removeIf_Small_RemoveHalf_standardDeviation=4012 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Large_RemoveNothing_mean=772914 INSTRUMENTATION_STATUS: removeIf_Large_RemoveNothing_median=785834 INSTRUMENTATION_STATUS: removeIf_Large_RemoveNothing_min=737947 INSTRUMENTATION_STATUS: removeIf_Large_RemoveNothing_standardDeviation=23808 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Small_RemoveAll_mean=194325 INSTRUMENTATION_STATUS: removeIf_Small_RemoveAll_median=196492 INSTRUMENTATION_STATUS: removeIf_Small_RemoveAll_min=186998 INSTRUMENTATION_STATUS: removeIf_Small_RemoveAll_standardDeviation=5091 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: removeIf_Small_RemoveNothing_mean=187122 INSTRUMENTATION_STATUS: removeIf_Small_RemoveNothing_median=187292 INSTRUMENTATION_STATUS: removeIf_Small_RemoveNothing_min=182272 INSTRUMENTATION_STATUS: removeIf_Small_RemoveNothing_standardDeviation=4902 INSTRUMENTATION_STATUS_CODE: -1 .INSTRUMENTATION_STATUS: valueAt_InBounds_mean=918 INSTRUMENTATION_STATUS: valueAt_InBounds_median=919 INSTRUMENTATION_STATUS: valueAt_InBounds_min=801 INSTRUMENTATION_STATUS: valueAt_InBounds_standardDeviation=80 INSTRUMENTATION_STATUS_CODE: -1 Perf test command: mmma -j ./frameworks/base/apct-tests/perftests/core/; adb install -r $OUT/data/app/CorePerfTests/CorePerfTests.apk; adb shell cmd package compile -m speed -f com.android.perftests.core; adb shell am instrument -w -e class android.util.ArraySetPerfTest com.android.perftests.core/android.support.test.runner.AndroidJUnitRunner Bug: 118339123 Bug: 117846754 Test: atest android.util.cts.ArraySetTest and benchmark tests (see above) Change-Id: Ic4b10fd2bbc7a745ca4e4029ca4829847812fabe
* Expose a few APIs in util collections.Jake Wharton2018-09-291-10/+11
| | | | | | | | | | 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/+9
| | | | | | | | | | | | | | | | | | | 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
* resolve merge conflicts of 5827257 to masterColin Cross2016-08-291-17/+35
|\ | | | | | | Change-Id: I0077b6991584fc33dcb1ca1aadb634ce930fef3a
| * Try to mitigate issue #31016187: system_server crash in ArraySet.Dianne Hackborn2016-08-251-16/+34
| | | | | | | | | | | | | | | | | | Instead of crashing, log a wtf and recover. This is not a problem in ArraySet, but caused by someone else using an ArraySet without protecting access to it. So whoever is calling at this point is not the cause, and it isn't worthwhile to let them crash. Change-Id: Iaefa4315b620c9fe24b31507e4aa47a8525c8540
* | Clean up style issues in ArraySet.Aurimas Liutikas2016-08-191-52/+64
|/ | | | | | | | | | | | | | Clean up style issues in preparation to copying ArraySet implementation to support library. Fixed: - Missing spaces around operators, casting - Added curly braces around if statements that span multiple lines - Renamed static variables to follow sFoo instead of mFoo - Moved = to the previous line Bug: 19109652 Change-Id: Id9a985723b158f51811b3cd796613d0e26fd7e61
* Removed warning when objects are added on wrong order.Felipe Leme2016-06-301-5/+8
| | | | | | | | | | | | append() is used to optimized insertions in the array, but it must preserve the order of the hashcode array; when it doesn't, it falls back to append(), but it should not log a warning message In particular, PendingIntentRecords might have different hashcodes across different processes. Fixes: 29912192 Change-Id: I0ab566249829ddb934fd51cf21399b68cb286bd5
* Mark app pending intents in notification extrasSvet Ganov2016-06-271-0/+26
| | | | | | | | | | | | | | | | | | | | | We need to make every peniding intent that went in the notification system to allow special handling of such intents when fired by a notification listener. If a pending intent from a notification is sent from a notification listener, we white-list the source app to run in data saver mode for a short period of time. The problem is that actions and the notificaion can have extras which bundles may contain pending intents but the system cannot look into the bundles as they may contain custom parcelable objects. To address this we keep a list of all pending intents in the notification allowing the system to access them without touching the bundle. Currently the pending intents are written to the parcel twice, once in the bundle and once as the explicit list. We can come up with a scheme to optimize this but since pending itents are just a binder pointer it is not worth the excecise. bug:29480440 Change-Id: I7328a47017ca226117adf7054900836619f5679b
* Utility to detect lock inversions in system.Jeff Sharkey2016-02-271-5/+11
| | | | | | | | | | | | | | | | | 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
* Add ArraySet to the SDK.Dianne Hackborn2015-06-111-2/+28
| | | | | | Also fix some documentation. Change-Id: I46025c3b5450e7cd671135b99ff3b298e223651d
* am 6695b992: Merge "Frameworks/base: Add removeAll for ArraySet"Andreas Gampe2015-03-051-0/+20
|\ | | | | | | | | * commit '6695b9920d15f8d9a17d6b0c66b863d1c2e38584': Frameworks/base: Add removeAll for ArraySet
| * Frameworks/base: Add removeAll for ArraySetAndreas Gampe2015-03-041-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a simple ArraySet.removeAll(ArraySet) method. This avoids two allocations, a MapCollections helper and an Iterator object, over the removeAll(Collection) code. KeySetManagerService heavily calls removeAll during boot (about 9K times in AOSP). This reduces GC stress and optimizes the removal (about half the time the removed collection has only one element). The removal method in KeySetManagerService is also done under a lock, so that it gates parallelization efforts in PackageManagerService. Bug: 19498314 Change-Id: Ib0e483adfd09831cd66ab19a820ebf6544a2b66f
* | Reduce PackageManager RAM usage: ArrayMap/Set.Jeff Sharkey2014-10-241-1/+8
|/ | | | | | | | | Transition PackageManager internals away from heavier HashMap/HashSet to use drop-in ArrayMap/ArraySet replacements. Saves ~38% RAM and thousands of objects on a typical device. Bug: 18115729 Change-Id: Ie107d2fee4b7baa4e3c3923231b4be877d1a5d2f
* 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
* Rework network stats to use proc state for fg/bg.Dianne Hackborn2014-07-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Switch to using the process state to determine whether a process should be foreground or background, instead of the boolean foreground given by the activity manager. This is for battery save mode, where we can now allow more apps to havenetwork access: everything whose process state is at least IMPORTANT_FOREGROUND, which allows music playback and other use-visible things to continue to have network access. Note this also impact the traditional background data disabled state, where now we allow anything top or better to have network access. This automatically includes all persistent processes, the current top activity, and any other processes hosting the top activity or being used by the top activity. So it broadens the set of apps that get network access, but I think this increases it to a reasonable set of things that may actually be needed for the foreground app to work correctly. Change-Id: Icb609a2cea280dc3fa3e83417f478ed77f3685aa
* Uses VMRuntime.newUnpaddedArray for ideal array sizesAdam Lesinski2014-03-271-8/+10
| | | | | | Bug:13028925 Change-Id: I0a9301248b10a339afbdc5e4ffe3310ac4fa1fb7
* Okay, I give in, add null key support to ArrayMap and ArraySet.Dianne Hackborn2013-07-251-14/+56
| | | | Change-Id: Iac5035f9c5884a9f9d5acb38132bb128d7a55249
* Make ArrayMap public! :)Dianne Hackborn2013-07-161-9/+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/+30
| | | | | | | | | | | | | | 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-0/+599
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