Skip to content

Commit

Permalink
Limit number of cpus and memory
Browse files Browse the repository at this point in the history
On big systems, mx dies since it spawns too many JVMs in parallel.  We now add
an option to limit the number of cpus from the command line.

Also the memory used to detect the Xlint options of javac is limited to prevent
VM crashes on parallel builds.
  • Loading branch information
Juergen Christ committed Feb 15, 2016
1 parent 6a8aeef commit 07dbb2a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ def cpu_count():
if is_jython():
from java.lang import Runtime
runtime = Runtime.getRuntime()
return runtime.availableProcessors()
cpus = runtime.availableProcessors()
else:
return multiprocessing.cpu_count()
cpus = multiprocessing.cpu_count()
if hasattr(_opts, 'cpu_count'):
return cpus if cpus <= _opts.cpu_count else _opts.cpu_count
else:
return cpus

try: subprocess.check_output
except: subprocess.check_output = check_output
Expand Down Expand Up @@ -6463,6 +6467,7 @@ def __init__(self, parents=None):
self.add_argument('--mx-tests', action='store_true', help='load mxtests suite (mx debugging)')
self.add_argument('--jdk', action='store', help='JDK to use for the "java" command', metavar='<tag:compliance>')
self.add_argument('--version-conflict-resolution', dest='version_conflict_resolution', action='store', help='resolution mechanism used when a suite is imported with different versions', default='suite', choices=['suite', 'none', 'latest', 'ignore'])
self.add_argument('-j', action='store', type=int, dest='cpu_count', help='the maximum number of cpus to use during build', metavar='<cpus>')
if get_os() != 'windows':
# Time outs are (currently) implemented with Unix specific functionality
self.add_argument('--timeout', help='timeout (in seconds) for command', type=int, default=0, metavar='<secs>')
Expand All @@ -6479,7 +6484,6 @@ def _parse_cmd_line(self, opts, firstParse):
parser.add_argument('--vm', action='store', dest='vm', help='the VM type to build/run')
parser.add_argument('--vmbuild', action='store', dest='vmbuild', help='the VM build to build/run')


# Parse the known mx global options and preserve the unknown args, command and
# command args for the second parse.
_, self.unknown = parser.parse_known_args(namespace=opts)
Expand Down Expand Up @@ -7541,7 +7545,7 @@ def getKnownJavacLints(self):
Gets the lint warnings supported by this JDK.
'''
if self._knownJavacLints is None:
out = subprocess.check_output([self.javac, '-X'], stderr=subprocess.STDOUT)
out = subprocess.check_output([self.javac, '-X', '-Xms8M'], stderr=subprocess.STDOUT)
if self.javaCompliance < JavaCompliance('1.9'):
lintre = re.compile(r"-Xlint:\{([a-z-]+(?:,[a-z-]+)*)\}")
m = lintre.search(out)
Expand Down

0 comments on commit 07dbb2a

Please sign in to comment.