From f185b3529284282ff4198f8d6dbd32403f5bd032 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Mon, 25 Jan 2021 08:50:07 -0800 Subject: [PATCH] [buck] allow setting the buck java heap size Summary: This is needed to address GC stalls due to a too small heap. Reviewed By: jvillard Differential Revision: D26045530 fbshipit-source-id: 590d1e72c --- infer/man/man1/infer-capture.txt | 4 ++++ infer/man/man1/infer-full.txt | 7 +++++++ infer/man/man1/infer.txt | 4 ++++ infer/src/base/Config.ml | 8 ++++++++ infer/src/base/Config.mli | 2 ++ infer/src/integration/Buck.ml | 17 ++++++++++++----- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/infer/man/man1/infer-capture.txt b/infer/man/man1/infer-capture.txt index be0ad46c3..be3b44ef5 100644 --- a/infer/man/man1/infer-capture.txt +++ b/infer/man/man1/infer-capture.txt @@ -160,6 +160,10 @@ BUCK OPTIONS binary and its version in the buck-java-flavor integration. (Conversely: --no-buck-java-flavor-suppress-config) + --buck-java-heap-size-gb int + Explicitly set the size of the Java heap of Buck processes, in + gigabytes. + --buck-merge-all-deps Activates: Find and merge all infer dependencies produced by buck. Use this flag if infer doesn't find any files to analyze after a diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index db59ec2d5..a7faa6c54 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -169,6 +169,10 @@ OPTIONS (Conversely: --no-buck-java-flavor-suppress-config) See also infer-capture(1). + --buck-java-heap-size-gb int + Explicitly set the size of the Java heap of Buck processes, in + gigabytes. See also infer-capture(1). + --buck-merge-all-deps Activates: Find and merge all infer dependencies produced by buck. Use this flag if infer doesn't find any files to analyze after a @@ -1322,6 +1326,9 @@ INTERNAL OPTIONS --buck-compilation-database-reset Cancel the effect of --buck-compilation-database. + --buck-java-heap-size-gb-reset + Cancel the effect of --buck-java-heap-size-gb. + --buck-targets-blacklist-reset Set --buck-targets-blacklist to the empty list. diff --git a/infer/man/man1/infer.txt b/infer/man/man1/infer.txt index 82dadd74d..3d7c2731c 100644 --- a/infer/man/man1/infer.txt +++ b/infer/man/man1/infer.txt @@ -169,6 +169,10 @@ OPTIONS (Conversely: --no-buck-java-flavor-suppress-config) See also infer-capture(1). + --buck-java-heap-size-gb int + Explicitly set the size of the Java heap of Buck processes, in + gigabytes. See also infer-capture(1). + --buck-merge-all-deps Activates: Find and merge all infer dependencies produced by buck. Use this flag if infer doesn't find any files to analyze after a diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 1c6d93046..7713ae7b0 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -699,6 +699,12 @@ and buck_compilation_database_depth = ~meta:"int" +and buck_java_heap_size_gb = + CLOpt.mk_int_opt ~long:"buck-java-heap-size-gb" + ~in_help:InferCommand.[(Capture, manual_buck)] + "Explicitly set the size of the Java heap of Buck processes, in gigabytes." ~meta:"int" + + and buck_java_flavor_suppress_config = CLOpt.mk_bool ~long:"buck-java-flavor-suppress-config" ~default:false ~in_help:InferCommand.[(Capture, manual_buck)] @@ -2758,6 +2764,8 @@ and buck_build_args_no_inline = RevList.to_list !buck_build_args_no_inline_rev and buck_cache_mode = (!buck || !genrule_mode) && not !debug +and buck_java_heap_size_gb = !buck_java_heap_size_gb + and buck_java_flavor_suppress_config = !buck_java_flavor_suppress_config and buck_merge_all_deps = !buck_merge_all_deps diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 0e5024184..e00c6f039 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -182,6 +182,8 @@ val buck_build_args_no_inline : string list val buck_cache_mode : bool +val buck_java_heap_size_gb : int option + val buck_merge_all_deps : bool val buck_mode : BuckMode.t option diff --git a/infer/src/integration/Buck.ml b/infer/src/integration/Buck.ml index 4c734b9d7..2f60dc110 100644 --- a/infer/src/integration/Buck.ml +++ b/infer/src/integration/Buck.ml @@ -51,18 +51,25 @@ let wrap_buck_call ?(extend_env = []) ~label cmd = Printf.sprintf "trap '' SIGQUIT ; exec %s >'%s'" escaped_cmd stdout_file in let env = + let explicit_buck_java_heap_size = + Option.map Config.buck_java_heap_size_gb ~f:(fun size -> Printf.sprintf "-Xmx%dG" size) + |> Option.to_list + in let existing_buck_extra_java_args = Sys.getenv buck_extra_java_args_env_var |> Option.to_list in let new_buck_extra_java_args = (* Instruct the JVM to avoid using signals. *) - String.concat ~sep:" " (existing_buck_extra_java_args @ ["-Xrs"]) + String.concat ~sep:" " + (existing_buck_extra_java_args @ explicit_buck_java_heap_size @ ["-Xrs"]) in + L.environment_info "Buck: setting %s to '%s'@\n" buck_extra_java_args_env_var + new_buck_extra_java_args ; `Extend ((buck_extra_java_args_env_var, new_buck_extra_java_args) :: extend_env) in let Unix.Process_info.{stdin; stdout; stderr; pid} = Unix.create_process_env ~prog:"sh" ~args:["-c"; sigquit_protected_cmd] ~env () in let buck_stderr = Unix.in_channel_of_descr stderr in - Utils.with_channel_in buck_stderr ~f:(L.progress "BUCK: %s@.") ; + Utils.with_channel_in buck_stderr ~f:(L.progress "BUCK: %s@\n") ; Unix.close stdin ; Unix.close stdout ; In_channel.close buck_stderr ; @@ -254,7 +261,7 @@ module Query = struct | `Assoc fields -> fields | _ -> - L.internal_error "Could not parse target json: %s@." (Yojson.Basic.to_string json) ; + L.internal_error "Could not parse target json: %s@\n" (Yojson.Basic.to_string json) ; [] in let get_json_field fieldname = function @@ -269,7 +276,7 @@ module Query = struct String.is_suffix ~suffix:".java" source_path && not (String.is_suffix ~suffix:"MetagenRoot.java" source_path) | _ -> - L.internal_error "Could not parse source path json: %s@." + L.internal_error "Could not parse source path json: %s@\n" (Yojson.Basic.to_string source_path_json) ; false in @@ -447,7 +454,7 @@ let inline_argument_files buck_args = let expanded_args = try Utils.with_file_in file_name ~f:In_channel.input_lines with exn -> - Logging.die UserError "Could not read from file '%s': %a@." file_name Exn.pp exn + Logging.die UserError "Could not read from file '%s': %a@\n" file_name Exn.pp exn in expanded_args else [buck_arg]