Skip to content

Commit

Permalink
Do not use Unsafe on Java 22+
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Dec 3, 2024
1 parent af438b1 commit ac3fcd9
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 8 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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 ]
Expand All @@ -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'

Expand All @@ -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}}
Empty file added annotation/build-test-java21
Empty file.
Empty file added classloader/build-test-java21
Empty file.
Empty file added constraint/build-test-java21
Empty file.
Empty file added cpu/build-test-java21
Empty file.
13 changes: 13 additions & 0 deletions cpu/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<executions>
<execution>
<id>sort-imports-java22</id>
<goals>
<goal>sort</goal>
</goals>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
5 changes: 1 addition & 4 deletions cpu/src/main/java/io/smallrye/common/cpu/CPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import sun.misc.Unsafe;

/**
* Enumerated type for CPU types.
*/
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions cpu/src/main/java/io/smallrye/common/cpu/JDK22Specific.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.smallrye.common.cpu;

import sun.misc.Unsafe;

final class JDK22Specific {
static final int ADDRESS_SIZE = Unsafe.ADDRESS_SIZE;
}
7 changes: 7 additions & 0 deletions cpu/src/main/java22/io/smallrye/common/cpu/JDK22Specific.java
Original file line number Diff line number Diff line change
@@ -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();
}
3 changes: 3 additions & 0 deletions cpu/src/main/java22/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module io.smallrye.common.cpu {
exports io.smallrye.common.cpu;
}
Empty file added expression/build-test-java21
Empty file.
Empty file added function/build-test-java21
Empty file.
Empty file added io/build-test-java21
Empty file.
Empty file added net/build-test-java21
Empty file.
Empty file added os/build-test-java21
Empty file.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<rules>
<requireJavaVersion>
<version>22</version>
</requireJavaVersion>
</rules>
</configuration>
</plugin>
<plugin>
<groupId>io.sundr</groupId>
<artifactId>sundr-maven-plugin</artifactId>
Expand Down
Empty file added ref/build-test-java21
Empty file.
Empty file added version/build-test-java21
Empty file.
Empty file added vertx-context/build-test-java21
Empty file.

0 comments on commit ac3fcd9

Please sign in to comment.