[cost] Add a FP test due to imprecise loop invariant

Summary:
This diff adds a false positive test that is introduced imprecise loop
invariant detection.

In the example, `i` and a temp variable `$irvar = get_size(arr)` are
all included in the control variables, so the complexity becomes
quadratic.  The problem is that `$irvar` is not addressed as a loop
invariant:

* `is.read` is analyzed as modifying a global
* all return variables, including `$irvar`, of unmodeled functions are invalidated

Reviewed By: ezgicicek

Differential Revision: D23051414

fbshipit-source-id: 011fd086b
master
Sungkeun Cho 4 years ago committed by Facebook GitHub Bot
parent 35de604422
commit 80c31ab8da

@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -336,6 +337,24 @@ public class ArrayListTest {
a.add(5); a.add(5);
for (int i = 0; i < a.get(0); i++) {} for (int i = 0; i < a.get(0); i++) {}
} }
boolean rand;
int get_size(ArrayList<Integer> arr) {
return arr.size();
}
void loop_invariant_linear_FP(ArrayList<Integer> arr, InputStream is) {
if (rand) {
arr = new ArrayList<>();
}
for (int i = 0; i < get_size(arr); i++) {
try {
is.read();
} catch (Exception e) {
}
}
}
} }
class LexicographicComparator implements java.util.Comparator<Person> { class LexicographicComparator implements java.util.Comparator<Person> {

@ -59,6 +59,7 @@ codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.constructor_add
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.constructor_linear(java.util.ArrayList):void, 9 + 5 ⋅ list.length + 3 ⋅ (list.length + 1), OnUIThread:false, [{list.length + 1},Loop,{list.length},Loop] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.constructor_linear(java.util.ArrayList):void, 9 + 5 ⋅ list.length + 3 ⋅ (list.length + 1), OnUIThread:false, [{list.length + 1},Loop,{list.length},Loop]
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.constructor_modify(java.util.ArrayList):void, 21 + 5 ⋅ (list.length + 4) + 3 ⋅ (list.length + 5), OnUIThread:false, [{list.length + 5},Loop,{list.length + 4},Loop] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.constructor_modify(java.util.ArrayList):void, 21 + 5 ⋅ (list.length + 4) + 3 ⋅ (list.length + 5), OnUIThread:false, [{list.length + 5},Loop,{list.length + 4},Loop]
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.empty_list_constant(int):void, 12, OnUIThread:false, [] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.empty_list_constant(int):void, 12, OnUIThread:false, []
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.get_size(java.util.ArrayList):int, 6, OnUIThread:false, []
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.id(java.util.ArrayList):void, 10, OnUIThread:false, [] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.id(java.util.ArrayList):void, 10, OnUIThread:false, []
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.init_with_put_linear(java.util.ArrayList):java.util.HashMap, 11 + 13 ⋅ a.length + 3 ⋅ (a.length + 1), OnUIThread:false, [{a.length + 1},Loop,{a.length},Loop] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.init_with_put_linear(java.util.ArrayList):java.util.HashMap, 11 + 13 ⋅ a.length + 3 ⋅ (a.length + 1), OnUIThread:false, [{a.length + 1},Loop,{a.length},Loop]
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.iterate_over_arraylist(java.util.ArrayList):void, 8 + 5 ⋅ list.length, OnUIThread:false, [{list.length},Loop] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.iterate_over_arraylist(java.util.ArrayList):void, 8 + 5 ⋅ list.length, OnUIThread:false, [{list.length},Loop]
@ -69,6 +70,7 @@ codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.iterate_while_h
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.iterate_with_iterator(java.util.ArrayList):void, 6 + 8 ⋅ list.length + 3 ⋅ (list.length + 1), OnUIThread:false, [{list.length + 1},Loop,{list.length},Loop] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.iterate_with_iterator(java.util.ArrayList):void, 6 + 8 ⋅ list.length + 3 ⋅ (list.length + 1), OnUIThread:false, [{list.length + 1},Loop,{list.length},Loop]
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.json_array_constructor_linear(java.util.ArrayList):void, 9 + 5 ⋅ arr.length + 3 ⋅ (arr.length + 1), OnUIThread:false, [{arr.length + 1},Loop,{arr.length},Loop] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.json_array_constructor_linear(java.util.ArrayList):void, 9 + 5 ⋅ arr.length + 3 ⋅ (arr.length + 1), OnUIThread:false, [{arr.length + 1},Loop,{arr.length},Loop]
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.linear(int,java.util.ArrayList):void, 7 + 9 ⋅ (-i + a.length + 1), OnUIThread:false, [{-i + a.length + 1},Loop] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.linear(int,java.util.ArrayList):void, 7 + 9 ⋅ (-i + a.length + 1), OnUIThread:false, [{-i + a.length + 1},Loop]
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.loop_invariant_linear_FP(java.util.ArrayList,java.io.InputStream):void, 14 + 8 ⋅ arr.length² + 9 ⋅ (arr.length + 1)², OnUIThread:false, [{arr.length + 1},Loop,{arr.length + 1},Loop,{arr.length},Loop,{arr.length},Loop]
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.max_linear(java.util.ArrayList):Person, 12 + people.length, OnUIThread:false, [{people.length},Modeled call to Collections.max] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.max_linear(java.util.ArrayList):Person, 12 + people.length, OnUIThread:false, [{people.length},Modeled call to Collections.max]
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.remove_string_from_list(java.lang.String):boolean, 13 + 12 ⋅ this.list.length + 3 ⋅ (this.list.length + 1), OnUIThread:false, [{this.list.length + 1},Loop,{this.list.length},Loop] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.remove_string_from_list(java.lang.String):boolean, 13 + 12 ⋅ this.list.length + 3 ⋅ (this.list.length + 1), OnUIThread:false, [{this.list.length + 1},Loop,{this.list.length},Loop]
codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.sortArrayList(java.util.ArrayList):void, 2 + list.length × log(list.length), OnUIThread:false, [{list.length},Modeled call to Collections.sort,{list.length},Modeled call to Collections.sort] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.sortArrayList(java.util.ArrayList):void, 2 + list.length × log(list.length), OnUIThread:false, [{list.length},Modeled call to Collections.sort,{list.length},Modeled call to Collections.sort]

Loading…
Cancel
Save