LambdaEagerTest.java revision 12651:6ef01bd40ce2
150477Speter/*
220973Swosch * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
311496Sphk * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
411496Sphk *
5110160Sseanc * This code is free software; you can redistribute it and/or modify it
6110160Sseanc * under the terms of the GNU General Public License version 2 only, as
711496Sphk * published by the Free Software Foundation.
8110160Sseanc *
9110160Sseanc * This code is distributed in the hope that it will be useful, but WITHOUT
1011497Sphk * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11116997Ssam * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12110160Sseanc * version 2 for more details (a copy is included in the LICENSE file that
13110160Sseanc * accompanied this code).
1491501Sjoe *
1591501Sjoe * You should have received a copy of the GNU General Public License version
16116997Ssam * 2 along with this work; if not, write to the Free Software Foundation,
17109007Sdes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18109024Sschweikh *
1941896Scracauer * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2041896Scracauer * or visit www.oracle.com if you need additional information or have any
21104442Swollman * questions.
22127527Smarcel */
23127527Smarcelpackage org.graalvm.compiler.jtt.lang;
24127527Smarcel
25127527Smarcelimport java.util.EnumSet;
26134439Sdesimport java.util.function.IntBinaryOperator;
27134439Sdes
28118506Sdesimport jdk.vm.ci.code.InstalledCode;
2941896Scracauerimport jdk.vm.ci.meta.DeoptimizationReason;
3018871Swollmanimport jdk.vm.ci.meta.ResolvedJavaMethod;
3118871Swollman
32151069Sdamienimport org.junit.Test;
33151069Sdamien
3421914Smsmithimport org.graalvm.compiler.core.common.GraalOptions;
3521914Smsmithimport org.graalvm.compiler.core.test.GraalCompilerTest;
36136618Smaximimport org.graalvm.compiler.nodes.StructuredGraph;
3786113Sphkimport org.graalvm.compiler.options.OptionValue;
3841826Scracauerimport org.graalvm.compiler.options.OptionValue.OverrideScope;
39122592Ssam
40135744Sdespublic class LambdaEagerTest extends GraalCompilerTest {
41135760Sjmg
4241826Scracauer    private static final EnumSet<DeoptimizationReason> UNRESOLVED_UNREACHED = EnumSet.of(DeoptimizationReason.Unresolved, DeoptimizationReason.UnreachedCode);
4386781Ssheldonh
44144944Savatar    private static int doBinary(IntBinaryOperator op, int x, int y) {
4541826Scracauer        return op.applyAsInt(x, y);
4694737Sdes    }
47147035Ssobomax
4822205Sjoerg    private static int add(int x, int y) {
49142871Strhodes        return x + y;
50142871Strhodes    }
51109007Sdes
5238973Sjb    public static int nonCapturing(int x, int y) {
5341896Scracauer        return doBinary((a, b) -> a + b, x, y);
5441896Scracauer    }
55109007Sdes
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