This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new b0bf1923a7 remove Unsafe.isIsJavaVersion9Plus (#1993)
b0bf1923a7 is described below
commit b0bf1923a7c0072e4a46db286b74b35c9a33d889
Author: PJ Fanning <[email protected]>
AuthorDate: Sat Aug 2 09:26:53 2025 +0100
remove Unsafe.isIsJavaVersion9Plus (#1993)
* remove Unsafe.isIsJavaVersion9Plus
* Update Unsafe.java
* Update Unsafe.java
---
.../org/apache/pekko/util/AsciiStringCopySpec.scala | 16 +++++-----------
actor/src/main/java/org/apache/pekko/util/Unsafe.java | 18 +-----------------
2 files changed, 6 insertions(+), 28 deletions(-)
diff --git
a/actor-tests/src/test/scala/org/apache/pekko/util/AsciiStringCopySpec.scala
b/actor-tests/src/test/scala/org/apache/pekko/util/AsciiStringCopySpec.scala
index 3c89cee8df..857a0f8ef5 100644
--- a/actor-tests/src/test/scala/org/apache/pekko/util/AsciiStringCopySpec.scala
+++ b/actor-tests/src/test/scala/org/apache/pekko/util/AsciiStringCopySpec.scala
@@ -22,17 +22,11 @@ class AsciiStringCopySpec extends AnyWordSpec with Matchers
{
"The copyUSAsciiStrToBytes optimization" must {
"select working algorithm" in {
- if (Unsafe.isIsJavaVersion9Plus) {
- Unsafe.testUSAsciiStrToBytesAlgorithm0("abc") should ===(true)
- // this is known to fail with JDK 11 on ARM32 (Raspberry Pi),
- // and therefore algorithm 0 is selected on that architecture
- Unsafe.testUSAsciiStrToBytesAlgorithm1("abc") should ===(true)
- Unsafe.testUSAsciiStrToBytesAlgorithm2("abc") should ===(false)
- } else {
- Unsafe.testUSAsciiStrToBytesAlgorithm0("abc") should ===(true)
- Unsafe.testUSAsciiStrToBytesAlgorithm1("abc") should ===(false)
- Unsafe.testUSAsciiStrToBytesAlgorithm2("abc") should ===(true)
- }
+ Unsafe.testUSAsciiStrToBytesAlgorithm0("abc") should ===(true)
+ // this is known to fail with JDK 11 on ARM32 (Raspberry Pi),
+ // and therefore algorithm 0 is selected on that architecture
+ Unsafe.testUSAsciiStrToBytesAlgorithm1("abc") should ===(true)
+ Unsafe.testUSAsciiStrToBytesAlgorithm2("abc") should ===(false)
}
"copy string internal representation successfully" in {
diff --git a/actor/src/main/java/org/apache/pekko/util/Unsafe.java
b/actor/src/main/java/org/apache/pekko/util/Unsafe.java
index c26ea4d9da..faaf820d3c 100644
--- a/actor/src/main/java/org/apache/pekko/util/Unsafe.java
+++ b/actor/src/main/java/org/apache/pekko/util/Unsafe.java
@@ -17,7 +17,6 @@ import org.apache.pekko.annotation.InternalApi;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
/** INTERNAL API */
@InternalApi
@@ -25,7 +24,6 @@ public final class Unsafe {
public static final sun.misc.Unsafe instance;
private static final long stringValueFieldOffset;
- private static final boolean isJavaVersion9Plus;
private static final int copyUSAsciiStrToBytesAlgorithm;
static {
@@ -51,15 +49,12 @@ public final class Unsafe {
}
stringValueFieldOffset = fo;
- isJavaVersion9Plus = isIsJavaVersion9Plus();
-
if (stringValueFieldOffset > -1) {
// Select optimization algorithm for `copyUSAciiBytesToStr`.
// For example algorithm 1 will fail with JDK 11 on ARM32 (Raspberry
Pi),
// and therefore algorithm 0 is selected on that architecture.
String testStr = "abc";
- if (isJavaVersion9Plus && testUSAsciiStrToBytesAlgorithm1(testStr))
- copyUSAsciiStrToBytesAlgorithm = 1;
+ if (testUSAsciiStrToBytesAlgorithm1(testStr))
copyUSAsciiStrToBytesAlgorithm = 1;
else if (testUSAsciiStrToBytesAlgorithm2(testStr))
copyUSAsciiStrToBytesAlgorithm = 2;
else copyUSAsciiStrToBytesAlgorithm = 0;
} else
@@ -71,17 +66,6 @@ public final class Unsafe {
}
}
- static boolean isIsJavaVersion9Plus() {
- // See Oracle section 1.5.3 at:
- //
https://docs.oracle.com/javase/8/docs/technotes/guides/versioning/spec/versioning2.html
- final int[] version =
-
Arrays.stream(System.getProperty("java.specification.version").split("\\."))
- .mapToInt(Integer::parseInt)
- .toArray();
- final int javaVersion = version[0] == 1 ? version[1] : version[0];
- return javaVersion > 8;
- }
-
static boolean testUSAsciiStrToBytesAlgorithm0(String str) {
try {
byte[] bytes = new byte[str.length()];
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]