LambdaEagerTest.java revision 12657:6ef01bd40ce2
1/* 2 * Copyright (c) 2014, 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 */ 23package org.graalvm.compiler.jtt.lang; 24 25import java.util.EnumSet; 26import java.util.function.IntBinaryOperator; 27 28import jdk.vm.ci.code.InstalledCode; 29import jdk.vm.ci.meta.DeoptimizationReason; 30import jdk.vm.ci.meta.ResolvedJavaMethod; 31 32import org.junit.Test; 33 34import org.graalvm.compiler.core.common.GraalOptions; 35import org.graalvm.compiler.core.test.GraalCompilerTest; 36import org.graalvm.compiler.nodes.StructuredGraph; 37import org.graalvm.compiler.options.OptionValue; 38import org.graalvm.compiler.options.OptionValue.OverrideScope; 39 40public class LambdaEagerTest extends GraalCompilerTest { 41 42 private static final EnumSet<DeoptimizationReason> UNRESOLVED_UNREACHED = EnumSet.of(DeoptimizationReason.Unresolved, DeoptimizationReason.UnreachedCode); 43 44 private static int doBinary(IntBinaryOperator op, int x, int y) { 45 return op.applyAsInt(x, y); 46 } 47 48 private static int add(int x, int y) { 49 return x + y; 50 } 51 52 public static int nonCapturing(int x, int y) { 53 return doBinary((a, b) -> a + b, x, y); 54 } 55 56 public static int nonCapturing2(int x, int y) { 57 return doBinary(LambdaEagerTest::add, x, y); 58 } 59 60 public static int capturing(int x, int y, int z) { 61 return doBinary((a, b) -> a + b - z, x, y); 62 } 63 64 @Test 65 public void testEagerResolveNonCapturing01() { 66 Result expected = new Result(3, null); 67 testAgainstExpected(getResolvedJavaMethod("nonCapturing"), expected, UNRESOLVED_UNREACHED, 1, 2); 68 } 69 70 @Test 71 public void testEagerResolveNonCapturing02() { 72 Result expected = new Result(3, null); 73 testAgainstExpected(getResolvedJavaMethod("nonCapturing2"), expected, UNRESOLVED_UNREACHED, 1, 2); 74 } 75 76 @Test 77 public void testEagerResolveCapturing() { 78 Result expected = new Result(0, null); 79 testAgainstExpected(getResolvedJavaMethod("capturing"), expected, UNRESOLVED_UNREACHED, 1, 2, 3); 80 } 81 82 @Override 83 @SuppressWarnings("try") 84 protected InstalledCode getCode(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile) { 85 try (OverrideScope scope = OptionValue.override(GraalOptions.InlineEverything, true)) { 86 return super.getCode(installedCodeOwner, graph, forceCompile); 87 } 88 } 89} 90