Set the hashtable loadfactor to 1 rather than 2.
authorNot Zed <notzed@gmail.com>
Sun, 26 Jan 2020 07:40:40 +0000 (18:10 +1030)
committerNot Zed <notzed@gmail.com>
Sun, 26 Jan 2020 07:40:40 +0000 (18:10 +1030)
Added some debug code to try to flush everything unreachable
or manually retired.

src/notzed.zcl/classes/api/Native.java

index 4260da2..db0dfbe 100644 (file)
@@ -866,6 +866,27 @@ public class Native {
                }
        }
 
+       public static void debugFlushAll() {
+               for (int i=0;i<3;i++) {
+                       try {
+                               System.gc();
+                               Thread.sleep(100);
+                       } catch (InterruptedException x) {
+                       }
+                       CHandle stale = (CHandle) references.poll();
+                       while (stale != null) {
+                               try {
+                                       synchronized (map) {
+                                               map.remove(stale.p);
+                                       }
+                                       stale.release();
+                               } catch (Throwable ex) {
+                               }
+                               stale = (CHandle) references.poll();
+                       }
+               }
+       }
+
        public static void debugDumpReachable(String title) {
                synchronized (map) {
                        System.out.println(title);
@@ -933,7 +954,7 @@ public class Native {
                }
 
                public void putAlways(CHandle h) {
-                       if (size > table.length * 2)
+                       if (size > table.length)
                                resize(table.length * 2);
 
                        int i = h.hashCode() & mask;