This is an automated email from the ASF dual-hosted git repository.
nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 53fe8a5dd7f IGNITE-25680 Refactor DirectBufferCleaner interface
(#12172)
53fe8a5dd7f is described below
commit 53fe8a5dd7fe80fbbc17ea419f5007f94c690544
Author: Maksim Davydov <[email protected]>
AuthorDate: Tue Aug 5 13:43:15 2025 +0300
IGNITE-25680 Refactor DirectBufferCleaner interface (#12172)
---
.../util/ReflectiveDirectBufferCleaner.java | 64 ----------------------
.../ignite/internal/util/DirectBufferCleaner.java | 32 -----------
.../ignite/internal/util/FeatureChecker.java | 2 +-
.../apache/ignite/internal/util/GridUnsafe.java | 2 +-
.../internal/util/UnsafeDirectBufferCleaner.java | 14 +++--
5 files changed, 10 insertions(+), 104 deletions(-)
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/util/ReflectiveDirectBufferCleaner.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/ReflectiveDirectBufferCleaner.java
deleted file mode 100644
index 00ac787f2bf..00000000000
---
a/modules/core/src/main/java/org/apache/ignite/internal/util/ReflectiveDirectBufferCleaner.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.util;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.ByteBuffer;
-
-/**
- * {@link DirectBufferCleaner} implementation based on {@code
sun.misc.Cleaner} and
- * {@code sun.nio.ch.DirectBuffer.cleaner()} method.
- *
- * Mote: This implementation will not work on Java 9+.
- */
-public class ReflectiveDirectBufferCleaner implements DirectBufferCleaner {
- /** Cleaner method. */
- private final Method cleanerMtd;
-
- /** Clean method. */
- private final Method cleanMtd;
-
- /** */
- public ReflectiveDirectBufferCleaner() {
- try {
- cleanerMtd =
Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
-
- }
- catch (ClassNotFoundException | NoSuchMethodException e) {
- throw new RuntimeException("No sun.nio.ch.DirectBuffer.cleaner()
method found", e);
- }
-
- try {
- cleanMtd = Class.forName("sun.misc.Cleaner").getMethod("clean");
- }
- catch (ClassNotFoundException | NoSuchMethodException e) {
- throw new RuntimeException("No sun.misc.Cleaner.clean() method
found", e);
- }
- }
-
- /** {@inheritDoc} */
- @Override public void clean(ByteBuffer buf) {
- try {
- cleanMtd.invoke(cleanerMtd.invoke(buf));
- }
- catch (IllegalAccessException | InvocationTargetException e) {
- throw new RuntimeException("Failed to invoke direct buffer
cleaner", e);
- }
- }
-}
diff --git
a/modules/unsafe/src/main/java/org/apache/ignite/internal/util/DirectBufferCleaner.java
b/modules/unsafe/src/main/java/org/apache/ignite/internal/util/DirectBufferCleaner.java
deleted file mode 100644
index 2608d8a4f1a..00000000000
---
a/modules/unsafe/src/main/java/org/apache/ignite/internal/util/DirectBufferCleaner.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.util;
-
-import java.nio.ByteBuffer;
-
-/**
- * Cleaner interface for {@code java.nio.ByteBuffer}.
- */
-public interface DirectBufferCleaner {
- /**
- * Cleans direct buffer.
- *
- * @param buf direct buffer.
- */
- public void clean(ByteBuffer buf);
-}
diff --git
a/modules/unsafe/src/main/java/org/apache/ignite/internal/util/FeatureChecker.java
b/modules/unsafe/src/main/java/org/apache/ignite/internal/util/FeatureChecker.java
index a5ec0a85d1b..1c8e9f784fe 100644
---
a/modules/unsafe/src/main/java/org/apache/ignite/internal/util/FeatureChecker.java
+++
b/modules/unsafe/src/main/java/org/apache/ignite/internal/util/FeatureChecker.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.util;
* Class extracted for fields from GridUnsafe to be absolutely independent
with current and future static block
* initialization effects.
*/
-public class FeatureChecker {
+class FeatureChecker {
/** Required Options to Run on Java 11. */
public static final String JAVA_11_OPTIONS =
"--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED\n" +
"--add-exports=java.base/sun.nio.ch=ALL-UNNAMED\n" +
diff --git
a/modules/unsafe/src/main/java/org/apache/ignite/internal/util/GridUnsafe.java
b/modules/unsafe/src/main/java/org/apache/ignite/internal/util/GridUnsafe.java
index 7b86f1a5eca..8b5a5adda7d 100644
---
a/modules/unsafe/src/main/java/org/apache/ignite/internal/util/GridUnsafe.java
+++
b/modules/unsafe/src/main/java/org/apache/ignite/internal/util/GridUnsafe.java
@@ -130,7 +130,7 @@ public abstract class GridUnsafe {
private static final boolean HAS_JAVA_NIO_ACCESS_MEMORY_SEGMENT_PARAM =
majorJavaVersion(jdkVersion()) >= 19;
/** Cleaner code for direct {@code java.nio.ByteBuffer}. */
- private static final DirectBufferCleaner DIRECT_BUF_CLEANER = new
UnsafeDirectBufferCleaner();
+ private static final UnsafeDirectBufferCleaner DIRECT_BUF_CLEANER = new
UnsafeDirectBufferCleaner();
/** JavaNioAccess object. If {@code null} then {@link
#NEW_DIRECT_BUF_CONSTRUCTOR} should be available. */
@Nullable private static final Object JAVA_NIO_ACCESS_OBJ;
diff --git
a/modules/unsafe/src/main/java/org/apache/ignite/internal/util/UnsafeDirectBufferCleaner.java
b/modules/unsafe/src/main/java/org/apache/ignite/internal/util/UnsafeDirectBufferCleaner.java
index 547f0925bf5..d76e38fcf9a 100644
---
a/modules/unsafe/src/main/java/org/apache/ignite/internal/util/UnsafeDirectBufferCleaner.java
+++
b/modules/unsafe/src/main/java/org/apache/ignite/internal/util/UnsafeDirectBufferCleaner.java
@@ -22,11 +22,9 @@ import java.nio.ByteBuffer;
import sun.misc.Unsafe;
/**
- * {@link DirectBufferCleaner} implementation based on {@code
Unsafe.invokeCleaner} method.
- *
- * Note: This implementation will work only for Java 9+.
+ * Cleaner for {@code java.nio.ByteBuffer} based on {@code
Unsafe.invokeCleaner} method.
*/
-public class UnsafeDirectBufferCleaner implements DirectBufferCleaner {
+class UnsafeDirectBufferCleaner {
/** Cleaner method. */
private final Method cleanerMtd;
@@ -40,8 +38,12 @@ public class UnsafeDirectBufferCleaner implements
DirectBufferCleaner {
}
}
- /** {@inheritDoc} */
- @Override public void clean(ByteBuffer buf) {
+ /**
+ * Cleans direct buffer.
+ *
+ * @param buf direct buffer.
+ */
+ public void clean(ByteBuffer buf) {
GridUnsafe.invoke(cleanerMtd, buf);
}
}