Help Needed: Gatling JVM Error

Hello community members,

I hope you’re all doing well. I’m currently facing an issue while trying to run Gatling, and I could really use your expertise and guidance to resolve it. Before I dive into the details, I’d like to express my gratitude in advance for your help and support. Your time and assistance are highly valued, and I promise to maintain a polite and respectful tone throughout this discussion.

Context:
I’m using Gatling for load testing, and I’ve encountered a Java Virtual Machine (JVM) error while running my tests.

Issue Description:
Here’s the command I’m using to run Gatling:

sh ${GATLING_BIN_DIR}/gatling.sh \
  -rm local \
  -s TestSimulation \
  -rd "Test" \
  -rf ${WORKSPACE}/user-files/results \
  -sf ${WORKSPACE}/user-files/simulations \
  -rsf ${WORKSPACE}/user-files/resources

And here’s the error message I’m encountering:

Error: VM option 'UseG1GC' is experimental and must be enabled via -XX:+UnlockExperimentalVMOptions.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Info:

  Model Name:	MacBook Air
  Chip:	Apple M2
java version "1.8.0_381"
Java(TM) SE Runtime Environment (build 1.8.0_381-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.381-b09, mixed mode)

Thank you for your support!

Ps. I tested adding the option via -ecjo "-XX:+UnlockExperimentalVMOptions" & --extra-run-jvm-options "-XX:+UnlockExperimentalVMOptions" and directly in the .sh script, but has the same error.

Hi @cmrg,

Which version of Gatling do you use? Latest is 3.9.5 and the script doesn’t contain the UseG1GC option (anymore).
If you do use the latest version, look into your JAVA_OPTS environment variables.

Cheers!

2 Likes

G1GC was made a stable feature that doesn’t require -XX:+UnlockExperimentalVMOptions as of Java 7u4, see Java SE 7 Update 4 Release Notes.

This means that you’re definitely not using Java 8u381 but actually a way older version. As @sbrevet suggested, check your JAVA_HOME env var.

2 Likes

So, that’s the link I used to download the 3.9.5 version:

https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/3.9.5/gatling-charts-highcharts-bundle-3.9.5-bundle.zip

And this is the $JAVA_OPTS of the gatling.sh:

JAVA_OPTS="${JAVA_OPTS} -Xms32M -Xmx128M"

I also echoed my $JAVA_OPTS and $JAVA_HOME but they’re blank, empty. I guess the script is using the java command on the $PATH:

if [ -n "$JAVA_HOME" ]; then
    JAVA="$JAVA_HOME"/bin/java
else
    JAVA=java
fi

/bin/gatling.sh

I’ve uninstalled my java of dubious origin, as I don’t really remember installing it, and installed the JDK from Adoptium and that weird error is now gone, but I’m having an error on the simulation, as I haven’t changed anything and this is just a cloned script I image it’s something with my environment again, any ideas?

08:05:56.924 [ERROR] i.g.a.Gatling$ - Run crashed
java.lang.ClassNotFoundException: TestSimulation
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:375)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$2(Selection.scala:73)
        at scala.util.Try$.apply(Try.scala:210)
        at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:73)
        ... 20 common frames omitted
Wrapped by: java.lang.IllegalArgumentException: User defined Simulation class TestSimulation could not be loaded
        at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:84)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$4(Selection.scala:88)
        at scala.Option.orElse(Option.scala:477)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$3(Selection.scala:88)
        at scala.Option.flatMap(Option.scala:283)
        at io.gatling.app.Selection$Selector.singleSimulationFromConfig(Selection.scala:87)
        at io.gatling.app.Selection$Selector.$anonfun$selection$1(Selection.scala:50)
        at scala.Option.getOrElse(Option.scala:201)
        at io.gatling.app.Selection$Selector.selection(Selection.scala:42)
        at io.gatling.app.Selection$.apply(Selection.scala:35)
        at io.gatling.app.Runner.run(Runner.scala:53)
        at io.gatling.app.Gatling$.start(Gatling.scala:89)
        at io.gatling.app.Gatling$.fromArgs(Gatling.scala:51)
        at io.gatling.app.Gatling$.main(Gatling.scala:39)
        at io.gatling.app.Gatling.main(Gatling.scala)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.gatling.plugin.util.ForkMain.runMain(ForkMain.java:67)
        at io.gatling.plugin.util.ForkMain.main(ForkMain.java:35)
java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.gatling.plugin.util.ForkMain.runMain(ForkMain.java:67)
        at io.gatling.plugin.util.ForkMain.main(ForkMain.java:35)
Caused by: java.lang.IllegalArgumentException: User defined Simulation class TestSimulation could not be loaded
        at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:84)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$4(Selection.scala:88)
        at scala.Option.orElse(Option.scala:477)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$3(Selection.scala:88)
        at scala.Option.flatMap(Option.scala:283)
        at io.gatling.app.Selection$Selector.singleSimulationFromConfig(Selection.scala:87)
        at io.gatling.app.Selection$Selector.$anonfun$selection$1(Selection.scala:50)
        at scala.Option.getOrElse(Option.scala:201)
        at io.gatling.app.Selection$Selector.selection(Selection.scala:42)
        at io.gatling.app.Selection$.apply(Selection.scala:35)
        at io.gatling.app.Runner.run(Runner.scala:53)
        at io.gatling.app.Gatling$.start(Gatling.scala:89)
        at io.gatling.app.Gatling$.fromArgs(Gatling.scala:51)
        at io.gatling.app.Gatling$.main(Gatling.scala:39)
        at io.gatling.app.Gatling.main(Gatling.scala)
        ... 6 more
Caused by: java.lang.ClassNotFoundException: TestSimulation
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:375)
        at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$2(Selection.scala:73)
        at scala.util.Try$.apply(Try.scala:210)
        at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:73)
        ... 20 more

What is the sh? I guess it’s a bash, a zsh, etc.

Why do you launch gatling with that and not your current session? (gatling.sh should be executable)

It feels like your “sh” command create a new environment.

Can you execute this list of commands and give us the different answers?

sh -c "which java"
sh -c "java -version"
sh -c "echo \$JAVA_HOME"
sh -c "echo `$JAVA_OPTS"

Cheers!

I make little investigation and wen you provide by -rm local -s TestSimulation name of Class that don’t exist (TestSimulation in this case) you get java.lang.ClassNotFoundException: TestSimulation
So please check if you have this Class in place.

1 Like

Yes, of course:

/usr/bin/java
openjdk version "17.0.8.1" 2023-08-24
OpenJDK Runtime Environment Temurin-17.0.8.1+1 (build 17.0.8.1+1)
OpenJDK 64-Bit Server VM Temurin-17.0.8.1+1 (build 17.0.8.1+1, mixed mode)

Ooh, my bad. Figured it out…

I was actually running my script from the root of my project and the user-files was scoped in a /test cd into that and it runs fine now, thanks y’all!

It was mainly the Java JDK and some amateurism in the end… :slight_smile:

1 Like