You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2025/08/07 22:35:39 UTC

[PR] use better byte buffer cleaner [pekko]

pjfanning opened a new pull request, #2020:
URL: https://github.com/apache/pekko/pull/2020

   * see #2019 
   * the existing cleaner code will not work in Java 9+
   * this new code copied from commons-io will mean that the cleaner works in all Java versions
   * the support it needs in sun.misc.Unsafe is deprecated in Java 23 but still exists and should work
   * worst case scenario is that Java 23+ users who don't allow sun.misc.Unsafe to work will not get the Cleaner to proactively clean the byte buffers and will need to rely on the Garbage Collector
   * I would like to backport this to Pekko 1.2.0


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2272073635


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // copied from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws ReflectiveOperationException;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws ReflectiveOperationException {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final Object theUnsafe;
+    private final Method invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      theUnsafe = field.get(null);
+      invokeCleaner = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);

Review Comment:
   ```java
   MethodHandles.Lookup lookup = MethodHandles.lookup();
   MethodHandle invokeCleaner = lookup.findVirtual(
   unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class));
   invokeCleaner = invokeCleaner.bindTo(PlatformDependent0.UNSAFE);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2262217125


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // copied from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws ReflectiveOperationException;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws ReflectiveOperationException {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final Object theUnsafe;
+    private final Method invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      theUnsafe = field.get(null);
+      invokeCleaner = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);

Review Comment:
   * I didn't write this code - I copied it from commons-io.
   * the old reflection methods are not deprecated
   * this code is called once in lifetime of the JVM



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #2020:
URL: https://github.com/apache/pekko/pull/2020#issuecomment-3167367752

   > > the existing code for cleaning byte buffers only supports Java 8 and doesn't use sun.misc.Unsafe - sun.misc.Unsafe only added this support in Java 9 (the support that was deprecated in Java 23)
   > 
   > Right so this is what I am wary of, because if I understand correctly we may have a case where this code fails to work in Java 23+ (due to `sun.misc.unsafe` being deprecated) unless the user supplies a flag to JVM instance in order to allow calling of deprecated methods.
   
   The code ignores exceptions - old version and new version. If you don't allow access to sun.misc.Unsafe, code will still work.
   The new code even remembers that it failed so it won't keep trying sun.misc.Unsafe.
   We can add documentation to warn users that they may need to set `--sun-misc-unsafe-memory-access=allow`. I'm not sure if that java flag is needed for the Cleaner support in sun.misc.Unsafe or if that flag is more about the memory access functions like the field offset ones.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "mdedetrich (via GitHub)" <gi...@apache.org>.
mdedetrich commented on PR #2020:
URL: https://github.com/apache/pekko/pull/2020#issuecomment-3167211990

   > the existing code for cleaning byte buffers only supports Java 8 and doesn't use sun.misc.Unsafe - sun.misc.Unsafe only added this support in Java 9 (the support that was deprecated in Java 23)
   
   Right so this is what I am wary of, because if I understand correctly we may have a case where this code fails to work in Java 23+ (due to `sun.misc.unsafe` being deprecated) unless the user supplies a JVM flag to allow calling of deprecated methods.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2273285822


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+import static java.lang.invoke.MethodType.methodType;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // adapted from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws Throwable;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws Throwable {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final MethodHandle invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {

Review Comment:
   SecurityException seems will be removed , how about just an Exception



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2261636715


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByeBuffers don't put pressure on the

Review Comment:
   There's a typo in 'ByeBuffers' - it should be 'ByteBuffers'.
   ```suggestion
    * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
   ```



##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByeBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // copied from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws ReflectiveOperationException;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws ReflectiveOperationException {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final Object theUnsafe;
+    private final Method invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      theUnsafe = field.get(null);
+      invokeCleaner = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws ReflectiveOperationException {
+      invokeCleaner.invoke(theUnsafe, buffer);
+    }
+  }
+
+  private static final Cleaner INSTANCE = getCleaner();
+
+  /**
+   * Releases memory held by the given {@link ByteBuffer}.
+   *
+   * @param buffer to release.
+   * @throws IllegalStateException on internal failure.
+   */
+  static void clean(final ByteBuffer buffer) {
+    try {
+      INSTANCE.clean(buffer);
+    } catch (final Exception e) {
+      throw new IllegalStateException("Failed to clean direct buffer.", e);
+    }
+  }
+
+  private static Cleaner getCleaner() {
+    try {
+      return new Java8Cleaner();
+    } catch (final Exception e) {
+      try {
+        return new Java9Cleaner();
+      } catch (final Exception e1) {
+        throw new IllegalStateException("Failed to initialize a Cleaner.", e);

Review Comment:
   The exception chaining is incorrect - when Java9Cleaner fails to initialize, the original Java8Cleaner exception 'e' is thrown instead of the more recent Java9Cleaner exception 'e1'. This could make debugging more difficult as it hides the actual failure reason.
   ```suggestion
           e1.addSuppressed(e);
           throw new IllegalStateException("Failed to initialize a Cleaner.", e1);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2273309092


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+import static java.lang.invoke.MethodType.methodType;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // adapted from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws Throwable;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws Throwable {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final MethodHandle invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      final Object theUnsafe = field.get(null);
+      MethodHandles.Lookup lookup = MethodHandles.lookup();
+      MethodHandle invokeCleaner =
+          lookup.findVirtual(
+              unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class));
+      this.invokeCleaner = invokeCleaner.bindTo(theUnsafe);
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws Throwable {
+      invokeCleaner.invokeExact(buffer);
+    }
+  }
+
+  private static final Cleaner INSTANCE = getCleaner();
+
+  /**
+   * Releases memory held by the given {@link ByteBuffer}.
+   *
+   * @param buffer to release.
+   * @throws IllegalStateException on internal failure.
+   */
+  static void clean(final ByteBuffer buffer) {
+    try {
+      INSTANCE.clean(buffer);
+    } catch (final Throwable t) {
+      throw new IllegalStateException("Failed to clean direct buffer.", t);

Review Comment:
   It isn't an unsupported exception if it gets here - INSTANCE is null if it is unsupported. I check for this at runtime.
   This is not a public API. It is not even a public class. It only needs to suit the way that I use it internally.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2262129132


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // copied from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws ReflectiveOperationException;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws ReflectiveOperationException {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final Object theUnsafe;
+    private final Method invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      theUnsafe = field.get(null);
+      invokeCleaner = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);

Review Comment:
   use method handle



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #2020:
URL: https://github.com/apache/pekko/pull/2020#issuecomment-3167425299

   I've added the documentation bit to https://github.com/apache/pekko/issues/1840


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #2020:
URL: https://github.com/apache/pekko/pull/2020


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #2020:
URL: https://github.com/apache/pekko/pull/2020#issuecomment-3166917348

   > @pjfanning The ForkjoinPool related thing should be updated too.
   
   the fokjoinpool code was already rewritten and no longer uses reflection or method handles


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2273292027


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+import static java.lang.invoke.MethodType.methodType;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // adapted from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws Throwable;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws Throwable {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final MethodHandle invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      final Object theUnsafe = field.get(null);
+      MethodHandles.Lookup lookup = MethodHandles.lookup();
+      MethodHandle invokeCleaner =
+          lookup.findVirtual(
+              unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class));
+      this.invokeCleaner = invokeCleaner.bindTo(theUnsafe);

