Skip to content

Replace JAVA_OPTS variable with JAVA_TOOL_OPTIONS #13256

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

Merged
merged 12 commits into from
Jun 16, 2025

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Jun 11, 2025

Pull Request Description

Use the standard _JAVA_OPTIONS environment variable where JAVA_OPTS option was used previously.

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • All code follows the
    Scala,
    Java,
    Rust
  • Manual testing performed:
    • With shell launchers runEngineDistribution --debug works (Linux, Mac, Windows)
    • With native image launchers runEngineDistribution --debug works
      • testing with ENSO_LAUNCHER env variable set to native,test,-ls,fast
      • Linux
      • Mac
      • Windows - works with 00657ec
    • With shell launchers runProjectManagerDistribution --debug works
      • Linux
      • Mac
      • Windows
    • With native image launchers runProjectManagerDistribution --debug works
      • Linux
      • Mac
      • Windows
    • Execution in IGV sends graphs
      • while testing it turns out current IGV cannot run on GraalVM 24: more info
    • Launch an Enso File works from the VSCode
    • "Launch an Enso File" works from the NetBeans

Copy link

github-actions bot commented Jun 11, 2025

✨ GUI Checks Results

Summary

  • 🧹 Prettier: ✅ Passed
  • 🧰 GUI Checks: ❌ Failed
  • 📚 Storybook: ❌ Failed

⚠️ Action Required: Please review the failed checks and fix them before merging.

See individual check results for more details.

@JaroslavTulach JaroslavTulach force-pushed the wip/jtulach/Use_JAVA_OPTIONS_13172 branch from 4ef2786 to df1ee08 Compare June 11, 2025 06:57
@jdunkerley
Copy link
Member

Do we need to get clients using ENSO_JVM_OPTS to change things?

@radeusgd
Copy link
Contributor

Do we need to get clients using ENSO_JVM_OPTS to change things?

Seems like that, since ENSO_JVM_OPTS seems to be no longer supported after this PR, if I read the code changes correctly.

@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented Jun 11, 2025

Do we need to get clients using ENSO_JVM_OPTS to change things?
Seems like that, since ENSO_JVM_OPTS seems to be no longer supported after this PR, if I read the code changes correctly.

  • Do we have clients using ENSO_JVM_OPTS? Ah, now I recon we do...
  • In such case we want to continue the ENSO_JVM_OPTS support.
  • Moreover right now I have problem with sbt:enso> runProjectManagerDistribution --debug as it tries to debug project-manager.jar...
  • I guess I back out 3ad53aa then ...
  • done in 492857e

