Add the annotation @IgnoreAllocations to stop tracking allocations whenever useless

Summary:public
Add support for stopping allocation tracking on methods annotated with IgnoreAllocations

Reviewed By: cristianoc

Differential Revision: D2979563

fb-gh-sync-id: 2699375
shipit-source-id: 2699375
master
jrm 9 years ago committed by Facebook Github Bot 9
parent ed580c59e9
commit 697778cc3b

@ -0,0 +1,19 @@
/*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.infer.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface IgnoreAllocations {}

@ -111,6 +111,7 @@ let verify_annotation = "com.facebook.infer.annotation.Verify"
let expensive = "Expensive"
let performance_critical = "PerformanceCritical"
let no_allocation = "NoAllocation"
let ignore_allocations = "IgnoreAllocations"
let ia_is_nullable ia =
ia_ends_with ia nullable
@ -158,6 +159,9 @@ let ia_is_performance_critical ia =
let ia_is_no_allocation ia =
ia_ends_with ia no_allocation
let ia_is_ignore_allocations ia =
ia_ends_with ia ignore_allocations
type annotation =
| Nullable
| Present

@ -74,6 +74,7 @@ val ia_is_verify : Sil.item_annotation -> bool
val ia_is_expensive : Sil.item_annotation -> bool
val ia_is_performance_critical : Sil.item_annotation -> bool
val ia_is_no_allocation : Sil.item_annotation -> bool
val ia_is_ignore_allocations : Sil.item_annotation -> bool
val ia_iter : (Sil.annotation -> unit) -> Sil.item_annotation -> unit

@ -141,8 +141,9 @@ let method_allocates tenv pname =
| Some { Specs.allocations } ->
allocations <> []
| None -> false in
is_allocator tenv pname
|| allocates ()
not (check_method Annotations.ia_is_ignore_allocations pname)
&& (is_allocator tenv pname
|| allocates ())
let lookup_location pname =

@ -10,6 +10,7 @@
package codetoanalyze.java.checkers;
import com.facebook.infer.annotation.NoAllocation;
import com.facebook.infer.annotation.IgnoreAllocations;
public class NoAllocationExample {
@ -50,4 +51,14 @@ public class NoAllocationExample {
throwsException();
}
@IgnoreAllocations
void acceptableAllocation() {
new Object();
}
@NoAllocation
void onlyAllocatesInAcceptableWay() {
acceptableAllocation();
}
}

Loading…
Cancel
Save