# HG changeset patch # User shade # Date 1481827254 -3600 # Node ID afe1acc2f8a137f7a977c33120b356282fff31f8 # Parent dada456637b003ce21e75b805d1017994c2c3029 alloc.uninit.* tests. diff -r dada456637b0 -r afe1acc2f8a1 src/main/java/org/openjdk/gcbench/GCBench.java --- 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 " + diff -r dada456637b0 -r afe1acc2f8a1 src/main/java/org/openjdk/gcbench/alloc/uninit/IntArray.java --- /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); + } + +}