@JaroslavTulach JaroslavTulach force-pushed the wip/jtulach/Use_JAVA_OPTIONS_13172 branch from b49fda6 to 00657ec Compare June 12, 2025 08:27
@@ -210,7 +210,7 @@ private static <S> void printFrame(
static String adjustCwdToProject(String fileToRun) {
assert fileToRun != null;
if (!ImageInfo.inImageRuntimeCode()) {
return null;
return System.getProperty("enso.user.dir");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • the 17e2200 change is unrelated to _JAVA_OPTIONS changed
  • but while testing various combinations of launcher I found out that
  • with native image enso launcher the following execution fails:
  • sbt:enso> runEngineDistribution --jvm --run test/Base_Tests
  • saying it cannot find test/Base_Tests project
  • the problem is that the NI part
    • properly resolves the project
    • changes CWD to the test directory
    • invokes the JVM main
  • however the CWD for the JVM part is already test directory
  • and resolving test/Base_Tests in that directory doesn't work
  • this change fixes the problem by providing the JVM part the location of the original CWD via a property

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You set enso.user.dir with

commandAndArgs.add("-Denso.user.dir=" + originalCwdOrNull);

meaning that it can be -Denso.user.dir=null. And then when you get the property here, doesn't it return the "null" string?

@@ -41,15 +41,6 @@ public static JVM create(File javaHome, String... options) {
// java.home
jvmArgs.add("-Djava.home=" + javaHome);

var jvmOptions = System.getenv("JAVA_OPTS");
Copy link
Member Author

@JaroslavTulach JaroslavTulach Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • removal of this JAVA_OPTS handling is possible because the _JAVA_OPTIONS are "standard" JVM variables
  • we don't need to pass them around ourselves
  • the HotSpot JVM will pick them automatically up once it starts
  • it is small benefit, but it is a simplification of the code

@hubertp
Copy link
Collaborator

hubertp commented Jun 13, 2025

Any reason for preferring _JAVA_OPTIONS rather than JAVA_TOOL_OPTIONS? The former is undocumented, while the latter is.

Copy link
Member

@Akirathan Akirathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good simplification.

@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented Jun 13, 2025

Any reason for preferring _JAVA_OPTIONS rather than JAVA_TOOL_OPTIONS? The former is undocumented, while the latter is.

The difference on on GraalVM/OracleJVM is minimal as https://bugs.openjdk.org/browse/JDK-4971166 explains. But you are right, it is more standard to use JAVA_TOOL_OPTIONS:

Tool vendors need a uniform mechanism for adding options to a launch of the VM.
Particularly, they need a mechanism whereby they can launch agents (such as a
JVMTI agent) along with the VM, even if the VM is embedded.

So we need a new name and it should indicate it's intended usage so slightly
lessen the likelyhood of misuse -- JAVA_TOOL_OPTIONS.

Let's make the switch before integrating! Thanks for pointing that out. Done in 80cae79

@JaroslavTulach JaroslavTulach changed the title Replace JAVA_OPTS variable with _JAVA_OPTIONS Replace JAVA_OPTS variable with JAVA_TOOL_OPTIONS Jun 13, 2025
@JaroslavTulach JaroslavTulach changed the title Replace JAVA_OPTS variable with JAVA_TOOL_OPTIONS Replace JAVA_OPTS variable with JAVA_TOOL_OPTIONS Jun 13, 2025
@JaroslavTulach JaroslavTulach requested a review from Frizi as a code owner June 13, 2025 13:44
@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented Jun 16, 2025

  • Current version of IGV doesn't run on JDK/GraalVM 24
  • there are problems with security manager - created Make IGV start on GraalVM 24.0.1 oracle/graal#11409
  • there are problems with --add-opens
  • turns out libgraal in GraalVM 24 doesn't support jdk.graal.PrintGraphPort property
  • only jargraal does it
  • as such IGV integration with Enso cannot dump graphs when running a file in the editor currently
  • but JAVA_TOOL_OPTIONS seem to work fine by itself
JAVA_TOOL_OPTIONS=--add-exports=java.base/jdk.internal.misc=jdk.graal.compiler,com.oracle.graal.graal_enterprise\
   -XX:-UseJVMCINativeLibrary\ 
  -Djdk.graal.Dump=:3\ 
  -Djdk.graal.PrintGraph=Network\
  ./enso --jvm --run ~/fac_tail.enso 10000
  • the above (put on a single line) does deliver graphs to IGV (on JDK21) via native image compiled enso

@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented Jun 16, 2025

While testing sbt runProjectManagerDistribution I found another problem (unrelated to JAVA_TOOL_OPTIONS):

[INFO] [2025-06-16T08:42:31.155] [org.enso.runtimeversionmanager.runner.Runner] Additional JVM options [-ea] from the ENSO_JVM_OPTS environment variable.

this happens only when the engine is native image. Because then the ENSO_JVM_OPTS aren't sent to the JVM, but are sent to the ./enso executable itself!

@@ -1,5 +1,4 @@
COMP_PATH=$(dirname "$0")/../component

JAVA_OPTS="--enable-native-access=org.graalvm.truffle --sun-misc-unsafe-memory-access=allow --add-opens=java.base/java.nio=ALL-UNNAMED $JAVA_OPTS"
JAVA_OPTS="--enable-native-access=org.graalvm.truffle --sun-misc-unsafe-memory-access=allow --add-opens=java.base/java.nio=ALL-UNNAMED"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That changes the behavior slightly but I understand why it is done this way.

@@ -210,7 +210,7 @@ private static <S> void printFrame(
static String adjustCwdToProject(String fileToRun) {
assert fileToRun != null;
if (!ImageInfo.inImageRuntimeCode()) {
return null;
return System.getProperty("enso.user.dir");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You set enso.user.dir with

commandAndArgs.add("-Denso.user.dir=" + originalCwdOrNull);

meaning that it can be -Denso.user.dir=null. And then when you get the property here, doesn't it return the "null" string?

Copy link
Contributor

@4e6 4e6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for my comment about the enso.user.dir it's good to go.

throws IOException, InterruptedException {
var useJNI = true;
var commandAndArgs = new ArrayList<String>();
if (originalCwdOrNull != null) {
Copy link
Member Author

@JaroslavTulach JaroslavTulach Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only set enso.user.dir when originalCwdOrNull is non-null. The problem mentioned here cannot happen, @4e6, I hope.

@JaroslavTulach JaroslavTulach merged commit a3bb302 into develop Jun 16, 2025
163 of 171 checks passed
@JaroslavTulach JaroslavTulach deleted the wip/jtulach/Use_JAVA_OPTIONS_13172 branch June 16, 2025 15:52
@hubertp
Copy link
Collaborator

hubertp commented Jun 17, 2025

The only drawback of this change is that

Picked up JAVA_TOOL_OPTIONS: ...

is now being printed always. AFAICT _JAVA_OPTIONS suffered from the same disease and it can't be suppressed.

@JaroslavTulach
Copy link
Member Author

The only drawback of this change is that

Picked up JAVA_TOOL_OPTIONS: ...

is now being printed always.

Yes, that's correct. Is it a problem for production? I hope not.

@hubertp
Copy link
Collaborator

hubertp commented Jun 17, 2025

Yes, that's correct. Is it a problem for production? I hope not.

It's annoying. I don't know why JDK authors decided to print a debug message to stderr 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants