reactor/BlockHound

Using JDK 18 or greater makes the JVM log an issue while loading `Unsafe.park`

Closed this issue · 1 comments

Expected Behavior

No JVM logs are printed that would indicate an issue with loading method Unsafe.park.

Actual Behavior

The following log statement is printed:

Method [jdk.internal.misc.Unsafe.park(ZJ)V] is annotated with @IntrinsicCandidate, but no compiler intrinsic is defined for the method.

Steps to Reproduce

When simply executing BlockHound.install() (even without passing an integration), the log statement is printed when running JDK 18 or greater. When evaluating the loaded Unsafe class' park methods with a debugger it shows the following information:

Unsafe.class.getDeclaredMethod("$$BlockHound$$_park", boolean.class, long.class)
   private final native void jdk.internal.misc.Unsafe.$$BlockHound$$_park(boolean,long)
Unsafe.class.getDeclaredMethod("$$BlockHound$$_park", boolean.class, long.class).getAnnotations()
   []

Unsafe.class.getDeclaredMethod("park", boolean.class, long.class)
  public void jdk.internal.misc.Unsafe.park(boolean,long)
Unsafe.class.getDeclaredMethod("park", boolean.class, long.class).getAnnotations()
  [ @jdk.internal.vm.annotation.IntrinsicCandidate() ]

Possible Solution

We suspect the cause for the log statement to be this JDK change that makes matching for compiler instrinsic on the park method require the method to be marked native, where before the keyword was needed to be optionally present. In other words, before JDK 18, the compiler intrinsic would be executed for the instrumented public void park(boolean, long) whereas that is not the case as of JDK 18 anymore.

BlockHound has the Unsafe.park method instrumented using ByteBuddy in NativeWrappingClassFileTransformer. The presence of the IntrinsicCandidate on the non-native park method causes the log statement.

Your Environment

Dependencies:

  • BlockHound: 1.0.8.RELEASE
  • Reactor BOM: 2023.0.2
  • ByteBuddy Parent: 1.14.11

JVM version (java -version):

openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode, sharing)

OS and version (eg uname -a):

Linux PDSoels-Latitude-5421 5.15.0-91-generic #101~20.04.1-Ubuntu SMP Thu Nov 16 14:22:28 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Tested with JDKs 18.0.2.1+1 (Temurin) and 21.0.2+13 (Temurin & Zulu).

@Badbond ;

thanks for your analysis.

I have attempted to do a candidate PR, see #393, can you please git it a try ?
I need to think more this week about the PR, but that would be nice if you could test it ?

to build the PR, use java8, and do:

./gradlew --no-daemon -Pversion=1.0.9.BUILD-SNAPSHOT publishToMavenLocal

Then you can validate using the 1.0.9.BUILD-SNAPSHOT located in your M2 local repo.

thanks !