1 /*
  2  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 package org.openjdk.bench.vm.gc.barriers.clone;
 26 
 27 import org.openjdk.jmh.annotations.*;
 28 
 29 import java.util.concurrent.TimeUnit;
 30 
 31 @Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
 32 @Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
 33 @Fork(value = 3, jvmArgs = {"-Xmx1g", "-Xms1g"})
 34 @BenchmarkMode(Mode.AverageTime)
 35 @OutputTimeUnit(TimeUnit.NANOSECONDS)
 36 @State(Scope.Thread)
 37 public class Plain {
 38 
 39     PayloadLargeRef largeRef = new PayloadLargeRef();
 40     PayloadSmallRef smallRef = new PayloadSmallRef();
 41     PayloadNonRef nonRef = new PayloadNonRef();
 42 
 43     @Benchmark
 44     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 45     public Object large() {
 46         return largeRef.clone();
 47     }
 48 
 49     @Benchmark
 50     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 51     public Object small() {
 52         return smallRef.clone();
 53     }
 54 
 55     @Benchmark
 56     @CompilerControl(CompilerControl.Mode.DONT_INLINE)
 57     public Object no() {
 58         return nonRef.clone();
 59     }
 60 
 61     private static class PayloadSmallRef implements Cloneable {
 62         Object x1 = new Object();
 63         Object x2 = new Object();
 64         Object x3 = new Object();
 65         Object x4 = new Object();
 66         Object x5 = new Object();
 67         Object x6 = new Object();
 68         Object x7 = new Object();
 69         Object x8 = new Object();
 70 
 71         @Override
 72         public PayloadSmallRef clone() {
 73             try {
 74                 return (PayloadSmallRef) super.clone();
 75             } catch (CloneNotSupportedException e) {
 76                 throw new AssertionError();
 77             }
 78         }
 79     }
 80 
 81     private static class PayloadLargeRef implements Cloneable {
 82         Object x1 = new Object();
 83         Object x2 = new Object();
 84         Object x3 = new Object();
 85         Object x4 = new Object();
 86         Object x5 = new Object();
 87         Object x6 = new Object();
 88         Object x7 = new Object();
 89         Object x8 = new Object();
 90         Object x9 = new Object();
 91         Object x10 = new Object();
 92         Object x11 = new Object();
 93         Object x12 = new Object();
 94         Object x13 = new Object();
 95         Object x14 = new Object();
 96         Object x15 = new Object();
 97         Object x16 = new Object();
 98 
 99         @Override
100         public PayloadLargeRef clone() {
101             try {
102                 return (PayloadLargeRef) super.clone();
103             } catch (CloneNotSupportedException e) {
104                 throw new AssertionError();
105             }
106         }
107     }
108 
109     private static class PayloadNonRef implements Cloneable {
110         int x1, x2, x3, x4, x5, x6, x7, x8;
111         public PayloadNonRef() {
112         }
113 
114         @Override
115         public PayloadNonRef clone() {
116             try {
117                 return (PayloadNonRef) super.clone();
118             } catch (CloneNotSupportedException e) {
119                 throw new AssertionError();
120             }
121         }
122     }
123 
124 }