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
master
jrm 9 years ago committed by facebook-github-bot-7
parent e03b36338b
commit 8636aa1f70

@ -31,16 +31,42 @@ let set_verbose_out path =
let models_jar = ref "" 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 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 collect set e =
let filename = e.Zip.filename in let filename = e.Zip.filename in
if not (Filename.check_suffix filename ".specs") then set if not (Filename.check_suffix filename ".specs") then set
else else
let proc_filename = (Filename.chop_extension (Filename.basename filename)) in let proc_filename = (Filename.chop_extension (Filename.basename filename)) in
StringSet.add proc_filename set in StringSet.add proc_filename set in
models_specs_filenames := IList.fold_left collect !models_specs_filenames (Zip.entries file_in); models_specs_filenames :=
Zip.close_in file_in 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 = let add_models jar_filename =

@ -14,6 +14,9 @@ open Sawja_pack
(** Jar file containing the models *) (** Jar file containing the models *)
val models_jar : string ref 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 *) (** 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 val add_models : string -> unit

@ -452,28 +452,10 @@ let return_type program tenv ms meth_kind =
let add_models_types tenv = 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 = let add_type t typename typ =
if not (Sil.tenv_mem t typename) then if not (Sil.tenv_mem t typename) then
Sil.tenv_add tenv typename typ in Sil.tenv_add tenv typename typ in
let models_tenv = Sil.tenv_iter (add_type tenv) !JClasspath.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
(* TODO #6604630: remove *) (* TODO #6604630: remove *)

Loading…
Cancel
Save