1 /* 2 * Copyright (c) 2014, 2015, 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 package org.graalvm.compiler.hotspot.test; 24 25 import org.junit.Test; 26 27 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; 28 import org.graalvm.compiler.core.test.GraalCompilerTest; 29 import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProviderImpl; 30 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; 31 import org.graalvm.compiler.nodes.ValueNode; 32 import org.graalvm.compiler.nodes.extended.ForeignCallNode; 33 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; 34 import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; 35 import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin; 36 37 import jdk.vm.ci.meta.JavaKind; 38 import jdk.vm.ci.meta.ResolvedJavaMethod; 39 40 /** 41 * Tests that deoptimization upon exception handling works. 42 */ 43 public class ForeignCallDeoptimizeTest extends GraalCompilerTest { 44 45 @Override 46 protected Plugins getDefaultGraphBuilderPlugins() { 47 ForeignCallsProvider foreignCalls = ((HotSpotProviders) getProviders()).getForeignCalls(); 48 49 Plugins ret = super.getDefaultGraphBuilderPlugins(); 50 ret.getInvocationPlugins().register(new InvocationPlugin() { 51 52 @Override 53 public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) { 54 ForeignCallNode node = new ForeignCallNode(foreignCalls, HotSpotForeignCallsProviderImpl.TEST_DEOPTIMIZE_CALL_INT, arg); 55 b.addPush(JavaKind.Int, node); 56 return true; 57 } 58 }, ForeignCallDeoptimizeTest.class, "testCallInt", int.class); 59 return ret; 60 } 61 62 public static int testCallInt(int value) { 63 return value; 64 } 65 66 public static int testForeignCall(int value) { 67 if (testCallInt(value) != value) { 68 throw new InternalError(); 69 } 70 return value; 71 } 72 73 @Test 74 public void test1() { 75 test("testForeignCall", 0); 76 } 77 78 @Test 79 public void test2() { 80 test("testForeignCall", -1); 81 } 82 }