From ac3fcd9d38c8e2f2b982ace5d12715955ace57ba Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Sat, 30 Nov 2024 13:43:53 -0600 Subject: [PATCH] Do not use Unsafe on Java 22+ --- .github/workflows/build.yml | 9 +++++---- annotation/build-test-java21 | 0 classloader/build-test-java21 | 0 constraint/build-test-java21 | 0 cpu/build-test-java21 | 0 cpu/pom.xml | 13 +++++++++++++ cpu/src/main/java/io/smallrye/common/cpu/CPU.java | 5 +---- .../java/io/smallrye/common/cpu/JDK22Specific.java | 7 +++++++ .../io/smallrye/common/cpu/JDK22Specific.java | 7 +++++++ cpu/src/main/java22/module-info.java | 3 +++ expression/build-test-java21 | 0 function/build-test-java21 | 0 io/build-test-java21 | 0 net/build-test-java21 | 0 os/build-test-java21 | 0 pom.xml | 12 ++++++++++++ ref/build-test-java21 | 0 version/build-test-java21 | 0 vertx-context/build-test-java21 | 0 19 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 annotation/build-test-java21 create mode 100644 classloader/build-test-java21 create mode 100644 constraint/build-test-java21 create mode 100644 cpu/build-test-java21 create mode 100644 cpu/src/main/java/io/smallrye/common/cpu/JDK22Specific.java create mode 100644 cpu/src/main/java22/io/smallrye/common/cpu/JDK22Specific.java create mode 100644 cpu/src/main/java22/module-info.java create mode 100644 expression/build-test-java21 create mode 100644 function/build-test-java21 create mode 100644 io/build-test-java21 create mode 100644 net/build-test-java21 create mode 100644 os/build-test-java21 create mode 100644 ref/build-test-java21 create mode 100644 version/build-test-java21 create mode 100644 vertx-context/build-test-java21 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b3d52f00..456d31bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: SmallRye Build env: - MAVEN_VERSION: 3.8.3 + MAVEN_VERSION: 3.9.9 IO_TAKARI_MAVEN_WRAPPER_VERSION: 0.7.7 on: @@ -42,13 +42,14 @@ jobs: java-version: | 17 21 + 23 cache: 'maven' cache-dependency-path: '**/pom.xml' - name: build with maven run: | mvn -q -N "io.takari:maven:${{env.IO_TAKARI_MAVEN_WRAPPER_VERSION}}:wrapper" "-Dmaven=${{env.MAVEN_VERSION}}" - ./mvnw -B -ntp formatter:validate verify javadoc:javadoc --file pom.xml "-Dexpected-cpu=x64,aarch64" "-Djava17.home=${{env.JAVA_HOME_17_X64}}${{env.JAVA_HOME_17_ARM64}}" + ./mvnw -B -ntp formatter:validate verify javadoc:javadoc --file pom.xml "-Dexpected-cpu=x64,aarch64" "-Djava17.home=${{env.JAVA_HOME_17_X64}}${{env.JAVA_HOME_17_ARM64}}" "-Djava21.home=${{env.JAVA_HOME_21_X64}}${{env.JAVA_HOME_21_ARM64}}" quality: needs: [ build ] @@ -62,7 +63,7 @@ jobs: - uses: actions/setup-java@v4 with: distribution: temurin - java-version: 17 + java-version: 21 cache: 'maven' cache-dependency-path: '**/pom.xml' @@ -74,7 +75,7 @@ jobs: - uses: actions/setup-java@v4 with: distribution: 'temurin' - java-version: 17 + java-version: 21 - name: sonar run: ./mvnw -B -ntp sonar:sonar -Dsonar.projectKey=smallrye_smallrye-common -Dsonar.token=${{secrets.SONAR_TOKEN}} diff --git a/annotation/build-test-java21 b/annotation/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/classloader/build-test-java21 b/classloader/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/constraint/build-test-java21 b/constraint/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/cpu/build-test-java21 b/cpu/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/cpu/pom.xml b/cpu/pom.xml index 00d9ea3b..6c667feb 100644 --- a/cpu/pom.xml +++ b/cpu/pom.xml @@ -34,6 +34,19 @@ + + net.revelc.code + impsort-maven-plugin + + + sort-imports-java22 + + sort + + none + + + diff --git a/cpu/src/main/java/io/smallrye/common/cpu/CPU.java b/cpu/src/main/java/io/smallrye/common/cpu/CPU.java index 1fca2f17..8ccbd739 100644 --- a/cpu/src/main/java/io/smallrye/common/cpu/CPU.java +++ b/cpu/src/main/java/io/smallrye/common/cpu/CPU.java @@ -10,8 +10,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import sun.misc.Unsafe; - /** * Enumerated type for CPU types. */ @@ -185,8 +183,7 @@ public static CPU host() { private static CPU check(CPU cpu) { ByteOrder no = ByteOrder.nativeOrder(); - // todo: in 22+, bytes = (int) ValueLayout.ADDRESS.byteSize(); - int bytes = Unsafe.ADDRESS_SIZE; + int bytes = JDK22Specific.ADDRESS_SIZE; if (cpu.pointerSizeBytes() == bytes && cpu.nativeByteOrder() == no) { // OK return cpu; diff --git a/cpu/src/main/java/io/smallrye/common/cpu/JDK22Specific.java b/cpu/src/main/java/io/smallrye/common/cpu/JDK22Specific.java new file mode 100644 index 00000000..30a41ce3 --- /dev/null +++ b/cpu/src/main/java/io/smallrye/common/cpu/JDK22Specific.java @@ -0,0 +1,7 @@ +package io.smallrye.common.cpu; + +import sun.misc.Unsafe; + +final class JDK22Specific { + static final int ADDRESS_SIZE = Unsafe.ADDRESS_SIZE; +} diff --git a/cpu/src/main/java22/io/smallrye/common/cpu/JDK22Specific.java b/cpu/src/main/java22/io/smallrye/common/cpu/JDK22Specific.java new file mode 100644 index 00000000..3f28f715 --- /dev/null +++ b/cpu/src/main/java22/io/smallrye/common/cpu/JDK22Specific.java @@ -0,0 +1,7 @@ +package io.smallrye.common.cpu; + +import java.lang.foreign.ValueLayout; + +final class JDK22Specific { + static final int ADDRESS_SIZE = (int) ValueLayout.ADDRESS.byteSize(); +} diff --git a/cpu/src/main/java22/module-info.java b/cpu/src/main/java22/module-info.java new file mode 100644 index 00000000..2ac176de --- /dev/null +++ b/cpu/src/main/java22/module-info.java @@ -0,0 +1,3 @@ +module io.smallrye.common.cpu { + exports io.smallrye.common.cpu; +} \ No newline at end of file diff --git a/expression/build-test-java21 b/expression/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/function/build-test-java21 b/function/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/io/build-test-java21 b/io/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/net/build-test-java21 b/net/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/os/build-test-java21 b/os/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/pom.xml b/pom.xml index ad7cd85a..c662b0c0 100644 --- a/pom.xml +++ b/pom.xml @@ -169,6 +169,18 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + 3.5.0 + + + + 22 + + + + io.sundr sundr-maven-plugin diff --git a/ref/build-test-java21 b/ref/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/version/build-test-java21 b/version/build-test-java21 new file mode 100644 index 00000000..e69de29b diff --git a/vertx-context/build-test-java21 b/vertx-context/build-test-java21 new file mode 100644 index 00000000..e69de29b