[starvation] fix conversions of int literals which need 64 bit ints

Summary: Trying to convert a large int literal to an OCaml int raises an exception.  The use case here actually needed a float anyway, so add an API for that.

Reviewed By: jeremydubreil

Differential Revision: D8550410

fbshipit-source-id: 382495b
master
Nikos Gorogiannis 7 years ago committed by Facebook Github Bot
parent baff08e198
commit e5d8f501f4

@ -61,6 +61,8 @@ let of_int i = of_int64 (Int64.of_int i)
let to_int (_, i, _) = Int64.to_int_exn i
let to_float (_, i, _) = Int64.to_float i
let null = (false, 0L, true)
let zero = of_int 0

@ -88,6 +88,9 @@ val shift_right : t -> t -> t
val sub : t -> t -> t
val to_int : t -> int
(** throws exception if literal is not representable as an OCaml int *)
val to_float : t -> float
val to_signed : t -> t option

@ -632,7 +632,7 @@ module Models = struct
| _, [AccessPath.FieldAccess field]
when String.equal "java.util.concurrent.TimeUnit" (Typ.Fieldname.Java.get_class field) ->
let fieldname = Typ.Fieldname.Java.get_field field in
let duration = float_of_int (IntLit.to_int duration_lit) in
let duration = IntLit.to_float duration_lit in
String.Map.find time_units fieldname
|> Option.value_map ~default:false ~f:(fun unit_in_secs ->
unit_in_secs *. duration >. android_anr_time_limit )

@ -76,4 +76,11 @@ class FutureGet {
future.get(5000001L, TimeUnit.MICROSECONDS);
} catch (TimeoutException e) {}
}
@UiThread
void getTimeout64BitsBad() throws InterruptedException, ExecutionException {
try {
future.get(9223372036854775807L, TimeUnit.MICROSECONDS);
} catch (TimeoutException e) {}
}
}

@ -15,6 +15,7 @@ codetoanalyze/java/starvation/Dedup.java, void Dedup.oneWayBad(), 36, DEADLOCK,
codetoanalyze/java/starvation/FutureGet.java, void FutureGet.getDirectBad(), 20, STARVATION, no_bucket, ERROR, [`void FutureGet.getDirectBad()`,calls `Object Future.get()` from `void FutureGet.getDirectBad()`]
codetoanalyze/java/starvation/FutureGet.java, void FutureGet.getIndirectBad(), 25, STARVATION, no_bucket, ERROR, [[Trace 1] `void FutureGet.getIndirectBad()`,locks `this.FutureGet.lock` in class `FutureGet*`,[Trace 2] `void FutureGet.getUnderLock()`,locks `this.FutureGet.lock` in class `FutureGet*`,calls `Object Future.get()` from `void FutureGet.getUnderLock()`]
codetoanalyze/java/starvation/FutureGet.java, void FutureGet.getTimeout50000001MicroSecondsBad(), 76, STARVATION, no_bucket, ERROR, [`void FutureGet.getTimeout50000001MicroSecondsBad()`,calls `Object Future.get(long,TimeUnit)` from `void FutureGet.getTimeout50000001MicroSecondsBad()`]
codetoanalyze/java/starvation/FutureGet.java, void FutureGet.getTimeout64BitsBad(), 83, STARVATION, no_bucket, ERROR, [`void FutureGet.getTimeout64BitsBad()`,calls `Object Future.get(long,TimeUnit)` from `void FutureGet.getTimeout64BitsBad()`]
codetoanalyze/java/starvation/FutureGet.java, void FutureGet.getTimeoutOneDayBad(), 41, STARVATION, no_bucket, ERROR, [`void FutureGet.getTimeoutOneDayBad()`,calls `Object Future.get(long,TimeUnit)` from `void FutureGet.getTimeoutOneDayBad()`]
codetoanalyze/java/starvation/FutureGet.java, void FutureGet.getTimeoutOneHourBad(), 55, STARVATION, no_bucket, ERROR, [`void FutureGet.getTimeoutOneHourBad()`,calls `Object Future.get(long,TimeUnit)` from `void FutureGet.getTimeoutOneHourBad()`]
codetoanalyze/java/starvation/IndirectBlock.java, void IndirectBlock.takeExpensiveLockOnUiThreadBad(), 22, STARVATION, no_bucket, ERROR, [[Trace 1] `void IndirectBlock.takeExpensiveLockOnUiThreadBad()`,locks `this.IndirectBlock.expensiveLock` in class `IndirectBlock*`,[Trace 2] `void IndirectBlock.doTransactUnderLock()`,locks `this.IndirectBlock.expensiveLock` in class `IndirectBlock*`,calls `boolean Binder.transact(int,Parcel,Parcel,int)` from `void IndirectBlock.doTransactUnderLock()`]

Loading…
Cancel
Save