eclipse-openj9 / openj9

Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Other
3.27k stars 721 forks source link

-Xnojit option disables AOT #17918

Open knn-k opened 1 year ago

knn-k commented 1 year ago

Using the -Xnojit option in the latest OpenJ9 seems to disable not only JIT compilation but also AOT loads.

See the following output from a recent nightly build:

$ ./jdk/bin/java -Xnojit -version
openjdk version "11.0.20-internal" 2023-07-18
OpenJDK Runtime Environment (build 11.0.20-internal+0-adhoc..BuildJDK11aarch64linuxNightly)
Eclipse OpenJ9 VM (build master-3dddeecdd80, JRE 11 Linux aarch64-64-Bit Compressed References 20230804_489 (JIT disabled, AOT enabled)
OpenJ9   - 3dddeecdd80
OMR      - 43a2b1d3416
JCL      - fd112235b4d based on jdk-11.0.20+8)

It says JIT disabled, AOT enabled for -Xnojit. Adding -Xaot:verbose shows no loading of AOT methods, saying AOT header validation failed: CH Table mismatch.

$ ./jdk/bin/java -Xnojit -Xaot:verbose,vlog=nojit.txt -version
openjdk version "11.0.20-internal" 2023-07-18
OpenJDK Runtime Environment (build 11.0.20-internal+0-adhoc..BuildJDK11aarch64linuxNightly)
Eclipse OpenJ9 VM (build master-3dddeecdd80, JRE 11 Linux aarch64-64-Bit Compressed References 20230804_489 (JIT disabled, AOT enabled)
OpenJ9   - 3dddeecdd80
OMR      - 43a2b1d3416
JCL      - fd112235b4d based on jdk-11.0.20+8)
$ cat nojit.txt.20230807.150849.21841
#INFO:  _______________________________________
#INFO:  Version Information:
#INFO:       JIT Level  - j9jit_20230805_0003_
#INFO:       JVM Level  - 20230804_489
#INFO:       GC Level   - 3dddeecdd80
#INFO:
#INFO:  _______________________________________
#INFO:  AOT
#INFO:  options specified:
#INFO:       verbose,vlog=nojit.txt
#INFO:
#INFO:  options in effect:
#INFO:       samplingFrequency=0
#INFO:       verbose=1
#INFO:       vlog=nojit.txt

#INFO:       compressedRefs shiftAmount=0
#INFO:  aggressivenessLevel=5
#INFO:  _______________________________________
#INFO:  JIT
#INFO:  options specified:
#INFO:       samplingFrequency=2
#INFO:
#INFO:  options in effect:
#INFO:       samplingFrequency=0
#INFO:       verbose=1
#INFO:       vlog=nojit.txt

#INFO:       compressedRefs shiftAmount=0
#INFO:  aggressivenessLevel=5
#INFO:  AOT header validation failed: CH Table mismatch.
knn-k commented 1 year ago

It used to work with OpenJ9 v0.38.0. The verbose log shows AOT methods are loaded.

$ ./jdk-11.0.19+7/bin/java -Xnojit -Xaot:verbose,vlog=nojit.txt -version
openjdk version "11.0.19" 2023-04-18
IBM Semeru Runtime Open Edition 11.0.19.0 (build 11.0.19+7)
Eclipse OpenJ9 VM 11.0.19.0 (build openj9-0.38.0, JRE 11 Linux aarch64-64-Bit Compressed References 20230523_692 (JIT disabled, AOT enabled)
OpenJ9   - d57d05932
OMR      - 855813495
JCL      - 629eb0c22b based on jdk-11.0.19+7)
$ less nojit.txt.20230807.151513.22116
#INFO:  _______________________________________
#INFO:  Version Information:
#INFO:       JIT Level  - j9jit_20230523_1445_
#INFO:       JVM Level  - 20230523_692
#INFO:       GC Level   - d57d05932
#INFO:
#INFO:  _______________________________________
#INFO:  AOT
#INFO:  options specified:
#INFO:       verbose,vlog=nojit.txt
#INFO:
#INFO:  options in effect:
#INFO:       samplingFrequency=0
#INFO:       verbose=1
#INFO:       vlog=nojit.txt

