From 8636aa1f700df1b969b217b26b96bd6a9825fd92 Mon Sep 17 00:00:00 2001 From: jrm Date: Tue, 10 Nov 2015 15:19:46 -0800 Subject: [PATCH] open the jar file of the model only once Summary: public The jar file of the models was opened twice before. This should reduce a little bit the IO of the capture. Reviewed By: cristianoc Differential Revision: D2626251 fb-gh-sync-id: 310bef4 --- infer/src/java/jClasspath.ml | 32 +++++++++++++++++++++++++++++--- infer/src/java/jClasspath.mli | 3 +++ infer/src/java/jTransType.ml | 20 +------------------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/infer/src/java/jClasspath.ml b/infer/src/java/jClasspath.ml index 7cb29ac25..29bf50478 100644 --- a/infer/src/java/jClasspath.ml +++ b/infer/src/java/jClasspath.ml @@ -31,16 +31,42 @@ let set_verbose_out path = let models_jar = ref "" +let models_tenv = ref (Sil.create_tenv ()) + + +let load_models_tenv zip_channel = + let models_tenv_filename_in_jar = + let root = Filename.concat Config.default_in_zip_results_dir Config.captured_dir_name in + Filename.concat root Config.global_tenv_filename in + let temp_tenv_filename = + DB.filename_from_string (Filename.temp_file "tmp_" Config.global_tenv_filename) in + let entry = Zip.find_entry zip_channel models_tenv_filename_in_jar in + let temp_tenv_file = DB.filename_to_string temp_tenv_filename in + let models_tenv = + try + Zip.copy_entry_to_file zip_channel entry temp_tenv_file; + match Sil.load_tenv_from_file temp_tenv_filename with + | None -> failwith "Models tenv file could not be loaded" + | Some tenv -> tenv + with + | Not_found -> failwith "Models tenv not found in jar file" + | Sys_error msg -> failwith ("Models jar could not be opened "^msg) in + DB.file_remove temp_tenv_filename; + models_tenv + + let collect_specs_filenames jar_filename = - let file_in = Zip.open_in jar_filename in + let zip_channel = Zip.open_in jar_filename in let collect set e = let filename = e.Zip.filename in if not (Filename.check_suffix filename ".specs") then set else let proc_filename = (Filename.chop_extension (Filename.basename filename)) in StringSet.add proc_filename set in - models_specs_filenames := IList.fold_left collect !models_specs_filenames (Zip.entries file_in); - Zip.close_in file_in + models_specs_filenames := + IList.fold_left collect !models_specs_filenames (Zip.entries zip_channel); + models_tenv := load_models_tenv zip_channel; + Zip.close_in zip_channel let add_models jar_filename = diff --git a/infer/src/java/jClasspath.mli b/infer/src/java/jClasspath.mli index 9209cbcee..74c951351 100644 --- a/infer/src/java/jClasspath.mli +++ b/infer/src/java/jClasspath.mli @@ -14,6 +14,9 @@ open Sawja_pack (** Jar file containing the models *) val models_jar : string ref +(** Type environment of the models *) +val models_tenv : Sil.tenv ref + (** Adds the set of procnames for the models of Java libraries so that methods with similar names are skipped during the capture *) val add_models : string -> unit diff --git a/infer/src/java/jTransType.ml b/infer/src/java/jTransType.ml index c34b019e0..4bfbdd66d 100644 --- a/infer/src/java/jTransType.ml +++ b/infer/src/java/jTransType.ml @@ -452,28 +452,10 @@ let return_type program tenv ms meth_kind = let add_models_types tenv = - let jar_tenv_filename = - let root = Filename.concat Config.default_in_zip_results_dir Config.captured_dir_name in - Filename.concat root Config.global_tenv_filename in - let temp_tenv_filename = - DB.filename_from_string (Filename.temp_file "tmp_" Config.global_tenv_filename) in let add_type t typename typ = if not (Sil.tenv_mem t typename) then Sil.tenv_add tenv typename typ in - let models_tenv = - try - let zip_channel = Zip.open_in !JClasspath.models_jar in - let entry = Zip.find_entry zip_channel jar_tenv_filename in - let temp_tenv_file = DB.filename_to_string temp_tenv_filename in - let () = Zip.copy_entry_to_file zip_channel entry temp_tenv_file in - match Sil.load_tenv_from_file temp_tenv_filename with - | None -> failwith "Models tenv file could not be loaded" - | Some tenv -> tenv - with - | Not_found -> failwith "Models tenv not found in jar file" - | Sys_error msg -> failwith ("Models jar could not be opened "^msg) in - Sil.tenv_iter (add_type tenv) models_tenv; - DB.file_remove temp_tenv_filename + Sil.tenv_iter (add_type tenv) !JClasspath.models_tenv (* TODO #6604630: remove *)