Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/SpillCode.java
41161 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package org.openjdk.bench.vm.compiler;2324import org.openjdk.jmh.annotations.Benchmark;25import org.openjdk.jmh.annotations.BenchmarkMode;26import org.openjdk.jmh.annotations.Mode;27import org.openjdk.jmh.annotations.OutputTimeUnit;28import org.openjdk.jmh.annotations.Param;29import org.openjdk.jmh.annotations.Scope;30import org.openjdk.jmh.annotations.State;3132import java.util.concurrent.TimeUnit;3334/**35* Test spill code generation.36*/37@BenchmarkMode(Mode.AverageTime)38@OutputTimeUnit(TimeUnit.NANOSECONDS)39@State(Scope.Thread)40public class SpillCode {4142@Param("10")43private int iterations;4445private int dummy;4647private int doSomeCalcsInLargeBlockWithInts(int start, int iter) {4849int a1, a2, a3, a4;50int b1, b2, b3, b4;51int c1, c2, c3, c4;52int d1, d2, d3, d4;53int e1, e2, e3, e4;54int f1, f2, f3, f4;55int g1, g2, g3, g4;56int h1, h2, h3, h4;5758// a1 = b1 = c1 = d1 = e1 = f1 = g1 = h1 = (start % 2);59a2 = b2 = c2 = d2 = e2 = f2 = g2 = h2 = (start % 2);60a3 = b3 = c3 = d3 = e3 = f3 = g3 = h3 = (start % 4);61a4 = b4 = c4 = d4 = e4 = f4 = g4 = h4 = (start % 8);6263for (int i = 0; i < iter; i++) {6465// for each section, only x1 needs to survive.6667// a1 = a2 = a3 = a4 = (start + a1) % 2;68a1 = start;69a1 = a1 + a2 + a3 + a4;70a2 = a1 + a2 + a3 + a4;71a3 = a1 + a2 + a3 + a4;72a4 = a1 + a2 + a3 + a4;73a1 = a1 + a2 + a3 + a4;74a2 = a1 + a2 + a3 + a4;75a3 = a1 + a2 + a3 + a4;76a4 = a1 + a2 + a3 + a4;77a1 = a1 + a2 + a3 + a4;78a2 = a1 + a2 + a3 + a4;79a3 = a1 + a2 + a3 + a4;80a4 = a1 + a2 + a3 + a4;8182// b1 = b2 = b3 = b4 = (a4 + b1) % 2;83b1 = a4;84b1 = b1 + b2 + b3 + b4;85b2 = b1 + b2 + b3 + b4;86b3 = b1 + b2 + b3 + b4;87b4 = b1 + b2 + b3 + b4;88b1 = b1 + b2 + b3 + b4;89b2 = b1 + b2 + b3 + b4;90b3 = b1 + b2 + b3 + b4;91b4 = b1 + b2 + b3 + b4;92b1 = b1 + b2 + b3 + b4;93b2 = b1 + b2 + b3 + b4;94b3 = b1 + b2 + b3 + b4;95b4 = b1 + b2 + b3 + b4;9697// c1 = c2 = c3 = c4 = (b4 + c1) % 2;98c1 = b4;99c1 = c1 + c2 + c3 + c4;100c2 = c1 + c2 + c3 + c4;101c3 = c1 + c2 + c3 + c4;102c4 = c1 + c2 + c3 + c4;103c1 = c1 + c2 + c3 + c4;104c2 = c1 + c2 + c3 + c4;105c3 = c1 + c2 + c3 + c4;106c4 = c1 + c2 + c3 + c4;107c1 = c1 + c2 + c3 + c4;108c2 = c1 + c2 + c3 + c4;109c3 = c1 + c2 + c3 + c4;110c4 = c1 + c2 + c3 + c4;111112// d1 = d2 = d3 = d4 = (c4 + d1) % 2;113d1 = c4;114d1 = d1 + d2 + d3 + d4;115d2 = d1 + d2 + d3 + d4;116d3 = d1 + d2 + d3 + d4;117d4 = d1 + d2 + d3 + d4;118d1 = d1 + d2 + d3 + d4;119d2 = d1 + d2 + d3 + d4;120d3 = d1 + d2 + d3 + d4;121d4 = d1 + d2 + d3 + d4;122d1 = d1 + d2 + d3 + d4;123d2 = d1 + d2 + d3 + d4;124d3 = d1 + d2 + d3 + d4;125d4 = d1 + d2 + d3 + d4;126127// e1 = e2 = e3 = e4 = (d4 + e1) % 2;128e1 = d4;129e1 = e1 + e2 + e3 + e4;130e2 = e1 + e2 + e3 + e4;131e3 = e1 + e2 + e3 + e4;132e4 = e1 + e2 + e3 + e4;133e1 = e1 + e2 + e3 + e4;134e2 = e1 + e2 + e3 + e4;135e3 = e1 + e2 + e3 + e4;136e4 = e1 + e2 + e3 + e4;137e1 = e1 + e2 + e3 + e4;138e2 = e1 + e2 + e3 + e4;139e3 = e1 + e2 + e3 + e4;140e4 = e1 + e2 + e3 + e4;141142// f1 = f2 = f3 = f4 = (e4 + f1) % 2;143f1 = e4;144f1 = f1 + f2 + f3 + f4;145f2 = f1 + f2 + f3 + f4;146f3 = f1 + f2 + f3 + f4;147f4 = f1 + f2 + f3 + f4;148f1 = f1 + f2 + f3 + f4;149f2 = f1 + f2 + f3 + f4;150f3 = f1 + f2 + f3 + f4;151f4 = f1 + f2 + f3 + f4;152f1 = f1 + f2 + f3 + f4;153f2 = f1 + f2 + f3 + f4;154f3 = f1 + f2 + f3 + f4;155f4 = f1 + f2 + f3 + f4;156157// g1 = g2 = g3 = g4 = (f4 + g1) % 2;158g1 = f4;159g1 = g1 + g2 + g3 + g4;160g2 = g1 + g2 + g3 + g4;161g3 = g1 + g2 + g3 + g4;162g4 = g1 + g2 + g3 + g4;163g1 = g1 + g2 + g3 + g4;164g2 = g1 + g2 + g3 + g4;165g3 = g1 + g2 + g3 + g4;166g4 = g1 + g2 + g3 + g4;167g1 = g1 + g2 + g3 + g4;168g2 = g1 + g2 + g3 + g4;169g3 = g1 + g2 + g3 + g4;170g4 = g1 + g2 + g3 + g4;171172// h1 = h2 = h3 = h4 = (g4 + h1) % 2;173h1 = g4;174h1 = h1 + h2 + h3 + h4;175h2 = h1 + h2 + h3 + h4;176h3 = h1 + h2 + h3 + h4;177h4 = h1 + h2 + h3 + h4;178h1 = h1 + h2 + h3 + h4;179h2 = h1 + h2 + h3 + h4;180h3 = h1 + h2 + h3 + h4;181h4 = h1 + h2 + h3 + h4;182h1 = h1 + h2 + h3 + h4;183h2 = h1 + h2 + h3 + h4;184h3 = h1 + h2 + h3 + h4;185h4 = h1 + h2 + h3 + h4;186187start = h4;188}189190return start;191}192193/**194* The test runs a loop with many local variables. The issue it reproduces is that if handled wrong, too many variables195* are put on and referenced on stack. The number of iterations is taken from global variable, to prevent static loop196* unrolling. Many of the variables used in the larger loop are local inside the block and do dnot need to survive from197* one iteration to the next.198*/199@Benchmark200public int testSpillForManyInts() throws Exception {201return doSomeCalcsInLargeBlockWithInts(dummy, iterations);202}203}204205206