Skip to content

Commit

Permalink
Allow JAVA_STACK and JAVA_MEM to be just the size. Fixes #2501.
Browse files Browse the repository at this point in the history
It was unclear whether -Xss and -Xmx prefixes were required, and now
they are imputed if missing. This fixes #2501 for Windows, but the
Unix shell script launcher needs the same change.
  • Loading branch information
jeff5 committed Mar 28, 2018
1 parent 7c6f862 commit 3e667d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -4,6 +4,7 @@ For more details, please see https://hg.python.org/jython

Developement tip
Bugs fixed
- [ 2501 ] JAVA_STACK doesn't work (fixed for Windows launcher only)
- [ 1866 ] Parser does not have mismatch token error messages caught by BaseRecognizer
- [ 1930 ] traceback raises exception in os.py
- [ 2419 ] List expected failures by OS platform in regrtest.py
Expand Down
27 changes: 22 additions & 5 deletions src/shell/jython.py
Expand Up @@ -48,14 +48,31 @@
def get_env(envvar, default=None):
""" Return the named environment variable, decoded to Unicode."""
v = os.environ.get(envvar, default)
# Tolerate default given as bytes, as we're bound to forget sometimes
# Result may be bytes but we want unicode for the command
if isinstance(v, bytes):
v = v.decode(ENCODING)
# Remove quotes sometimes necessary around the value
if v is not None and v.startswith('"') and v.endswith('"'):
v = v[1:-1]
return v

def get_env_mem(envvar, default):
""" Return the named memory environment variable, decoded to Unicode.
The default should begin with -Xmx or -Xss as in the java command,
but this part will be added to the environmental value if missing.
"""
# Tolerate default given as bytes, as we're bound to forget sometimes
if isinstance(default, bytes):
default = default.decode(ENCODING)
v = os.environ.get(envvar, default)
# Result may be bytes but we want unicode for the command
if isinstance(v, bytes):
v = v.decode(ENCODING)
# Accept either a form like 16m or one like -Xmx16m
if not v.startswith(u"-X"):
v = default[:4] + v
return v

def encode_list(args, encoding=ENCODING):
""" Convert list of Unicode strings to list of encoded byte strings."""
r = []
Expand Down Expand Up @@ -268,14 +285,14 @@ def java_mem(self):
if hasattr(self.args, "mem"):
return self.args.mem
else:
return get_env("JAVA_MEM", "-Xmx512m")
return get_env_mem("JAVA_MEM", "-Xmx512m")

@property
def java_stack(self):
if hasattr(self.args, "stack"):
return self.args.stack
else:
return os.environ.get("JAVA_STACK", "-Xss2560k")
return get_env_mem("JAVA_STACK", "-Xss2560k")

@property
def java_opts(self):
Expand Down Expand Up @@ -386,9 +403,9 @@ def print_help():
--profile: run with the Java Interactive Profiler (http://jiprof.sf.net)
-- : pass remaining arguments through to Jython
Jython launcher environment variables:
JAVA_MEM : Java memory (sets via -Xmx)
JAVA_MEM : Java memory size as a java option e.g. -Xmx600m or just 600m
JAVA_STACK : Java stack size as a java option e.g. -Xss5120k or just 5120k
JAVA_OPTS : options to pass directly to Java
JAVA_STACK : Java stack size (sets via -Xss)
JAVA_HOME : Java installation directory
JYTHON_HOME: Jython installation directory
JYTHON_OPTS: default command line arguments
Expand Down

0 comments on commit 3e667d7

Please sign in to comment.