1 package org.openjdk.bench.vm.gc.barriers.clone;
  2 
  3 import org.openjdk.jmh.annotations.*;
  4 
  5 import java.util.concurrent.TimeUnit;
  6 
  7 @Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
  8 @Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
  9 @Fork(value = 3, jvmArgs = {"-Xmx1g", "-Xms1g"})
 10 @BenchmarkMode(Mode.AverageTime)
 11 @OutputTimeUnit(TimeUnit.NANOSECONDS)
 12 @State(Scope.Thread)
 13 public class Plain {
 14 
 15     PayloadLargeRef largeRef = new PayloadLargeRef();
 16     PayloadSmallRef smallRef = new PayloadSmallRef();
 17     PayloadNonRef nonRef = new PayloadNonRef();
 18 
 19     @Benchmark
 20     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 21     public Object large() {
 22         return largeRef.clone();
 23     }
 24 
 25     @Benchmark
 26     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 27     public Object small() {
 28         return smallRef.clone();
 29     }
 30 
 31     @Benchmark
 32     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 33     public Object no() {
 34         return nonRef.clone();
 35     }
 36 
 37     private static class PayloadSmallRef implements Cloneable {
 38         Object x1 = new Object();
 39         Object x2 = new Object();
 40         Object x3 = new Object();
 41         Object x4 = new Object();
 42         Object x5 = new Object();
 43         Object x6 = new Object();
 44         Object x7 = new Object();
 45         Object x8 = new Object();
 46 
 47         @Override
 48         public PayloadSmallRef clone() {
 49             try {
 50                 return (PayloadSmallRef) super.clone();
 51             } catch (CloneNotSupportedException e) {
 52                 throw new AssertionError();
 53             }
 54         }
 55     }
 56 
 57     private static class PayloadLargeRef implements Cloneable {
 58         Object x1 = new Object();
 59         Object x2 = new Object();
 60         Object x3 = new Object();
 61         Object x4 = new Object();
 62         Object x5 = new Object();
 63         Object x6 = new Object();
 64         Object x7 = new Object();
 65         Object x8 = new Object();
 66         Object x9 = new Object();
 67         Object x10 = new Object();
 68         Object x11 = new Object();
 69         Object x12 = new Object();
 70         Object x13 = new Object();
 71         Object x14 = new Object();
 72         Object x15 = new Object();
 73         Object x16 = new Object();
 74 
 75         @Override
 76         public PayloadLargeRef clone() {
 77             try {
 78                 return (PayloadLargeRef) super.clone();
 79             } catch (CloneNotSupportedException e) {
 80                 throw new AssertionError();
 81             }
 82         }
 83     }
 84 
 85     private static class PayloadNonRef implements Cloneable {
 86         int x1, x2, x3, x4, x5, x6, x7, x8;
 87         public PayloadNonRef() {
 88         }
 89 
 90         @Override
 91         public PayloadNonRef clone() {
 92             try {
 93                 return (PayloadNonRef) super.clone();
 94             } catch (CloneNotSupportedException e) {
 95                 throw new AssertionError();
 96             }
 97         }
 98     }
 99 
100 }