Review Comment:
   In Netty, there is an buffer(1) and try to clean it ,but seems we don;t have it here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2273303007


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+import static java.lang.invoke.MethodType.methodType;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // adapted from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws Throwable;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws Throwable {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final MethodHandle invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      final Object theUnsafe = field.get(null);
+      MethodHandles.Lookup lookup = MethodHandles.lookup();
+      MethodHandle invokeCleaner =
+          lookup.findVirtual(
+              unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class));
+      this.invokeCleaner = invokeCleaner.bindTo(theUnsafe);

Review Comment:
   the code is not a copy of netty - it is copied from the Apache project, commons-io



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2272072002


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // copied from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws ReflectiveOperationException;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws ReflectiveOperationException {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final Object theUnsafe;
+    private final Method invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      theUnsafe = field.get(null);
+      invokeCleaner = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);

Review Comment:
   It was using reflection too in Netty's CleanerJava9, but in 4.2, it's now using method handle, method handle is a litter faster.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2273328172


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+import static java.lang.invoke.MethodType.methodType;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // adapted from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws Throwable;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws Throwable {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final MethodHandle invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      final Object theUnsafe = field.get(null);
+      MethodHandles.Lookup lookup = MethodHandles.lookup();
+      MethodHandle invokeCleaner =
+          lookup.findVirtual(
+              unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class));
+      this.invokeCleaner = invokeCleaner.bindTo(theUnsafe);

