[cost][inferbo] Add models for androidx.collection

Summary:
- Model them like pseudo_collections.
- Need to add androidx.collection jar file from [here](https://mvnrepository.com/artifact/androidx.collection/collection/1.1.0) for tests.
- Add tests.

Reviewed By: skcho

Differential Revision: D17831346

fbshipit-source-id: a059531fb
master
Ezgi Çiçek 5 years ago committed by Facebook Github Bot
parent 023b6f5905
commit 9882b37c6c

@ -66,10 +66,23 @@ let implements_list = implements "java.util.List"
let implements_xmob_utils class_name = implements ("com.moblica.common.xmob.utils." ^ class_name)
let implements_pseudo_collection t s =
implements "android.util.SparseArray" t s
|| implements "android.util.SparseIntArray" t s
|| implements_xmob_utils "IntArrayList" t s
let implements_pseudo_collection =
let androidx_class_names =
List.map
~f:(fun class_name -> "androidx.collection." ^ class_name)
[ "ArrayMap"
; "ArraySet"
; "CircularArray"
; "LongSparseArray"
; "LruCache"
; "SimpleArrayMap"
; "SparseArrayCompat" ]
in
fun t s ->
implements "android.util.SparseArray" t s
|| implements "android.util.SparseIntArray" t s
|| implements_xmob_utils "IntArrayList" t s
|| List.exists ~f:(fun class_name -> implements class_name t s) androidx_class_names
let implements_enumeration = implements "java.util.Enumeration"

@ -1,6 +1,7 @@
{
"external-java-packages": [
"android.",
"androidx.",
"com.android.",
"com.fasterxml",
"com.google.",

@ -0,0 +1,20 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import androidx.collection.SparseArrayCompat;
public class AndroidXCollectionTest {
public void iterate_over_sparsearraycompat_linear(SparseArrayCompat<Integer> sa) {
for (int i = 0, size = sa.size(); i < size; i++) {}
}
public void call_iterate_over_sparsearraycompat_const() {
SparseArrayCompat<Integer> sa = new SparseArrayCompat<Integer>();
sa.put(0, Integer.MAX_VALUE);
iterate_over_sparsearraycompat_linear(sa);
}
}

@ -1,5 +1,6 @@
codetoanalyze/java/performance/A.java, B$BArray.error():void, 4, EXPENSIVE_ALLOCATION, no_bucket, ERROR, [with estimated cost 4, O(1), degree = 0]
codetoanalyze/java/performance/A.java, B.error():void, 4, EXPENSIVE_ALLOCATION, no_bucket, ERROR, [with estimated cost 4, O(1), degree = 0]
codetoanalyze/java/performance/AndroidXCollectionTest.java, AndroidXCollectionTest.iterate_over_sparsearraycompat_linear(androidx.collection.SparseArrayCompat):void, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 5 + 5 ⋅ sa.length, O(sa.length), degree = 1,{sa.length},Loop at line 12]
codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_overrun_bad():void, 4, BUFFER_OVERRUN_L2, no_bucket, ERROR, [<Offset trace>,Assignment,<Length trace>,Array declaration,Array access: Offset: [2, 8] Size: 8]
codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_weird_ok(long[],int):void, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 2 + 13 ⋅ length, O(length), degree = 1,{length},Loop at line 30]
codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.binary_search_log(java.lang.String[]):int, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 2 + log(arr.length), O(log(arr.length)), degree = 0 + 1⋅log,{arr.length},Modeled call to Arrays.binarySearch]

@ -8,6 +8,7 @@ ROOT_DIR = $(TESTS_DIR)/../..
include $(ROOT_DIR)/Makefile.config
ANDROID = $(JAVA_LIB_DIR)/android/android-23.jar
ANDROIDX_COLLECTION = $(JAVA_LIB_DIR)/androidx/collection-1.1.0.jar
ANDROIDSUPPORT = $(DEPENDENCIES_DIR)/java/android/support/v4/android-support-v4.jar
ANNOTATIONS = $(ANNOTATIONS_DIR)/annotations.jar
GUAVA = $(DEPENDENCIES_DIR)/java/guava/guava-23.0.jar
@ -16,4 +17,4 @@ JSR305 = $(DEPENDENCIES_DIR)/java/jsr-305/jsr305.jar
INJECT = $(DEPENDENCIES_DIR)/java/jsr-330/javax.inject.jar
SUNTOOLS = $(DEPENDENCIES_DIR)/java/sun-tools/tools.jar
CLASSPATH=$(ANDROID):$(ANDROIDSUPPORT):$(ANNOTATIONS):$(GUAVA):$(JACKSON):$(JSR305):$(INJECT):$(SUNTOOLS):$(JAVA_BUILTINS_DIR):.
CLASSPATH=$(ANDROID):$(ANDROIDX_COLLECTION):$(ANDROIDSUPPORT):$(ANNOTATIONS):$(GUAVA):$(JACKSON):$(JSR305):$(INJECT):$(SUNTOOLS):$(JAVA_BUILTINS_DIR):.

Loading…
Cancel
Save