1 /* 2 * Copyright (c) 2020, Oracle and/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 package org.openjdk.bench.vm.compiler; 24 25 import org.openjdk.jmh.annotations.Benchmark; 26 import org.openjdk.jmh.annotations.BenchmarkMode; 27 import org.openjdk.jmh.annotations.Mode; 28 import org.openjdk.jmh.annotations.OutputTimeUnit; 29 import org.openjdk.jmh.annotations.Param; 30 import org.openjdk.jmh.annotations.Scope; 31 import org.openjdk.jmh.annotations.Setup; 32 import org.openjdk.jmh.annotations.State; 33 import org.openjdk.jmh.annotations.Fork; 34 35 import org.openjdk.jmh.infra.Blackhole; 36 37 import java.util.concurrent.TimeUnit; 38 39 @Fork(jvmArgsPrepend = {"-XX:-EliminateAllocations", "-XX:-DoEscapeAnalysis"}) 40 @BenchmarkMode(Mode.Throughput) 41 @OutputTimeUnit(TimeUnit.SECONDS) 42 @State(Scope.Thread) 43 public class ClearMemory { 44 class Payload8 { 45 public long f0; 46 public long f1; 47 public long f2; 48 public long f3; 49 public long f4; 50 public long f5; 51 public long f6; 52 public long f7; 53 Payload8()54 public Payload8() { 55 this.f0 = 1; 56 } 57 } 58 59 class Payload7 { 60 public long f0; 61 public long f1; 62 public long f2; 63 public long f3; 64 public long f4; 65 public long f5; 66 public long f6; 67 Payload7()68 public Payload7() { 69 this.f0 = 1; 70 } 71 } 72 73 class Payload6 { 74 public long f0; 75 public long f1; 76 public long f2; 77 public long f3; 78 public long f4; 79 public long f5; 80 Payload6()81 public Payload6() { 82 this.f0 = 1; 83 } 84 } 85 86 class Payload5 { 87 public long f0; 88 public long f1; 89 public long f2; 90 public long f3; 91 public long f4; 92 Payload5()93 public Payload5() { 94 this.f0 = 1; 95 } 96 } 97 98 class Payload4 { 99 public long f0; 100 public long f1; 101 public long f2; 102 public long f3; 103 Payload4()104 public Payload4() { 105 this.f0 = 1; 106 } 107 } 108 109 @Setup Setup()110 public void Setup() { 111 } 112 113 @Benchmark testClearMemory1K(Blackhole bh)114 public void testClearMemory1K(Blackhole bh) { 115 Object [] objs = new Object[64]; 116 bh.consume(objs); 117 } 118 @Benchmark testClearMemory2K(Blackhole bh)119 public void testClearMemory2K(Blackhole bh) { 120 Object [] objs = new Object[128]; 121 bh.consume(objs); 122 } 123 @Benchmark testClearMemory4K(Blackhole bh)124 public void testClearMemory4K(Blackhole bh) { 125 Object [] objs = new Object[256]; 126 bh.consume(objs); 127 } 128 @Benchmark testClearMemory8K(Blackhole bh)129 public void testClearMemory8K(Blackhole bh) { 130 Object [] objs = new Object[512]; 131 bh.consume(objs); 132 } 133 @Benchmark testClearMemory16K(Blackhole bh)134 public void testClearMemory16K(Blackhole bh) { 135 Object [] objs = new Object[1024]; 136 bh.consume(objs); 137 } 138 @Benchmark testClearMemory32K(Blackhole bh)139 public void testClearMemory32K(Blackhole bh) { 140 Object [] objs = new Object[2048]; 141 bh.consume(objs); 142 } 143 @Benchmark testClearMemory1M(Blackhole bh)144 public void testClearMemory1M(Blackhole bh) { 145 Object [] objs = new Object[65536]; 146 bh.consume(objs); 147 } 148 @Benchmark testClearMemory8M(Blackhole bh)149 public void testClearMemory8M(Blackhole bh) { 150 Object [] objs = new Object[524288]; 151 bh.consume(objs); 152 } 153 @Benchmark testClearMemory56B(Blackhole bh)154 public void testClearMemory56B(Blackhole bh) { 155 Payload7 obj = new Payload7(); 156 bh.consume(obj); 157 } 158 @Benchmark testClearMemory48B(Blackhole bh)159 public void testClearMemory48B(Blackhole bh) { 160 Payload6 obj = new Payload6(); 161 bh.consume(obj); 162 } 163 @Benchmark testClearMemory40B(Blackhole bh)164 public void testClearMemory40B(Blackhole bh) { 165 Payload5 obj = new Payload5(); 166 bh.consume(obj); 167 } 168 @Benchmark testClearMemory32B(Blackhole bh)169 public void testClearMemory32B(Blackhole bh) { 170 Payload4 obj = new Payload4(); 171 bh.consume(obj); 172 } 173 @Benchmark testClearMemory24B(Blackhole bh)174 public void testClearMemory24B(Blackhole bh) { 175 Payload4 obj = new Payload4(); 176 bh.consume(obj); 177 } 178 } 179