From b790ac8c146e9d258bfa04f6b447ccaec1136a73 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Fri, 28 Apr 2017 11:49:58 -0700 Subject: [PATCH] [infer][java] load the global type environment at most once per process Summary: The Java frontend creates a single `tenv` file per `javac` invocation, but the code loading the `tenv` for a given Java procedure in the backend was not taking advantage of it. Also, with the lazy dynamic dispatch algorithm, the procedure name can be created on-demand and therefore defeat the approach to load the tenv by looking at the call graph to associate existing procedure names to the corresponding serialized tenv file. This diff should also fix this last point. Reviewed By: sblackshear Differential Revision: D4969254 fbshipit-source-id: 66ed318 --- infer/src/backend/exe_env.ml | 37 +++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/infer/src/backend/exe_env.ml b/infer/src/backend/exe_env.ml index ffc74a203..6d0defb70 100644 --- a/infer/src/backend/exe_env.ml +++ b/infer/src/backend/exe_env.ml @@ -161,19 +161,34 @@ let file_data_to_cfg file_data = then file_data.cfg <- Cfg.load_cfg_from_file file_data.cfg_file; file_data.cfg +let java_global_tenv = + lazy + (match Tenv.load_from_file DB.global_tenv_fname with + | None -> + failwithf + "Could not load the global tenv at path %s@." + (DB.filename_to_string DB.global_tenv_fname) + | Some tenv -> tenv) + (** return the type environment associated to the procedure *) let get_tenv exe_env proc_name = - match get_file_data exe_env proc_name with - | Some file_data -> ( - match file_data_to_tenv file_data with - | Some tenv -> - tenv - | None -> - failwithf "get_tenv: tenv not found for %a in file %s" - Typ.Procname.pp proc_name (DB.filename_to_string file_data.tenv_file) - ) - | None -> - failwithf "get_tenv: file_data not found for %a" Typ.Procname.pp proc_name + match proc_name with + | Typ.Procname.Java _ -> + Lazy.force java_global_tenv + | _ -> + begin + match get_file_data exe_env proc_name with + | Some file_data -> ( + match file_data_to_tenv file_data with + | Some tenv -> + tenv + | None -> + failwithf "get_tenv: tenv not found for %a in file %s" + Typ.Procname.pp proc_name (DB.filename_to_string file_data.tenv_file) + ) + | None -> + failwithf "get_tenv: file_data not found for %a" Typ.Procname.pp proc_name + end (** return the cfg associated to the procedure *) let get_cfg exe_env pname =