1 /*
   2  * Copyright (c) 2016, 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 /*
  24  */
  25 package org.graalvm.compiler.core.test;
  26 
  27 import org.junit.Test;
  28 
  29 import org.graalvm.compiler.code.CompilationResult;
  30 import org.graalvm.compiler.core.phases.HighTier;
  31 import org.graalvm.compiler.nodes.StructuredGraph;
  32 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  33 import org.graalvm.compiler.options.OptionValue;
  34 import org.graalvm.compiler.options.OptionValue.OverrideScope;
  35 import org.graalvm.compiler.phases.tiers.Suites;
  36 
  37 import jdk.vm.ci.meta.ResolvedJavaMethod;
  38 
  39 public final class DontReuseArgumentSpaceTest extends GraalCompilerTest {
  40 
  41     @Override
  42     @SuppressWarnings("try")
  43     protected Suites createSuites() {
  44         try (OverrideScope scope = OptionValue.override(HighTier.Options.Inline, false)) {
  45             return super.createSuites();
  46         }
  47     }
  48 
  49     @BytecodeParserNeverInline
  50     public static int killArguments(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
  51         return a + b + c + d + e + f + g + h + i + j;
  52     }
  53 
  54     @BytecodeParserNeverInline
  55     public static int callTwice(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
  56         /*
  57          * Call the same method twice so the arguments are in the same place each time and might
  58          * appear to be redundant moves.
  59          */
  60         killArguments(a, b, c, d, e, f, g, h, i, j);
  61         return killArguments(a, b, c, d, e, f, g, h, i, j);
  62     }
  63 
  64     @Test
  65     public void run0() throws Throwable {
  66         /*
  67          * Exercise the methods once so everything is resolved
  68          */
  69         callTwice(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  70 
  71         /*
  72          * Create a standalone compile of killArguments. This test assumes that zapping of argument
  73          * space is being performed by the backend.
  74          */
  75         ResolvedJavaMethod javaMethod = getResolvedJavaMethod("killArguments");
  76         StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.YES);
  77         CompilationResult compilationResult = compile(javaMethod, graph);
  78         getBackend().createDefaultInstalledCode(javaMethod, compilationResult);
  79 
  80         test("callTwice", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  81     }
  82 }