[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
master
Nikos Gorogiannis 4 years ago committed by Facebook GitHub Bot
parent ad84126184
commit f185b35292

@ -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

@ -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.

@ -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

@ -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

@ -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

@ -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]

Loading…
Cancel
Save