Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Xmx not passed to script JVM #4922

Open
skirge opened this issue Sep 13, 2024 · 2 comments
Open

[Bug] Xmx not passed to script JVM #4922

skirge opened this issue Sep 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@skirge
Copy link

skirge commented Sep 13, 2024

Describe the bug

-J-Xmx flag is not passed to JVM which is running script

To Reproduce
Steps to reproduce the behavior:

  1. invoke joern with -J-Xmx24G --script somescript.sc
  2. run ps and notice that java process running replpp.scripting.NonForkingScriptRunner is missing -Xmx flag provided on command line

I think that ScriptRunning.exec is not passing additional JVM command line arguments to created java process.
As a result analysis crashes with OutOfMemory error despite providing flag on command line to increase heap to maximum.

Expected behavior
Xmx flag should be passed to jvm running the script

@skirge skirge added the bug Something isn't working label Sep 13, 2024
@LPirch
Copy link

LPirch commented Nov 20, 2024

Hello, same problem here. This is my script (script.sc):

@main def exec() = {
  System.out.println(Runtime.getRuntime().maxMemory())
  System.out.println(Runtime.getRuntime().availableProcessors())
}

Normal Behavior in Joern Shell

  1. joern -J-Xmx12G -J-XX:ActiveProcessorCount=3
  2. joern> System.out.println(Runtime.getRuntime().maxMemory()) prints "12884901888" (12GB)
  3. joern> System.out.println(Runtime.getRuntime().availableProcessors()) prints "3"

Bugged Behavior in Script

  1. joern -J-Xmx12G -J-XX:ActiveProcessorCount=3 --script script.sc
  2. prints the full amount available on my machine

The same applies if called with JAVA_OPTS in both cases.

@LPirch
Copy link

LPirch commented Nov 20, 2024

For anyone who stumbles across this: Here is my current workaround.

script.sc:

def foo(m: Method) = m.ast.size

def main(argA: String) = {
    cpg.method.map(foo).sum

    System.out.println(Runtime.getRuntime().maxMemory())
    System.out.println(Runtime.getRuntime().availableProcessors())
    System.out.println(argA)
}

run_script.sh:

#!/usr/bin/env bash

set -eu

MAX_MEMORY="40G"
MAX_CORES=32

if [ $# -lt 4 ]; then
    echo "Usage: $0 <cpg_file> <script_file> <args>"
    exit 1
fi

cpg_file=$1; shift
script_file=$1; shift
args=$(IFS=, ; echo "$*")
echo -e "main($args)" | joern -J-Xmx$MAX_MEMORY -J-XX:ActiveProcessorCount=$MAX_CORES $cpg_file --import $script_file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants