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

Java arguments specified via jvmArgs are ignored for incremental compilation #507

Closed
tashoyan opened this issue Aug 26, 2021 · 7 comments
Closed
Assignees

Comments

@tashoyan
Copy link

tashoyan commented Aug 26, 2021

The original goal was to increase Java stack size for the Scala compilation with help of the -Xss Java argument:

<plugin>
  <groupId>net.alchim31.maven</groupId>
  <artifactId>scala-maven-plugin</artifactId>
  <configuration>
    ...
    <jvmArgs>
      <jvmArg>-Xss2m</jvmArg>
    </jvmArgs>
    ...
  </configuration>
<plugin>

It looks like all settings from jvmArgs are completely ignored for the goals compile and testCompile.
Surprisingly, jvmArgs are effective (not ignored) for the goal doc-jar.
The problem occurs for scala-maven-plugin versions starting from 4.0.0. For the version 3.4.6 the problem does not occur.

This is a severe problem, as it leaves no possibility to overcome StackOverflowError during Scala compilation. For example: Stackoverflow in typechecker.Typers$Typer.

I am attaching a simple Maven project illustrating the problem. Here the JVM argument -XshowSettings:all is used as a marker: JVM settings are printed only when running the goal doc-jar - neither compile nor testCompile goals.
scalac-xss.tar.gz

java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode)
@davidB
Copy link
Owner

davidB commented Aug 28, 2021

For compile and testCompile, jvmArgs are only used when recompilationMode is all. Since 4.5.0 the default value is incremental, in this case compilation (zinc based) is made in the same jvm than maven.

@tashoyan
Copy link
Author

If we use the default value of recompileMode, then we have to tune the settings of the JVM running Maven. We can do it by putting a file .mvn/jvm.config in the project directory, as described in Maven configuration. This works!
Maybe makes sense to describe this behavior in the documentation. Otherwise, it is quite difficult to figure out, how to customize JVM settings for Scala compilation.

@slandelle slandelle changed the title Java arguments specified via jvmArgs are ignored for compilation Java arguments specified via jvmArgs are ignored for incremental compilation Jul 17, 2022
@slandelle
Copy link
Collaborator

I'm going to try and fix this.

@slandelle slandelle self-assigned this Nov 22, 2022
@slandelle
Copy link
Collaborator

So actually, this is super complicated to implement. The incremental compiler needs a huge amount of parameters, it would be a huge effort. Not impossible, but not something I'll be able to tackle any time soon.

As a workaround, I think we could:

  1. either disable the incremental mode when jvmArgs are defined
  2. or default to all instead of incremental when jvmArgs are defined and crash if incremental is explicitly defined along with jvmArgs

@davidB WDYT?

@davidB
Copy link
Owner

davidB commented Nov 23, 2022

I prefer 2. (less magic/hidden behavior for end-user). I guess by "crash" you mean exit with an error message to explain the cause.

Thanks @slandelle for your support.

slandelle added a commit that referenced this issue Nov 29, 2022
…close #507

Motivation:

The incremental mode which is now the default one doesn't handle jvmArgs as it can't run in a forked process.
A user might need this for example in order to increase the Xss to compile complex code with lots of method chaining and type inference.

Modification:

* introduce a new Fork class (only used for the incremental compiler for now.
* run the incremental compiler as soon as jvmArgs are defined

Result:

The default incremental compiler now properly handles jvmArgs.
slandelle added a commit that referenced this issue Nov 29, 2022
…close #507

Motivation:

The incremental mode which is now the default one doesn't handle jvmArgs as it can't run in a forked process.
A user might need this for example in order to increase the Xss to compile complex code with lots of method chaining and type inference.

Modification:

* introduce a new Fork class (only used for the incremental compiler for now.
* run the incremental compiler as soon as jvmArgs are defined

Result:

The default incremental compiler now properly handles jvmArgs.
@slandelle
Copy link
Collaborator

slandelle commented Nov 29, 2022

@davidB Actually, I ended up implementing the process forking. PTAL #659

slandelle added a commit that referenced this issue Nov 29, 2022
…close #507

Motivation:

The incremental mode which is now the default one doesn't handle jvmArgs as it can't run in a forked process.
A user might need this for example in order to increase the Xss to compile complex code with lots of method chaining and type inference.

Modification:

* introduce a new Fork class (only used for the incremental compiler for now.
* run the incremental compiler as soon as jvmArgs are defined

Result:

The default incremental compiler now properly handles jvmArgs.
slandelle added a commit that referenced this issue Nov 29, 2022
…close #507

Motivation:

The incremental mode which is now the default one doesn't handle jvmArgs as it can't run in a forked process.
A user might need this for example in order to increase the Xss to compile complex code with lots of method chaining and type inference.

Modification:

* introduce a new Fork class (only used for the incremental compiler for now.
* run the incremental compiler as soon as jvmArgs are defined

Result:

The default incremental compiler now properly handles jvmArgs.
slandelle added a commit that referenced this issue Nov 29, 2022
…close #507

Motivation:

The incremental mode which is now the default one doesn't handle jvmArgs as it can't run in a forked process.
A user might need this for example in order to increase the Xss to compile complex code with lots of method chaining and type inference.

Modification:

* introduce a new Fork class (only used for the incremental compiler for now.
* run the incremental compiler as soon as jvmArgs are defined

Result:

The default incremental compiler now properly handles jvmArgs.
slandelle added a commit that referenced this issue Nov 29, 2022
…close #507

Motivation:

The incremental mode which is now the default one doesn't handle jvmArgs as it can't run in a forked process.
A user might need this for example in order to increase the Xss to compile complex code with lots of method chaining and type inference.

Modification:

* introduce a new Fork class (only used for the incremental compiler for now.
* run the incremental compiler as soon as jvmArgs are defined

Result:

The default incremental compiler now properly handles jvmArgs.
@slandelle
Copy link
Collaborator

Fixed in 4.8.0

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

No branches or pull requests

3 participants