Mercurial > hg > gc-bench
view src/main/java/org/openjdk/gcbench/roots/Locals.java @ 88:583fef4276f5
Update license and copyright headers.
author | shade |
---|---|
date | Wed, 22 Nov 2017 15:58:02 +0100 |
parents | d41292cbeb90 |
children |
line wrap: on
line source
/* * Copyright (c) 2017, Red Hat Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package org.openjdk.gcbench.roots; import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; import org.openjdk.jmh.infra.Control; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) @Fork(value = 1, jvmArgsAppend = "-Xss32m") @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) @Threads(Threads.MAX) @State(Scope.Thread) public class Locals { List<Object> list; @Param({"100000"}) private int size; @Setup public void setup() { size = Math.max(100, size); list = new ArrayList<>(); for (int c = 0; c < size; c++) { list.add(new Object()); } } @Benchmark public void test(Control cnt, Blackhole bh) throws InterruptedException { recursiveLocal(cnt, bh, list, 10); } @CompilerControl(CompilerControl.Mode.DONT_INLINE) private void recursiveLocal(Control cnt, Blackhole bh, List<Object> list, int i) { bh.consume(new int[64]); // Allocation pressure to trigger GCs. Object o00, o01, o02, o03, o04, o05, o06, o07, o08, o09; o00 = o01 = o02 = o03 = o04 = o05 = o06 = o07 = o08 = o09 = null; if (i < list.size()) { o00 = list.get(i - 0); o01 = list.get(i - 1); o02 = list.get(i - 2); o03 = list.get(i - 3); o04 = list.get(i - 4); o05 = list.get(i - 5); o06 = list.get(i - 6); o07 = list.get(i - 7); o08 = list.get(i - 8); o09 = list.get(i - 9); recursiveLocal(cnt, bh, list, i + 1); } else { if (cnt.startMeasurement) { // Do not leave until we are finished while (!cnt.stopMeasurement) { bh.consume(new Object()); } } } bh.consume(o00); bh.consume(o01); bh.consume(o02); bh.consume(o03); bh.consume(o04); bh.consume(o05); bh.consume(o06); bh.consume(o07); bh.consume(o08); bh.consume(o09); } }