# HG changeset patch # User Christian Humer # Date 1409594899 -7200 # Node ID 004e3f0a0517f27e2d7c25689e8dd9619c9ed137 # Parent e9c1199271992932df90539fa98b42aab62d96d0 Truffle: added new infrastructure for graal truffle runtime tests using SL. diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/sl/TestCompilationThreshold.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/sl/TestCompilationThreshold.sl Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,19 @@ +/* + * This test verifies the compilation threshold property. + */ +function test() { +} + +function main() { + /* TODO disableSplitting is required because otherwise it needs more calls to warm up. This still needs to be fixed. */ + disableSplitting(test); + threshold = getOption("TruffleCompilationThreshold"); + i = 0; + while (i < threshold -1) { + test(); + i = i + 1; + } + assertFalse(isOptimized(waitForOptimization(test))); + test(); // triggers compilation + assertTrue(isOptimized(waitForOptimization(test))); +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/sl/TestInliningMaxCallerSize.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/sl/TestInliningMaxCallerSize.sl Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,26 @@ +/* + * This test verifies that CallTargets cannot exceed the TruffleInliningMaxCallerSize limit when inlining. + */ +function inlinableFunction() { + generateDummyNodes(getOption("TruffleInliningMaxCallerSize") - 8); +} + +function notInlinableFunction() { + generateDummyNodes(getOption("TruffleInliningMaxCallerSize") - 7); +} + +function test1() { + inlinableFunction(); +} + +function test2() { + notInlinableFunction(); +} + +function main() { + waitForOptimization(callUntilOptimized(test1)); + assertTrue(isInlined(test1, inlinableFunction), "inlinableFunction is not inlined"); + + waitForOptimization(callUntilOptimized(test2)); + assertFalse(isInlined(test2, notInlinableFunction), "notInlinableFunction is inlined"); +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SLTruffleGraalTestSuite.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SLTruffleGraalTestSuite.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test; + +import org.junit.*; +import org.junit.runner.*; + +import com.oracle.graal.truffle.test.builtins.*; +import com.oracle.truffle.sl.test.*; + +@RunWith(SLTestRunner.class) +@SLTestSuite({"graal/com.oracle.graal.truffle.test/sl", "sl"}) +public class SLTruffleGraalTestSuite { + + public static void main(String[] args) throws Exception { + SLTestRunner.runInMain(SLTruffleGraalTestSuite.class, args); + } + + @BeforeClass + public static void setupTestRunner() { + SLTestRunner.setRepeats(1); + SLTestRunner.installBuiltin(SLGetOptionBuiltinFactory.getInstance()); + SLTestRunner.installBuiltin(SLSetOptionBuiltinFactory.getInstance()); + SLTestRunner.installBuiltin(SLIsOptimizedBuiltinFactory.getInstance()); + SLTestRunner.installBuiltin(SLWaitForOptimizationBuiltinFactory.getInstance()); + SLTestRunner.installBuiltin(SLDisableSplittingBuiltinFactory.getInstance()); + SLTestRunner.installBuiltin(SLCallUntilOptimizedBuiltinFactory.getInstance()); + SLTestRunner.installBuiltin(SLIsInlinedBuiltinFactory.getInstance()); + SLTestRunner.installBuiltin(SLGenerateDummyNodesBuiltinFactory.getInstance()); + } + + /* + * Our "mx unittest" command looks for methods that are annotated with @Test. By just defining + * an empty method, this class gets included and the test suite is properly executed. + */ + @Test + public void unittest() { + } +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLCallUntilOptimizedBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLCallUntilOptimizedBuiltin.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test.builtins; + +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +/** + * Calls a given function until the Graal runtime decides to optimize the function. Use + * waitForOptimization(function) to wait until the runtime system has completed the + * possibly parallel optimization. + * + * @see SLWaitForOptimizationBuiltin + */ +@NodeInfo(shortName = "callUntilOptimized") +public abstract class SLCallUntilOptimizedBuiltin extends SLGraalRuntimeBuiltin { + + private static final int MAX_CALLS = 10000; + private static final Object[] EMPTY_ARGS = new Object[0]; + + @Child private IndirectCallNode indirectCall = Truffle.getRuntime().createIndirectCallNode(); + + @Specialization + public SLFunction callUntilCompiled(VirtualFrame frame, SLFunction function) { + OptimizedCallTarget oct = ((OptimizedCallTarget) function.getCallTarget()); + for (int i = 0; i < MAX_CALLS; i++) { + if (((GraalTruffleRuntime) Truffle.getRuntime()).isCompiling(oct) || oct.isValid()) { + break; + } else { + indirectCall.call(frame, oct, EMPTY_ARGS); + } + } + return function; + } +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLDisableSplittingBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLDisableSplittingBuiltin.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test.builtins; + +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.CompilerDirectives.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +/** + * Disables splitting for a given {@link SLFunction} instance. If no function is given the splitting + * will be disabled for the calling function. + */ +@NodeInfo(shortName = "disableSplitting") +public abstract class SLDisableSplittingBuiltin extends SLGraalRuntimeBuiltin { + + @Specialization + @SlowPath + public SLFunction disableSplitting(SLFunction function) { + OptimizedCallTarget target = (OptimizedCallTarget) function.getCallTarget(); + for (OptimizedCallTarget oct : findDuplicateCallTargets(target)) { + ((SLRootNode) oct.getRootNode()).setSplittable(false); + } + return function; + } + + @Specialization + @SlowPath + public SLNull disableSplitting(@SuppressWarnings("unused") SLNull argument) { + RootNode parentRoot = Truffle.getRuntime().getCallerFrame().getCallNode().getRootNode(); + ((SLRootNode) parentRoot).setSplittable(false); + return SLNull.SINGLETON; + } + +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLGenerateDummyNodesBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLGenerateDummyNodesBuiltin.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test.builtins; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +/** + * Generates a given number of dummy nodes and replaces the root of the current method with them. + * This builtin is guaranteed to be executed only once. + */ +@NodeInfo(shortName = "generateDummyNodes") +public abstract class SLGenerateDummyNodesBuiltin extends SLGraalRuntimeBuiltin { + + @Specialization + public Object generateNodes(long count) { + CompilerAsserts.neverPartOfCompilation("generateNodes should never get optimized."); + FrameInstance callerFrame = Truffle.getRuntime().getCallerFrame(); + SLRootNode root = (SLRootNode) callerFrame.getCallNode().getRootNode(); + root.getBodyNode().replace(createBinaryTree((int) (count - 1))); + return SLNull.SINGLETON; + } + + private SLDummyNode createBinaryTree(int nodeCount) { + if (nodeCount > 3) { + int leftSize = nodeCount / 2; + SLDummyNode left = createBinaryTree(leftSize); + SLDummyNode right = createBinaryTree(nodeCount - leftSize - 1); + return new SLDummyNode(left, right); + } else { + if (nodeCount <= 0) { + return null; + } + SLDummyNode left = null; + SLDummyNode right = null; + if (nodeCount > 1) { + left = new SLDummyNode(null, null); + if (nodeCount > 2) { + right = new SLDummyNode(null, null); + } + } + return new SLDummyNode(left, right); + } + } + + @NodeInfo(cost = NodeCost.MONOMORPHIC) + private static class SLDummyNode extends SLExpressionNode { + + @Child private SLDummyNode left; + @Child private SLDummyNode right; + + public SLDummyNode(SLDummyNode left, SLDummyNode right) { + super(null); + this.left = left; + this.right = right; + } + + @Override + public Object executeGeneric(VirtualFrame frame) { + if (left != null) { + left.executeGeneric(frame); + } + if (right != null) { + right.executeGeneric(frame); + } + return null; + } + + } + +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLGetOptionBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLGetOptionBuiltin.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test.builtins; + +import com.oracle.graal.options.*; +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.CompilerDirectives.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.nodes.*; + +/** + * Looks up the value of an option in {@link TruffleCompilerOptions}. In the future this builtin + * might be extend to lookup other options as well. + */ +@NodeInfo(shortName = "getOption") +public abstract class SLGetOptionBuiltin extends SLGraalRuntimeBuiltin { + + @Specialization + @SlowPath + public Object getOption(String name) { + TruffleCompilerOptions_Options options = new TruffleCompilerOptions_Options(); + for (OptionDescriptor option : options) { + if (option.getName().equals(name)) { + return convertValue(option.getOptionValue().getValue()); + } + } + return null; + } + + private static Object convertValue(Object value) { + // Improve this method as you need it. + if (value instanceof Integer) { + return (long) (int) value; + } + return value; + } + +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLGraalRuntimeBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLGraalRuntimeBuiltin.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test.builtins; + +import java.util.*; + +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.CompilerDirectives.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.api.source.*; +import com.oracle.truffle.sl.builtins.*; + +public abstract class SLGraalRuntimeBuiltin extends SLBuiltinNode { + + public SLGraalRuntimeBuiltin() { + super(null); + assignSourceSection(new NullSourceSection("SL Builtin", getClass().getAnnotation(NodeInfo.class).shortName())); + if (!(Truffle.getRuntime() instanceof GraalTruffleRuntime)) { + throw new AssertionError("Graal runtime builtins can only be used inside of a Graal runtime."); + } + } + + /** + * Finds all call targets available for the same original call target. This might be useful if a + * {@link CallTarget} got duplicated due to splitting. + */ + @SlowPath + protected static final Set findDuplicateCallTargets(OptimizedCallTarget originalCallTarget) { + final Set allCallTargets = new HashSet<>(); + allCallTargets.add(originalCallTarget); + for (RootCallTarget target : Truffle.getRuntime().getCallTargets()) { + if (target instanceof OptimizedCallTarget) { + OptimizedCallTarget oct = (OptimizedCallTarget) target; + if (oct.getSplitSource() == originalCallTarget) { + allCallTargets.add(oct); + } + } + } + return allCallTargets; + } + + /** + * Finds all {@link DirectCallNode} instances calling a certain original {@link CallTarget} in + * the caller function. + */ + @SlowPath + protected static final Set findCallsTo(OptimizedCallTarget originalCallTarget) { + FrameInstance frame = Truffle.getRuntime().getCallerFrame(); + RootNode root = frame.getCallNode().getRootNode(); + return findCallsTo(root, originalCallTarget); + } + + /** + * Finds all {@link DirectCallNode} instances calling a certain original {@link CallTarget} in a + * given {@link RootNode}. + */ + @SlowPath + protected static final Set findCallsTo(RootNode root, OptimizedCallTarget originalCallTarget) { + final Set allCallNodes = new HashSet<>(); + root.accept(new NodeVisitor() { + public boolean visit(Node node) { + if (node instanceof DirectCallNode) { + DirectCallNode callNode = (DirectCallNode) node; + if (callNode.getCallTarget() == originalCallTarget || callNode.getSplitCallTarget() == originalCallTarget) { + allCallNodes.add(callNode); + } + } + return true; + } + }); + return allCallNodes; + } +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLIsInlinedBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLIsInlinedBuiltin.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test.builtins; + +import java.util.*; + +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.CompilerDirectives.SlowPath; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +/** + * Returns true if a function got inlined for all calls from a given {@link SLFunction} + * . If no direct calls to the given {@link SLFunction} could be resolved or the call got inlined + * for some callsites and for some not then an {@link AssertionError} is thrown. + */ +@NodeInfo(shortName = "isInlined") +public abstract class SLIsInlinedBuiltin extends SLGraalRuntimeBuiltin { + + @Specialization + @SlowPath + public Object isInlined(SLFunction parent, SLFunction inlinedFunction) { + boolean allFalse = true; + boolean allTrue = true; + for (OptimizedCallTarget parentTarget : findDuplicateCallTargets((OptimizedCallTarget) parent.getCallTarget())) { + Set callNodes = findCallsTo(parentTarget.getRootNode(), (OptimizedCallTarget) inlinedFunction.getCallTarget()); + for (DirectCallNode directCall : callNodes) { + if (directCall.isInlined()) { + allFalse = false; + } else { + allTrue = false; + } + } + } + if (allFalse && allTrue) { + throw new AssertionError(String.format("No calls found from %s to %s .", parent, inlinedFunction)); + } else if (!allFalse && !allTrue) { + throw new AssertionError(String.format("Some calls from %s to %s are inlined and some are not.", parent, inlinedFunction)); + } + if (allTrue) { + return true; + } else { + return false; + } + } +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLIsOptimizedBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLIsOptimizedBuiltin.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test.builtins; + +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.CompilerDirectives.SlowPath; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +/** + * Checks whether or not a function is optimized by the Graal runtime. + */ +@NodeInfo(shortName = "isOptimized") +public abstract class SLIsOptimizedBuiltin extends SLGraalRuntimeBuiltin { + + @Specialization + @SlowPath + public boolean isOptimized(SLFunction function) { + OptimizedCallTarget target = (OptimizedCallTarget) function.getCallTarget(); + for (OptimizedCallTarget foundTarget : findDuplicateCallTargets(target)) { + if (foundTarget.isValid()) { + return true; + } + } + return false; + } +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLSetOptionBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLSetOptionBuiltin.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test.builtins; + +import com.oracle.graal.options.*; +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.CompilerDirectives.SlowPath; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.nodes.*; + +/** + * Sets an option value in {@link TruffleCompilerOptions}. In the future this builtin might be + * extend to lookup other options as well. + */ +@NodeInfo(shortName = "setOption") +public abstract class SLSetOptionBuiltin extends SLGraalRuntimeBuiltin { + + @Specialization + @SlowPath + public Object setOption(String name, Object value) { + TruffleCompilerOptions_Options options = new TruffleCompilerOptions_Options(); + for (OptionDescriptor option : options) { + if (option.getName().equals(name)) { + option.getOptionValue().setValue(convertValue(value)); + } + } + return value; + } + + private static Object convertValue(Object value) { + // Improve this method as you need it. + if (value instanceof Long) { + long longValue = (long) value; + if (longValue == (int) longValue) { + return (int) longValue; + } + } + return value; + } + +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLWaitForOptimizationBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/builtins/SLWaitForOptimizationBuiltin.java Mon Sep 01 20:08:19 2014 +0200 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.test.builtins; + +import java.util.concurrent.*; + +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +/** + * Waits for the optimization of a function to complete if it was already triggered. If no + * optimization was triggered then this builtin does nothing. + */ +@NodeInfo(shortName = "waitForOptimization") +public abstract class SLWaitForOptimizationBuiltin extends SLGraalRuntimeBuiltin { + + @Specialization + public SLFunction waitForOptimization(SLFunction function, long timeout) { + OptimizedCallTarget target = (OptimizedCallTarget) function.getCallTarget(); + GraalTruffleRuntime runtime = ((GraalTruffleRuntime) Truffle.getRuntime()); + + for (OptimizedCallTarget effectiveCallTarget : findDuplicateCallTargets(target)) { + try { + runtime.waitForCompilation(effectiveCallTarget, timeout); + } catch (ExecutionException | TimeoutException e) { + throw new RuntimeException(e); + } + } + return function; + } + + @Specialization + public SLFunction waitForCompilation(SLFunction function, @SuppressWarnings("unused") SLNull timeout) { + return waitForOptimization(function, 120000); + } + +} diff -r e9c119927199 -r 004e3f0a0517 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java Mon Sep 01 20:08:18 2014 +0200 +++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java Mon Sep 01 20:08:19 2014 +0200 @@ -45,7 +45,7 @@ public final class SLTestRunner extends ParentRunner { - private static int repeats = 10; + private static int repeats = 1; private static final String SOURCE_SUFFIX = ".sl"; private static final String INPUT_SUFFIX = ".input"; diff -r e9c119927199 -r 004e3f0a0517 mx/projects --- a/mx/projects Mon Sep 01 20:08:18 2014 +0200 +++ b/mx/projects Mon Sep 01 20:08:19 2014 +0200 @@ -843,7 +843,7 @@ # graal.truffle.test project@com.oracle.graal.truffle.test@subDir=graal project@com.oracle.graal.truffle.test@sourceDirs=src -project@com.oracle.graal.truffle.test@dependencies=com.oracle.graal.truffle,com.oracle.graal.compiler.test +project@com.oracle.graal.truffle.test@dependencies=com.oracle.graal.truffle,com.oracle.graal.compiler.test,com.oracle.truffle.sl.test project@com.oracle.graal.truffle.test@checkstyle=com.oracle.graal.graph project@com.oracle.graal.truffle.test@javaCompliance=1.8 project@com.oracle.graal.truffle.test@workingSets=Graal,Truffle,Test