From b5587ea346c08c14f68e9e803b3e8ae441d66e83 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 +++++---- 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 +++ pom.xml | 12 ++++++++++++ 8 files changed, 48 insertions(+), 8 deletions(-) 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 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/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/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