Skip to content

Commit 092fd33

Browse files
committed
Enhance JVM argument handling: add default heap size and native access flag
1 parent c926196 commit 092fd33

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

bindings/python/src/arcadedb_embedded/jvm.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,20 @@ def _build_jvm_args() -> list[str]:
151151
# 2. Headless mode if not set (Critical for server environments)
152152
if not any(arg.startswith("-Djava.awt.headless=") for arg in jvm_args):
153153
jvm_args.append("-Djava.awt.headless=true")
154+
155+
# 3. Default heap if user did not set one
156+
if not any(arg.startswith("-Xmx") for arg in jvm_args):
157+
jvm_args.append("-Xmx4g")
158+
159+
# 4. Allow native access for JPype (required by newer JDKs)
160+
if not any(arg.startswith("--enable-native-access") for arg in jvm_args):
161+
jvm_args.append("--enable-native-access=ALL-UNNAMED")
154162
else:
155163
# Default: 4GB heap, headless mode, SIMD vector support
156164
jvm_args = [
157165
"-Xmx4g",
158166
"-Djava.awt.headless=true",
167+
"--enable-native-access=ALL-UNNAMED",
159168
"--add-modules=jdk.incubator.vector",
160169
]
161170

bindings/python/tests/test_jvm_args.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def test_defaults_no_env_vars():
1111
assert "-Xmx4g" in args
1212
assert "-Djava.awt.headless=true" in args
1313
assert "--add-modules=jdk.incubator.vector" in args
14+
assert "--enable-native-access=ALL-UNNAMED" in args
1415
# Should have default error log
1516
assert any("hs_err_pid" in arg for arg in args)
1617

@@ -27,21 +28,32 @@ def test_custom_jvm_args_merging():
2728
# Mandatory args injected
2829
assert "-Djava.awt.headless=true" in args
2930
assert "--add-modules=jdk.incubator.vector" in args
31+
assert "--enable-native-access=ALL-UNNAMED" in args
32+
33+
34+
def test_custom_jvm_args_injects_heap_default_when_missing():
35+
"""Ensure we add a heap default if user omits -Xmx."""
36+
with patch.dict(os.environ, {"ARCADEDB_JVM_ARGS": "-Dfoo=bar"}, clear=True):
37+
args = _build_jvm_args()
38+
assert "-Xmx4g" in args
39+
assert "-Dfoo=bar" in args
3040

3141

3242
def test_custom_jvm_args_no_duplicates():
3343
"""Test that we don't duplicate flags if user provides them."""
34-
custom_args = "-Xmx2g -Djava.awt.headless=false --add-modules=jdk.incubator.vector"
44+
custom_args = "-Xmx2g -Djava.awt.headless=false --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED"
3545
with patch.dict(os.environ, {"ARCADEDB_JVM_ARGS": custom_args}, clear=True):
3646
args = _build_jvm_args()
3747

3848
# Should NOT add defaults if present
3949
# Count occurrences
4050
modules_count = sum(1 for a in args if "jdk.incubator.vector" in a)
4151
headless_count = sum(1 for a in args if "headless" in a)
52+
native_count = sum(1 for a in args if "enable-native-access" in a)
4253

4354
assert modules_count == 1
4455
assert headless_count == 1
56+
assert native_count == 1
4557

4658
# Verify user's explicit choice is respected (e.g., they might want headless=false for some reason)
4759
# Note: Our logic just checks key presence, it doesn't force overwrite if key exists with different value.

0 commit comments

Comments
 (0)