changeset 48:afe1acc2f8a1

alloc.uninit.* tests.
author shade
date Thu, 15 Dec 2016 19:40:54 +0100
parents dada456637b0
children d869414b90b4
files src/main/java/org/openjdk/gcbench/GCBench.java src/main/java/org/openjdk/gcbench/alloc/uninit/IntArray.java
diffstat 2 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/openjdk/gcbench/GCBench.java	Fri Dec 09 15:37:18 2016 +0100
+++ b/src/main/java/org/openjdk/gcbench/GCBench.java	Thu Dec 15 19:40:54 2016 +0100
@@ -173,6 +173,19 @@
             ));
         }
 
+        {
+            String groupDescr = "Allocates the uninitialized arrays in almost completely empty heap as fast as it can. " +
+                    "This is the torturous test that allocates more objects than any pure Java application can do, and " +
+                    "stresses the allocation paths in collector. ";
+
+            tests.add(new DimensionalTest(baseOpts, org.openjdk.gcbench.alloc.uninit.IntArray.class,
+                    "alloc.uninit.intarray", groupDescr + "Allocates uninitialized int[] arrays of different sizes.",
+                    Dimensions.threads(),
+                    Dimensions.heapSize(Sequence.powersOfTwo_WithMax(1024, MaxHeapDetector.MAX_HEAP)),
+                    Dimensions.size(Sequence.powersOfTen(1, 10_000))
+            ));
+        }
+
         if (false) { // TODO: Enable back once they are important again
             String groupDescr = "Allocates the objects in almost completely empty heap, with rate limiting. " +
                     "If the collector needs some headroom to do cleanup, rate limited tests would show how much " +
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/org/openjdk/gcbench/alloc/uninit/IntArray.java	Thu Dec 15 19:40:54 2016 +0100
@@ -0,0 +1,37 @@
+package org.openjdk.gcbench.alloc.uninit;
+
+import jdk.internal.misc.Unsafe;
+import org.openjdk.jmh.annotations.*;
+
+import java.lang.reflect.Field;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@State(Scope.Benchmark)
+@Fork(jvmArgsPrepend = {"--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED"})
+public class IntArray {
+
+    static final Unsafe U;
+    static final long OFF_REF;
+
+    static {
+        try {
+            Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
+            unsafeField.setAccessible(true);
+            U = (Unsafe) unsafeField.get(null);
+            OFF_REF  = U.objectFieldOffset(IntArray.class.getDeclaredField("ref"));
+        } catch (Exception e) {
+            throw new AssertionError(e);
+        }
+    }
+
+    @Param({"1"})
+    int size;
+
+    @Benchmark
+    public Object test() {
+        return U.allocateUninitializedArray(int.class, size);
+    }
+
+}