Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use Unsafe on Java 22+ #381

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
2 changes: 1 addition & 1 deletion cpu/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module smallrye.common.cpu {
module io.smallrye.common.cpu {
requires jdk.unsupported;

exports io.smallrye.common.cpu;
Expand Down
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.
Loading