Review Comment:
   so we can't adjust it?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2273948959


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+import static java.lang.invoke.MethodType.methodType;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // adapted from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws Throwable;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws Throwable {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final MethodHandle invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      final Object theUnsafe = field.get(null);
+      MethodHandles.Lookup lookup = MethodHandles.lookup();
+      MethodHandle invokeCleaner =
+          lookup.findVirtual(
+              unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class));
+      this.invokeCleaner = invokeCleaner.bindTo(theUnsafe);

Review Comment:
   I've added the initialisation time check that you requested



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2274301216


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -104,15 +104,33 @@ static void clean(final ByteBuffer buffer) {
   }
 
   private static Cleaner getCleaner() {
+    Cleaner cleaner = null;
     try {
-      return new Java8Cleaner();
+      cleaner = new Java8Cleaner();
     } catch (final Exception e) {
       try {
-        return new Java9Cleaner();
+        cleaner = new Java9Cleaner();
       } catch (final Exception e1) {
-        throw new IllegalStateException("Failed to initialize a Cleaner.", e);
+        System.err.println(
+            "WARNING: Failed to initialize a ByteBuffer Cleaner. This means "
+                + "direct ByteBuffers will only be cleaned upon garbage collection. Reason: "
+                + e1);
       }
     }
+    if (cleaner != null) {
+      try {
+        ByteBuffer testByteBuffer = ByteBuffer.allocateDirect(1);
+        cleaner.clean(testByteBuffer);

Review Comment:
   nice!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2262223750


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // copied from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws ReflectiveOperationException;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws ReflectiveOperationException {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final Object theUnsafe;
+    private final Method invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      theUnsafe = field.get(null);
+      invokeCleaner = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);

Review Comment:
   importantly, I intend to backport this code to 1.2.0 because it is a bug fix - so I need the code to work with Java 8



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #2020:
URL: https://github.com/apache/pekko/pull/2020#issuecomment-3166814255

   @pjfanning The ForkjoinPool related thing should be updated too.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "mdedetrich (via GitHub)" <gi...@apache.org>.
mdedetrich commented on PR #2020:
URL: https://github.com/apache/pekko/pull/2020#issuecomment-3166998131

   > * the support it needs in sun.misc.Unsafe is deprecated in Java 23 but still exists and should work
   
   To clarify, this is also the case for the current state of affairs right?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2261639079


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByeBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // copied from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws ReflectiveOperationException;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws ReflectiveOperationException {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final Object theUnsafe;
+    private final Method invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      theUnsafe = field.get(null);
+      invokeCleaner = unsafeClass.getMethod("invokeCleaner", ByteBuffer.class);
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws ReflectiveOperationException {
+      invokeCleaner.invoke(theUnsafe, buffer);
+    }
+  }
+
+  private static final Cleaner INSTANCE = getCleaner();
+
+  /**
+   * Releases memory held by the given {@link ByteBuffer}.
+   *
+   * @param buffer to release.
+   * @throws IllegalStateException on internal failure.
+   */
+  static void clean(final ByteBuffer buffer) {
+    try {
+      INSTANCE.clean(buffer);
+    } catch (final Exception e) {
+      throw new IllegalStateException("Failed to clean direct buffer.", e);
+    }
+  }
+
+  private static Cleaner getCleaner() {
+    try {
+      return new Java8Cleaner();
+    } catch (final Exception e) {
+      try {
+        return new Java9Cleaner();
+      } catch (final Exception e1) {
+        throw new IllegalStateException("Failed to initialize a Cleaner.", e);

Review Comment:
   this is from the commons-io code and in the end, we ignore the exception anyway



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #2020:
URL: https://github.com/apache/pekko/pull/2020#issuecomment-3167020860

   > > * the support it needs in sun.misc.Unsafe is deprecated in Java 23 but still exists and should work
   > 
   > To clarify, this is also the case for the current state of affairs right?
   
   * the existing code for cleaning byte buffers only supports Java 8 and doesn't use sun.misc.Unsafe - sun.misc.Unsafe only added this support in Java 9 (the support that was deprecated in Java 23)
   * the other Pekko code that uses sun.misc.Unsafe has all been removed in main branch
       * some of those usages were mandatory (ie the Pekko code used sun.misc.Unsafe and if it failed then Pekko failed
       * this usage and some of the old usages are optional - if it fails, Pekko will carry on with a less optimal solution


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] use better byte buffer cleaner [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #2020:
URL: https://github.com/apache/pekko/pull/2020#discussion_r2273293415


##########
actor/src/main/java/org/apache/pekko/io/ByteBufferCleaner.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.pekko.io;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+
+import static java.lang.invoke.MethodType.methodType;
+
+/**
+ * Cleans a direct {@link ByteBuffer}. Without manual intervention, direct ByteBuffers will be
+ * cleaned eventually upon garbage collection. However, this should not be relied upon since it may
+ * not occur in a timely fashion - especially since off heap ByteBuffers don't put pressure on the
+ * garbage collector.
+ *
+ * <p><strong>Warning:</strong> Do not attempt to use a direct {@link ByteBuffer} that has been
+ * cleaned or bad things will happen. Don't use this class unless you can ensure that the cleaned
+ * buffer will not be accessed anymore.
+ *
+ * <p>See <a href=https://bugs.openjdk.java.net/browse/JDK-4724038>JDK-4724038</a>
+ */
+final class ByteBufferCleaner {
+
+  // adapted from
+  // https://github.com/apache/commons-io/blob/441115a4b5cd63ae808dd4c40fc238cb52c8048f/src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java
+
+  private interface Cleaner {
+    void clean(ByteBuffer buffer) throws Throwable;
+  }
+
+  private static final class Java8Cleaner implements Cleaner {
+
+    private final Method cleanerMethod;
+    private final Method cleanMethod;
+
+    private Java8Cleaner() throws ReflectiveOperationException, SecurityException {
+      cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
+      cleanerMethod = Class.forName("sun.nio.ch.DirectBuffer").getMethod("cleaner");
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws Throwable {
+      final Object cleaner = cleanerMethod.invoke(buffer);
+      if (cleaner != null) {
+        cleanMethod.invoke(cleaner);
+      }
+    }
+  }
+
+  private static final class Java9Cleaner implements Cleaner {
+
+    private final MethodHandle invokeCleaner;
+
+    private Java9Cleaner() throws ReflectiveOperationException, SecurityException {
+      final Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
+      final Field field = unsafeClass.getDeclaredField("theUnsafe");
+      field.setAccessible(true);
+      final Object theUnsafe = field.get(null);
+      MethodHandles.Lookup lookup = MethodHandles.lookup();
+      MethodHandle invokeCleaner =
+          lookup.findVirtual(
+              unsafeClass, "invokeCleaner", methodType(void.class, ByteBuffer.class));
+      this.invokeCleaner = invokeCleaner.bindTo(theUnsafe);
+    }
+
+    @Override
+    public void clean(final ByteBuffer buffer) throws Throwable {
+      invokeCleaner.invokeExact(buffer);
+    }
+  }
+
+  private static final Cleaner INSTANCE = getCleaner();
+
+  /**
+   * Releases memory held by the given {@link ByteBuffer}.
+   *
+   * @param buffer to release.
+   * @throws IllegalStateException on internal failure.
+   */
+  static void clean(final ByteBuffer buffer) {
+    try {
+      INSTANCE.clean(buffer);
+    } catch (final Throwable t) {
+      throw new IllegalStateException("Failed to clean direct buffer.", t);

Review Comment:
   UnsupportedOperationException



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org