You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Cleaner used multiple monitors to protect its datastructures. And
as datastructre a (manually) linked list was used. The datastructure
was updated to a ConcurrentHashMap and the multiple monitor usages are
replaced with a ReentrandReadWriteLocks.
Performance numbers:
Commandline:
java -jar target/benchmarks.jar -t 1000 -i 1 -wi 0
========== 5.14.0 ==========
Result "eu.doppelhelix.jna.jmh.MyBenchmark.testMethod":
1211666,184 ±(99.9%) 134595,856 ops/s [Average]
(min, avg, max) = (1178371,132, 1211666,184, 1271195,212), stdev = 34954,116
CI (99.9%): [1077070,328, 1346262,040] (assumes normal distribution)
Estimated CPU Load: 650%
========== 5.14.0 ==========
Result "eu.doppelhelix.jna.jmh.MyBenchmark.testMethod":
3260953,271 ±(99.9%) 655799,010 ops/s [Average]
(min, avg, max) = (3092006,068, 3260953,271, 3527896,224), stdev = 170308,920
CI (99.9%): [2605154,261, 3916752,281] (assumes normal distribution)
Estimated CPU Load: 1500%
============================
Code:
package eu.doppelhelix.jna.jmh;
import com.sun.jna.internal.Cleaner;
import java.util.concurrent.atomic.AtomicLong;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.infra.Blackhole;
public class MyBenchmark {
@benchmark
public void testMethod(Blackhole blackhole) {
DummyObject dummyObj = new DummyObject();
DummyObjectCleaner dummyCleaner = new DummyObjectCleaner(blackhole, dummyObj.getDummyValue());
Cleaner.getCleaner().register(dummyObj, dummyCleaner);
}
public static class DummyObject {
private static final AtomicLong ai = new AtomicLong();
private final String dummyValue;
public DummyObject() {
this.dummyValue = "d " + ai.incrementAndGet();
}
public String getDummyValue() {
return dummyValue;
}
}
public static class DummyObjectCleaner implements Runnable{
private final Blackhole bh;
private final String data;
public DummyObjectCleaner(Blackhole bh, String data) {
this.bh = bh;
this.data = data;
}
public void run() {
this.bh.consume(this.data);
}
}
}
0 commit comments