From 19b445e00cb5fed7d073e5496d2def50bdeff3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Thu, 6 Jun 2019 09:23:48 -0700 Subject: [PATCH] [cost] Add PERFORMANCE_VARIATION FP test for Java access methods Reviewed By: mbouaziz Differential Revision: D15695390 fbshipit-source-id: 45f6bb68a --- .../costs_summary.json.exp | 2 +- .../introduced.exp | 6 ++++-- .../preexisting.exp | 2 +- .../src/DiffExample.java.current | 20 +++++++++++++++++++ .../src/DiffExample.java.previous | 14 +++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/infer/tests/build_systems/differential_of_costs_report/costs_summary.json.exp b/infer/tests/build_systems/differential_of_costs_report/costs_summary.json.exp index 9732fbb52..526cdfd6a 100644 --- a/infer/tests/build_systems/differential_of_costs_report/costs_summary.json.exp +++ b/infer/tests/build_systems/differential_of_costs_report/costs_summary.json.exp @@ -1 +1 @@ -{"top":{"current":4,"previous":2},"zero":{"current":0,"previous":0},"degrees":[{"degree":0,"current":6,"previous":4},{"degree":100,"current":2,"previous":4},{"degree":101,"current":4,"previous":0},{"degree":200,"current":0,"previous":4}]} \ No newline at end of file +{"top":{"current":4,"previous":2},"zero":{"current":0,"previous":0},"degrees":[{"degree":0,"current":7,"previous":7},{"degree":100,"current":2,"previous":4},{"degree":101,"current":4,"previous":0},{"degree":200,"current":3,"previous":4}]} \ No newline at end of file diff --git a/infer/tests/build_systems/differential_of_costs_report/introduced.exp b/infer/tests/build_systems/differential_of_costs_report/introduced.exp index aea04238d..aa0261a6c 100644 --- a/infer/tests/build_systems/differential_of_costs_report/introduced.exp +++ b/infer/tests/build_systems/differential_of_costs_report/introduced.exp @@ -1,5 +1,7 @@ -INFINITE_EXECUTION_TIME_CALL, no_bucket, src/DiffExample.java, DiffExample.f1(int):void, 0, [Unbounded loop,Loop at line 26] -PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample.f4(int):int, 0, [Updated Cost is 6 + 5 ⋅ k (degree is 1),{k},Loop at line 45] +PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample$1.toString():java.lang.String, 0, [Updated Cost is 16 + 13 ⋅ this.this$0.z + 5 ⋅ this.this$0.z × this.this$0.z (degree is 2),{this.this$0.z},call to void DiffExample.f8(int),call to int DiffExample.f4(int),Loop at line 57,{this.this$0.z},call to void DiffExample.f8(int),Loop at line 79] +PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample.access$000(int):void, 0, [Updated Cost is 7 + 13 ⋅ x0 + 5 ⋅ x0 × x0 (degree is 2),{x0},call to void DiffExample.f8(int),call to int DiffExample.f4(int),Loop at line 57,{x0},call to void DiffExample.f8(int),Loop at line 79] +INFINITE_EXECUTION_TIME_CALL, no_bucket, src/DiffExample.java, DiffExample.f1(int):void, 0, [Unbounded loop,Loop at line 38] +PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample.f4(int):int, 0, [Updated Cost is 6 + 5 ⋅ k (degree is 1),{k},Loop at line 57] PERFORMANCE_VARIATION, no_bucket, src/DiffExample.java, DiffExample.f5(java.util.ArrayList):void, 0, [Updated Cost is 2 + list.length × log(list.length) (degree is 1 + 1⋅log),{list.length},Modeled call to Collections.sort,{list.length},Modeled call to Collections.sort] INFINITE_EXECUTION_TIME_CALL, no_bucket, src/DiffExampleColdStart.java, DiffExampleColdStart.f1(int):void, 0, [Unbounded loop,Loop at line 26] TIME_COMPLEXITY_INCREASE_COLD_START, no_bucket, src/DiffExampleColdStart.java, DiffExampleColdStart.f4(int):int, 0, [Updated Cost is 6 + 5 ⋅ k (degree is 1),{k},Loop at line 45] diff --git a/infer/tests/build_systems/differential_of_costs_report/preexisting.exp b/infer/tests/build_systems/differential_of_costs_report/preexisting.exp index 5102bbbd9..393cbaf3d 100644 --- a/infer/tests/build_systems/differential_of_costs_report/preexisting.exp +++ b/infer/tests/build_systems/differential_of_costs_report/preexisting.exp @@ -1,2 +1,2 @@ -INFINITE_EXECUTION_TIME_CALL, no_bucket, src/DiffExample.java, DiffExample.f7(int):void, 0, [Call to void DiffExample.f1(int),Unbounded loop,Loop at line 26] +INFINITE_EXECUTION_TIME_CALL, no_bucket, src/DiffExample.java, DiffExample.f7(int):void, 0, [Call to void DiffExample.f1(int),Unbounded loop,Loop at line 38] INFINITE_EXECUTION_TIME_CALL, no_bucket, src/DiffExampleColdStart.java, DiffExampleColdStart.f7(int):void, 0, [Call to void DiffExampleColdStart.f1(int),Unbounded loop,Loop at line 26] diff --git a/infer/tests/build_systems/differential_of_costs_report/src/DiffExample.java.current b/infer/tests/build_systems/differential_of_costs_report/src/DiffExample.java.current index 7a71243d7..8ef4dbe53 100644 --- a/infer/tests/build_systems/differential_of_costs_report/src/DiffExample.java.current +++ b/infer/tests/build_systems/differential_of_costs_report/src/DiffExample.java.current @@ -10,6 +10,7 @@ import java.util.ArrayList; // This class has the following costs: // 1 bottom (zero), 2 constant, 1 linear, 1 top // constructor: constant +// private access$000 method for accessing f8 // f1: top // f2: bottom (zero) // f3: constant @@ -17,9 +18,20 @@ import java.util.ArrayList; // f5: n log n // f6: n log n // f7: top by call to f1 +// f8: quadratic public class DiffExample { + int z; + ArrayList list = + new ArrayList() { + + @Override + public String toString() { + f8(z); + return super.toString(); + } + }; // cost: top private static void f1(int k) { int i = 0; @@ -61,4 +73,12 @@ public class DiffExample { private static void f7(int k) { f1(k); } + + // cost: quadratic + private static void f8(int k) { + for (int i = 0; i < k; i++) { + f4(k); + } + } + } diff --git a/infer/tests/build_systems/differential_of_costs_report/src/DiffExample.java.previous b/infer/tests/build_systems/differential_of_costs_report/src/DiffExample.java.previous index 8fcea2023..9470f8ea1 100644 --- a/infer/tests/build_systems/differential_of_costs_report/src/DiffExample.java.previous +++ b/infer/tests/build_systems/differential_of_costs_report/src/DiffExample.java.previous @@ -4,10 +4,13 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ + +import java.util.ArrayList; // This class has the following costs: // 2 constant, 1 linear, 1 quadratic // constructor: constant +// private access$000 method for accessing f4 // f1: linear // f2: quadratic // f4: constant @@ -16,6 +19,17 @@ // f7: top public class DiffExample { + + int z; + ArrayList list = + new ArrayList() { + + @Override + public String toString() { + f4(z); + return super.toString(); + } + }; // cost: linear private static int f1(int k) { for (int i = 0; i < k; i++) {