Mercurial > hg > gc-bench
changeset 79:e08d29090857
alloc.special.* cases
author | shade |
---|---|
date | Thu, 26 Oct 2017 12:02:48 +0200 |
parents | f69f4c3fa113 |
children | 7fa076c63a42 |
files | src/main/java/org/openjdk/gcbench/alloc/special/Finalizables.java src/main/java/org/openjdk/gcbench/alloc/special/PhantomRefs.java src/main/java/org/openjdk/gcbench/alloc/special/SoftRefs.java src/main/java/org/openjdk/gcbench/alloc/special/WeakRefs.java |
diffstat | 4 files changed, 128 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/openjdk/gcbench/alloc/special/Finalizables.java Thu Oct 26 12:02:48 2017 +0200 @@ -0,0 +1,26 @@ +package org.openjdk.gcbench.alloc.special; + +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; + +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Benchmark) +public class Finalizables { + + @Benchmark + public void test(Blackhole bh) { + bh.consume(new Finalizable()); + bh.consume(new byte[10000]); + } + + public static class Finalizable { + @Override + protected void finalize() throws Throwable { + super.finalize(); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/openjdk/gcbench/alloc/special/PhantomRefs.java Thu Oct 26 12:02:48 2017 +0200 @@ -0,0 +1,33 @@ +package org.openjdk.gcbench.alloc.special; + +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; + +import java.lang.ref.PhantomReference; +import java.lang.ref.ReferenceQueue; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Benchmark) +public class PhantomRefs { + + ReferenceQueue<Object> rq; + + @Setup + public void setup() { + rq = new ReferenceQueue<>(); + } + + public void drain() { + while (rq.poll() != null); // drain + } + + @Benchmark + public void test(Blackhole bh) { + drain(); + bh.consume(new PhantomReference<>(new Object(), rq)); + bh.consume(new byte[10000]); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/openjdk/gcbench/alloc/special/SoftRefs.java Thu Oct 26 12:02:48 2017 +0200 @@ -0,0 +1,34 @@ +package org.openjdk.gcbench.alloc.special; + +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; + +import java.lang.ref.PhantomReference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.SoftReference; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Benchmark) +public class SoftRefs { + + ReferenceQueue<Object> rq; + + @Setup + public void setup() { + rq = new ReferenceQueue<>(); + } + + public void drain() { + while (rq.poll() != null); // drain + } + + @Benchmark + public void test(Blackhole bh) { + drain(); + bh.consume(new SoftReference<>(new Object(), rq)); + bh.consume(new byte[10000]); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/org/openjdk/gcbench/alloc/special/WeakRefs.java Thu Oct 26 12:02:48 2017 +0200 @@ -0,0 +1,35 @@ +package org.openjdk.gcbench.alloc.special; + +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; + +import java.lang.ref.PhantomReference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.SoftReference; +import java.lang.ref.WeakReference; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@State(Scope.Benchmark) +public class WeakRefs { + + ReferenceQueue<Object> rq; + + @Setup + public void setup() { + rq = new ReferenceQueue<>(); + } + + public void drain() { + while (rq.poll() != null); // drain + } + + @Benchmark + public void test(Blackhole bh) { + drain(); + bh.consume(new WeakReference<>(new Object(), rq)); + bh.consume(new byte[10000]); + } + +}