oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
19.99k stars 1.6k forks source link

JS on stock JDK11 keeps restarting compilation #798

Closed rsalvador closed 1 year ago

rsalvador commented 5 years ago

We have a big js script that we call from java and works well with graalvm-rc9: takes 30secs on the first execution and progressively optimizes it until after around 200 invocations is at 600ms and stays that way for all subsequent invocations. But when running with jdk11+graal jars it never gets to optimize completely, it takes also 30secs on the first run and goes down to about 800ms at around the 100 invocation, but at than point it goes back to 30 secs and stars going down again, this roller coaster keeps repeating forever. Truffle seems to discard all the compilation work done and start from scratch every time.

wirthi commented 5 years ago

Hi,

thanks for you report. Can you by any chance provide a minified version of it so we can look at it? We are not aware of any systematic problem like that on JDK11. My first guess would be you don't use Graal at all, but if you go from 30sec to 800ms, that implies Graal does it's job in principle.

Have you tried whether the graal.TraceTruffleCompilation or graal.TraceTruffleTransferToInterpreter flags give you any resonable output? If it's a recompile loop, the first one might already show you what method is recompiled. Second option might show you the culprit that is causing the deoptimization/recompilation (but will create lots of output upfront).

Best, Christian

rsalvador commented 5 years ago

Hi, unfortunately, I won't be able to provide a minified version.

When I reported this issue in https://gitter.im/graalvm/graal-core @chumer say that you may have one known issue that is similar to what you describe and to report it in github. I could verify if it is fixed.

I did try graal.TraceTruffleCompilation and it reports it is continously compiling, when running under the graalvm it eventually stops compiling, but in jdk11 it keeps printing compilations all the time.

With graalvm those are the statistics after it goes down to 800ms:

Truffle runtime statistics:
  Compilations                                      : 3690
    Success                                         : 3468
    Failed                                          : 221
    Interrupted                                     : 1
  Invalidated                                       : 2
  Queues                                            : 14847
  Dequeues                                          : 11403
  Splits                                            : 25002
  Compilation Accuracy                              : 0.999458
  Queue Accuracy                                    : 0.231966
  Compilation Utilization                           : 1.029433
  Remaining Compilation Queue                       : 0

But with jdk11 it keeps compiling forever, i.e. after a few hours:

Truffle runtime statistics:
  Compilations                                      : 151390
    Success                                         : 141463
    Failed                                          : 9890
    Interrupted                                     : 37
  Invalidated                                       : 122
  Queues                                            : 549722
  Dequeues                                          : 410026
  Splits                                            : 649977
  Compilation Accuracy                              : 0.999194
  Queue Accuracy                                    : 0.254121
  Compilation Utilization                           : 0.442809
  Remaining Compilation Queue                       : 0

Just tried graal.TraceTruffleTransferToInterpreter, but it doesn't report anything around the time when it goes back to 30secs, it only reported a few messages at the start of the program.

Let me know if there is anything else we could do to debug or if there are any points in the graalvm code where I could set breakpoints to track what could be happening.

ghost commented 5 years ago

Are you running with the latest graal compiler from the rc? Stock jdk11 has an older version.. I've replaced it with for example --upgrade-module-path=c:/dev/code/graal/modules-rc8/compiler-1.0.0-rc8.jar

rsalvador commented 5 years ago

I am running with the latest rc9 from https://mvnrepository.com/artifact/org.graalvm.compiler/compiler/1.0.0-rc9 The same problem happened with 1.0.0-rc8

wirthi commented 1 year ago

I am closing this stale old ticket. If you still experience this problem with a newer version of GraalVM/Graal.js, please report a ticket at https://www.github.com/oracle/graaljs

It feels like this was a setup issue on stock JVM. We have some documentation at https://www.graalvm.org/22.1/reference-manual/js/RunOnJDK/ for that.

Also, make sure you are using a shared engine when using multiple Contexts to compile JavaScript: https://www.graalvm.org/22.1/reference-manual/embed-languages/#code-caching-across-multiple-contexts