in programs/buck_tool.py [0:0]
def _get_java_args(self, version_uid, extra_default_options=None):
with Tracing("BuckTool._get_java_args"):
java_args = []
if "BUCK_DEFAULT_FILESYSTEM" not in os.environ and (
sys.platform == "darwin" or sys.platform.startswith("linux")
):
# Change default filesystem to custom filesystem for memory optimizations
# Calls like Paths.get() would return optimized Path implementation
if self.get_buck_compiled_java_version() >= 9:
# In Java 9+, the default file system provider gets initialized in the middle of
# loading the jar for the main class (bootstrapper.jar for Buck). Due to a
# potential circular dependency, we can't place BuckFileSystemProvider in
# bootstrapper.jar, or even in a separate jar on the regular classpath. To
# ensure BuckFileSystemProvider is available early enough, we add it to the JVM
# bootstrap classloader (not to be confused with Buck's bootstrapper) via the
# bootclasspath. Note that putting everything in bootstrapper.jar and putting it
# on the bootclasspath is problematic due to subtle classloader issues during
# in-process Java compilation.
#
# WARNING: The JVM appears to be sensitive about where this argument appears in
# the argument list. It needs to come first, or it *sometimes* doesn't
# get picked up. We don't understand exactly when or why this occurs.
java_args.append(
"-Xbootclasspath/a:" + self._get_buckfilesystem_classpath()
)
java_args.append(
"-Djava.nio.file.spi.DefaultFileSystemProvider="
"com.facebook.buck.core.filesystems.BuckFileSystemProvider"
)
java_args.extend(
[
"-Xmx{0}m".format(JAVA_MAX_HEAP_SIZE_MB),
"-Djava.awt.headless=true",
"-Djna.nosys=true",
"-Djava.util.logging.config.class=com.facebook.buck.cli.bootstrapper.LogConfig",
"-Dbuck.test_util_no_tests_dir=true",
"-Dbuck.version_uid={0}".format(version_uid),
"-Dbuck.buckd_dir={0}".format(self._buck_project.buckd_dir),
"-Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog",
"-Dbuck.git_commit={0}".format(self._get_buck_version_uid()),
"-Dbuck.git_commit_timestamp={0}".format(
self._get_buck_version_timestamp()
),
"-Dbuck.binary_hash={0}".format(self._get_buck_binary_hash()),
"-Dbuck.base_buck_out_dir={0}".format(
self._buck_project.get_buck_out_relative_dir()
),
]
)
resource_lock_path = self._get_resource_lock_path()
if resource_lock_path is not None:
java_args.append(
"-Dbuck.resource_lock_path={0}".format(resource_lock_path)
)
for resource in self._get_exported_resources():
if self._has_resource(resource):
java_args.append(
"-Dbuck.{0}={1}".format(
resource.name, self._get_resource(resource)
)
)
if sys.platform == "darwin":
java_args.append("-Dbuck.enable_objc=true")
java_args.append(
"-Djava.library.path="
+ os.path.dirname(self._get_resource(Resource("libjcocoa.dylib")))
)
if (
"BUCK_DEBUG_MODE" in os.environ
and os.environ.get("BUCK_DEBUG_MODE") != "0"
):
suspend = "n" if os.environ.get("BUCK_DEBUG_MODE") == "2" else "y"
port = "8888"
java_args.append(
"-agentlib:jdwp=transport=dt_socket,"
"server=y,suspend=" + suspend + ",quiet=y,address=" + port
)
if suspend == "y":
logging.info("Waiting for debugger on port {}...".format(port))
if (
"BUCK_HTTP_PORT" in os.environ
and os.environ.get("BUCK_HTTP_PORT").lstrip("+-").isdigit()
):
java_args.append(
"-Dbuck.httpserver.port=" + os.environ.get("BUCK_HTTP_PORT")
)
if os.environ.get("BUCK_DEBUG_SOY"):
java_args.append("-Dbuck.soy.debug=true")
java_args.extend(extra_default_options or [])
if self._buck_project.buck_javaargs:
java_args.extend(shlex.split(self._buck_project.buck_javaargs))
if self._buck_project.buck_javaargs_local:
java_args.extend(shlex.split(self._buck_project.buck_javaargs_local))
java_args.extend(self._get_extra_java_args())
extra_java_args = os.environ.get("BUCK_EXTRA_JAVA_ARGS")
if extra_java_args:
java_args.extend(shlex.split(extra_java_args))
# Remove unsupported args on newer Java versions. This is only here temporarily to
# simplify the transition while we need to support multiple versions of the JVM.
# TODO: Remove once Java 11 upgrade is done.
if self.get_buck_compiled_java_version() >= 9:
unsupported_args = set(
[
# `-verbose:gc` and `-XX:+PrintGCDetails` are technically supported, but log
# to stdout, which is problematic when Buck's output needs to be
# programmatically parsed. So we disallow them. `-Xlog:gc:/path/to/gc.log`
# should be used in Java 11 instead.
"-verbose:gc",
"-XX:+PrintGCDetails",
"-XX:+PrintGCDateStamps",
"-XX:+PrintGCTimeStamps",
"-XX:+UseParNewGC",
]
)
stripped_args = []
for arg in java_args:
if arg in unsupported_args:
logging.warning(
"Warning: Removing JVM arg `%s`, which is not supported in Java %d.",
arg,
self.get_buck_compiled_java_version(),
)
elif arg.startswith("-Xloggc"):
logging.warning(
"Warning: JVM arg `-Xloggc` is deprecated in Java %d. Replacing with `-Xlog:gc`.",
self.get_buck_compiled_java_version(),
)
# Though the JVM will make this replacement itself, it stupidly logs the
# deprecation warning to stdout, which will break programmatic parsing of
# Buck's output.
stripped_args.append(arg.replace("-Xloggc", "-Xlog:gc"))
else:
stripped_args.append(arg)
java_args = stripped_args
return java_args