#INFO:       compressedRefs shiftAmount=0
#INFO:  aggressivenessLevel=5
#INFO:  _______________________________________
#INFO:  JIT
#INFO:  options specified:
#INFO:       samplingFrequency=2
#INFO:
#INFO:  options in effect:
#INFO:       samplingFrequency=0
#INFO:       verbose=1
#INFO:       vlog=nojit.txt

#INFO:       compressedRefs shiftAmount=0
#INFO:  aggressivenessLevel=5
+ (AOT load) com/ibm/jit/JITHelpers.putCharInArrayByIndex(Ljava/lang/Object;IC)V @ 0000FFFF7FAFE064-0000FFFF7FAFE648 Q_SZ=0 Q_SZI=0 QW=1 j9m=0000000000031C08 bcsz=173 compThreadID=0
+ (AOT load) java/lang/Object.<init>()V @ 0000FFFF7FAFE690-0000FFFF7FAFE6F0 Q_SZ=0 Q_SZI=0 QW=1 j9m=00000000000231C8 bcsz=1 compThreadID=0
! (AOT load) java/lang/String.lengthInternal()I Q_SZ=1 Q_SZI=1 QW=2 j9m=000000000002E3D8 time=355us compilationRelocationFailure (stringCompressionValidationFailure) memLimit=262144 KB compThreadID=0
...
knn-k commented 1 year ago

I can reproduce the problem using a recent x86-64 Linux build with the same failure message: AOT header validation failed: CH Table mismatch.

$ ./jdk/bin/java -Xnojit -version
openjdk version "11.0.20-internal" 2023-07-18
OpenJDK Runtime Environment (build 11.0.20-internal+0-adhoc..BuildJDK11x86-64linuxNightly)
Eclipse OpenJ9 VM (build master-3dddeec, JRE 11 Linux amd64-64-Bit Compressed References 20230805_609 (JIT disabled, AOT enabled)
OpenJ9   - 3dddeec
OMR      - 43a2b1d
JCL      - fd11223 based on jdk-11.0.20+8)
knn-k commented 1 year ago

The message was introduced by PR #17260.

dsouzai commented 1 year ago

Hm I'll need to think about this. The reason you're seeing that message is because -Xnojit disables CH Table Optimizations, which causes a header mismatch.

Now, -Xnojit should allow AOT loads since that's been the existing behaviour, but at the same time, disabling CHTable Opts was the main guess for the cause of https://github.com/eclipse-openj9/openj9/issues/17250. For example, we create this runtime assumption during relocation when we have an Inlined Virtual Method https://github.com/eclipse-openj9/openj9/blob/b03193f9bd4ecc031240f8e5c9ff459095a9eb16/runtime/compiler/runtime/RelocationRecord.cpp#L3039

but we only compensate the assumption if CHTable opts are enabled https://github.com/eclipse-openj9/openj9/blob/b03193f9bd4ecc031240f8e5c9ff459095a9eb16/runtime/compiler/control/HookedByTheJit.cpp#L2758-L2764

There's probably a few different solutions here, but some that I can think of right now are:

  1. Enable CHTable Opts for -Xnojit
  2. Find all the places we compensate assumptions, and allow them to run even if CHTable Opts are disabled
  3. If during relocation we try to create any assumptions but CHTable Opts are disabled, then fail the load

1 is obviously the easiest solution, but I'm not sure what the implications of it are. 2 is probably the right way of going about it but it can be error prone if we miss a code path and is not future proof. 3 is also a very simple solution since there are a very small set of places we create assumptions at load, but it will likely result in a large number of AOT load failures.

@mpirvu @vijaysun-omr @mstoodle what do you guys think?

mpirvu commented 1 year ago

I think that (1) is the right solution. The main purpose of -Xnojit was (I presume) to eliminate the overhead of JIT compilations, whereas AOT load are cheap enough to be allowed. I cannot think of any technical impediment to prevent CHTable optimizations in -Xnojit case and I don't think that -Xnojit with CHTable is going to make the overhead of AOT loads unbearably expensive.

mstoodle commented 1 year ago

I agree with @mpirvu, although it could be tweaked to only keep CHTable Opts if AOT loads are possible (i.e. connected to a shared cache or any other conditions under which AOT loads could happen in future).

knn-k commented 10 months ago

Any plan to fix this? Thanks.

dsouzai commented 10 months ago

Sorry, this must've flown under the radar; I'll take a look at this probably next week or so.