You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2022/07/01 16:20:31 UTC

[activemq-artemis-native] 03/03: Removing finalize calls, using Java11, Using Cleaner API in some tests that are validating leaks

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis-native.git

commit 291b77ffc1af88f6cb5858a8a3af0fa8ceebecad
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Fri Jul 1 11:39:12 2022 -0400

    Removing finalize calls, using Java11, Using Cleaner API in some tests that are validating leaks
---
 pom.xml                                               | 17 +++--------------
 .../artemis/nativo/jlibaio/LibaioContext.java         |  5 -----
 .../artemis/nativo/jlibaio/test/LibaioTest.java       | 19 ++++++++++++++-----
 3 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/pom.xml b/pom.xml
index 16b4602..4d4a6de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,8 +50,8 @@
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 
         <!-- See also maven.compiler.release in the java9on profile -->
-        <maven.compiler.source>1.8</maven.compiler.source>
-        <maven.compiler.target>1.8</maven.compiler.target>
+        <maven.compiler.source>11</maven.compiler.source>
+        <maven.compiler.target>11</maven.compiler.target>
 
         <activemq-surefire-argline>
             -Dtest.stress.time=${test.stress.time} -Djava.library.path="${activemq.basedir}/target/lib/linux-${os.arch}"
@@ -222,15 +222,6 @@
                 </plugins>
             </build>
         </profile>
-        <profile>
-            <id>java9on</id>
-            <activation>
-                <jdk>[9,)</jdk>
-            </activation>
-            <properties>
-                <maven.compiler.release>8</maven.compiler.release>
-            </properties>
-        </profile>
     </profiles>
 
     <build>
@@ -368,9 +359,6 @@
             </resource>
         </resources>
         <plugins>
-            <plugin>
-                <artifactId>maven-source-plugin</artifactId>
-            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-help-plugin</artifactId>
@@ -516,6 +504,7 @@
                     </execution>
                 </executions>
             </plugin>
+
         </plugins>
     </build>
 
diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java
index bdde812..fe90410 100644
--- a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java
+++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java
@@ -255,11 +255,6 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
       }
    }
 
-   @Override
-   protected void finalize() throws Throwable { //TODO: remove?
-      super.finalize();
-      close();
-   }
 
    /**
     * It will open a file. If you set the direct flag = false then you won't need to use the special buffer.
diff --git a/src/test/java/org/apache/activemq/artemis/nativo/jlibaio/test/LibaioTest.java b/src/test/java/org/apache/activemq/artemis/nativo/jlibaio/test/LibaioTest.java
index 074597f..ec8b73d 100644
--- a/src/test/java/org/apache/activemq/artemis/nativo/jlibaio/test/LibaioTest.java
+++ b/src/test/java/org/apache/activemq/artemis/nativo/jlibaio/test/LibaioTest.java
@@ -20,6 +20,7 @@ package org.apache.activemq.artemis.nativo.jlibaio.test;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.lang.ref.Cleaner;
 import java.lang.ref.WeakReference;
 import java.nio.ByteBuffer;
 import java.util.concurrent.CountDownLatch;
@@ -703,13 +704,19 @@ public class LibaioTest {
 
    static class TestInfo implements SubmitInfo {
 
-      static AtomicInteger count = new AtomicInteger();
+      static final Cleaner cleaner;
 
-      @Override
-      protected void finalize() throws Throwable {
-         super.finalize();
-         count.decrementAndGet();
+      static {
+         Cleaner tempCleaner;
+         try {
+            tempCleaner = Cleaner.create();
+         } catch (Throwable e) {
+            e.printStackTrace();
+            tempCleaner = null;
+         }
+         cleaner = tempCleaner;
       }
+      static AtomicInteger count = new AtomicInteger();
 
       public static void checkLeaks() throws InterruptedException {
          for (int i = 0; count.get() != 0 && i < 50; i++) {
@@ -728,6 +735,8 @@ public class LibaioTest {
 
       TestInfo() {
          count.incrementAndGet();
+         cleaner.register(this, count::decrementAndGet);
+
       }
 
       @Override