# HG changeset patch # User Christian Humer # Date 1390910106 -3600 # Node ID 739194d1e813733b1d4435d9d9821d73bdc5590f # Parent 3840d61e0e6883497d8650530790e0848d803e77# Parent dbd67029477061f391221aa1ee0049b2afccb06a Merge. diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ExternalCompilationResult.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ExternalCompilationResult.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ExternalCompilationResult.java Tue Jan 28 12:55:06 2014 +0100 @@ -60,4 +60,11 @@ public long getEntryPoint() { return entryPoint; } + + /** + * Gets the {@linkplain #getTargetCode() code} in this compilation result as a string. + */ + public String getCodeString() { + return new String(getTargetCode(), 0, getTargetCodeSize()); + } } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DefaultProfilingInfo.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DefaultProfilingInfo.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DefaultProfilingInfo.java Tue Jan 28 12:55:06 2014 +0100 @@ -95,4 +95,8 @@ public String toString() { return "BaseProfilingInfo<" + MetaUtil.profileToString(this, null, "; ") + ">"; } + + public void setMature() { + // Do nothing + } } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ProfilingInfo.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ProfilingInfo.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ProfilingInfo.java Tue Jan 28 12:55:06 2014 +0100 @@ -121,4 +121,9 @@ */ boolean isMature(); + /** + * Force data to be treated as mature if possible. + */ + + void setMature(); } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java Tue Jan 28 12:55:06 2014 +0100 @@ -26,6 +26,7 @@ public class ControlPTXTest extends PTXTest { + @Ignore("[CUDA] *** Error (status=702): Synchronize kernel") @Test public void testControl() { test("testLoop", 42); diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java Tue Jan 28 12:55:06 2014 +0100 @@ -63,7 +63,6 @@ return 32.0 + a; } - @Ignore @Test public void testSub() { compileKernel("testSub2F"); @@ -98,7 +97,7 @@ return 32.0 - a; } - @Ignore + @Ignore("[CUDA] *** Error (209) Failed to load module data with online compiler options for method testMul2F") @Test public void testMul() { compileKernel("testMul2F"); @@ -133,7 +132,7 @@ return 32.0 * a; } - @Ignore + @Ignore("[CUDA] *** Error (209) Failed to load module data with online compiler options for method testDiv2F") @Test public void testDiv() { compileKernel("testDiv2F"); @@ -168,7 +167,6 @@ return 32.0 / a; } - @Ignore @Test public void testNeg() { compileKernel("testNeg2F"); @@ -183,12 +181,11 @@ return -a; } - @Ignore + @Ignore("need linkage to PTX remainder") @Test public void testRem() { - // need linkage to PTX remainder() - // compileKernel("testRem2F"); - // compileKernel("testRem2D"); + compileKernel("testRem2F"); + compileKernel("testRem2D"); } public static float testRem2F(float a, float b) { @@ -199,7 +196,7 @@ return a % b; } - @Ignore + @Ignore("[CUDA] *** Error (209) Failed to load module data with online compiler options for method testF2I") @Test public void testFloatConversion() { compileKernel("testF2I"); diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ObjectPTXTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ObjectPTXTest.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2013, 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.compiler.ptx.test; + +import java.util.*; + +import org.junit.*; + +public class ObjectPTXTest extends PTXTest { + + static class A { + boolean z = true; + byte b = 17; + char c = 'D'; + short s = 12345; + int i = 0x1234565; + long l; + Object o; + float f; + double d; + } + + @Ignore("Object parameters not yet GC safe") + @Test + public void test0() { + for (long l : new long[]{Long.MIN_VALUE, -10, 0, 1, 2, 10, Long.MAX_VALUE}) { + A a = new A(); + a.l = l; + test("testLong", l * 2, a); + } + } + + public static long testLong(long l, A a) { + return a.l + l; + } + + @Ignore("Object parameters not yet GC safe") + @Test + public void test1() { + for (int i : new int[]{Integer.MIN_VALUE, -10, 0, 1, 2, 10, Integer.MAX_VALUE}) { + A a = new A(); + a.i = i; + test("testInt", i * 2, a); + } + } + + public static int testInt(int i, A a) { + return a.i + i; + } + + @Ignore("Object parameters not yet GC safe") + @Test + public void test2() { + A a = new A(); + a.z = true; + test("testBoolean", a); + a.z = false; + test("testBoolean", a); + } + + public static boolean testBoolean(A a) { + return a.z; + } + + @Ignore("Object parameters not yet GC safe") + @Test + public void test3() { + for (byte b : new byte[]{Byte.MIN_VALUE, -10, 0, 1, 2, 10, Byte.MAX_VALUE}) { + A a = new A(); + a.b = b; + test("testByte", b, a); + } + } + + public static int testByte(byte b, A a) { + return a.b + b; + } + + @Ignore("Object parameters not yet GC safe") + @Test + public void test4() { + for (short s : new short[]{Short.MIN_VALUE, -10, 0, 1, 2, 10, Short.MAX_VALUE}) { + A a = new A(); + a.s = s; + test("testShort", s, a); + } + } + + public static int testShort(short s, A a) { + return a.s + s; + } + + @Ignore("Object parameters not yet GC safe") + @Test + public void test5() { + for (char c : new char[]{Character.MIN_VALUE, 1, 2, 10, Character.MAX_VALUE}) { + A a = new A(); + a.c = c; + test("testChar", (char) (c - 5), a); + } + } + + public static int testChar(char c, A a) { + return a.c + c; + } + + @Ignore("Object parameters not yet GC safe") + @Test + public void test6() { + for (float f : new float[]{Float.MIN_VALUE, Float.MIN_NORMAL, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NaN, -11.45F, -0.0F, 0.0F, 2, 10, Float.MAX_VALUE}) { + A a = new A(); + a.f = f; + test("testFloat", f * 2, a); + } + } + + public static float testFloat(float f, A a) { + return a.f + f; + } + + @Ignore("Object parameters not yet GC safe") + @Test + public void test7() { + for (double d : new double[]{Double.MIN_VALUE, Double.MIN_NORMAL, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY - 11.45D, -0.0D, 0.0D, 2, 10, Double.MAX_VALUE}) { + A a = new A(); + a.d = d; + test("testDouble", d * 2, a); + } + } + + public static double testDouble(double d, A a) { + return a.d + d; + } + + @Ignore("Object return values not yet supported") + @Test + public void test9() { + for (Object o : new Object[]{null, "object", new Object(), new HashMap()}) { + A a = new A(); + a.o = o; + test("testObject", a); + } + } + + public static Object testObject(A a) { + return a.o; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXPhase.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXPhase.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2013, 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.compiler.ptx.test; - -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.type.*; -import com.oracle.graal.phases.*; - -public class PTXPhase extends Phase { - - @Override - protected void run(StructuredGraph graph) { - /* - * Assume that null checks would be done on the CPU caller side prior to copying data onto - * the GPU. - */ - for (ParameterNode param : graph.getNodes(ParameterNode.class)) { - if (param.stamp() instanceof ObjectStamp) { - param.setStamp(StampFactory.declaredNonNull(((ObjectStamp) param.stamp()).type())); - } - } - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java Tue Jan 28 12:55:06 2014 +0100 @@ -69,7 +69,15 @@ Assume.assumeTrue(ptxBackend.isDeviceInitialized()); HotSpotNmethod installedPTXCode = installKernel(method, ptxCode); StructuredGraph wrapper = new PTXWrapperBuilder(method, installedPTXCode, (HotSpotProviders) getProviders()).getGraph(); - return super.getCode(method, wrapper); + + // The PTX C++ layer expects a 1:1 relationship between kernel compilation + // and kernel execution as it creates a cuContext in the former and + // destroys it in the latter. So, each kernel installed requires a unique + // wrapper. + // TODO: do cuContext management properly + boolean forceCompile = true; + + return getCode(method, wrapper, forceCompile); } protected static void compileAndPrintCode(PTXTest test) { diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Tue Jan 28 12:55:06 2014 +0100 @@ -578,7 +578,11 @@ protected CompilationResult compile(ResolvedJavaMethod method, final StructuredGraph graph) { CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false); return compileGraph(graph, cc, method, getProviders(), getBackend(), getCodeCache().getTarget(), null, getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, getProfilingInfo(graph), - new SpeculationLog(), getSuites(), true, new CompilationResult(), CompilationResultBuilderFactory.Default); + getSpeculationLog(), getSuites(), true, new CompilationResult(), CompilationResultBuilderFactory.Default); + } + + protected SpeculationLog getSpeculationLog() { + return null; } protected InstalledCode addMethod(final ResolvedJavaMethod method, final CompilationResult compResult) { diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InfopointReasonTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InfopointReasonTest.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InfopointReasonTest.java Tue Jan 28 12:55:06 2014 +0100 @@ -63,7 +63,7 @@ final StructuredGraph graph = parse(method); CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false); final CompilationResult cr = compileGraph(graph, cc, graph.method(), getProviders(), getBackend(), getCodeCache().getTarget(), null, getDefaultGraphBuilderSuite(), - OptimisticOptimizations.ALL, getProfilingInfo(graph), new SpeculationLog(), getSuites(), true, new CompilationResult(), CompilationResultBuilderFactory.Default); + OptimisticOptimizations.ALL, getProfilingInfo(graph), null, getSuites(), true, new CompilationResult(), CompilationResultBuilderFactory.Default); for (Infopoint sp : cr.getInfopoints()) { assertNotNull(sp.reason); if (sp instanceof Call) { @@ -86,7 +86,7 @@ CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false); PhaseSuite graphBuilderSuite = getCustomGraphBuilderSuite(GraphBuilderConfiguration.getEagerInfopointDefault()); final CompilationResult cr = compileGraph(graph, cc, graph.method(), getProviders(), getBackend(), getCodeCache().getTarget(), null, graphBuilderSuite, OptimisticOptimizations.ALL, - getProfilingInfo(graph), new SpeculationLog(), getSuites(), true, new CompilationResult(), CompilationResultBuilderFactory.Default); + getProfilingInfo(graph), getSpeculationLog(), getSuites(), true, new CompilationResult(), CompilationResultBuilderFactory.Default); int lineSPs = 0; for (Infopoint sp : cr.getInfopoints()) { assertNotNull(sp.reason); diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ProfilingInfoTest.java Tue Jan 28 12:55:06 2014 +0100 @@ -323,7 +323,10 @@ } } - return javaMethod.getProfilingInfo(); + ProfilingInfo info = javaMethod.getProfilingInfo(); + // The execution counts are low so force maturity + info.setMature(); + return info; } private void resetProfile(String methodName) { diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java Tue Jan 28 12:55:06 2014 +0100 @@ -43,8 +43,8 @@ import com.oracle.graal.lir.asm.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.java.*; -import com.oracle.graal.nodes.type.*; import com.oracle.graal.phases.*; +import com.oracle.graal.phases.common.*; import com.oracle.graal.phases.tiers.*; import com.oracle.graal.phases.util.*; import com.oracle.graal.runtime.*; @@ -139,13 +139,12 @@ Providers providers = backend.getProviders(); TargetDescription target = providers.getCodeCache().getTarget(); PhaseSuite graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite().copy(); - graphBuilderSuite.appendPhase(new HSAILPhase()); - new HSAILPhase().apply(graph); + graphBuilderSuite.appendPhase(new NonNullParametersPhase()); CallingConvention cc = CodeUtil.getCallingConvention(providers.getCodeCache(), Type.JavaCallee, graph.method(), false); SuitesProvider suitesProvider = backend.getSuites(); try { HSAILCompilationResult compResult = compileGraph(graph, cc, graph.method(), providers, backend, target, null, graphBuilderSuite, OptimisticOptimizations.NONE, getProfilingInfo(graph), - new SpeculationLog(), suitesProvider.getDefaultSuites(), true, new HSAILCompilationResult(), CompilationResultBuilderFactory.Default); + null, suitesProvider.getDefaultSuites(), true, new HSAILCompilationResult(), CompilationResultBuilderFactory.Default); if ((validDevice) && (compResult.getTargetCode() != null)) { long kernel = toGPU.generateKernel(compResult.getTargetCode(), graph.method().getName()); @@ -173,18 +172,6 @@ } } - private static class HSAILPhase extends Phase { - - @Override - protected void run(StructuredGraph graph) { - for (ParameterNode param : graph.getNodes(ParameterNode.class)) { - if (param.stamp() instanceof ObjectStamp) { - param.setStamp(StampFactory.declaredNonNull(((ObjectStamp) param.stamp()).type())); - } - } - } - } - protected HSAILCompilationResult() { } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Tue Jan 28 12:55:06 2014 +0100 @@ -34,14 +34,14 @@ import java.util.*; import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.CallingConvention.*; +import com.oracle.graal.api.code.CallingConvention.Type; import com.oracle.graal.api.meta.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.ptx.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.ptx.*; import com.oracle.graal.debug.*; -import com.oracle.graal.debug.Debug.*; +import com.oracle.graal.debug.Debug.Scope; import com.oracle.graal.graph.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.HotSpotReplacementsImpl.GraphProducer; @@ -58,6 +58,7 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.cfg.*; import com.oracle.graal.phases.*; +import com.oracle.graal.phases.common.*; import com.oracle.graal.phases.tiers.*; import com.oracle.graal.word.*; @@ -67,7 +68,7 @@ public class PTXHotSpotBackend extends HotSpotBackend { /** - * Descriptor for the PTX runtime method for launching a kernel. The C++ signature is: + * Descriptor for the PTX runtime method for calling a kernel. The C++ signature is: * *
      *     jlong (JavaThread* thread,
@@ -77,11 +78,14 @@
      *            jint dimZ,
      *            jlong parametersAndReturnValueBuffer,
      *            jint parametersAndReturnValueBufferSize,
+     *            jint objectParametersCount,
+     *            jlong objectParametersOffsets,
+     *            jlong pinnedObjects,
      *            jint encodedReturnTypeSize)
      * 
*/ // @formatter:off - public static final ForeignCallDescriptor LAUNCH_KERNEL = new ForeignCallDescriptor("execute_kernel_from_vm", long.class, + public static final ForeignCallDescriptor CALL_KERNEL = new ForeignCallDescriptor("execute_kernel_from_vm", long.class, Word.class, // thread long.class, // kernel int.class, // dimX @@ -89,6 +93,9 @@ int.class, // dimZ long.class, // parametersAndReturnValueBuffer int.class, // parametersAndReturnValueBufferSize + int.class, // objectParameterCount + long.class, // objectParameterOffsets + long.class, // pinnedObjects int.class); // encodedReturnTypeSize // @formatter:on @@ -114,7 +121,7 @@ CompilerToGPU compilerToGPU = getRuntime().getCompilerToGPU(); if (deviceInitialized) { long launchKernel = compilerToGPU.getLaunchKernelAddress(); - hostForeignCalls.registerForeignCall(LAUNCH_KERNEL, launchKernel, NativeCall, DESTROYS_REGISTERS, NOT_LEAF, NOT_REEXECUTABLE, ANY_LOCATION); + hostForeignCalls.registerForeignCall(CALL_KERNEL, launchKernel, NativeCall, DESTROYS_REGISTERS, NOT_LEAF, NOT_REEXECUTABLE, ANY_LOCATION); } super.completeInitialization(); } @@ -166,11 +173,13 @@ HotSpotProviders providers = getProviders(); CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, method, false); PhaseSuite graphBuilderSuite = providers.getSuites().getDefaultGraphBuilderSuite(); + graphBuilderSuite.appendPhase(new NonNullParametersPhase()); Suites suites = providers.getSuites().getDefaultSuites(); - ExternalCompilationResult ptxCode = compileGraph(graph, cc, method, providers, this, this.getTarget(), null, graphBuilderSuite, OptimisticOptimizations.NONE, getProfilingInfo(graph), - new SpeculationLog(), suites, true, new ExternalCompilationResult(), CompilationResultBuilderFactory.Default); + ExternalCompilationResult ptxCode = compileGraph(graph, cc, method, providers, this, this.getTarget(), null, graphBuilderSuite, OptimisticOptimizations.NONE, getProfilingInfo(graph), null, + suites, true, new ExternalCompilationResult(), CompilationResultBuilderFactory.Default); if (makeBinary) { try (Scope ds = Debug.scope("GeneratingKernelBinary")) { + assert ptxCode.getTargetCode() != null; long kernel = getRuntime().getCompilerToGPU().generateKernel(ptxCode.getTargetCode(), method.getName()); ptxCode.setEntryPoint(kernel); } catch (Throwable e) { @@ -178,7 +187,6 @@ } } return ptxCode; - } /** diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotSuitesProvider.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotSuitesProvider.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2012, 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.hotspot.ptx; - -import com.oracle.graal.java.*; -import com.oracle.graal.phases.*; -import com.oracle.graal.phases.tiers.*; - -public class PTXHotSpotSuitesProvider implements SuitesProvider { - - private final Suites defaultSuites; - private final PhaseSuite defaultGraphBuilderSuite; - - public PTXHotSpotSuitesProvider() { - this.defaultGraphBuilderSuite = createGraphBuilderSuite(); - this.defaultSuites = createSuites(); - } - - public Suites getDefaultSuites() { - return defaultSuites; - } - - public Suites createSuites() { - return Suites.createDefaultSuites(); - } - - public PhaseSuite getDefaultGraphBuilderSuite() { - return defaultGraphBuilderSuite; - } - - protected PhaseSuite createGraphBuilderSuite() { - PhaseSuite suite = new PhaseSuite<>(); - suite.appendPhase(new GraphBuilderPhase(GraphBuilderConfiguration.getDefault())); - return suite; - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXWrapperBuilder.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXWrapperBuilder.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXWrapperBuilder.java Tue Jan 28 12:55:06 2014 +0100 @@ -55,21 +55,62 @@ /** * Utility for building a graph that "wraps" a compiled PTX kernel. Such a wrapper handles the - * transition from the host CPU to the GPU and back. The graph created is something like the - * following pseudo code with UPPER CASE denoting compile-time constants: + * transition from the host CPU to the GPU and back. The wrapper allocate 3 on-stack buffers: + *
    + *
  • PARAMS: a buffer for the kernel parameters and one word for the on-device address of the + * return value (if any).
  • + *
  • PINNED: a buffer into which the address of pinned objects is saved.
  • + *
  • OBJECT_OFFSETS: the offsets of the object values in PARAMS.
  • + *
+ * + * + * The PARAMS buffer is the {@code CU_LAUNCH_PARAM_BUFFER_POINTER} buffer passed in the + * {@code extra} argument to the {@code cuLaunchKernel} function. This buffer contains the + * parameters to the call. The buffer is word aligned and each parameter is aligned in the buffer + * according to its data size. The wrapper copies the incoming arguments into the buffer as is. The + * native {@link PTXHotSpotBackend#CALL_KERNEL callKernel} function will pin the memory for each + * object parameter (using {@code cuMemHostRegister}) and then replace the object pointer in PARAMS + * with an on-device pointer to the object's memory (see {@code cuMemHostGetDevicePointer}). The + * function saves pinned object pointer into PINNED so that it can unpinned once the kernel returns. + * The object pointers in PARAMS are specified by OBJECT_OFFSETS. + *

+ * As a concrete example, for a kernel whose Java method signature is: * *

- *     T kernel(p0, p1, ..., pN) {
- *         jint bufSize = SIZE_OF_ALIGNED_PARAMS_AND_RETURN_VALUE_WITH_PADDING(p0, p1, ..., pN);
- *         jbyte buf[bufSize] = {p0, PAD(p1), p1, ..., PAD(pN), pN};
- *         jlong result = PTX_LAUNCH_KERNEL(THREAD_REGISTER, KERNEL_ENTRY_POINT, dimX, dimY, dimZ, buf, bufSize, encodedReturnTypeSize);
- *         return convert(result);
+ *     static int kernel(int p1, short p2, Object p3, long p4)
+ * 
+ * + * the graph created is shown below as psuedo-code: + * + *
+ *     int kernel_wrapper(int p1, short p2, oop p3, long p4) {
+ *         address kernelAddr = kernel.start;
+ *         if (kernelAddr == 0) {
+ *             deopt(InvalidateRecompile, RuntimeConstraint);
+ *         }
+ *         byte PARAMS[32];
+ *         word PINNED[1]; // note: no refmap
+ *         int OBJECT_OFFSETS[1] = {8};
+ *         ((int*) PARAMS)[0] = p1;
+ *         ((short*) PARAMS)[2] = p2;
+ *         ((word*) PARAMS)[1] = p3;
+ *         ((long*) PARAMS)[2] = p4;
+ *         int result = CALL_KERNEL(THREAD_REGISTER, KERNEL_ENTRY_POINT, 1, 1, 1, PARAMS, 32, 1, OBJECT_OFFSETS, PINNED, 4);
+ *         if (clearPendingException(thread)) {
+ *             deopt(None, RuntimeConstraint);
+ *         }
+ *         return result;
  *     }
  * 
*

* The generated graph includes a reference to the {@link HotSpotNmethod} for the kernel. There must * be another reference to the same {@link HotSpotNmethod} object to ensure that the nmethod is not * unloaded by the next full GC. + *

+ * TODO: Only the memory for objects passed as parameters is pinned. Surely the memory for other + * objects accessed in the kernel reachable from the parameter objects needs to be pinned as well? + *

+ * TODO: Objects references within kernels are currently completely hidden from GC. */ public class PTXWrapperBuilder extends GraphKit { @@ -92,11 +133,23 @@ int[] javaParameterOffsetsInKernelParametersBuffer; /** - * Constants denoting the arguments to {@link PTXHotSpotBackend#LAUNCH_KERNEL}. + * Constants denoting the arguments to {@link PTXHotSpotBackend#CALL_KERNEL}. */ + // @formatter:off enum LaunchArg { - Thread, Kernel, DimX, DimY, DimZ, ParametersAndReturnValueBuffer, ParametersAndReturnValueBufferSize, EncodedReturnTypeSize + Thread, + Kernel, + DimX, + DimY, + DimZ, + ParametersAndReturnValueBuffer, + ParametersAndReturnValueBufferSize, + ObjectParametersCount, + ObjectParametersOffsets, + PinnedObjects, + EncodedReturnTypeSize } + // @formatter:on /** * Creates the graph implementing the CPU to GPU transition. @@ -108,6 +161,7 @@ public PTXWrapperBuilder(ResolvedJavaMethod method, HotSpotNmethod kernel, HotSpotProviders providers) { super(new StructuredGraph(method), providers); int wordSize = providers.getCodeCache().getTarget().wordSize; + int intSize = Integer.SIZE / Byte.SIZE; Kind wordKind = providers.getCodeCache().getTarget().wordKind; Signature sig = method.getSignature(); boolean isStatic = isStatic(method.getModifiers()); @@ -117,17 +171,18 @@ int javaParametersIndex = 0; Kind returnKind = sig.getReturnKind(); - BitSet objects = new BitSet(); + List objectSlots = new ArrayList<>(javaParameters.length); if (!isStatic) { - allocateParameter(Kind.Object, javaParametersIndex++, objects, wordSize); + allocateParameter(Kind.Object, javaParametersIndex++, objectSlots, wordSize); } for (int sigIndex = 0; sigIndex < sigCount; sigIndex++) { Kind kind = sig.getParameterKind(sigIndex); - allocateParameter(kind, javaParametersIndex++, objects, wordSize); + allocateParameter(kind, javaParametersIndex++, objectSlots, wordSize); } bufSize = roundUp(bufSize, wordSize); - // Add slot for holding pointer to device memory storing return value + // Add slot for the device memory pointer. The kernel writes a + // pointer in this slot that points to the return value. int encodedReturnTypeSize = 0; if (returnKind != Kind.Void) { bufSize += wordSize; @@ -140,7 +195,29 @@ InvokeNode kernelStart = createInvoke(getClass(), "getKernelStart", ConstantNode.forObject(kernel, providers.getMetaAccess(), getGraph())); - AllocaNode buf = append(new AllocaNode(bufSize / wordSize, objects)); + AllocaNode buf = append(new AllocaNode(bufSize / wordSize, new BitSet())); + ValueNode objectParametersOffsets; + ValueNode pinnedObjects; + ConstantNode nullWord = ConstantNode.forIntegerKind(wordKind, 0L, getGraph()); + if (objectSlots.isEmpty()) { + objectParametersOffsets = ConstantNode.forLong(0, getGraph()); + pinnedObjects = ConstantNode.forLong(0, getGraph()); + } else { + int intsPerWord = wordSize / intSize; + int slots = roundUp(objectSlots.size(), intsPerWord); + objectParametersOffsets = append(new AllocaNode(slots, new BitSet())); + // No refmap for pinned objects list since kernel execution is (currently) GC unsafe + pinnedObjects = append(new AllocaNode(objectSlots.size(), new BitSet())); + + // Initialize the object parameter offsets array + int index = 0; + for (int slot : objectSlots) { + int offset = slot * wordSize; + LocationNode location = ConstantLocationNode.create(FINAL_LOCATION, Kind.Int, index * intSize, getGraph()); + append(new WriteNode(objectParametersOffsets, ConstantNode.forInt(offset, getGraph()), location, BarrierType.NONE, false, false)); + index++; + } + } Map args = new EnumMap<>(LaunchArg.class); args.put(Thread, append(new ReadRegisterNode(providers.getRegisters().getThreadRegister(), true, false))); @@ -150,6 +227,9 @@ args.put(DimZ, forInt(1, getGraph())); args.put(ParametersAndReturnValueBuffer, buf); args.put(ParametersAndReturnValueBufferSize, forInt(bufSize, getGraph())); + args.put(ObjectParametersCount, forInt(objectSlots.size(), getGraph())); + args.put(ObjectParametersOffsets, objectParametersOffsets); + args.put(PinnedObjects, pinnedObjects); args.put(EncodedReturnTypeSize, forInt(encodedReturnTypeSize, getGraph())); int sigIndex = isStatic ? 0 : -1; @@ -162,7 +242,7 @@ } if (returnKind != Kind.Void) { LocationNode location = ConstantLocationNode.create(FINAL_LOCATION, wordKind, bufSize - wordSize, getGraph()); - append(new WriteNode(buf, ConstantNode.forIntegerKind(wordKind, 0L, getGraph()), location, BarrierType.NONE, false, false)); + append(new WriteNode(buf, nullWord, location, BarrierType.NONE, false, false)); } FrameStateBuilder fsb = new FrameStateBuilder(method, getGraph(), true); @@ -170,7 +250,7 @@ getGraph().start().setStateAfter(fs); ValueNode[] launchArgsArray = args.values().toArray(new ValueNode[args.size()]); - ForeignCallNode result = append(new ForeignCallNode(providers.getForeignCalls(), LAUNCH_KERNEL, launchArgsArray)); + ForeignCallNode result = append(new ForeignCallNode(providers.getForeignCalls(), CALL_KERNEL, launchArgsArray)); result.setDeoptimizationState(fs); ConstantNode isObjectResultArg = ConstantNode.forBoolean(returnKind == Kind.Object, getGraph()); @@ -193,7 +273,11 @@ case Long: returnValue = result; break; - case Float: + case Float: { + ValueNode asInt = unique(new ConvertNode(Kind.Long, Kind.Int, result)); + returnValue = unique(new ReinterpretNode(Kind.Float, asInt)); + break; + } case Double: returnValue = unique(new ReinterpretNode(returnKind, result)); break; @@ -220,12 +304,12 @@ } /** - * Allocates a slot in the kernel parameters' buffer for a Java parameter. + * Computes offset and size of space in PARAMS for a Java parameter. * * @param kind the kind of the parameter * @param javaParametersIndex the index of the Java parameter */ - private void allocateParameter(Kind kind, int javaParametersIndex, BitSet objects, int wordSize) { + private void allocateParameter(Kind kind, int javaParametersIndex, List objectSlots, int wordSize) { int kindByteSize = kind == Kind.Object ? wordSize : kind.getBitCount() / Byte.SIZE; bufSize = roundUp(bufSize, kindByteSize); javaParameterOffsetsInKernelParametersBuffer[javaParametersIndex] = bufSize; @@ -233,7 +317,7 @@ if (kind == Kind.Object) { stamp = StampFactory.object(); int slot = bufSize / wordSize; - objects.set(slot); + objectSlots.add(slot); } else { stamp = StampFactory.forKind(kind); } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/AheadOfTimeCompilationTest.java Tue Jan 28 12:55:06 2014 +0100 @@ -205,7 +205,7 @@ // create suites everytime, as we modify options for the compiler final Suites suitesLocal = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend().getSuites().createSuites(); final CompilationResult compResult = compileGraph(graph, cc, method, getProviders(), getBackend(), getCodeCache().getTarget(), null, getDefaultGraphBuilderSuite(), - OptimisticOptimizations.ALL, getProfilingInfo(graph), new SpeculationLog(), suitesLocal, true, new CompilationResult(), CompilationResultBuilderFactory.Default); + OptimisticOptimizations.ALL, getProfilingInfo(graph), getSpeculationLog(), suitesLocal, true, new CompilationResult(), CompilationResultBuilderFactory.Default); addMethod(method, compResult); } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Tue Jan 28 12:55:06 2014 +0100 @@ -258,6 +258,8 @@ */ long[] collectCounters(); + boolean isMature(long metaspaceMethodData); + /** * Generate a unique id to identify the result of the compile. */ diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Tue Jan 28 12:55:06 2014 +0100 @@ -169,5 +169,7 @@ public native long[] collectCounters(); + public native boolean isMature(long method); + public native int allocateCompileId(HotSpotResolvedJavaMethod method, int entryBCI); } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethodData.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethodData.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethodData.java Tue Jan 28 12:55:06 2014 +0100 @@ -207,6 +207,14 @@ return cells * config.dataLayoutCellSize; } + /** + * Returns whether profiling ran long enough that the profile information is mature. Other + * informational data will still be valid even if the profile isn't mature. + */ + public boolean isProfileMature() { + return runtime().getCompilerToVM().isMature(metaspaceMethodData); + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotProfilingInfo.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotProfilingInfo.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotProfilingInfo.java Tue Jan 28 12:55:06 2014 +0100 @@ -34,6 +34,7 @@ private final HotSpotMethodData methodData; private final HotSpotResolvedJavaMethod method; + private boolean isMature; private int position; private int hintPosition; private int hintBCI; @@ -47,6 +48,7 @@ this.method = method; this.includeNormal = includeNormal; this.includeOSR = includeOSR; + this.isMature = methodData.isProfileMature(); hintPosition = 0; hintBCI = -1; } @@ -58,24 +60,36 @@ @Override public JavaTypeProfile getTypeProfile(int bci) { + if (!isMature) { + return null; + } findBCI(bci, false); return dataAccessor.getTypeProfile(methodData, position); } @Override public JavaMethodProfile getMethodProfile(int bci) { + if (!isMature) { + return null; + } findBCI(bci, false); return dataAccessor.getMethodProfile(methodData, position); } @Override public double getBranchTakenProbability(int bci) { + if (!isMature) { + return -1; + } findBCI(bci, false); return dataAccessor.getBranchTakenProbability(methodData, position); } @Override public double[] getSwitchProbabilities(int bci) { + if (!isMature) { + return null; + } findBCI(bci, false); return dataAccessor.getSwitchProbabilities(methodData, position); } @@ -94,6 +108,9 @@ @Override public int getExecutionCount(int bci) { + if (!isMature) { + return -1; + } findBCI(bci, false); return dataAccessor.getExecutionCount(methodData, position); } @@ -172,11 +189,20 @@ @Override public boolean isMature() { - return true; + return isMature; + } + + public void ignoreMature() { + isMature = true; } @Override public String toString() { return "HotSpotProfilingInfo<" + MetaUtil.profileToString(this, null, "; ") + ">"; } + + @Override + public void setMature() { + isMature = true; + } } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/Stub.java Tue Jan 28 12:55:06 2014 +0100 @@ -146,8 +146,8 @@ // The stub itself needs the incoming calling convention. CallingConvention incomingCc = linkage.getIncomingCallingConvention(); final CompilationResult compResult = compileGraph(graph, incomingCc, getInstalledCodeOwner(), providers, backend, codeCache.getTarget(), null, - providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, getProfilingInfo(graph), new SpeculationLog(), - providers.getSuites().getDefaultSuites(), true, new CompilationResult(), CompilationResultBuilderFactory.Default); + providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, getProfilingInfo(graph), null, providers.getSuites().getDefaultSuites(), true, + new CompilationResult(), CompilationResultBuilderFactory.Default); assert destroyedRegisters != null; try (Scope s = Debug.scope("CodeInstall")) { diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.java.decompiler.test/src/com/oracle/graal/java/decompiler/test/TestUtil.java --- a/graal/com.oracle.graal.java.decompiler.test/src/com/oracle/graal/java/decompiler/test/TestUtil.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.java.decompiler.test/src/com/oracle/graal/java/decompiler/test/TestUtil.java Tue Jan 28 12:55:06 2014 +0100 @@ -49,7 +49,7 @@ new GraphBuilderPhase.Instance(metaAccess, GraphBuilderConfiguration.getEagerDefault(), OptimisticOptimizations.ALL).apply(graph); PhaseSuite graphBuilderSuite = suitesProvider.getDefaultGraphBuilderSuite(); CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, graph.method(), false); - compileGraph(graph, cc, method, providers, backend, providers.getCodeCache().getTarget(), null, graphBuilderSuite, OptimisticOptimizations.ALL, getProfilingInfo(graph), new SpeculationLog(), - suites, true, new CompilationResult(), CompilationResultBuilderFactory.Default); + compileGraph(graph, cc, method, providers, backend, providers.getCodeCache().getTarget(), null, graphBuilderSuite, OptimisticOptimizations.ALL, getProfilingInfo(graph), null, suites, true, + new CompilationResult(), CompilationResultBuilderFactory.Default); } } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Tue Jan 28 12:55:06 2014 +0100 @@ -316,7 +316,7 @@ spillSize += (slots * target.wordSize); if (!objects.isEmpty()) { - assert objects.length() < slots; + assert objects.length() <= slots; StackSlot result = null; for (int slotIndex = 0; slotIndex < slots; slotIndex++) { StackSlot objectSlot = null; diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/NonNullParametersPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/NonNullParametersPhase.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013, 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.phases.common; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.type.*; +import com.oracle.graal.phases.*; + +/** + * Modifies the stamp of all object {@linkplain ParameterNode parameters} in a graph to denote they + * are non-null. This can be used for graphs where the caller null checks all arguments. + */ +public class NonNullParametersPhase extends Phase { + + @Override + protected void run(StructuredGraph graph) { + for (ParameterNode param : graph.getNodes(ParameterNode.class)) { + if (param.stamp() instanceof ObjectStamp) { + param.setStamp(StampFactory.declaredNonNull(((ObjectStamp) param.stamp()).type())); + } + } + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/CollapseFrameForSingleSideEffectPhase.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/CollapseFrameForSingleSideEffectPhase.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/CollapseFrameForSingleSideEffectPhase.java Tue Jan 28 12:55:06 2014 +0100 @@ -24,6 +24,7 @@ import java.util.*; +import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.util.*; import com.oracle.graal.phases.*; @@ -42,25 +43,94 @@ * The invalid frame states ensure that no deoptimization to a snippet frame state will happen. */ public class CollapseFrameForSingleSideEffectPhase extends Phase { - @Override - protected void run(StructuredGraph graph) { - ReentrantNodeIterator.apply(new CollapseFrameForSingleSideEffectClosure(), graph.start(), null, null); + + private static class IterationState { + public final IterationState previous; + public final Node node; + public final Collection merge; + public final boolean invalid; + + private IterationState(IterationState previous, Node node, Collection merge, boolean invalid) { + this.previous = previous; + this.node = node; + this.merge = merge; + this.invalid = invalid; + } + + public IterationState() { + this(null, null, null, false); + } + + public IterationState addSideEffect(StateSplit sideEffect) { + return new IterationState(this, sideEffect.asNode(), null, true); + } + + public IterationState addBranch(AbstractBeginNode begin) { + return new IterationState(this, begin, null, this.invalid); + } + + public static IterationState merge(MergeNode merge, Collection before, boolean invalid) { + return new IterationState(null, merge, before, invalid); + } + + public void markAll(NodeBitMap set) { + IterationState state = this; + while (state != null && state.node != null && !set.contains(state.node)) { + set.mark(state.node); + if (state.merge != null) { + for (IterationState branch : state.merge) { + branch.markAll(set); + } + } + state = state.previous; + } + } + + public void markMasked(NodeBitMap unmasked, NodeBitMap masked) { + IterationState state = this; + while (state != null && state.node != null && !masked.contains(state.node)) { + if (state.node instanceof StateSplit) { + unmasked.mark(state.node); + StateSplit split = (StateSplit) state.node; + if (split.hasSideEffect() && state.previous != null) { + state.previous.markAll(masked); + return; + } + } + + if (state.merge != null) { + for (IterationState branch : state.merge) { + branch.markMasked(unmasked, masked); + } + } + state = state.previous; + } + } } - private static class CollapseFrameForSingleSideEffectClosure extends NodeIteratorClosure { + @Override + protected void run(StructuredGraph graph) { + CollapseFrameForSingleSideEffectClosure closure = new CollapseFrameForSingleSideEffectClosure(); + ReentrantNodeIterator.apply(closure, graph.start(), new IterationState(), null); + closure.finishProcessing(graph); + } + + private static class CollapseFrameForSingleSideEffectClosure extends NodeIteratorClosure { + + private List returnStates = new ArrayList<>(); + private List unwindStates = new ArrayList<>(); @Override - protected StateSplit processNode(FixedNode node, StateSplit currentState) { - StateSplit state = currentState; + protected IterationState processNode(FixedNode node, IterationState currentState) { + IterationState state = currentState; if (node instanceof StateSplit) { StateSplit stateSplit = (StateSplit) node; FrameState frameState = stateSplit.stateAfter(); if (frameState != null) { - // the stateSplit == currentState case comes from merge handling - if (stateSplit.hasSideEffect() || stateSplit == currentState) { + if (stateSplit.hasSideEffect()) { stateSplit.setStateAfter(createInvalidFrameState(node)); - state = stateSplit; - } else if (hasInvalidState(state)) { + state = state.addSideEffect(stateSplit); + } else if (currentState.invalid) { stateSplit.setStateAfter(createInvalidFrameState(node)); } else { stateSplit.setStateAfter(null); @@ -70,53 +140,77 @@ } } } - if (node instanceof ControlSinkNode && state != null) { - state.setStateAfter(node.graph().add(new FrameState(FrameState.AFTER_BCI))); + if (node instanceof ReturnNode) { + returnStates.add(currentState); + } else if (node instanceof UnwindNode) { + unwindStates.add(currentState); } return state; } @Override - protected StateSplit merge(MergeNode merge, List states) { + protected IterationState merge(MergeNode merge, List states) { boolean invalid = false; - for (StateSplit state : states) { - if (state != null && state.stateAfter() != null && state.stateAfter().bci == FrameState.INVALID_FRAMESTATE_BCI) { + for (IterationState state : states) { + if (state.invalid) { invalid = true; - state.setStateAfter(merge.graph().add(new FrameState(FrameState.AFTER_BCI))); + break; } } - if (invalid) { - // at the next processNode call, stateSplit == currentState == merge - return merge; - } else { - return null; + return IterationState.merge(merge, states, invalid); + } + + public void finishProcessing(StructuredGraph graph) { + NodeBitMap maskedSideEffects = new NodeBitMap(graph); + NodeBitMap returnSideEffects = new NodeBitMap(graph); + NodeBitMap unwindSideEffects = new NodeBitMap(graph); + + for (IterationState returnState : returnStates) { + returnState.markMasked(returnSideEffects, maskedSideEffects); + } + for (IterationState unwindState : unwindStates) { + unwindState.markMasked(unwindSideEffects, maskedSideEffects); + } + + for (Node returnSideEffect : returnSideEffects) { + if (!unwindSideEffects.contains(returnSideEffect) && !maskedSideEffects.contains(returnSideEffect)) { + StateSplit split = (StateSplit) returnSideEffect; + if (split.getState() != null) { + split.setStateAfter(graph.add(new FrameState(FrameState.AFTER_BCI))); + } + } + } + + for (Node unwindSideEffect : unwindSideEffects) { + if (!returnSideEffects.contains(unwindSideEffect) && !maskedSideEffects.contains(unwindSideEffect)) { + StateSplit split = (StateSplit) unwindSideEffect; + if (split.getState() != null) { + split.setStateAfter(graph.add(new FrameState(FrameState.AFTER_EXCEPTION_BCI))); + } + } } } @Override - protected StateSplit afterSplit(AbstractBeginNode node, StateSplit oldState) { - return oldState; + protected IterationState afterSplit(AbstractBeginNode node, IterationState oldState) { + return oldState.addBranch(node); } @Override - protected Map processLoop(LoopBeginNode loop, StateSplit initialState) { - LoopInfo info = ReentrantNodeIterator.processLoop(this, loop, initialState); - if (!hasInvalidState(initialState)) { - boolean isNowInvalid = false; - for (StateSplit endState : info.endStates.values()) { - isNowInvalid |= hasInvalidState(endState); - } - if (isNowInvalid) { - loop.setStateAfter(createInvalidFrameState(loop)); - info = ReentrantNodeIterator.processLoop(this, loop, loop); - } + protected Map processLoop(LoopBeginNode loop, IterationState initialState) { + LoopInfo info = ReentrantNodeIterator.processLoop(this, loop, initialState); + + boolean isNowInvalid = initialState.invalid; + for (IterationState endState : info.endStates.values()) { + isNowInvalid |= endState.invalid; } - return info.exitStates; - } - private static boolean hasInvalidState(StateSplit state) { - assert state == null || (state.stateAfter() != null && state.stateAfter().bci == FrameState.INVALID_FRAMESTATE_BCI) : state + " " + state.stateAfter(); - return state != null; + if (isNowInvalid) { + loop.setStateAfter(createInvalidFrameState(loop)); + } + + IterationState endState = IterationState.merge(loop, info.endStates.values(), isNowInvalid); + return ReentrantNodeIterator.processLoop(this, loop, endState).exitStates; } private static FrameState createInvalidFrameState(FixedNode node) { diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java Tue Jan 28 12:55:06 2014 +0100 @@ -70,7 +70,7 @@ protected InstalledCode assertPartialEvalEquals(String methodName, RootNode root, Arguments arguments) { Assumptions assumptions = new Assumptions(true); StructuredGraph actual = partialEval(root, arguments, assumptions, true); - InstalledCode result = new TruffleCompilerImpl().compileMethodHelper(actual, GraphBuilderConfiguration.getDefault(), assumptions, root.toString()); + InstalledCode result = new TruffleCompilerImpl().compileMethodHelper(actual, GraphBuilderConfiguration.getDefault(), assumptions, root.toString(), getSpeculationLog()); StructuredGraph expected = parseForComparison(methodName); removeFrameStates(actual); Assert.assertEquals(getCanonicalGraphString(expected, true), getCanonicalGraphString(actual, true)); diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Tue Jan 28 12:55:06 2014 +0100 @@ -48,7 +48,6 @@ import com.oracle.graal.runtime.*; import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.impl.*; import com.oracle.truffle.api.nodes.*; /** @@ -73,9 +72,9 @@ return "Graal Truffle Runtime"; } - public CallTarget createCallTarget(RootNode rootNode) { + public RootCallTarget createCallTarget(RootNode rootNode) { if (!acceptForCompilation(rootNode)) { - return new DefaultCallTarget(rootNode); + return new UnoptimizedCallTarget(rootNode); } if (truffleCompiler == null) { truffleCompiler = new TruffleCompilerImpl(); @@ -198,8 +197,8 @@ CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, graph.method(), false); Backend backend = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend(); CompilationResultBuilderFactory factory = getOptimizedCallTargetInstrumentationFactory(backend.getTarget().arch.getName(), javaMethod); - return compileGraph(graph, cc, javaMethod, providers, backend, providers.getCodeCache().getTarget(), null, graphBuilderSuite, OptimisticOptimizations.ALL, getProfilingInfo(graph), - new SpeculationLog(), suites, true, new CompilationResult(), factory); + return compileGraph(graph, cc, javaMethod, providers, backend, providers.getCodeCache().getTarget(), null, graphBuilderSuite, OptimisticOptimizations.ALL, getProfilingInfo(graph), null, + suites, true, new CompilationResult(), factory); } private static Providers getGraalProviders() { diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Tue Jan 28 12:55:06 2014 +0100 @@ -50,12 +50,13 @@ private final TruffleInlining inlining; private boolean compilationEnabled; private int callCount; + private SpeculationLog speculationLog = new SpeculationLog(); protected OptimizedCallTarget(RootNode rootNode, TruffleCompiler compiler, int invokeCounter, int compilationThreshold) { super(rootNode); this.compiler = compiler; this.compilationProfile = new CompilationProfile(compilationThreshold, invokeCounter, rootNode.toString()); - this.rootNode.setCallTarget(this); + this.getRootNode().setCallTarget(this); if (TruffleUseTimeForCompilationDecision.getValue()) { compilationPolicy = new TimedCompilationPolicy(); @@ -117,7 +118,7 @@ installedCode = null; compilationProfile.reportInvalidated(); if (TraceTruffleCompilation.getValue()) { - OUT.printf("[truffle] invalidated %-48s |Inv# %d |Replace# %d\n", rootNode, compilationProfile.getInvalidationCount(), + OUT.printf("[truffle] invalidated %-48s |Inv# %d |Replace# %d\n", getRootNode(), compilationProfile.getInvalidationCount(), compilationProfile.getNodeReplaceCount()); } } @@ -183,7 +184,7 @@ return installedCodeTask.get(); } catch (InterruptedException | ExecutionException e) { compilationEnabled = false; - OUT.printf("[truffle] opt failed %-48s %s\n", rootNode, e.getMessage()); + OUT.printf("[truffle] opt failed %-48s %s\n", getRootNode(), e.getMessage()); if (e.getCause() instanceof BailoutException) { // Bailout => move on. } else { @@ -212,8 +213,8 @@ } public Object executeHelper(PackedFrame caller, Arguments args) { - VirtualFrame frame = createFrame(rootNode.getFrameDescriptor(), caller, args); - return rootNode.execute(frame); + VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), caller, args); + return getRootNode().execute(frame); } protected static FrameWithoutBoxing createFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments args) { @@ -305,4 +306,8 @@ }); } } + + public SpeculationLog getSpeculationLog() { + return speculationLog; + } } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Tue Jan 28 12:55:06 2014 +0100 @@ -156,7 +156,7 @@ } long timePartialEvaluationFinished = System.nanoTime(); int nodeCountPartialEval = graph.getNodeCount(); - InstalledCode compiledMethod = compileMethodHelper(graph, config, assumptions, compilable.toString()); + InstalledCode compiledMethod = compileMethodHelper(graph, config, assumptions, compilable.toString(), compilable.getSpeculationLog()); long timeCompilationFinished = System.nanoTime(); int nodeCountLowered = graph.getNodeCount(); @@ -210,7 +210,7 @@ } } - public InstalledCode compileMethodHelper(StructuredGraph graph, GraphBuilderConfiguration config, Assumptions assumptions, String name) { + public InstalledCode compileMethodHelper(StructuredGraph graph, GraphBuilderConfiguration config, Assumptions assumptions, String name, SpeculationLog speculationLog) { try (Scope s = Debug.scope("TruffleFinal")) { Debug.dump(graph, "After TruffleTier"); } catch (Throwable e) { @@ -223,7 +223,7 @@ CallingConvention cc = getCallingConvention(codeCache, Type.JavaCallee, graph.method(), false); CompilationResult compilationResult = new CompilationResult(name); result = compileGraph(graph, cc, graph.method(), providers, backend, codeCache.getTarget(), null, createGraphBuilderSuite(config), OptimisticOptimizations.ALL, getProfilingInfo(graph), - new SpeculationLog(), suites, false, compilationResult, CompilationResultBuilderFactory.Default); + speculationLog, suites, false, compilationResult, CompilationResultBuilderFactory.Default); } catch (Throwable e) { throw Debug.handle(e); } @@ -246,7 +246,7 @@ InstalledCode installedCode = null; try (Scope s = Debug.scope("CodeInstall", providers.getCodeCache()); TimerCloseable a = CodeInstallationTime.start()) { - installedCode = providers.getCodeCache().addMethod(graph.method(), result, null); + installedCode = providers.getCodeCache().addMethod(graph.method(), result, speculationLog); } catch (Throwable e) { throw Debug.handle(e); } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleDebugJavaMethod.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleDebugJavaMethod.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleDebugJavaMethod.java Tue Jan 28 12:55:06 2014 +0100 @@ -26,14 +26,14 @@ import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; -import com.oracle.truffle.api.impl.*; +import com.oracle.truffle.api.*; /** * Enables a Truffle compilable to masquerade as a {@link JavaMethod} for use as a context value in * {@linkplain Debug#scope(String, Object...) debug scopes}. */ public class TruffleDebugJavaMethod implements JavaMethod { - private final DefaultCallTarget compilable; + private final RootCallTarget compilable; private static final JavaType declaringClass = new JavaType() { @@ -95,7 +95,7 @@ } }; - public TruffleDebugJavaMethod(DefaultCallTarget compilable) { + public TruffleDebugJavaMethod(RootCallTarget compilable) { this.compilable = compilable; } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInliningImpl.java Tue Jan 28 12:55:06 2014 +0100 @@ -28,7 +28,7 @@ import java.util.*; import com.oracle.graal.debug.*; -import com.oracle.truffle.api.impl.*; +import com.oracle.truffle.api.*; import com.oracle.truffle.api.nodes.*; class TruffleInliningImpl implements TruffleInlining { @@ -207,7 +207,7 @@ } } - static List getInlinableCallSites(final DefaultCallTarget target) { + static List getInlinableCallSites(final RootCallTarget target) { final ArrayList inlinableCallSites = new ArrayList<>(); target.getRootNode().accept(new NodeVisitor() { diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleTreeDumpHandler.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleTreeDumpHandler.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleTreeDumpHandler.java Tue Jan 28 12:55:06 2014 +0100 @@ -23,15 +23,15 @@ package com.oracle.graal.truffle; import com.oracle.graal.debug.*; -import com.oracle.truffle.api.impl.*; +import com.oracle.truffle.api.*; import com.oracle.truffle.api.nodes.*; public class TruffleTreeDumpHandler implements DebugDumpHandler { @Override public void dump(Object object, final String message) { - if (object instanceof DefaultCallTarget) { - DefaultCallTarget callTarget = (DefaultCallTarget) object; + if (object instanceof RootCallTarget) { + RootCallTarget callTarget = (RootCallTarget) object; if (callTarget.getRootNode() != null) { new GraphPrintVisitor().beginGroup(callTarget.toString()).beginGraph(message).visit(callTarget.getRootNode()).printToNetwork(); } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/UnoptimizedCallTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/UnoptimizedCallTarget.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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; + +import com.oracle.truffle.api.impl.*; +import com.oracle.truffle.api.nodes.*; + +/** + * Call target that is not optimized by Graal upon surpassing a specific invocation threshold. + */ +public final class UnoptimizedCallTarget extends DefaultCallTarget { + + protected UnoptimizedCallTarget(RootNode rootNode) { + super(rootNode); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CallTarget.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CallTarget.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CallTarget.java Tue Jan 28 12:55:06 2014 +0100 @@ -27,8 +27,7 @@ import com.oracle.truffle.api.frame.*; /** - * Represents the target of a call. Instances of this interface can be created using the - * {@link TruffleRuntime#createCallTarget(com.oracle.truffle.api.nodes.RootNode)} method. + * Represents the target of a call. */ public abstract class CallTarget { diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/RootCallTarget.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/RootCallTarget.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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.truffle.api; + +import com.oracle.truffle.api.nodes.*; + +/** + * Represents the target of a call to a {@link RootNode}, i.e., to another tree of nodes. Instances + * of this class can be created using {@link TruffleRuntime#createCallTarget(RootNode)}. + */ +public abstract class RootCallTarget extends CallTarget { + + private final RootNode rootNode; + + public RootCallTarget(RootNode function) { + this.rootNode = function; + this.rootNode.setCallTarget(this); + } + + @Override + public String toString() { + return rootNode.toString(); + } + + public RootNode getRootNode() { + return rootNode; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntime.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntime.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleRuntime.java Tue Jan 28 12:55:06 2014 +0100 @@ -48,7 +48,7 @@ * represents the entry point * @return the new call target object */ - CallTarget createCallTarget(RootNode rootNode); + RootCallTarget createCallTarget(RootNode rootNode); /** * Creates a new assumption object that can be checked and invalidated. diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultAssumption.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultAssumption.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultAssumption.java Tue Jan 28 12:55:06 2014 +0100 @@ -24,11 +24,16 @@ */ package com.oracle.truffle.api.impl; +import com.oracle.truffle.api.*; import com.oracle.truffle.api.nodes.*; -public final class DefaultAssumption extends AbstractAssumption { +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link TruffleRuntime#createAssumption()} to create an {@link Assumption}. + */ +final class DefaultAssumption extends AbstractAssumption { - public DefaultAssumption(String name) { + DefaultAssumption(String name) { super(name); } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallTarget.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallTarget.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultCallTarget.java Tue Jan 28 12:55:06 2014 +0100 @@ -28,27 +28,19 @@ import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.nodes.*; -public class DefaultCallTarget extends CallTarget { - - protected final RootNode rootNode; +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link TruffleRuntime#createCallTarget(RootNode)} to create a {@link RootCallTarget}. + */ +public class DefaultCallTarget extends RootCallTarget { - public DefaultCallTarget(RootNode function) { - this.rootNode = function; - this.rootNode.setCallTarget(this); - } - - @Override - public String toString() { - return rootNode.toString(); + protected DefaultCallTarget(RootNode function) { + super(function); } @Override public Object call(PackedFrame caller, Arguments args) { - VirtualFrame frame = new DefaultVirtualFrame(rootNode.getFrameDescriptor(), caller, args); - return rootNode.execute(frame); - } - - public RootNode getRootNode() { - return rootNode; + VirtualFrame frame = new DefaultVirtualFrame(getRootNode().getFrameDescriptor(), caller, args); + return getRootNode().execute(frame); } } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultMaterializedFrame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultMaterializedFrame.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultMaterializedFrame.java Tue Jan 28 12:55:06 2014 +0100 @@ -27,11 +27,16 @@ import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link TruffleRuntime#createMaterializedFrame(Arguments)} or {@link Frame#materialize()} to + * create a {@link MaterializedFrame}. + */ final class DefaultMaterializedFrame implements MaterializedFrame, PackedFrame { private final DefaultVirtualFrame wrapped; - protected DefaultMaterializedFrame(DefaultVirtualFrame wrapped) { + DefaultMaterializedFrame(DefaultVirtualFrame wrapped) { this.wrapped = wrapped; } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultPackedFrame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultPackedFrame.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultPackedFrame.java Tue Jan 28 12:55:06 2014 +0100 @@ -26,11 +26,15 @@ import com.oracle.truffle.api.frame.*; +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link Frame#pack()} to create a {@link PackedFrame}. + */ final class DefaultPackedFrame implements PackedFrame { private final DefaultVirtualFrame wrapped; - protected DefaultPackedFrame(DefaultVirtualFrame wrapped) { + DefaultPackedFrame(DefaultVirtualFrame wrapped) { this.wrapped = wrapped; } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultTruffleRuntime.java Tue Jan 28 12:55:06 2014 +0100 @@ -31,16 +31,25 @@ /** * Default implementation of the Truffle runtime if the virtual machine does not provide a better * performing alternative. + *

+ * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link Truffle#getRuntime()} to retrieve the current {@link TruffleRuntime}. */ public final class DefaultTruffleRuntime implements TruffleRuntime { + public DefaultTruffleRuntime() { + if (Truffle.getRuntime() != null) { + throw new IllegalArgumentException("Cannot instantiate DefaultTruffleRuntime. Use Truffle.getRuntime() instead."); + } + } + @Override public String getName() { return "Default Truffle Runtime"; } @Override - public CallTarget createCallTarget(RootNode rootNode) { + public RootCallTarget createCallTarget(RootNode rootNode) { return new DefaultCallTarget(rootNode); } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java Tue Jan 28 12:55:06 2014 +0100 @@ -29,7 +29,12 @@ import com.oracle.truffle.api.*; import com.oracle.truffle.api.frame.*; -public final class DefaultVirtualFrame implements VirtualFrame { +/** + * This is an implementation-specific class. Do not use or instantiate it. Instead, use + * {@link TruffleRuntime#createVirtualFrame(PackedFrame, Arguments, FrameDescriptor)} to create a + * {@link VirtualFrame}. + */ +final class DefaultVirtualFrame implements VirtualFrame { private final FrameDescriptor descriptor; private final PackedFrame caller; @@ -37,7 +42,7 @@ private Object[] locals; private byte[] tags; - public DefaultVirtualFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments arguments) { + DefaultVirtualFrame(FrameDescriptor descriptor, PackedFrame caller, Arguments arguments) { this.descriptor = descriptor; this.caller = caller; this.arguments = arguments; diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/AbstractTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/AbstractTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 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.truffle.sl.test; - -import java.io.*; - -import org.junit.*; - -import com.oracle.truffle.sl.*; - -public class AbstractTest { - - public static final int REPEATS = 10; - private static final String NEWLINE = System.getProperty("line.separator"); - - private static String concat(String[] string) { - StringBuilder result = new StringBuilder(); - for (String s : string) { - result.append(s).append(NEWLINE); - } - return result.toString(); - } - - private static String repeat(String s, int count) { - StringBuilder result = new StringBuilder(s.length() * count); - for (int i = 0; i < count; i++) { - result.append(s); - } - return result.toString(); - } - - protected static void executeSL(String[] input, String[] expectedOutput, boolean useConsole) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - PrintStream printer = new PrintStream(useConsole ? new SplitOutputStream(out, System.err) : out); - PrintStream origErr = System.err; - System.setErr(printer); - - SimpleLanguage.run("(test)", concat(input), printer, REPEATS, false); - - System.setErr(origErr); - Assert.assertEquals(repeat(concat(expectedOutput), REPEATS), new String(out.toByteArray())); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/AddTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/AddTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class AddTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { ", - " print(3 + 4); ", - " print(3 + \"4\"); ", - " print(\"3\" + 4); ", - " print(\"3\" + \"4\"); ", - " print(3 + 4000000000000); ", - " print(3000000000000 + 4); ", - " print(3000000000000 + 4000000000000); ", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "7", - "34", - "34", - "34", - "4000000000003", - "3000000000004", - "7000000000000", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/BuiltinsTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/BuiltinsTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class BuiltinsTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { ", - " print(\"Hello World!\"); ", - " time(); ", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "Hello World!", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/CallTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/CallTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class CallTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function ret(a) { return a; } ", - "function dub(a) { return a * 2; } ", - "function inc(a) { return a + 1; } ", - "function dec(a) { return a - 1; } ", - "function call(f, v) { return f(v); } ", - "function main { ", - " print(ret(42));", - " print(dub(21));", - " print(inc(41));", - " print(dec(43));", - " print(call(ret, 42));", - " print(call(dub, 21));", - " print(call(inc, 41));", - " print(call(dec, 43));", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "42", - "42", - "42", - "42", - "42", - "42", - "42", - "42", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/ComparisonTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/ComparisonTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class ComparisonTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { ", - " print(4 < 20); ", - " print(4 < \"20\"); ", - " print(\"4\" < 20); ", - " print(\"4\" < \"20\"); ", - " print(4 < 20000000000000); ", - " print(4000000000000 < 20); ", - " print(4000000000000 < 20000000000000); ", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "true", - "false", - "false", - "false", - "true", - "false", - "true", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/DivTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/DivTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class DivTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { ", - " print(4 / 2); ", - " print(4 / 4000000000000); ", - " print(3000000000000 / 3); ", - " print(3000000000000 / 3000000000000); ", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "2", - "0", - "1000000000000", - "1", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/FibonacciTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/FibonacciTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 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.truffle.sl.test; - -import javax.script.*; - -import org.junit.*; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.sl.*; -import com.oracle.truffle.sl.runtime.*; - -// @formatter:off -public class FibonacciTest extends AbstractTest{ - - private static String[] INPUT = new String[] { - "function fib(num) { ", - " if (num < 1) {return 0;}", - " n1 = 0;", - " n2 = 1;", - " i = 1;", - " while (i < num) {", - " next = n2 + n1;", - " n1 = n2;", - " n2 = next;", - " i = i + 1;", - " }", - " return n2;", - "}", - "function main(num) { ", - " return fib(num);", - "} ", - }; - - // java reference - private static int test(int num) { - if (num <= 0) { - return 0; - } - int n1 = 0; - int n2 = 1; - for (int i = 1; i < num; i++) { - final int next = n2 + n1; - n1 = n2; - n2 = next; - } - return n2; - } - - private static final int TEST_VALUE = 42; - private static final int ITERATIONS = 5000; - - @Test - public void test() throws ScriptException { - StringBuilder s = new StringBuilder(); - for (String line : INPUT) { - s.append(line).append("\n"); - } - final SLContext context = new SLContext(System.out); - final Source source = context.getSourceManager().get("(fib test)", s.toString()); - SLScript script = SLScript.create(context, source); - Integer reference = test(TEST_VALUE); - for (int i = 0; i < ITERATIONS; i++) { - if (!reference.equals(script.run(TEST_VALUE))) { - throw new AssertionError(); - } - } - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/LoopPrintTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/LoopPrintTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class LoopPrintTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { ", - " i = 0; ", - " while (i < 1000) { ", - " i = i + 1; ", - " } ", - " print(i); ", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "1000", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/LoopTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/LoopTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class LoopTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { ", - " i = 0; ", - " while (i < 1000) { ", - " i = i + 1; ", - " } ", - " return i; ", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "1000", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/MulTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/MulTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class MulTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { ", - " print(3 * 4); ", - " print(3 * 4000000000000); ", - " print(3000000000000 * 4); ", - " print(3000000000000 * 4000000000000); ", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "12", - "12000000000000", - "12000000000000", - "12000000000000000000000000", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2012, 2013, 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.truffle.sl.test; + +import java.io.*; +import java.nio.file.*; +import java.nio.file.attribute.*; +import java.util.*; + +import org.junit.*; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.source.*; +import com.oracle.truffle.sl.*; +import com.oracle.truffle.sl.runtime.*; + +public class SLTestRunner { + + private static final int REPEATS = 10; + private static final String TEST_DIR = "graal/com.oracle.truffle.sl.test/tests"; + private static final String INPUT_SUFFIX = ".sl"; + private static final String OUTPUT_SUFFIX = ".output"; + + static class TestCase { + protected final String name; + protected final Source input; + protected final String expectedOutput; + protected String actualOutput; + + protected TestCase(String name, Source input, String expectedOutput) { + this.name = name; + this.input = input; + this.expectedOutput = expectedOutput; + } + } + + protected boolean useConsole = false; + + protected final SourceManager sourceManager = new SourceManager(); + protected final List testCases = new ArrayList<>(); + + protected boolean runTests(String namePattern) throws IOException { + Path testsRoot = FileSystems.getDefault().getPath(TEST_DIR); + + Files.walkFileTree(testsRoot, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path inputFile, BasicFileAttributes attrs) throws IOException { + String name = inputFile.getFileName().toString(); + if (name.endsWith(INPUT_SUFFIX)) { + name = name.substring(0, name.length() - INPUT_SUFFIX.length()); + Path outputFile = inputFile.resolveSibling(name + OUTPUT_SUFFIX); + if (!Files.exists(outputFile)) { + throw new Error("Output file does not exist: " + outputFile); + } + + testCases.add(new TestCase(name, sourceManager.get(inputFile.toString()), new String(Files.readAllBytes(outputFile)))); + } + return FileVisitResult.CONTINUE; + } + }); + + if (testCases.size() == 0) { + System.out.format("No test cases match filter %s", namePattern); + return false; + } + + boolean success = true; + for (TestCase testCase : testCases) { + if (namePattern.length() == 0 || testCase.name.toLowerCase().contains(namePattern.toLowerCase())) { + success = success & executeTest(testCase); + } + } + return success; + } + + protected boolean executeTest(TestCase testCase) { + System.out.format("Running %s\n", testCase.name); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintStream printer = new PrintStream(useConsole ? new SplitOutputStream(out, System.err) : out); + PrintStream origErr = System.err; + try { + System.setErr(printer); + SLContext context = new SLContext(sourceManager, printer); + SLMain.run(context, testCase.input, null, REPEATS); + } catch (Throwable ex) { + ex.printStackTrace(printer); + } finally { + System.setErr(origErr); + } + testCase.actualOutput = new String(out.toByteArray()); + + if (testCase.actualOutput.equals(repeat(testCase.expectedOutput, REPEATS))) { + System.out.format("OK %s\n", testCase.name); + return true; + } else { + if (!useConsole) { + System.out.format("== Expected ==\n%s\n", testCase.expectedOutput); + System.out.format("== Actual ==\n%s\n", testCase.actualOutput); + } + System.out.format("FAILED %s\n", testCase.name); + return false; + } + } + + private static String repeat(String s, int count) { + StringBuilder result = new StringBuilder(s.length() * count); + for (int i = 0; i < count; i++) { + result.append(s); + } + return result.toString(); + } + + public static void main(String[] args) throws IOException { + String namePattern = ""; + if (args.length > 0) { + namePattern = args[0]; + } + boolean success = new SLTestRunner().runTests(namePattern); + if (!success) { + System.exit(1); + } + } + + @Test + public void test() throws IOException { + Assert.assertTrue(runTests("")); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SubTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SubTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class SubTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { ", - " print(3 - 4); ", - " print(3 - 4000000000000); ", - " print(3000000000000 - 4); ", - " print(3000000000000 - 4000000000000); ", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "-1", - "-3999999999997", - "2999999999996", - "-1000000000000", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SumTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SumTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class SumTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { ", - " i = 0; ", - " sum = 0; ", - " while (i < 100000) { ", - " sum = sum + 1000000; ", - " i = i + 1; ", - " } ", - " return sum; ", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "100000000000", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/TernaryTest.java --- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/TernaryTest.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.test; - -import org.junit.*; - -// @formatter:off -public class TernaryTest extends AbstractTest { - - private static String[] INPUT = new String[] { - "function main { " + - " print(#(1 < 2) ? 1 : 2);" + - " print(#(2 < 1) ? 100000000000000 : 1); ", - " print(#(1 < 2) ? 100000000000000 : 1); ", - " print(#(2 < 1) ? \"wrong\" : \"true\");", - " print(#(2 < 1) ? \"wrong\" : 1);", - "} ", - }; - - private static String[] OUTPUT = new String[] { - "1", - "1", - "100000000000000", - "true", - "1", - }; - - @Test - public void test() { - executeSL(INPUT, OUTPUT, false); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Add.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Add.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,7 @@ +7 +34 +34 +34 +4000000000003 +3000000000004 +7000000000000 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Add.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Add.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,9 @@ +function main() { + print(3 + 4); + print(3 + "4"); + print("3" + 4); + print("3" + "4"); + print(3 + 4000000000000); + print(3000000000000 + 4); + print(3000000000000 + 4000000000000); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Arithmetic.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Arithmetic.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,10 @@ +5 +1 +-3 +14 +11 +5 +-3 +1 +18 +11 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Arithmetic.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Arithmetic.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,12 @@ +function main() { + print(3 + 4 - 2); + print(3 - 4 + 2); + print(3 - 4 - 2); + print(3 * 4 + 2); + print(3 + 4 * 2); + print(3 + (4 - 2)); + print(3 - (4 + 2)); + print(3 - (4 - 2)); + print(3 * (4 + 2)); + print(3 + (4 * 2)); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Builtins.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Builtins.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,1 @@ +Hello World! diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Builtins.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Builtins.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,4 @@ +function main() { + print("Hello World!"); + time(); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Call.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Call.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,8 @@ +42 +42 +42 +42 +42 +42 +42 +42 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Call.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Call.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,16 @@ +function ret(a) { return a; } +function dub(a) { return a * 2; } +function inc(a) { return a + 1; } +function dec(a) { return a - 1; } +function call(f, v) { return f(v); } + +function main() { + print(ret(42)); + print(dub(21)); + print(inc(41)); + print(dec(43)); + print(call(ret, 42)); + print(call(dub, 21)); + print(call(inc, 41)); + print(call(dec, 43)); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Comparison.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Comparison.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,7 @@ +true +false +false +false +true +false +true diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Comparison.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Comparison.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,9 @@ +function main() { + print(4 < 20); + print(4 < "20"); + print("4" < 20); + print("4" < "20"); + print(4 < 20000000000000); + print(4000000000000 < 20); + print(4000000000000 < 20000000000000); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/DefineFunction.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/DefineFunction.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,2 @@ +42 +38 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/DefineFunction.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/DefineFunction.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,11 @@ +function foo() { + print(test(40, 2)); +} + +function main() { + defineFunction("function test(a, b) { return a + b; }"); + foo(); + + defineFunction("function test(a, b) { return a - b; }"); + foo(); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Div.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Div.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,4 @@ +2 +0 +1000000000000 +1 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Div.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Div.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,6 @@ +function main() { + print(4 / 2); + print(4 / 4000000000000); + print(3000000000000 / 3); + print(3000000000000 / 3000000000000); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Fibonacci.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Fibonacci.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,1 @@ +267914296 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Fibonacci.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Fibonacci.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,17 @@ +function fib(num) { + if (num < 1) {return 0;} + n1 = 0; + n2 = 1; + i = 1; + while (i < num) { + next = n2 + n1; + n1 = n2; + n2 = next; + i = i + 1; + } + return n2; +} + +function main() { + print(fib(42)); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Loop.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Loop.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,1 @@ +1000 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Loop.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Loop.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,7 @@ +function main() { + i = 0; + while (i < 1000) { + i = i + 1; + } + return i; +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/LoopPrint.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/LoopPrint.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,1 @@ +1000 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/LoopPrint.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/LoopPrint.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,7 @@ +function main() { + i = 0; + while (i < 1000) { + i = i + 1; + } + print(i); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Mul.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Mul.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,4 @@ +12 +12000000000000 +12000000000000 +12000000000000000000000000 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Mul.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Mul.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,6 @@ +function main() { + print(3 * 4); + print(3 * 4000000000000); + print(3000000000000 * 4); + print(3000000000000 * 4000000000000); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Sub.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Sub.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,4 @@ +-1 +-3999999999997 +2999999999996 +-1000000000000 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Sub.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Sub.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,6 @@ +function main() { + print(3 - 4); + print(3 - 4000000000000); + print(3000000000000 - 4); + print(3000000000000 - 4000000000000); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Sum.output --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Sum.output Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,1 @@ +100000000000 diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl.test/tests/Sum.sl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl.test/tests/Sum.sl Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,9 @@ +function main() { + i = 0; + sum = 0; + while (i < 100000) { + sum = sum + 1000000; + i = i + 1; + } + return sum; +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLException.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2014, 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.truffle.sl; + +public class SLException extends RuntimeException { + private static final long serialVersionUID = -6799734410727348507L; + + public SLException(String message) { + super(message); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2012, 2013, 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.truffle.sl; + +import java.io.*; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.api.source.*; +import com.oracle.truffle.sl.parser.*; +import com.oracle.truffle.sl.runtime.*; + +public class SLMain { + + private static final Object[] NO_ARGUMENTS = new Object[0]; + + public static void main(String[] args) { + SourceManager sourceManager = new SourceManager(); + Source source = sourceManager.get(args[0]); + SLContext context = new SLContext(sourceManager, System.err); + run(context, source, System.out, 1); + } + + public static void run(SLContext context, Source source, PrintStream logOutput, int repeats) { + if (logOutput != null) { + logOutput.println("== running on " + Truffle.getRuntime().getName()); + } + + Parser.parseSL(context, source); + SLFunction main = context.getFunctionRegistry().lookup("main"); + if (main.getCallTarget() == null) { + throw new SLException("No function main() found."); + } + + if (logOutput != null) { + printScript(context, logOutput); + } + try { + for (int i = 0; i < repeats; i++) { + long start = System.nanoTime(); + Object result = main.getCallTarget().call(null, new SLArguments(NO_ARGUMENTS)); + long end = System.nanoTime(); + + if (result != SLNull.INSTANCE) { + context.getPrintOutput().println(result); + } + if (logOutput != null) { + logOutput.printf("== iteration %d: %.3f ms\n", (i + 1), (end - start) / 1000000.0); + } + } + + } finally { + if (logOutput != null) { + printScript(context, logOutput); + } + } + } + + private static void printScript(SLContext context, PrintStream logOutput) { + for (SLFunction function : context.getFunctionRegistry().getFunctions()) { + if (function.getCallTarget() != null) { + logOutput.println("=== function " + function.getName()); + NodeUtil.printTree(logOutput, function.getCallTarget().getRootNode()); + } + } + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 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.truffle.sl; - -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.api.nodes.*; - -@TypeSystemReference(SLTypes.class) -public class SLNode extends Node { - - public SLNode() { - // No source attribution - super(null); - } - - @Override - public String toString() { - return getEncapsulatingSourceSection() != null ? getEncapsulatingSourceSection().toString() : super.toString(); - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLNodeFactory.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLNodeFactory.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl; - -import java.math.*; -import java.util.*; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; -import com.oracle.truffle.sl.nodes.ArithmeticNodeFactory.AddNodeFactory; -import com.oracle.truffle.sl.nodes.ArithmeticNodeFactory.DivNodeFactory; -import com.oracle.truffle.sl.nodes.ArithmeticNodeFactory.MulNodeFactory; -import com.oracle.truffle.sl.nodes.ArithmeticNodeFactory.SubNodeFactory; -import com.oracle.truffle.sl.nodes.*; -import com.oracle.truffle.sl.parser.*; -import com.oracle.truffle.sl.runtime.*; - -public class SLNodeFactory { - - private final SLContext context; - - private Parser parser; - private FrameDescriptor frameDescriptor; - private TypedNode returnValue; - - private Source source; - private String currentFunctionName; - - public SLNodeFactory(SLContext context) { - this.context = context; - } - - public void setSource(Source source) { - this.source = source; - } - - public void setParser(Parser parser) { - this.parser = parser; - } - - public void startFunction() { - frameDescriptor = new FrameDescriptor(); - } - - public void createFunction(StatementNode body, String name, String[] parameterNames) { - context.getFunctionRegistry().register(name, FunctionRootNode.createFunction(body, frameDescriptor, name, returnValue, parameterNames)); - this.currentFunctionName = name; - this.returnValue = null; - } - - private T assignSource(T node) { - node.assignSourceSection(ParserUtils.createSourceSection(source, currentFunctionName, parser)); - return node; - } - - public TypedNode createLocal(String name) { - return assignSource(new ReadUninitializedNode(context, frameDescriptor.findOrAddFrameSlot(name, FrameSlotKind.Int))); - } - - public TypedNode createStringLiteral(String value) { - return assignSource(new StringLiteralNode(value)); - } - - public TypedNode createAssignment(TypedNode read, TypedNode assignment) { - FrameSlot slot = ((ReadUninitializedNode) read).getSlot(); - return assignSource(WriteLocalNodeFactory.create(slot, assignment)); - } - - public StatementNode createWhile(ConditionNode condition, StatementNode body) { - return assignSource(new WhileNode(condition, body)); - } - - public StatementNode createBlock(List statements) { - return assignSource(new BlockNode(statements.toArray(new StatementNode[statements.size()]))); - } - - public TypedNode createCall(TypedNode function, TypedNode[] parameters) { - return assignSource(FunctionCallNode.create(function, parameters)); - } - - public TypedNode createBinary(String operation, TypedNode left, TypedNode right) { - TypedNode binary; - switch (operation) { - case "+": - binary = AddNodeFactory.create(left, right); - break; - case "*": - binary = MulNodeFactory.create(left, right); - break; - case "/": - binary = DivNodeFactory.create(left, right); - break; - case "-": - binary = SubNodeFactory.create(left, right); - break; - case "<": - binary = LessThanNodeFactory.create(left, right); - break; - case "&&": - binary = LogicalAndNodeFactory.create(left, right); - break; - default: - throw new RuntimeException("unexpected operation: " + operation); - } - return assignSource(binary); - } - - public TypedNode createNumericLiteral(String value) { - try { - return assignSource(new IntegerLiteralNode(Integer.parseInt(value))); - } catch (NumberFormatException ex) { - return assignSource(new BigIntegerLiteralNode(new BigInteger(value))); - } - } - - public StatementNode createReturn(TypedNode value) { - FrameSlot slot = frameDescriptor.findOrAddFrameSlot("", FrameSlotKind.Int); - if (returnValue == null) { - returnValue = ReadLocalNodeFactory.create(slot); - } - StatementNode write = WriteLocalNodeFactory.create(slot, value); - return assignSource(new ReturnNode(write)); - } - - public TypedNode createTernary(TypedNode condition, TypedNode thenPart, TypedNode elsePart) { - return assignSource(TernaryNodeFactory.create(condition, thenPart, elsePart)); - } - - public StatementNode createIf(ConditionNode condition, StatementNode then, StatementNode elseNode) { - return assignSource(IfNodeFactory.create(then, elseNode, condition)); - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLScript.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLScript.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 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.truffle.sl; - -import javax.script.*; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.sl.parser.*; -import com.oracle.truffle.sl.runtime.*; - -public final class SLScript { - - private final SLContext context; - private final CallTarget main; - - private SLScript(SLContext context, CallTarget mainFunction) { - this.context = context; - this.main = mainFunction; - } - - public SLContext getContext() { - return context; - } - - public CallTarget getMain() { - return main; - } - - public Object run(Object... arguments) { - return main.call(null, new SLArguments(arguments)); - } - - @Override - public String toString() { - return main.toString(); - } - - public static SLScript create(SLContext context, Source source) throws ScriptException { - SLNodeFactory factory = new SLNodeFactory(context); - Parser parser = new Parser(new Scanner(source.getInputStream()), factory); - factory.setParser(parser); - factory.setSource(source); - String error = parser.ParseErrors(); - if (!error.isEmpty()) { - throw new ScriptException(String.format("Error(s) parsing script: %s", error)); - } - - CallTarget main = context.getFunctionRegistry().lookup("main"); - if (main == null) { - throw new ScriptException("No main function found."); - } - return new SLScript(context, main); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLTypes.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLTypes.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl; - -import java.math.*; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.sl.runtime.*; - -@TypeSystem({int.class, BigInteger.class, boolean.class, String.class, CallTarget.class, SLNull.class, Object[].class}) -public class SLTypes { - - @TypeCheck - public boolean isSLNull(Object value) { - return SLNull.INSTANCE == value; - } - - @TypeCast - public SLNull asSLNull(Object value) { - assert isSLNull(value); - return SLNull.INSTANCE; - } - - @ImplicitCast - public BigInteger castBigInteger(int integer) { - return BigInteger.valueOf(integer); - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SimpleLanguage.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SimpleLanguage.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 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.truffle.sl; - -import java.io.*; - -import javax.script.*; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.impl.*; -import com.oracle.truffle.api.nodes.*; -import com.oracle.truffle.sl.runtime.*; - -public class SimpleLanguage { - - private static final Object[] NO_ARGUMENTS = new Object[0]; - - public static void main(String[] args) { - run(args[0], System.out, 10, true); - } - - public static void run(String name, String input, PrintStream printOutput, int repeats, boolean log) { - if (log) { - // CheckStyle: stop system..print check - System.out.printf("== running on %s\n", Truffle.getRuntime().getName()); - // CheckStyle: resume system..print check - } - - final SLContext context = new SLContext(printOutput); - final Source source = context.getSourceManager().get(name, input); - - run(context, source, printOutput, repeats, log); - } - - public static void run(String fileName, PrintStream printOutput, int repeats, boolean log) { - if (log) { - // CheckStyle: stop system..print check - System.out.printf("== running on %s\n", Truffle.getRuntime().getName()); - // CheckStyle: resume system..print check - } - - final SLContext context = new SLContext(printOutput); - final Source source = context.getSourceManager().get(fileName); - - run(context, source, printOutput, repeats, log); - } - - public static void run(SLContext context, Source source, PrintStream printOutput, int repeats, boolean log) { - - SLScript script; - try { - script = SLScript.create(context, source); - } catch (ScriptException e) { - // TODO temporary hack - throw new RuntimeException(e); - } - - if (log) { - printScript(script); - } - try { - for (int i = 0; i < repeats; i++) { - long start = System.nanoTime(); - Object result = script.run(NO_ARGUMENTS); - long end = System.nanoTime(); - - if (result != null) { - printOutput.println(result); - } - if (log) { - // CheckStyle: stop system..print check - System.out.printf("== iteration %d: %.3f ms\n", (i + 1), (end - start) / 1000000.0); - // CheckStyle: resume system..print check - } - } - - } finally { - if (log) { - printScript(script); - } - } - } - - private static void printScript(SLScript script) { - NodeUtil.printTree(System.out, ((DefaultCallTarget) script.getMain()).getRootNode()); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/BuiltinNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/BuiltinNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.builtins; - -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.sl.nodes.*; -import com.oracle.truffle.sl.runtime.*; - -@NodeField(name = "context", type = SLContext.class) -@NodeChild(value = "arguments", type = TypedNode[].class) -public abstract class BuiltinNode extends TypedNode { - - public abstract SLContext getContext(); - - public abstract TypedNode[] getArguments(); - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/DefaultBuiltins.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/DefaultBuiltins.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.builtins; - -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.sl.nodes.*; -import com.oracle.truffle.sl.runtime.*; - -public abstract class DefaultBuiltins { - - public static void install(SLContext c) { - installBuiltin(c, PrintBuiltinFactory.getInstance(), "print"); - installBuiltin(c, TimeBuiltinFactory.getInstance(), "time"); - } - - private static void installBuiltin(SLContext context, NodeFactory factory, String name) { - context.getFunctionRegistry().register(name, FunctionRootNode.createBuiltin(context, factory, name)); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/PrintBuiltin.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/PrintBuiltin.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.builtins; - -import com.oracle.truffle.api.dsl.*; - -public abstract class PrintBuiltin extends BuiltinNode { - - @Specialization - public int doInt(int value) { - getContext().getPrintOutput().println(value); - return value; - } - - @Specialization - public boolean doBoolean(boolean value) { - getContext().getPrintOutput().println(value); - return value; - } - - @Specialization - public String doString(String value) { - getContext().getPrintOutput().println(value); - return value; - } - - @Specialization - public Object doGeneric(Object value) { - getContext().getPrintOutput().println(value.toString()); - return value; - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLBuiltinNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLBuiltinNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.builtins; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +@NodeField(name = "context", type = SLContext.class) +@NodeChild(value = "arguments", type = SLExpressionNode[].class) +public abstract class SLBuiltinNode extends SLExpressionNode { + + public abstract SLContext getContext(); + + public abstract SLExpressionNode[] getArguments(); + +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLDefineFunctionBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLDefineFunctionBuiltin.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.builtins; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.parser.*; + +public abstract class SLDefineFunctionBuiltin extends SLBuiltinNode { + + @Specialization + public String defineFunction(String code) { + Source source = getContext().getSourceManager().get("dynamic", code); + Parser.parseSL(getContext(), source); + return code; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLPrintBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLPrintBuiltin.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.builtins; + +import com.oracle.truffle.api.dsl.*; + +public abstract class SLPrintBuiltin extends SLBuiltinNode { + + @Specialization + public long print(long value) { + getContext().getPrintOutput().println(value); + return value; + } + + @Specialization + public boolean print(boolean value) { + getContext().getPrintOutput().println(value); + return value; + } + + @Specialization + public String print(String value) { + getContext().getPrintOutput().println(value); + return value; + } + + @Specialization + public Object print(Object value) { + getContext().getPrintOutput().println(value.toString()); + return value; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLTimeBuiltin.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLTimeBuiltin.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.builtins; + +import com.oracle.truffle.api.dsl.*; + +public abstract class SLTimeBuiltin extends SLBuiltinNode { + + public static final long START_TIME = System.currentTimeMillis(); + + @Specialization + public long time() { + return System.nanoTime(); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/TimeBuiltin.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/TimeBuiltin.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.builtins; - -import com.oracle.truffle.api.dsl.*; - -public abstract class TimeBuiltin extends BuiltinNode { - - public static final long START_TIME = System.currentTimeMillis(); - - @Specialization - public int doInt() { - return (int) (System.currentTimeMillis() - START_TIME); - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArgumentsNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArgumentsNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; - -public final class ArgumentsNode extends TypedNode { - - @Children private final TypedNode[] arguments; - - public ArgumentsNode(TypedNode[] arguments) { - this.arguments = adoptChildren(arguments); - } - - public TypedNode[] getArguments() { - return arguments; - } - - @Override - public Object[] executeGeneric(VirtualFrame frame) { - return executeArray(frame); - } - - @Override - @ExplodeLoop - public Object[] executeArray(VirtualFrame frame) { - Object[] argumentValues = new Object[arguments.length]; - for (int i = 0; i < arguments.length; i++) { - argumentValues[i] = arguments[i].executeGeneric(frame); - } - return argumentValues; - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArithmeticNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ArithmeticNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import java.math.*; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.dsl.*; - -public abstract class ArithmeticNode extends BinaryNode { - - public abstract static class AddNode extends ArithmeticNode { - - @Specialization(rewriteOn = ArithmeticException.class) - int doInt(int left, int right) { - return ExactMath.addExact(left, right); - } - - @Specialization - BigInteger doBigInteger(BigInteger left, BigInteger right) { - return left.add(right); - } - - @Specialization - String doString(String left, String right) { - return left + right; - } - - @Specialization(guards = "isString") - String add(Object left, Object right) { - return left.toString() + right.toString(); - } - } - - public abstract static class SubNode extends ArithmeticNode { - - @Specialization(rewriteOn = ArithmeticException.class) - int sub(int left, int right) { - return ExactMath.subtractExact(left, right); - } - - @Specialization - BigInteger sub(BigInteger left, BigInteger right) { - return left.subtract(right); - } - - } - - public abstract static class DivNode extends ArithmeticNode { - - @Specialization(rewriteOn = ArithmeticException.class) - int div(int left, int right) { - return left / right; - } - - @Specialization - BigInteger div(BigInteger left, BigInteger right) { - return left.divide(right); - } - } - - public abstract static class MulNode extends ArithmeticNode { - - @Specialization(rewriteOn = ArithmeticException.class) - int mul(int left, int right) { - return ExactMath.multiplyExact(left, right); - } - - @Specialization - BigInteger mul(BigInteger left, BigInteger right) { - return left.multiply(right); - } - - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BigIntegerLiteralNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BigIntegerLiteralNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import java.math.*; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; - -public final class BigIntegerLiteralNode extends TypedNode { - - private final BigInteger value; - - public BigIntegerLiteralNode(BigInteger value) { - this.value = value; - } - - @Override - public BigInteger executeBigInteger(VirtualFrame frame) throws UnexpectedResultException { - return value; - } - - @Override - public Object executeGeneric(VirtualFrame frame) { - return value; - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BinaryNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BinaryNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.dsl.*; - -@NodeChildren({@NodeChild("leftNode"), @NodeChild("rightNode")}) -public abstract class BinaryNode extends TypedNode { - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BlockNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BlockNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; - -public class BlockNode extends StatementNode { - - @Children private final StatementNode[] statements; - - public BlockNode(StatementNode[] statements) { - this.statements = adoptChildren(statements); - } - - @Override - @ExplodeLoop - public void executeVoid(VirtualFrame frame) { - for (StatementNode statement : statements) { - statement.executeVoid(frame); - } - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BreakException.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BreakException.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.nodes.*; - -public final class BreakException extends ControlFlowException { - - private static final long serialVersionUID = -91013036379258890L; -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BreakNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BreakNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; - -public final class BreakNode extends StatementNode { - - private final BreakException target; - - public BreakNode(BreakException target) { - this.target = target; - } - - @Override - public void executeVoid(VirtualFrame frame) { - throw target; - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ConditionNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ConditionNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; - -public abstract class ConditionNode extends StatementNode { - - public abstract boolean executeCondition(VirtualFrame frame); - - @Override - public void executeVoid(VirtualFrame frame) { - executeCondition(frame); - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ContinueException.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ContinueException.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.nodes.*; - -public final class ContinueException extends ControlFlowException { - - private static final long serialVersionUID = 5329687983726237188L; -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ContinueNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ContinueNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; - -public final class ContinueNode extends StatementNode { - - private final ContinueException target; - - public ContinueNode(ContinueException target) { - this.target = target; - } - - @Override - public void executeVoid(VirtualFrame frame) { - throw target; - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FrameSlotNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FrameSlotNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; - -public abstract class FrameSlotNode extends TypedNode { - - protected final FrameSlot slot; - - public FrameSlotNode(FrameSlot slot) { - this.slot = slot; - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionBodyNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionBodyNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; - -public class FunctionBodyNode extends TypedNode { - - @Child private StatementNode body; - @Child private TypedNode returnValue; - @Child private StatementNode writeArguments; - - private FrameDescriptor frameDescriptor; - - public FunctionBodyNode(FrameDescriptor frameDescriptor, StatementNode body, TypedNode returnValue, String[] parameterNames) { - this.frameDescriptor = frameDescriptor; - this.body = adoptChild(body); - this.returnValue = adoptChild(returnValue); - this.writeArguments = adoptChild(new BlockNode(createWriteArguments(parameterNames))); - } - - @Override - public Object executeGeneric(VirtualFrame frame) { - writeArguments.executeVoid(frame); - try { - body.executeVoid(frame); - } catch (ReturnException ex) { - // Nothing to do, we just need to return. - } - if (returnValue != null) { - return returnValue.executeGeneric(frame); - } else { - return null; - } - } - - @Override - public Node copy() { - FunctionBodyNode copy = (FunctionBodyNode) super.copy(); - copy.frameDescriptor = frameDescriptor.shallowCopy(); - return copy; - } - - private StatementNode[] createWriteArguments(String[] parameterNames) { - StatementNode[] writeNodes = new StatementNode[parameterNames.length]; - for (int i = 0; i < parameterNames.length; i++) { - FrameSlot frameSlot = frameDescriptor.findOrAddFrameSlot(parameterNames[i]); - writeNodes[i] = WriteLocalNodeFactory.create(frameSlot, new ReadArgumentNode(i)); - } - return writeNodes; - } - - public FrameDescriptor getFrameDescriptor() { - return frameDescriptor; - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionRootNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/FunctionRootNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 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.truffle.sl.nodes; - -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.builtins.*; -import com.oracle.truffle.sl.runtime.*; - -public final class FunctionRootNode extends RootNode { - - @Child private TypedNode body; - - private final TypedNode uninitializedBody; - private final String name; - private final boolean inlineImmediatly; - - private FunctionRootNode(FrameDescriptor frameDescriptor, TypedNode body, String name, boolean inlineImmediatly) { - super(null, frameDescriptor); - this.uninitializedBody = NodeUtil.cloneNode(body); - this.body = adoptChild(body); - this.name = name; - this.inlineImmediatly = inlineImmediatly; - } - - public static CallTarget createBuiltin(SLContext context, NodeFactory factory, String name) { - int argumentCount = factory.getExecutionSignature().size(); - TypedNode[] arguments = new TypedNode[argumentCount]; - for (int i = 0; i < arguments.length; i++) { - arguments[i] = new ReadArgumentNode(i); - } - BuiltinNode buitinBody = factory.createNode(arguments, context); - FunctionRootNode root = new FunctionRootNode(new FrameDescriptor(), buitinBody, name, true); - return Truffle.getRuntime().createCallTarget(root); - } - - public static CallTarget createFunction(StatementNode body, FrameDescriptor frameDescriptor, String name, TypedNode returnValue, String[] parameterNames) { - FunctionBodyNode bodyContainer = new FunctionBodyNode(frameDescriptor, body, returnValue, parameterNames); - FunctionRootNode root = new FunctionRootNode(frameDescriptor, bodyContainer, name, false); - return Truffle.getRuntime().createCallTarget(root); - } - - @Override - public Object execute(VirtualFrame frame) { - return body.executeGeneric(frame); - } - - public boolean isInlineImmediatly() { - return inlineImmediatly; - } - - @Override - public RootNode inline() { - return new FunctionRootNode(getFrameDescriptor().shallowCopy(), NodeUtil.cloneNode(uninitializedBody), name, inlineImmediatly); - } - - @Override - public int getInlineNodeCount() { - return NodeUtil.countNodes(uninitializedBody); - } - - @Override - public boolean isInlinable() { - return true; - } - - public Node getUninitializedBody() { - return uninitializedBody; - } - - @Override - public String toString() { - return "function " + name; - } - - public String getName() { - return name; - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IfNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IfNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.utilities.*; - -@NodeChild(value = "conditionNode", type = ConditionNode.class) -public abstract class IfNode extends StatementNode { - - @Child private StatementNode thenPartNode; - @Child private StatementNode elsePartNode; - - private final BranchProfile ifBranch = new BranchProfile(); - private final BranchProfile elseBranch = new BranchProfile(); - - public IfNode(StatementNode thenPart, StatementNode elsePart) { - this.thenPartNode = adoptChild(thenPart); - this.elsePartNode = adoptChild(elsePart); - } - - protected IfNode(IfNode node) { - this(node.thenPartNode, node.elsePartNode); - } - - @Specialization - public void doVoid(VirtualFrame frame, boolean condition) { - if (condition) { - ifBranch.enter(); - thenPartNode.executeVoid(frame); - } else { - if (elsePartNode != null) { - elseBranch.enter(); - elsePartNode.executeVoid(frame); - } - } - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IntegerLiteralNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IntegerLiteralNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; - -public final class IntegerLiteralNode extends TypedNode { - - private final int value; - - public IntegerLiteralNode(int value) { - this.value = value; - } - - @Override - public int executeInteger(VirtualFrame frame) throws UnexpectedResultException { - return value; - } - - @Override - public Object executeGeneric(VirtualFrame frame) { - return value; - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LessThanNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LessThanNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import java.math.*; - -import com.oracle.truffle.api.dsl.*; - -public abstract class LessThanNode extends BinaryNode { - - @Specialization - public boolean doInteger(int left, int right) { - return left < right; - } - - @Specialization - public boolean doBigInteger(BigInteger left, BigInteger right) { - return left.compareTo(right) < 0; - } - - @Specialization(guards = "isString") - public boolean doString(Object left, Object right) { - return left.toString().compareTo(right.toString()) < 0; - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LogicalAndNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/LogicalAndNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.dsl.*; - -@SuppressWarnings("unused") -public abstract class LogicalAndNode extends BinaryNode { - - @ShortCircuit("rightNode") - public boolean needsRightNode(boolean left) { - return left; - } - - @ShortCircuit("rightNode") - public boolean needsRightNode(Object left) { - return left instanceof Boolean && (Boolean) left; - } - - @Specialization - public boolean doBoolean(boolean left, boolean hasRight, boolean right) { - return hasRight && right; - } - - @Generic - public Object doGeneric(Object left, boolean hasRight, Object right) { - throw new RuntimeException("operation not defined for type " + left.getClass().getSimpleName()); - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/NullLiteralNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/NullLiteralNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.sl.runtime.*; - -public final class NullLiteralNode extends TypedNode { - - @Override - public Object executeGeneric(VirtualFrame frame) { - return executeNull(frame); - } - - @Override - public SLNull executeNull(VirtualFrame frame) { - return SLNull.INSTANCE; - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadArgumentNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadArgumentNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.utilities.*; -import com.oracle.truffle.sl.runtime.*; - -public class ReadArgumentNode extends TypedNode { - - private final int index; - - private final BranchProfile outOfBounds = new BranchProfile(); - private final BranchProfile inBounds = new BranchProfile(); - - public ReadArgumentNode(int index) { - this.index = index; - } - - @Override - public Object executeGeneric(VirtualFrame frame) { - Object[] args = SLArguments.get(frame).arguments; - if (index < args.length) { - inBounds.enter(); - return args[index]; - } else { - outOfBounds.enter(); - return SLNull.INSTANCE; - } - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadFunctionNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadFunctionNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, 2013, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.utilities.*; -import com.oracle.truffle.sl.runtime.*; - -public final class ReadFunctionNode extends TypedNode { - - private final SLFunctionRegistry registry; - private final String name; - private final BranchProfile invalidFunction = new BranchProfile(); - - public ReadFunctionNode(SLFunctionRegistry registry, String name) { - this.registry = registry; - this.name = name; - } - - @Override - public Object executeGeneric(VirtualFrame frame) { - return executeCallTarget(frame); - } - - @Override - public CallTarget executeCallTarget(VirtualFrame frame) { - CallTarget target = registry.lookup(name); - if (target != null) { - return target; - } - invalidFunction.enter(); - throw new RuntimeException("Function with name '" + name + "' not found."); - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadLocalNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadLocalNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.api.frame.*; - -@PolymorphicLimit(1) -public abstract class ReadLocalNode extends FrameSlotNode { - - public ReadLocalNode(FrameSlot slot) { - super(slot); - } - - public ReadLocalNode(ReadLocalNode specialized) { - this(specialized.slot); - } - - @Specialization(rewriteOn = {FrameSlotTypeException.class}) - public int doInteger(VirtualFrame frame) throws FrameSlotTypeException { - return frame.getInt(slot); - } - - @Specialization(rewriteOn = {FrameSlotTypeException.class}) - public boolean doBoolean(VirtualFrame frame) throws FrameSlotTypeException { - return frame.getBoolean(slot); - } - - @Specialization(rewriteOn = {FrameSlotTypeException.class}) - public Object doObject(VirtualFrame frame) throws FrameSlotTypeException { - return frame.getObject(slot); - } - - @Generic - public Object doGeneric(VirtualFrame frame) { - return frame.getValue(slot); - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadUninitializedNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReadUninitializedNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.sl.runtime.*; - -public class ReadUninitializedNode extends TypedNode { - - private final SLContext context; - private final FrameSlot slot; - - public ReadUninitializedNode(SLContext context, FrameSlot slot) { - this.context = context; - this.slot = slot; - } - - public FrameSlot getSlot() { - return slot; - } - - @Override - public Object executeGeneric(VirtualFrame frame) { - CompilerDirectives.transferToInterpreter(); - Object result = frame.getValue(slot); - String identifier = (String) slot.getIdentifier(); - if (result == null) { - // function access - return replace(new ReadFunctionNode(context.getFunctionRegistry(), identifier)).executeGeneric(frame); - } else { - // local variable access - return replace(ReadLocalNodeFactory.create(slot)).executeGeneric(frame); - } - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReturnException.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReturnException.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.nodes.*; - -public final class ReturnException extends ControlFlowException { - - private static final long serialVersionUID = 4073191346281369231L; -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReturnNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/ReturnNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; - -public class ReturnNode extends StatementNode { - - private static final ReturnException EXCEPTION = new ReturnException(); - - @Child private StatementNode expr; - - public ReturnNode(StatementNode expr) { - this.expr = adoptChild(expr); - } - - @Override - public void executeVoid(VirtualFrame frame) { - expr.executeVoid(frame); - throw EXCEPTION; - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLBinaryNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLBinaryNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; + +import com.oracle.truffle.api.dsl.*; + +@NodeChildren({@NodeChild("leftNode"), @NodeChild("rightNode")}) +public abstract class SLBinaryNode extends SLExpressionNode { + + public boolean isString(Object a, Object b) { + return a instanceof String || b instanceof String; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLExpressionNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLExpressionNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; + +import java.math.*; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +public abstract class SLExpressionNode extends SLStatementNode { + + public abstract Object executeGeneric(VirtualFrame frame); + + public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException { + return SLTypesGen.SLTYPES.expectBoolean(executeGeneric(frame)); + } + + public long executeLong(VirtualFrame frame) throws UnexpectedResultException { + return SLTypesGen.SLTYPES.expectLong(executeGeneric(frame)); + } + + public BigInteger executeBigInteger(VirtualFrame frame) throws UnexpectedResultException { + return SLTypesGen.SLTYPES.expectBigInteger(executeGeneric(frame)); + } + + public String executeString(VirtualFrame frame) throws UnexpectedResultException { + return SLTypesGen.SLTYPES.expectString(executeGeneric(frame)); + } + + public SLFunction executeFunction(VirtualFrame frame) throws UnexpectedResultException { + return SLTypesGen.SLTYPES.expectSLFunction(executeGeneric(frame)); + } + + public Object[] executeArray(VirtualFrame frame) throws UnexpectedResultException { + return SLTypesGen.SLTYPES.expectObjectArray(executeGeneric(frame)); + } + + public SLNull executeNull(VirtualFrame frame) throws UnexpectedResultException { + return SLTypesGen.SLTYPES.expectSLNull(executeGeneric(frame)); + } + + public final boolean executeCondition(VirtualFrame frame) { + try { + return executeBoolean(frame); + } catch (UnexpectedResultException ex) { + throw new RuntimeException("Illegal type for condition: " + ex.getResult().getClass().getSimpleName()); + } + } + + @Override + public void executeVoid(VirtualFrame frame) { + executeGeneric(frame); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLRootNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLRootNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2012, 2013, 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.truffle.sl.nodes; + +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.builtins.*; +import com.oracle.truffle.sl.nodes.controlflow.*; +import com.oracle.truffle.sl.nodes.local.*; +import com.oracle.truffle.sl.runtime.*; + +public final class SLRootNode extends RootNode { + + @Child private SLExpressionNode body; + + private final SLExpressionNode uninitializedBody; + private final String name; + private final boolean inlineImmediatly; + + public static RootCallTarget createFunction(String name, FrameDescriptor frameDescriptor, SLStatementNode body) { + SLFunctionBodyNode bodyContainer = new SLFunctionBodyNode(frameDescriptor, body); + SLRootNode root = new SLRootNode(frameDescriptor, bodyContainer, name, false); + return Truffle.getRuntime().createCallTarget(root); + } + + public static RootCallTarget createBuiltin(SLContext context, NodeFactory factory, String name) { + int argumentCount = factory.getExecutionSignature().size(); + SLExpressionNode[] arguments = new SLExpressionNode[argumentCount]; + for (int i = 0; i < arguments.length; i++) { + arguments[i] = new SLReadArgumentNode(i); + } + SLBuiltinNode buitinBody = factory.createNode(arguments, context); + SLRootNode root = new SLRootNode(new FrameDescriptor(), buitinBody, name, true); + return Truffle.getRuntime().createCallTarget(root); + } + + private SLRootNode(FrameDescriptor frameDescriptor, SLExpressionNode body, String name, boolean inlineImmediatly) { + super(null, frameDescriptor); + this.uninitializedBody = NodeUtil.cloneNode(body); + this.body = adoptChild(body); + this.name = name; + this.inlineImmediatly = inlineImmediatly; + } + + @Override + public Object execute(VirtualFrame frame) { + return body.executeGeneric(frame); + } + + public boolean isInlineImmediatly() { + return inlineImmediatly; + } + + @Override + public RootNode inline() { + return new FunctionRootNode(getFrameDescriptor().shallowCopy(), NodeUtil.cloneNode(uninitializedBody), name, inlineImmediatly); + } + + @Override + public int getInlineNodeCount() { + return NodeUtil.countNodes(uninitializedBody); + } + + @Override + public boolean isInlinable() { + return true; + } + + public Node getUninitializedBody() { + return uninitializedBody; + } + + @Override + public String toString() { + return "function " + name; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLStatementNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012, 2013, 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.truffle.sl.nodes; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; + +@TypeSystemReference(SLTypes.class) +public abstract class SLStatementNode extends Node { + + public abstract void executeVoid(VirtualFrame frame); + + @Override + public String toString() { + return getEncapsulatingSourceSection() != null ? getEncapsulatingSourceSection().toString() : super.toString(); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLTypes.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/SLTypes.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; + +import java.math.*; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.runtime.*; + +@TypeSystem({long.class, BigInteger.class, boolean.class, String.class, SLFunction.class, SLNull.class, Object[].class}) +public class SLTypes { + + @TypeCheck + public boolean isSLNull(Object value) { + return SLNull.INSTANCE == value; + } + + @TypeCast + public SLNull asSLNull(Object value) { + assert isSLNull(value); + return SLNull.INSTANCE; + } + + @ImplicitCast + public BigInteger castBigInteger(long value) { + return BigInteger.valueOf(value); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StatementNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StatementNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.sl.*; - -public abstract class StatementNode extends SLNode { - - public abstract void executeVoid(VirtualFrame frame); - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StringLiteralNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StringLiteralNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; - -public final class StringLiteralNode extends TypedNode { - - private final String value; - - public StringLiteralNode(String value) { - this.value = value; - } - - @Override - public String executeString(VirtualFrame frame) { - return value; - } - - @Override - public Object executeGeneric(VirtualFrame frame) { - return value; - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TernaryNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TernaryNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import java.math.*; - -import com.oracle.truffle.api.dsl.*; - -@SuppressWarnings("unused") -@NodeChildren({@NodeChild(value = "conditionNode", type = ConditionNode.class), @NodeChild("ifPartNode"), @NodeChild("elsePartNode")}) -public abstract class TernaryNode extends TypedNode { - - @ShortCircuit("ifPartNode") - public boolean needsIfPart(boolean condition) { - return condition; - } - - @ShortCircuit("elsePartNode") - public boolean needsElsePart(boolean condition, boolean hasIfPart, Object ifPart) { - return !hasIfPart; - } - - @Specialization - public int doInteger(boolean condition, boolean hasIfPart, int ifPart, boolean hasElsePart, int elsePart) { - return hasIfPart ? ifPart : elsePart; - } - - @Specialization - public BigInteger doBigInteger(boolean condition, boolean hasIfPart, BigInteger ifPart, boolean hasElsePart, BigInteger elsePart) { - return hasIfPart ? ifPart : elsePart; - } - - @Specialization - public Object doObject(boolean condition, boolean hasIfPart, Object ifPart, boolean hasElsePart, Object elsePart) { - return hasIfPart ? ifPart : elsePart; - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TypedNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/TypedNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import java.math.*; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; -import com.oracle.truffle.sl.*; -import com.oracle.truffle.sl.runtime.*; - -public abstract class TypedNode extends ConditionNode { - - @Override - public final boolean executeCondition(VirtualFrame frame) { - try { - return executeBoolean(frame); - } catch (UnexpectedResultException ex) { - throw new RuntimeException("Illegal type for condition: " + ex.getResult().getClass().getSimpleName()); - } - } - - public abstract Object executeGeneric(VirtualFrame frame); - - public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException { - return SLTypesGen.SLTYPES.expectBoolean(executeGeneric(frame)); - } - - public int executeInteger(VirtualFrame frame) throws UnexpectedResultException { - return SLTypesGen.SLTYPES.expectInteger(executeGeneric(frame)); - } - - public BigInteger executeBigInteger(VirtualFrame frame) throws UnexpectedResultException { - return SLTypesGen.SLTYPES.expectBigInteger(executeGeneric(frame)); - } - - public String executeString(VirtualFrame frame) throws UnexpectedResultException { - return SLTypesGen.SLTYPES.expectString(executeGeneric(frame)); - } - - public CallTarget executeCallTarget(VirtualFrame frame) throws UnexpectedResultException { - return SLTypesGen.SLTYPES.expectCallTarget(executeGeneric(frame)); - } - - public Object[] executeArray(VirtualFrame frame) throws UnexpectedResultException { - return SLTypesGen.SLTYPES.expectObjectArray(executeGeneric(frame)); - } - - public SLNull executeNull(VirtualFrame frame) throws UnexpectedResultException { - return SLTypesGen.SLTYPES.expectSLNull(executeGeneric(frame)); - } - - @Override - public final void executeVoid(VirtualFrame frame) { - executeGeneric(frame); - } - - public boolean isString(Object a, Object b) { - return a instanceof String || b instanceof String; - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WhileNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WhileNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.utilities.*; - -public class WhileNode extends StatementNode { - - @Child private ConditionNode condition; - - @Child private StatementNode body; - - private final BreakException breakTarget; - private final ContinueException continueTarget; - - private final BranchProfile continueMismatch = new BranchProfile(); - private final BranchProfile continueMatch = new BranchProfile(); - private final BranchProfile breakMismatch = new BranchProfile(); - private final BranchProfile breakMatch = new BranchProfile(); - - public WhileNode(ConditionNode condition, StatementNode body) { - this.condition = adoptChild(condition); - this.body = adoptChild(body); - - this.breakTarget = new BreakException(); - this.continueTarget = new ContinueException(); - } - - @Override - public void executeVoid(VirtualFrame frame) { - try { - while (condition.executeCondition(frame)) { - try { - body.executeVoid(frame); - } catch (ContinueException ex) { - if (ex != continueTarget) { - continueMismatch.enter(); - throw ex; - } - continueMatch.enter(); - // Fall through to next loop iteration. - } - } - } catch (BreakException ex) { - if (ex != breakTarget) { - breakMismatch.enter(); - throw ex; - } - breakMatch.enter(); - // Done executing this loop, exit method to execute statement following the loop. - } - } -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WriteLocalNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WriteLocalNode.java Tue Jan 28 12:52:57 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2012, 2012, 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.truffle.sl.nodes; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.dsl.*; -import com.oracle.truffle.api.frame.*; - -@NodeChild(value = "rightNode", type = TypedNode.class) -public abstract class WriteLocalNode extends FrameSlotNode { - - public WriteLocalNode(FrameSlot slot) { - super(slot); - } - - public WriteLocalNode(WriteLocalNode node) { - this(node.slot); - } - - @Specialization(guards = "isIntKind") - public int write(VirtualFrame frame, int right) { - frame.setInt(slot, right); - return right; - } - - @Specialization(guards = "isBooleanKind") - public boolean write(VirtualFrame frame, boolean right) { - frame.setBoolean(slot, right); - return right; - } - - @Specialization(guards = "isObjectKind") - public Object writeGeneric(VirtualFrame frame, Object right) { - frame.setObject(slot, right); - return right; - } - - protected final boolean isIntKind() { - return isKind(FrameSlotKind.Int); - } - - protected final boolean isBooleanKind() { - return isKind(FrameSlotKind.Boolean); - } - - protected final boolean isObjectKind() { - if (slot.getKind() != FrameSlotKind.Object) { - CompilerDirectives.transferToInterpreter(); - slot.setKind(FrameSlotKind.Object); - } - return true; - } - - private boolean isKind(FrameSlotKind kind) { - return slot.getKind() == kind || initialSetKind(kind); - } - - private boolean initialSetKind(FrameSlotKind kind) { - if (slot.getKind() == FrameSlotKind.Illegal) { - CompilerDirectives.transferToInterpreter(); - slot.setKind(kind); - return true; - } - return false; - } - -} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLAbstractDispatchNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLAbstractDispatchNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, 2013, 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.truffle.sl.nodes.call; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +abstract class SLAbstractDispatchNode extends Node { + + protected static final int INLINE_CACHE_SIZE = 2; + + protected abstract Object executeCall(VirtualFrame frame, SLFunction function, SLArguments arguments); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLArgumentsNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLArgumentsNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.call; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; + +public final class SLArgumentsNode extends SLExpressionNode { + + @Children private final SLExpressionNode[] arguments; + + public SLArgumentsNode(SLExpressionNode[] arguments) { + this.arguments = adoptChildren(arguments); + } + + public SLExpressionNode[] getArguments() { + return arguments; + } + + @Override + public Object[] executeGeneric(VirtualFrame frame) { + return executeArray(frame); + } + + @Override + @ExplodeLoop + public Object[] executeArray(VirtualFrame frame) { + Object[] argumentValues = new Object[arguments.length]; + for (int i = 0; i < arguments.length; i++) { + argumentValues[i] = arguments[i].executeGeneric(frame); + } + return argumentValues; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLCallNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLCallNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013, 2013, 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.truffle.sl.nodes.call; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +public final class SLCallNode extends SLExpressionNode { + + public static SLCallNode create(SLExpressionNode function, SLExpressionNode[] arguments) { + return new SLCallNode(function, arguments, new SLUninitializedCallNode()); + } + + @Child protected SLExpressionNode functionNode; + @Children protected final SLExpressionNode[] argumentNodes; + @Child protected SLAbstractDispatchNode dispatchNode; + + private SLCallNode(SLExpressionNode functionNode, SLExpressionNode[] argumentNodes, SLAbstractDispatchNode dispatchNode) { + this.functionNode = adoptChild(functionNode); + this.argumentNodes = adoptChildren(argumentNodes); + this.dispatchNode = adoptChild(dispatchNode); + } + + @Override + @ExplodeLoop + public Object executeGeneric(VirtualFrame frame) { + SLFunction function; + try { + function = functionNode.executeFunction(frame); + } catch (UnexpectedResultException e) { + throw new UnsupportedOperationException("Call to " + e.getMessage() + " not supported."); + } + + Object[] argumentValues = new Object[argumentNodes.length]; + for (int i = 0; i < argumentNodes.length; i++) { + argumentValues[i] = argumentNodes[i].executeGeneric(frame); + } + SLArguments arguments = new SLArguments(argumentValues); + + return dispatchNode.executeCall(frame, function, arguments); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDirectDispatchNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLDirectDispatchNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 2013, 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.truffle.sl.nodes.call; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +abstract class SLDirectDispatchNode extends SLAbstractDispatchNode { + + protected final SLFunction cachedFunction; + protected final RootCallTarget cachedCallTarget; + protected final Assumption cachedCallTargetStable; + + @Child protected SLAbstractDispatchNode nextNode; + + protected SLDirectDispatchNode(SLAbstractDispatchNode next, SLFunction cachedFunction) { + this.cachedFunction = cachedFunction; + this.cachedCallTarget = cachedFunction.getCallTarget(); + this.cachedCallTargetStable = cachedFunction.getCallTargetStable(); + this.nextNode = adoptChild(next); + } + + @Override + protected final Object executeCall(VirtualFrame frame, SLFunction function, SLArguments arguments) { + if (this.cachedFunction == function) { + try { + cachedCallTargetStable.check(); + return executeCurrent(frame, arguments); + } catch (InvalidAssumptionException ex) { + /* + * Remove ourselfs from the polymorphic inline cache, so that we fail the check only + * once. + */ + replace(nextNode); + /* + * Execute the next node in the chain by falling out of the if block. + */ + } + } + return nextNode.executeCall(frame, function, arguments); + } + + protected abstract Object executeCurrent(VirtualFrame frame, SLArguments arguments); +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLGenericDispatchNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLGenericDispatchNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, 2013, 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.truffle.sl.nodes.call; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.runtime.*; + +final class SLGenericDispatchNode extends SLAbstractDispatchNode { + + @Override + protected Object executeCall(VirtualFrame frame, SLFunction function, SLArguments arguments) { + return function.getCallTarget().call(frame.pack(), arguments); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLInlinableDirectDispatchNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLInlinableDirectDispatchNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2013, 2013, 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.truffle.sl.nodes.call; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +final class SLInlinableDirectDispatchNode extends SLDirectDispatchNode implements InlinableCallSite { + + @CompilationFinal private int callCount; + + protected SLInlinableDirectDispatchNode(SLAbstractDispatchNode next, SLFunction cachedFunction) { + super(next, cachedFunction); + } + + @Override + protected Object executeCurrent(VirtualFrame frame, SLArguments arguments) { + if (CompilerDirectives.inInterpreter()) { + callCount++; + } + return cachedCallTarget.call(frame.pack(), arguments); + } + + @Override + public boolean inline(FrameFactory factory) { + CompilerAsserts.neverPartOfCompilation(); + RootNode root = cachedCallTarget.getRootNode(); + SLExpressionNode inlinedNode = ((SLRootNode) root).inline(); + assert inlinedNode != null; + replace(new SLInlinedDirectDispatchNode(this, inlinedNode), "Inlined " + root); + /* We are always able to inline if required. */ + return true; + } + + @Override + public int getCallCount() { + return callCount; + } + + @Override + public void resetCallCount() { + callCount = 0; + } + + @Override + public Node getInlineTree() { + RootNode root = cachedCallTarget.getRootNode(); + if (root instanceof SLRootNode) { + return ((SLRootNode) root).getUninitializedBody(); + } + return null; + } + + @Override + public CallTarget getCallTarget() { + return cachedCallTarget; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLInlinedDirectDispatchNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLInlinedDirectDispatchNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013, 2013, 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.truffle.sl.nodes.call; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +final class SLInlinedDirectDispatchNode extends SLDirectDispatchNode implements InlinedCallSite { + + private final FrameDescriptor descriptor; + @Child private SLExpressionNode inlinedBody; + + protected SLInlinedDirectDispatchNode(SLInlinableDirectDispatchNode prev, SLExpressionNode inlinedBody) { + super(prev.nextNode, prev.cachedFunction); + this.descriptor = cachedCallTarget.getRootNode().getFrameDescriptor(); + this.inlinedBody = adoptChild(inlinedBody); + } + + @Override + protected Object executeCurrent(VirtualFrame frame, SLArguments arguments) { + VirtualFrame newFrame = Truffle.getRuntime().createVirtualFrame(frame.pack(), arguments, descriptor); + return inlinedBody.executeGeneric(newFrame); + } + + @Override + public CallTarget getCallTarget() { + return cachedCallTarget; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLUninitializedCallNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/call/SLUninitializedCallNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013, 2013, 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.truffle.sl.nodes.call; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.runtime.*; + +final class SLUninitializedCallNode extends SLAbstractDispatchNode { + + @Override + protected Object executeCall(VirtualFrame frame, SLFunction function, SLArguments arguments) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + + SLAbstractDispatchNode cur = this; + int depth = 0; + while (cur.getParent() instanceof SLAbstractDispatchNode) { + cur = (SLAbstractDispatchNode) cur.getParent(); + depth++; + } + SLCallNode callNode = (SLCallNode) cur.getParent(); + + SLAbstractDispatchNode specialized; + if (depth < INLINE_CACHE_SIZE) { + SLAbstractDispatchNode next = new SLUninitializedCallNode(); + SLAbstractDispatchNode direct = new SLInlinableDirectDispatchNode(next, function); + specialized = replace(direct); + } else { + SLAbstractDispatchNode generic = new SLGenericDispatchNode(); + specialized = callNode.dispatchNode.replace(generic); + } + + return specialized.executeCall(frame, function, arguments); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLBlockNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLBlockNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; + +public class SLBlockNode extends SLStatementNode { + + @Children private final SLStatementNode[] statements; + + public SLBlockNode(SLStatementNode[] statements) { + this.statements = adoptChildren(statements); + } + + @Override + @ExplodeLoop + public void executeVoid(VirtualFrame frame) { + for (SLStatementNode statement : statements) { + statement.executeVoid(frame); + } + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLBreakException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLBreakException.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.nodes.*; + +public final class SLBreakException extends ControlFlowException { + + public static final SLBreakException SINGLETON = new SLBreakException(); + + private static final long serialVersionUID = -91013036379258890L; + + private SLBreakException() { + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLBreakNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLBreakNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.nodes.*; + +public final class SLBreakNode extends SLStatementNode { + + @Override + public void executeVoid(VirtualFrame frame) { + throw SLBreakException.SINGLETON; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLContinueException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLContinueException.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.nodes.*; + +public final class SLContinueException extends ControlFlowException { + + public static final SLContinueException SINGLETON = new SLContinueException(); + + private static final long serialVersionUID = 5329687983726237188L; + + private SLContinueException() { + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLContinueNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLContinueNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.nodes.*; + +public final class SLContinueNode extends SLStatementNode { + + @Override + public void executeVoid(VirtualFrame frame) { + throw SLContinueException.SINGLETON; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLFunctionBodyNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLFunctionBodyNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +public class SLFunctionBodyNode extends SLExpressionNode { + + @Child private SLStatementNode body; + + private FrameDescriptor frameDescriptor; + + public SLFunctionBodyNode(FrameDescriptor frameDescriptor, SLStatementNode body) { + this.frameDescriptor = frameDescriptor; + this.body = adoptChild(body); + } + + @Override + public Object executeGeneric(VirtualFrame frame) { + try { + body.executeVoid(frame); + } catch (SLReturnException ex) { + return ex.getResult(); + } + return SLNull.INSTANCE; + } + + @Override + public Node copy() { + SLFunctionBodyNode copy = (SLFunctionBodyNode) super.copy(); + copy.frameDescriptor = frameDescriptor.shallowCopy(); + return copy; + } + + public FrameDescriptor getFrameDescriptor() { + return frameDescriptor; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLIfNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLIfNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.utilities.*; +import com.oracle.truffle.sl.nodes.*; + +public class SLIfNode extends SLStatementNode { + @Child private SLExpressionNode conditionNode; + @Child private SLStatementNode thenPartNode; + @Child private SLStatementNode elsePartNode; + + private final BranchProfile thenTaken = new BranchProfile(); + private final BranchProfile elseTaken = new BranchProfile(); + + public SLIfNode(SLExpressionNode conditionNode, SLStatementNode thenPartNode, SLStatementNode elsePartNode) { + this.conditionNode = adoptChild(conditionNode); + this.thenPartNode = adoptChild(thenPartNode); + this.elsePartNode = adoptChild(elsePartNode); + } + + @Override + public void executeVoid(VirtualFrame frame) { + if (conditionNode.executeCondition(frame)) { + thenTaken.enter(); + thenPartNode.executeVoid(frame); + } else { + if (elsePartNode != null) { + elseTaken.enter(); + elsePartNode.executeVoid(frame); + } + } + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLReturnException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLReturnException.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.nodes.*; + +public final class SLReturnException extends ControlFlowException { + + private static final long serialVersionUID = 4073191346281369231L; + + private final Object result; + + public SLReturnException(Object result) { + this.result = result; + } + + public Object getResult() { + return result; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLReturnNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLReturnNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.nodes.*; + +public class SLReturnNode extends SLStatementNode { + + @Child private SLExpressionNode expr; + + public SLReturnNode(SLExpressionNode expr) { + this.expr = adoptChild(expr); + } + + @Override + public void executeVoid(VirtualFrame frame) { + Object result = expr.executeGeneric(frame); + throw new SLReturnException(result); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLWhileNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/controlflow/SLWhileNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.controlflow; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.utilities.*; +import com.oracle.truffle.sl.nodes.*; + +public class SLWhileNode extends SLStatementNode { + + @Child private SLExpressionNode condition; + @Child private SLStatementNode body; + + private final BranchProfile continueTaken = new BranchProfile(); + private final BranchProfile breakTaken = new BranchProfile(); + + public SLWhileNode(SLExpressionNode condition, SLStatementNode body) { + this.condition = adoptChild(condition); + this.body = adoptChild(body); + } + + @Override + public void executeVoid(VirtualFrame frame) { + try { + while (condition.executeCondition(frame)) { + try { + body.executeVoid(frame); + } catch (SLContinueException ex) { + continueTaken.enter(); + /* Fall through to next loop iteration. */ + } + } + } catch (SLBreakException ex) { + breakTaken.enter(); + /* Done executing this loop, exit method to execute statement following the loop. */ + } + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLAddNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLAddNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import java.math.*; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +public abstract class SLAddNode extends SLBinaryNode { + + @Specialization(rewriteOn = ArithmeticException.class) + long add(long left, long right) { + return ExactMath.addExact(left, right); + } + + @Specialization + BigInteger add(BigInteger left, BigInteger right) { + return left.add(right); + } + + @Specialization + String add(String left, String right) { + return left + right; + } + + @Specialization(guards = "isString") + String add(Object left, Object right) { + return left.toString() + right.toString(); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLBigIntegerLiteralNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLBigIntegerLiteralNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import java.math.*; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.nodes.*; + +public final class SLBigIntegerLiteralNode extends SLExpressionNode { + + private final BigInteger value; + + public SLBigIntegerLiteralNode(BigInteger value) { + this.value = value; + } + + @Override + public BigInteger executeBigInteger(VirtualFrame frame) { + return value; + } + + @Override + public Object executeGeneric(VirtualFrame frame) { + return value; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLDivNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLDivNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import java.math.*; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +public abstract class SLDivNode extends SLBinaryNode { + + @Specialization(rewriteOn = ArithmeticException.class) + long div(long left, long right) { + return left / right; + } + + @Specialization + BigInteger div(BigInteger left, BigInteger right) { + return left.divide(right); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLEqualNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLEqualNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +public abstract class SLEqualNode extends SLBinaryNode { + + @Specialization + public boolean equal(long left, long right) { + return left == right; + } + + @Specialization + public boolean equal(boolean left, boolean right) { + return left == right; + } + + @Generic + public boolean equal(Object left, Object right) { + return left.equals(right); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLFunctionLiteralNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLFunctionLiteralNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +public final class SLFunctionLiteralNode extends SLExpressionNode { + + private final SLFunction value; + + public SLFunctionLiteralNode(SLFunction value) { + this.value = value; + } + + @Override + public SLFunction executeFunction(VirtualFrame frame) { + return value; + } + + @Override + public Object executeGeneric(VirtualFrame frame) { + return value; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLessOrEqualNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLessOrEqualNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import java.math.*; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +public abstract class SLLessOrEqualNode extends SLBinaryNode { + + @Specialization + public boolean lessOrEqual(long left, long right) { + return left <= right; + } + + @Specialization + public boolean lessOrEqual(BigInteger left, BigInteger right) { + return left.compareTo(right) <= 0; + } + + @Specialization(guards = "isString") + public boolean lessOrEqual(Object left, Object right) { + return left.toString().compareTo(right.toString()) <= 0; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLessThanNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLessThanNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import java.math.*; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +public abstract class SLLessThanNode extends SLBinaryNode { + + @Specialization + public boolean lessThan(long left, long right) { + return left < right; + } + + @Specialization + public boolean lessThan(BigInteger left, BigInteger right) { + return left.compareTo(right) < 0; + } + + @Specialization(guards = "isString") + public boolean lessThan(Object left, Object right) { + return left.toString().compareTo(right.toString()) < 0; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalAndNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalAndNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +@SuppressWarnings("unused") +public abstract class SLLogicalAndNode extends SLBinaryNode { + + @ShortCircuit("rightNode") + public boolean needsRightNode(boolean left) { + return left; + } + + @ShortCircuit("rightNode") + public boolean needsRightNode(Object left) { + return left instanceof Boolean && needsRightNode(((Boolean) left).booleanValue()); + } + + @Specialization + public boolean doBoolean(boolean left, boolean hasRight, boolean right) { + return left && right; + } + + @Generic + public Object doGeneric(Object left, boolean hasRight, Object right) { + throw new RuntimeException("operation not defined for type " + left.getClass().getSimpleName()); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalOrNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLogicalOrNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +@SuppressWarnings("unused") +public abstract class SLLogicalOrNode extends SLBinaryNode { + + @ShortCircuit("rightNode") + public boolean needsRightNode(boolean left) { + return !left; + } + + @ShortCircuit("rightNode") + public boolean needsRightNode(Object left) { + return left instanceof Boolean && needsRightNode(((Boolean) left).booleanValue()); + } + + @Specialization + public boolean doBoolean(boolean left, boolean hasRight, boolean right) { + return left || right; + } + + @Generic + public Object doGeneric(Object left, boolean hasRight, Object right) { + throw new RuntimeException("operation not defined for type " + left.getClass().getSimpleName()); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLongLiteralNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLLongLiteralNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; + +public final class SLLongLiteralNode extends SLExpressionNode { + + private final long value; + + public SLLongLiteralNode(long value) { + this.value = value; + } + + @Override + public long executeLong(VirtualFrame frame) throws UnexpectedResultException { + return value; + } + + @Override + public Object executeGeneric(VirtualFrame frame) { + return value; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLMulNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLMulNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import java.math.*; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +public abstract class SLMulNode extends SLBinaryNode { + + @Specialization(rewriteOn = ArithmeticException.class) + long mul(long left, long right) { + return ExactMath.multiplyExact(left, right); + } + + @Specialization + BigInteger mul(BigInteger left, BigInteger right) { + return left.multiply(right); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLNotEqualNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLNotEqualNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +public abstract class SLNotEqualNode extends SLBinaryNode { + + @Specialization + public boolean notEqual(long left, long right) { + return left != right; + } + + @Specialization + public boolean notEqual(boolean left, boolean right) { + return left != right; + } + + @Generic + public boolean equal(Object left, Object right) { + return !left.equals(right); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLStringLiteralNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLStringLiteralNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.nodes.*; + +public final class SLStringLiteralNode extends SLExpressionNode { + + private final String value; + + public SLStringLiteralNode(String value) { + this.value = value; + } + + @Override + public String executeString(VirtualFrame frame) { + return value; + } + + @Override + public Object executeGeneric(VirtualFrame frame) { + return value; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLSubNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLSubNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.expression; + +import java.math.*; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.sl.nodes.*; + +public abstract class SLSubNode extends SLBinaryNode { + + @Specialization(rewriteOn = ArithmeticException.class) + long sub(long left, long right) { + return ExactMath.subtractExact(left, right); + } + + @Specialization + BigInteger sub(BigInteger left, BigInteger right) { + return left.subtract(right); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/local/ReadLocalNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/local/ReadLocalNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.local; + +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.nodes.*; + +@PolymorphicLimit(1) +public abstract class ReadLocalNode extends SLExpressionNode { + + private final FrameSlot slot; + + public ReadLocalNode(FrameSlot slot) { + this.slot = slot; + } + + public ReadLocalNode(ReadLocalNode specialized) { + this(specialized.slot); + } + + @Specialization(rewriteOn = {FrameSlotTypeException.class}) + public long readLong(VirtualFrame frame) throws FrameSlotTypeException { + return frame.getLong(slot); + } + + @Specialization(rewriteOn = {FrameSlotTypeException.class}) + public boolean readBoolean(VirtualFrame frame) throws FrameSlotTypeException { + return frame.getBoolean(slot); + } + + @Specialization(rewriteOn = {FrameSlotTypeException.class}) + public Object readObject(VirtualFrame frame) throws FrameSlotTypeException { + return frame.getObject(slot); + } + + @Generic + public Object doGeneric(VirtualFrame frame) { + return frame.getValue(slot); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/local/SLReadArgumentNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/local/SLReadArgumentNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.local; + +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.utilities.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; + +public class SLReadArgumentNode extends SLExpressionNode { + + private final int index; + + private final BranchProfile outOfBounds = new BranchProfile(); + + public SLReadArgumentNode(int index) { + this.index = index; + } + + @Override + public Object executeGeneric(VirtualFrame frame) { + Object[] args = SLArguments.getFromFrame(frame); + if (index < args.length) { + return args[index]; + } else { + outOfBounds.enter(); + return SLNull.INSTANCE; + } + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/local/WriteLocalNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/local/WriteLocalNode.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.nodes.local; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.sl.nodes.*; + +@NodeChild(value = "rightNode", type = SLExpressionNode.class) +public abstract class WriteLocalNode extends SLExpressionNode { + + private final FrameSlot slot; + + public WriteLocalNode(FrameSlot slot) { + this.slot = slot; + } + + public WriteLocalNode(WriteLocalNode node) { + this(node.slot); + } + + @Specialization(guards = "isLongKind") + protected final long write(VirtualFrame frame, long right) { + frame.setLong(slot, right); + return right; + } + + @Specialization(guards = "isBooleanKind") + protected final boolean write(VirtualFrame frame, boolean right) { + frame.setBoolean(slot, right); + return right; + } + + @Specialization(guards = "isObjectKind") + protected final Object writeGeneric(VirtualFrame frame, Object right) { + frame.setObject(slot, right); + return right; + } + + protected final boolean isLongKind() { + return isKind(FrameSlotKind.Long); + } + + protected final boolean isBooleanKind() { + return isKind(FrameSlotKind.Boolean); + } + + protected final boolean isObjectKind() { + if (slot.getKind() != FrameSlotKind.Object) { + CompilerDirectives.transferToInterpreter(); + slot.setKind(FrameSlotKind.Object); + } + return true; + } + + private boolean isKind(FrameSlotKind kind) { + return slot.getKind() == kind || initialSetKind(kind); + } + + private boolean initialSetKind(FrameSlotKind kind) { + if (slot.getKind() == FrameSlotKind.Illegal) { + CompilerDirectives.transferToInterpreter(); + slot.setKind(kind); + return true; + } + return false; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.frame --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.frame Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.frame Tue Jan 28 12:55:06 2014 +0100 @@ -30,8 +30,10 @@ import java.util.*; +import com.oracle.truffle.api.*; import com.oracle.truffle.sl.*; import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; // Checkstyle: stop // @formatter:off @@ -49,9 +51,9 @@ public final Errors errors; private final SLNodeFactory factory; -->declarations - public Parser(Scanner scanner, SLNodeFactory factory) { - this.scanner = scanner; - this.factory = factory; + public Parser(SLContext context, Source source) { + this.scanner = new Scanner(source.getInputStream()); + this.factory = new SLNodeFactory(context, source, this); errors = new Errors(); } @@ -132,28 +134,22 @@ -->initialization }; - public String ParseErrors() { - java.io.PrintStream oldStream = System.out; - - java.io.OutputStream out = new java.io.ByteArrayOutputStream(); - java.io.PrintStream newStream = new java.io.PrintStream(out); - - errors.errorStream = newStream; - - Parse(); - - String errorStream = out.toString(); - errors.errorStream = oldStream; - - return errorStream; - + public static void parseSL(SLContext context, Source source) { + Parser parser = new Parser(context, source); + parser.Parse(); + if (parser.errors.errors.size() > 0) { + StringBuilder msg = new StringBuilder("Error(s) parsing script:\n"); + for (String error : parser.errors.errors) { + msg.append(error).append("\n"); + } + throw new SLException(msg.toString()); + } } } // end Parser class Errors { - public int count = 0; // number of errors detected - public java.io.PrintStream errorStream = System.out; // error messages go to this stream + protected final List errors = new ArrayList<>(); public String errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text protected void printMsg(int line, int column, String msg) { @@ -171,7 +167,7 @@ pos = b.indexOf("{2}"); if (pos >= 0) b.replace(pos, pos + 3, msg); - errorStream.println(b.toString()); + errors.add(b.toString()); } public void SynErr(int line, int col, int n) { @@ -182,17 +178,14 @@ break; } printMsg(line, col, s); - count++; } public void SemErr(int line, int col, String s) { printMsg(line, col, s); - count++; } public void SemErr(String s) { - errorStream.println(s); - count++; + errors.add(s); } public void Warning(int line, int col, String s) { @@ -200,7 +193,7 @@ } public void Warning(String s) { - errorStream.println(s); + errors.add(s); } } // Errors diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java Tue Jan 28 12:55:06 2014 +0100 @@ -27,8 +27,10 @@ import java.util.*; +import com.oracle.truffle.api.*; import com.oracle.truffle.sl.*; import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.runtime.*; // Checkstyle: stop // @formatter:off @@ -37,7 +39,7 @@ public static final int _identifier = 1; public static final int _stringLiteral = 2; public static final int _numericLiteral = 3; - public static final int maxT = 29; + public static final int maxT = 30; static final boolean T = true; static final boolean x = false; @@ -51,9 +53,9 @@ public final Errors errors; private final SLNodeFactory factory; - public Parser(Scanner scanner, SLNodeFactory factory) { - this.scanner = scanner; - this.factory = factory; + public Parser(SLContext context, Source source) { + this.scanner = new Scanner(source.getInputStream()); + this.factory = new SLNodeFactory(context, source, this); errors = new Errors(); } @@ -130,113 +132,142 @@ void Function() { Expect(4); - factory.startFunction(); Expect(1); String name = t.val; - List parameterNames = new ArrayList<>(); - if (la.kind == 5) { + Expect(5); + List parameters = new ArrayList<>(); + if (la.kind == 1) { Get(); - if (la.kind == 1) { - Get(); - parameterNames.add(t.val); - } + parameters.add(t.val); while (la.kind == 6) { Get(); Expect(1); - parameterNames.add(t.val); + parameters.add(t.val); } - Expect(7); } - StatementNode body = Block(); - factory.createFunction(body, name, parameterNames.toArray(new String[parameterNames.size()])); + Expect(7); + factory.startFunction(name, parameters); + SLStatementNode body = Block(); + factory.finishFunction(body); } - StatementNode Block() { - StatementNode result; - List statements = new ArrayList<>(); + SLStatementNode Block() { + SLStatementNode result; + factory.startBlock(); + List statements = new ArrayList<>(); Expect(8); while (StartOf(1)) { - StatementNode statement = Statement(); + SLStatementNode statement = Statement(); statements.add(statement); } Expect(9); - result = factory.createBlock(statements); + result = factory.finishBlock(statements); return result; } - StatementNode Statement() { - StatementNode result; + SLStatementNode Statement() { + SLStatementNode result; result = null; - if (la.kind == 13) { + switch (la.kind) { + case 15: { result = WhileStatement(); - } else if (la.kind == 11) { + break; + } + case 10: { + Get(); + result = factory.createBreak(); + Expect(11); + break; + } + case 12: { + Get(); + result = factory.createContinue(); + Expect(11); + break; + } + case 13: { result = IfStatement(); - } else if (la.kind == 14) { + break; + } + case 16: { result = ReturnStatement(); - } else if (StartOf(2)) { + break; + } + case 1: case 2: case 3: case 5: { result = Expression(); - Expect(10); - } else SynErr(30); + Expect(11); + break; + } + default: SynErr(31); break; + } return result; } - StatementNode WhileStatement() { - StatementNode result; - Expect(13); + SLStatementNode WhileStatement() { + SLStatementNode result; + Expect(15); Expect(5); - ConditionNode condition = Expression(); + SLExpressionNode condition = Expression(); Expect(7); - StatementNode body = Block(); + SLStatementNode body = Block(); result = factory.createWhile(condition, body); return result; } - StatementNode IfStatement() { - StatementNode result; - Expect(11); + SLStatementNode IfStatement() { + SLStatementNode result; + Expect(13); Expect(5); - ConditionNode condition = Expression(); + SLExpressionNode condition = Expression(); Expect(7); - StatementNode thenNode = null; StatementNode elseNode = null; - thenNode = Block(); - if (la.kind == 12) { + SLStatementNode thenPart = Block(); + SLStatementNode elsePart = null; + if (la.kind == 14) { Get(); - elseNode = Block(); + elsePart = Block(); } - result = factory.createIf(condition, thenNode, elseNode); + result = factory.createIf(condition, thenPart, elsePart); return result; } - StatementNode ReturnStatement() { - StatementNode result; - Expect(14); - TypedNode value = Expression(); - Expect(10); + SLStatementNode ReturnStatement() { + SLStatementNode result; + Expect(16); + SLExpressionNode value = Expression(); + Expect(11); result = factory.createReturn(value); return result; } - TypedNode Expression() { - TypedNode result; - result = ValueExpression(); - if (StartOf(3)) { + SLExpressionNode Expression() { + SLExpressionNode result; + result = LogicTerm(); + while (la.kind == 17) { + Get(); + String op = t.val; + SLExpressionNode right = LogicTerm(); + result = factory.createBinary(op, result, right); + } + return result; + } + + SLExpressionNode LogicTerm() { + SLExpressionNode result; + result = LogicFactor(); + while (la.kind == 18) { + Get(); + String op = t.val; + SLExpressionNode right = LogicFactor(); + result = factory.createBinary(op, result, right); + } + return result; + } + + SLExpressionNode LogicFactor() { + SLExpressionNode result; + result = Arithmetic(); + if (StartOf(2)) { switch (la.kind) { - case 15: { - Get(); - break; - } - case 16: { - Get(); - break; - } - case 17: { - Get(); - break; - } - case 18: { - Get(); - break; - } case 19: { Get(); break; @@ -245,130 +276,101 @@ Get(); break; } + case 21: { + Get(); + break; + } + case 22: { + Get(); + break; + } + case 23: { + Get(); + break; + } + case 24: { + Get(); + break; + } } String op = t.val; - TypedNode right = ValueExpression(); + SLExpressionNode right = Arithmetic(); result = factory.createBinary(op, result, right); } return result; } - TypedNode ValueExpression() { - TypedNode result; + SLExpressionNode Arithmetic() { + SLExpressionNode result; result = Term(); - while (la.kind == 21 || la.kind == 22) { - if (la.kind == 21) { + while (la.kind == 25 || la.kind == 26) { + if (la.kind == 25) { Get(); } else { Get(); } String op = t.val; - TypedNode right = Term(); - result = factory.createBinary(op, result, right); - } - return result; - } - - TypedNode Term() { - TypedNode result; - result = Factor(); - while (la.kind == 23 || la.kind == 24) { - if (la.kind == 23) { - Get(); - } else { - Get(); - } - String op = t.val; - TypedNode right = Factor(); + SLExpressionNode right = Term(); result = factory.createBinary(op, result, right); } return result; } - TypedNode Factor() { - TypedNode result; - result = null; - if (la.kind == 1) { - result = VariableRefOrCall(); - } else if (la.kind == 2) { - result = StringLiteral(); - } else if (la.kind == 3) { - result = NumericLiteral(); - } else if (la.kind == 25) { - result = Ternary(); - } else if (la.kind == 5) { - Get(); - result = Expression(); - Expect(7); - } else SynErr(31); - return result; - } - - TypedNode VariableRefOrCall() { - TypedNode result; - result = VariableRef(); - if (la.kind == 5 || la.kind == 28) { - if (la.kind == 5) { - TypedNode[] parameters = Parameters(); - result = factory.createCall(result, parameters); + SLExpressionNode Term() { + SLExpressionNode result; + result = Factor(); + while (la.kind == 27 || la.kind == 28) { + if (la.kind == 27) { + Get(); } else { Get(); - TypedNode assignment = Expression(); - result = factory.createAssignment(result, assignment); } + String op = t.val; + SLExpressionNode right = Factor(); + result = factory.createBinary(op, result, right); } return result; } - TypedNode StringLiteral() { - TypedNode result; - Expect(2); - result = factory.createStringLiteral(t.val.substring(1, t.val.length() - 1)); - return result; - } - - TypedNode NumericLiteral() { - TypedNode result; - Expect(3); - result = factory.createNumericLiteral(t.val); - return result; - } - - TypedNode Ternary() { - TypedNode result; - TypedNode condition, thenPart, elsePart; - Expect(25); - condition = Expression(); - Expect(26); - thenPart = Expression(); - Expect(27); - elsePart = Expression(); - result = factory.createTernary(condition, thenPart, elsePart); - return result; - } - - TypedNode VariableRef() { - TypedNode result; - Expect(1); - result = factory.createLocal(t.val); - return result; - } - - TypedNode[] Parameters() { - TypedNode[] result; - Expect(5); - List parameters = new ArrayList<>(); - if (StartOf(2)) { - TypedNode e1 = Expression(); - parameters.add(e1); - while (la.kind == 6) { + SLExpressionNode Factor() { + SLExpressionNode result; + result = null; + if (la.kind == 1) { + Get(); + String name = t.val; + if (la.kind == 5) { Get(); - TypedNode e2 = Expression(); - parameters.add(e2); - } - } - result = parameters.toArray(new TypedNode[parameters.size()]); - Expect(7); + List parameters = new ArrayList<>(); + SLExpressionNode parameter; + if (StartOf(3)) { + parameter = Expression(); + parameters.add(parameter); + while (la.kind == 6) { + Get(); + parameter = Expression(); + parameters.add(parameter); + } + } + result = factory.createCall(factory.createRead(name), parameters); + Expect(7); + } else if (la.kind == 29) { + Get(); + SLExpressionNode value = Expression(); + result = factory.createAssignment(name, value); + } else if (StartOf(4)) { + result = factory.createRead(name); + } else SynErr(32); + } else if (la.kind == 2) { + Get(); + result = factory.createStringLiteral(t.val.substring(1, t.val.length() - 1)); + } else if (la.kind == 3) { + Get(); + result = factory.createNumericLiteral(t.val); + } else if (la.kind == 5) { + Get(); + result = Expression(); + Expect(7); + } else SynErr(33); return result; } @@ -384,35 +386,30 @@ } private static final boolean[][] set = { - {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, - {x,T,T,T, x,T,x,x, x,x,x,T, x,T,T,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x}, - {x,T,T,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x}, - {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x} + {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,T,T,T, x,T,x,x, x,x,T,x, T,T,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,x,x,x, x,x,x,x}, + {x,T,T,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,T,T, x,x,x,T, x,x,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x} }; - public String ParseErrors() { - java.io.PrintStream oldStream = System.out; - - java.io.OutputStream out = new java.io.ByteArrayOutputStream(); - java.io.PrintStream newStream = new java.io.PrintStream(out); - - errors.errorStream = newStream; - - Parse(); - - String errorStream = out.toString(); - errors.errorStream = oldStream; - - return errorStream; - + public static void parseSL(SLContext context, Source source) { + Parser parser = new Parser(context, source); + parser.Parse(); + if (parser.errors.errors.size() > 0) { + StringBuilder msg = new StringBuilder("Error(s) parsing script:\n"); + for (String error : parser.errors.errors) { + msg.append(error).append("\n"); + } + throw new SLException(msg.toString()); + } } } // end Parser class Errors { - public int count = 0; // number of errors detected - public java.io.PrintStream errorStream = System.out; // error messages go to this stream + protected final List errors = new ArrayList<>(); public String errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text protected void printMsg(int line, int column, String msg) { @@ -430,7 +427,7 @@ pos = b.indexOf("{2}"); if (pos >= 0) b.replace(pos, pos + 3, msg); - errorStream.println(b.toString()); + errors.add(b.toString()); } public void SynErr(int line, int col, int n) { @@ -446,44 +443,43 @@ case 7: s = "\")\" expected"; break; case 8: s = "\"{\" expected"; break; case 9: s = "\"}\" expected"; break; - case 10: s = "\";\" expected"; break; - case 11: s = "\"if\" expected"; break; - case 12: s = "\"else\" expected"; break; - case 13: s = "\"while\" expected"; break; - case 14: s = "\"return\" expected"; break; - case 15: s = "\"<\" expected"; break; - case 16: s = "\">\" expected"; break; - case 17: s = "\"<=\" expected"; break; - case 18: s = "\">=\" expected"; break; - case 19: s = "\"==\" expected"; break; - case 20: s = "\"!=\" expected"; break; - case 21: s = "\"+\" expected"; break; - case 22: s = "\"-\" expected"; break; - case 23: s = "\"*\" expected"; break; - case 24: s = "\"/\" expected"; break; - case 25: s = "\"#\" expected"; break; - case 26: s = "\"?\" expected"; break; - case 27: s = "\":\" expected"; break; - case 28: s = "\"=\" expected"; break; - case 29: s = "??? expected"; break; - case 30: s = "invalid Statement"; break; - case 31: s = "invalid Factor"; break; + case 10: s = "\"break\" expected"; break; + case 11: s = "\";\" expected"; break; + case 12: s = "\"continue\" expected"; break; + case 13: s = "\"if\" expected"; break; + case 14: s = "\"else\" expected"; break; + case 15: s = "\"while\" expected"; break; + case 16: s = "\"return\" expected"; break; + case 17: s = "\"||\" expected"; break; + case 18: s = "\"&&\" expected"; break; + case 19: s = "\"<\" expected"; break; + case 20: s = "\">\" expected"; break; + case 21: s = "\"<=\" expected"; break; + case 22: s = "\">=\" expected"; break; + case 23: s = "\"==\" expected"; break; + case 24: s = "\"!=\" expected"; break; + case 25: s = "\"+\" expected"; break; + case 26: s = "\"-\" expected"; break; + case 27: s = "\"*\" expected"; break; + case 28: s = "\"/\" expected"; break; + case 29: s = "\"=\" expected"; break; + case 30: s = "??? expected"; break; + case 31: s = "invalid Statement"; break; + case 32: s = "invalid Factor"; break; + case 33: s = "invalid Factor"; break; default: s = "error " + n; break; } printMsg(line, col, s); - count++; } public void SemErr(int line, int col, String s) { printMsg(line, col, s); - count++; } public void SemErr(String s) { - errorStream.println(s); - count++; + errors.add(s); } public void Warning(int line, int col, String s) { @@ -491,7 +487,7 @@ } public void Warning(String s) { - errorStream.println(s); + errors.add(s); } } // Errors diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SLNodeFactory.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2012, 2012, 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.truffle.sl.parser; + +import java.math.*; +import java.util.*; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.frame.*; +import com.oracle.truffle.api.nodes.*; +import com.oracle.truffle.sl.nodes.*; +import com.oracle.truffle.sl.nodes.call.*; +import com.oracle.truffle.sl.nodes.controlflow.*; +import com.oracle.truffle.sl.nodes.expression.*; +import com.oracle.truffle.sl.nodes.local.*; +import com.oracle.truffle.sl.runtime.*; + +public class SLNodeFactory { + + static class LexicalScope { + protected final LexicalScope outer; + protected final Map locals; + + public LexicalScope(LexicalScope outer) { + this.outer = outer; + this.locals = new HashMap<>(); + if (outer != null) { + locals.putAll(outer.locals); + } + } + } + + /* State while parsing a source unit. */ + private final SLContext context; + private final Source source; + private final Parser parser; + + /* State while parsing a function. */ + private String functionName; + private FrameDescriptor frameDescriptor; + private List methodNodes; + + /* State while parsing a block. */ + private LexicalScope lexicalScope; + + public SLNodeFactory(SLContext context, Source source, Parser parser) { + this.context = context; + this.source = source; + this.parser = parser; + } + + public void startFunction(String name, List parameters) { + assert functionName == null; + assert frameDescriptor == null; + assert lexicalScope == null; + + functionName = name; + frameDescriptor = new FrameDescriptor(); + startBlock(); + + /* + * Method parameters are assigned to local variables at the beginning of the method. This + * ensures that accesses to parameters are specialized the same way as local variables are + * specialized. + */ + methodNodes = new ArrayList<>(parameters.size()); + for (int i = 0; i < parameters.size(); i++) { + methodNodes.add(createAssignment(parameters.get(i), new SLReadArgumentNode(i))); + } + } + + public void finishFunction(SLStatementNode body) { + methodNodes.add(body); + SLStatementNode methodBlock = finishBlock(methodNodes); + assert lexicalScope == null : "Wrong scoping of blocks in parser"; + + context.getFunctionRegistry().register(functionName, SLRootNode.createFunction(functionName, frameDescriptor, methodBlock)); + + functionName = null; + frameDescriptor = null; + lexicalScope = null; + } + + public void startBlock() { + lexicalScope = new LexicalScope(lexicalScope); + } + + public SLStatementNode finishBlock(List statements) { + lexicalScope = lexicalScope.outer; + + List flattened = new ArrayList<>(statements.size()); + flattenBlocks(statements, flattened); + if (flattened.size() == 1) { + return flattened.get(0); + } else { + return assignSource(new SLBlockNode(flattened.toArray(new SLStatementNode[flattened.size()]))); + } + } + + private void flattenBlocks(Iterable statements, List flattened) { + for (Node statement : statements) { + if (statement instanceof SLBlockNode) { + flattenBlocks(statement.getChildren(), flattened); + } else { + flattened.add((SLStatementNode) statement); + } + } + } + + private T assignSource(T node) { + assert functionName != null; + node.assignSourceSection(ParserUtils.createSourceSection(source, functionName, parser)); + return node; + } + + public SLExpressionNode createAssignment(String name, SLExpressionNode value) { + FrameSlot frameSlot = frameDescriptor.findOrAddFrameSlot(name); + lexicalScope.locals.put(name, frameSlot); + return assignSource(WriteLocalNodeFactory.create(frameSlot, value)); + } + + public SLExpressionNode createRead(String name) { + FrameSlot frameSlot = lexicalScope.locals.get(name); + if (frameSlot != null) { + /* Read of a local variable. */ + return assignSource(ReadLocalNodeFactory.create(frameSlot)); + } else { + /* Read of a global name. In our language, the only global names are functions. */ + return new SLFunctionLiteralNode(context.getFunctionRegistry().lookup(name)); + } + } + + public SLExpressionNode createNumericLiteral(String value) { + try { + return assignSource(new SLLongLiteralNode(Long.parseLong(value))); + } catch (NumberFormatException ex) { + return assignSource(new SLBigIntegerLiteralNode(new BigInteger(value))); + } + } + + public SLExpressionNode createStringLiteral(String value) { + return assignSource(new SLStringLiteralNode(value)); + } + + public SLStatementNode createWhile(SLExpressionNode condition, SLStatementNode body) { + return assignSource(new SLWhileNode(condition, body)); + } + + public SLStatementNode createBreak() { + return assignSource(new SLBreakNode()); + } + + public SLStatementNode createContinue() { + return assignSource(new SLContinueNode()); + } + + public SLExpressionNode createCall(SLExpressionNode function, List parameters) { + return assignSource(SLCallNode.create(function, parameters.toArray(new SLExpressionNode[parameters.size()]))); + } + + public SLExpressionNode createBinary(String operation, SLExpressionNode left, SLExpressionNode right) { + SLExpressionNode binary; + switch (operation) { + case "+": + binary = SLAddNodeFactory.create(left, right); + break; + case "*": + binary = SLMulNodeFactory.create(left, right); + break; + case "/": + binary = SLDivNodeFactory.create(left, right); + break; + case "-": + binary = SLSubNodeFactory.create(left, right); + break; + case "<": + binary = SLLessThanNodeFactory.create(left, right); + break; + case "<=": + binary = SLLessOrEqualNodeFactory.create(left, right); + break; + case "==": + binary = SLEqualNodeFactory.create(left, right); + break; + case "!=": + binary = SLNotEqualNodeFactory.create(left, right); + break; + case "&&": + binary = SLLogicalAndNodeFactory.create(left, right); + break; + case "||": + binary = SLLogicalOrNodeFactory.create(left, right); + break; + default: + throw new RuntimeException("unexpected operation: " + operation); + } + return assignSource(binary); + } + + public SLStatementNode createReturn(SLExpressionNode value) { + return assignSource(new SLReturnNode(value)); + } + + public SLStatementNode createIf(SLExpressionNode condition, SLStatementNode then, SLStatementNode elseNode) { + return assignSource(new SLIfNode(condition, then, elseNode)); + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Scanner.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Scanner.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Scanner.java Tue Jan 28 12:55:06 2014 +0100 @@ -311,8 +311,8 @@ static final char EOL = '\n'; static final int eofSym = 0; - static final int maxT = 29; - static final int noSym = 29; + static final int maxT = 30; + static final int noSym = 30; public Buffer buffer; // scanner buffer @@ -347,23 +347,24 @@ start.set(123, 9); start.set(125, 10); start.set(59, 11); - start.set(60, 24); - start.set(62, 25); - start.set(61, 26); - start.set(33, 15); - start.set(43, 17); - start.set(45, 18); - start.set(42, 19); - start.set(47, 20); - start.set(35, 21); - start.set(63, 22); - start.set(58, 23); + start.set(124, 12); + start.set(38, 14); + start.set(60, 25); + start.set(62, 26); + start.set(61, 27); + start.set(33, 19); + start.set(43, 21); + start.set(45, 22); + start.set(42, 23); + start.set(47, 24); start.set(Buffer.EOF, -1); literals.put("function", new Integer(4)); - literals.put("if", new Integer(11)); - literals.put("else", new Integer(12)); - literals.put("while", new Integer(13)); - literals.put("return", new Integer(14)); + literals.put("break", new Integer(10)); + literals.put("continue", new Integer(12)); + literals.put("if", new Integer(13)); + literals.put("else", new Integer(14)); + literals.put("while", new Integer(15)); + literals.put("return", new Integer(16)); } @@ -519,69 +520,73 @@ } // NextCh already done case 1: recEnd = pos; recKind = 1; - if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); state = 1; break;} + if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z') {AddCh(); state = 1; break;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 2: - if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); state = 2; break;} - else if (ch == '"') {AddCh(); state = 3; break;} + if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); state = 2; break;} + else if (ch == '"') {AddCh(); state = 3; break;} else {state = 0; break;} - case 3: + case 3: {t.kind = 2; break loop;} case 4: recEnd = pos; recKind = 3; - if (ch >= '0' && ch <= '9') {AddCh(); state = 4; break;} + if (ch >= '0' && ch <= '9') {AddCh(); state = 4; break;} else {t.kind = 3; break loop;} - case 5: + case 5: {t.kind = 3; break loop;} - case 6: + case 6: {t.kind = 5; break loop;} - case 7: + case 7: {t.kind = 6; break loop;} - case 8: + case 8: {t.kind = 7; break loop;} - case 9: + case 9: {t.kind = 8; break loop;} - case 10: + case 10: {t.kind = 9; break loop;} - case 11: - {t.kind = 10; break loop;} - case 12: + case 11: + {t.kind = 11; break loop;} + case 12: + if (ch == '|') {AddCh(); state = 13; break;} + else {state = 0; break;} + case 13: {t.kind = 17; break loop;} - case 13: + case 14: + if (ch == '&') {AddCh(); state = 15; break;} + else {state = 0; break;} + case 15: {t.kind = 18; break loop;} - case 14: - {t.kind = 19; break loop;} - case 15: - if (ch == '=') {AddCh(); state = 16; break;} - else {state = 0; break;} - case 16: - {t.kind = 20; break loop;} - case 17: + case 16: {t.kind = 21; break loop;} - case 18: + case 17: {t.kind = 22; break loop;} - case 19: + case 18: {t.kind = 23; break loop;} - case 20: + case 19: + if (ch == '=') {AddCh(); state = 20; break;} + else {state = 0; break;} + case 20: {t.kind = 24; break loop;} - case 21: + case 21: {t.kind = 25; break loop;} - case 22: + case 22: {t.kind = 26; break loop;} - case 23: + case 23: {t.kind = 27; break loop;} case 24: - recEnd = pos; recKind = 15; - if (ch == '=') {AddCh(); state = 12; break;} - else {t.kind = 15; break loop;} + {t.kind = 28; break loop;} case 25: - recEnd = pos; recKind = 16; - if (ch == '=') {AddCh(); state = 13; break;} - else {t.kind = 16; break loop;} + recEnd = pos; recKind = 19; + if (ch == '=') {AddCh(); state = 16; break;} + else {t.kind = 19; break loop;} case 26: - recEnd = pos; recKind = 28; - if (ch == '=') {AddCh(); state = 14; break;} - else {t.kind = 28; break loop;} + recEnd = pos; recKind = 20; + if (ch == '=') {AddCh(); state = 17; break;} + else {t.kind = 20; break loop;} + case 27: + recEnd = pos; recKind = 29; + if (ch == '=') {AddCh(); state = 18; break;} + else {t.kind = 29; break loop;} } } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg Tue Jan 28 12:55:06 2014 +0100 @@ -24,6 +24,7 @@ PRODUCTIONS + SimpleLanguage = Function @@ -32,30 +33,46 @@ } . + Function = -"function" (. factory.startFunction(); .) -identifier (. String name = t.val; - List parameterNames = new ArrayList<>(); .) -["(" [identifier (. parameterNames.add(t.val); .) -] {"," identifier (. parameterNames.add(t.val); .) -} ")"] -Block (. factory.createFunction(body, name, parameterNames.toArray(new String[parameterNames.size()])); .) +"function" +identifier (. String name = t.val; .) +"(" (. List parameters = new ArrayList<>(); .) +[ + identifier (. parameters.add(t.val); .) + { + "," + identifier (. parameters.add(t.val); .) + } +] +")" (. factory.startFunction(name, parameters); .) +Block (. factory.finishFunction(body); .) . -Block -= (. List statements = new ArrayList<>(); .) + + +Block += (. factory.startBlock(); + List statements = new ArrayList<>(); .) "{" { - Statement (. statements.add(statement); .) + Statement (. statements.add(statement); .) } -"}" (. result = factory.createBlock(statements); .) +"}" (. result = factory.finishBlock(statements); .) . -Statement + +Statement = (. result = null; .) ( WhileStatement +| + "break" (. result = factory.createBreak(); .) + ";" +| + "continue" (. result = factory.createContinue(); .) + ";" | IfStatement | @@ -65,109 +82,117 @@ ) . -IfStatement + +IfStatement = -"if" "(" Expression ")" (. StatementNode thenNode = null; StatementNode elseNode = null; .) -Block -["else" Block] (. result = factory.createIf(condition, thenNode, elseNode); .) +"if" +"(" +Expression +")" +Block (. SLStatementNode elsePart = null; .) +[ + "else" + Block +] (. result = factory.createIf(condition, thenPart, elsePart); .) . -WhileStatement + +WhileStatement = "while" "(" -Expression +Expression ")" -Block (. result = factory.createWhile(condition, body); .) +Block (. result = factory.createWhile(condition, body); .) +. + + +ReturnStatement += +"return" +Expression ";" (. result = factory.createReturn(value); .) . -ReturnStatement +Expression = -"return" -Expression ";" (. result = factory.createReturn(value); .) +LogicTerm +{ + "||" (. String op = t.val; .) + LogicTerm (. result = factory.createBinary(op, result, right); .) +} . -Expression + +LogicTerm = -ValueExpression +LogicFactor +{ + "&&" (. String op = t.val; .) + LogicFactor (. result = factory.createBinary(op, result, right); .) +} +. + + +LogicFactor += +Arithmetic [ - ("<" | ">" | "<=" | ">=" | "==" | "!=" ) (. String op = t.val; .) - ValueExpression (. result = factory.createBinary(op, result, right); .) + ("<" | "<=" | "==" | "!=" ) (. String op = t.val; .) + Arithmetic (. result = factory.createBinary(op, result, right); .) ] . -ValueExpression + +Arithmetic = Term { ("+" | "-") (. String op = t.val; .) - Term (. result = factory.createBinary(op, result, right); .) + Term (. result = factory.createBinary(op, result, right); .) } . -Term + +Term = Factor { ("*" | "/") (. String op = t.val; .) - Factor (. result = factory.createBinary(op, result, right); .) + Factor (. result = factory.createBinary(op, result, right); .) } . -Factor + +Factor = (. result = null; .) ( - VariableRefOrCall -| - StringLiteral + identifier (. String name = t.val; .) + ( + "(" (. List parameters = new ArrayList<>(); + SLExpressionNode parameter; .) + [ + Expression (. parameters.add(parameter); .) + { + "," + Expression (. parameters.add(parameter); .) + } + ] (. result = factory.createCall(factory.createRead(name), parameters); .) + ")" + | + "=" + Expression (. result = factory.createAssignment(name, value); .) + | + (. result = factory.createRead(name); .) + ) | - NumericLiteral + stringLiteral (. result = factory.createStringLiteral(t.val.substring(1, t.val.length() - 1)); .) | - Ternary + numericLiteral (. result = factory.createNumericLiteral(t.val); .) | "(" Expression ")" ) . -Ternary (. TypedNode condition, thenPart, elsePart; .) -= -"#" Expression "?" Expression ":" Expression - (. result = factory.createTernary(condition, thenPart, elsePart); .) -. - -VariableRefOrCall -= -VariableRef -[ - (Parameters) (. result = factory.createCall(result, parameters); .) -| ("=" Expression) (. result = factory.createAssignment(result, assignment); .) -] -. - -Parameters -= -"(" (. List parameters = new ArrayList<>(); .) -[Expression (. parameters.add(e1); .) -{"," Expression (. parameters.add(e2); .) -} -] (. result = parameters.toArray(new TypedNode[parameters.size()]); .) -")" -. - -VariableRef -= -identifier (. result = factory.createLocal(t.val); .) -. - -StringLiteral -= -stringLiteral (. result = factory.createStringLiteral(t.val.substring(1, t.val.length() - 1)); .) -. - -NumericLiteral -= -numericLiteral (. result = factory.createNumericLiteral(t.val); .) -. END SimpleLanguage. diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLArguments.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLArguments.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLArguments.java Tue Jan 28 12:55:06 2014 +0100 @@ -27,13 +27,13 @@ public final class SLArguments extends Arguments { - public final Object[] arguments; + private final Object[] arguments; public SLArguments(Object[] arguments) { this.arguments = arguments; } - public static SLArguments get(VirtualFrame frame) { - return frame.getArguments(SLArguments.class); + public static Object[] getFromFrame(VirtualFrame frame) { + return frame.getArguments(SLArguments.class).arguments; } } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java Tue Jan 28 12:55:06 2014 +0100 @@ -24,32 +24,43 @@ import java.io.*; +import com.oracle.truffle.api.dsl.*; import com.oracle.truffle.api.source.*; import com.oracle.truffle.sl.builtins.*; +import com.oracle.truffle.sl.nodes.*; public final class SLContext { - - private final PrintStream printOutput; + private final SourceManager sourceManager; + private final PrintStream output; private final SLFunctionRegistry functionRegistry; - private final SourceManager sourceManager; - public SLContext(PrintStream print) { - this.printOutput = print; + public SLContext(SourceManager sourceManager, PrintStream output) { + this.sourceManager = sourceManager; + this.output = output; this.functionRegistry = new SLFunctionRegistry(); - DefaultBuiltins.install(this); - this.sourceManager = new SourceManager(); + + installBuiltins(); + } + + public SourceManager getSourceManager() { + return sourceManager; } public PrintStream getPrintOutput() { - return printOutput; + return output; } public SLFunctionRegistry getFunctionRegistry() { return functionRegistry; } - public SourceManager getSourceManager() { - return sourceManager; + private void installBuiltins() { + installBuiltin(SLPrintBuiltinFactory.getInstance(), "print"); + installBuiltin(SLTimeBuiltinFactory.getInstance(), "time"); + installBuiltin(SLDefineFunctionBuiltinFactory.getInstance(), "defineFunction"); } + private void installBuiltin(NodeFactory factory, String name) { + getFunctionRegistry().register(name, SLRootNode.createBuiltin(this, factory, name)); + } } diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunction.java Tue Jan 28 12:55:06 2014 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014, 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.truffle.sl.runtime; + +import com.oracle.truffle.api.*; +import com.oracle.truffle.api.utilities.*; + +public final class SLFunction { + + private final String name; + private RootCallTarget callTarget; + private final CyclicAssumption callTargetStable; + + protected SLFunction(String name) { + this.name = name; + this.callTargetStable = new CyclicAssumption(name); + } + + public String getName() { + return name; + } + + protected void setCallTarget(RootCallTarget callTarget) { + this.callTarget = callTarget; + callTargetStable.invalidate(); + } + + public RootCallTarget getCallTarget() { + return callTarget; + } + + public Assumption getCallTargetStable() { + return callTargetStable.getAssumption(); + } + + @Override + public String toString() { + return "function " + name; + } +} diff -r 3840d61e0e68 -r 739194d1e813 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunctionRegistry.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunctionRegistry.java Tue Jan 28 12:52:57 2014 +0100 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLFunctionRegistry.java Tue Jan 28 12:55:06 2014 +0100 @@ -28,17 +28,23 @@ public final class SLFunctionRegistry { - private Map map = new HashMap<>(); + private final Map functions = new HashMap<>(); - public void register(String name, CallTarget target) { - if (map.containsKey(name)) { - throw new IllegalArgumentException(String.format("Function with name '%s' already exists.", name)); + public SLFunction lookup(String name) { + SLFunction result = functions.get(name); + if (result == null) { + result = new SLFunction(name); + functions.put(name, result); } - map.put(name, target); + return result; } - public CallTarget lookup(String name) { - return map.get(name); + public void register(String name, RootCallTarget callTarget) { + SLFunction function = lookup(name); + function.setCallTarget(callTarget); } + public Collection getFunctions() { + return functions.values(); + } } diff -r 3840d61e0e68 -r 739194d1e813 mx/mx_graal.py --- a/mx/mx_graal.py Tue Jan 28 12:52:57 2014 +0100 +++ b/mx/mx_graal.py Tue Jan 28 12:55:06 2014 +0100 @@ -1358,7 +1358,7 @@ def sl(args): """run an SL program""" vmArgs, slArgs = _extract_VM_args(args) - vm(vmArgs + ['-cp', mx.classpath("com.oracle.truffle.sl"), "com.oracle.truffle.sl.SimpleLanguage"] + slArgs) + vm(vmArgs + ['-cp', mx.classpath("com.oracle.truffle.sl"), "com.oracle.truffle.sl.SLMain"] + slArgs) def trufflejar(args=None): """make truffle.jar""" diff -r 3840d61e0e68 -r 739194d1e813 mx/projects --- a/mx/projects Tue Jan 28 12:52:57 2014 +0100 +++ b/mx/projects Tue Jan 28 12:55:06 2014 +0100 @@ -24,15 +24,15 @@ library@DACAPO_SCALA@path=lib/dacapo-scala-0.1.0-20120216.jar library@DACAPO_SCALA@urls=http://repo.scalabench.org/snapshots/org/scalabench/benchmarks/scala-benchmark-suite/0.1.0-SNAPSHOT/scala-benchmark-suite-0.1.0-20120216.103539-3.jar -library@OKRA@path=lib/okra-1.5.jar -library@OKRA@urls=http://cr.openjdk.java.net/~tdeneau/okra-1.5.jar -library@OKRA@sourcePath=lib/okra-1.5-src.jar -library@OKRA@sourceUrls=http://cr.openjdk.java.net/~tdeneau/okra-1.5-src.jar +library@OKRA@path=lib/okra-1.6.jar +library@OKRA@urls=http://cr.openjdk.java.net/~tdeneau/okra-1.6.jar +library@OKRA@sourcePath=lib/okra-1.6-src.jar +library@OKRA@sourceUrls=http://cr.openjdk.java.net/~tdeneau/okra-1.6-src.jar -library@OKRA_WITH_SIM@path=lib/okra-1.5-with-sim.jar -library@OKRA_WITH_SIM@urls=http://cr.openjdk.java.net/~tdeneau/okra-1.5-with-sim.jar -library@OKRA_WITH_SIM@sourcePath=lib/okra-1.5-with-sim-src.jar -library@OKRA_WITH_SIM@sourceUrls=http://cr.openjdk.java.net/~tdeneau/okra-1.5-with-sim-src.jar +library@OKRA_WITH_SIM@path=lib/okra-1.6-with-sim.jar +library@OKRA_WITH_SIM@urls=http://cr.openjdk.java.net/~tdeneau/okra-1.6-with-sim.jar +library@OKRA_WITH_SIM@sourcePath=lib/okra-1.6-with-sim-src.jar +library@OKRA_WITH_SIM@sourceUrls=http://cr.openjdk.java.net/~tdeneau/okra-1.6-with-sim-src.jar library@JRUBYPARSER@path=lib/jrubyparser-0.5.0.jar library@JRUBYPARSER@urls=http://repo1.maven.org/maven2/org/jruby/jrubyparser/0.5.0/jrubyparser-0.5.0.jar diff -r 3840d61e0e68 -r 739194d1e813 src/gpu/ptx/vm/gpu_ptx.cpp --- a/src/gpu/ptx/vm/gpu_ptx.cpp Tue Jan 28 12:52:57 2014 +0100 +++ b/src/gpu/ptx/vm/gpu_ptx.cpp Tue Jan 28 12:55:06 2014 +0100 @@ -39,6 +39,7 @@ gpu::Ptx::cuda_cu_ctx_create_func_t gpu::Ptx::_cuda_cu_ctx_create; gpu::Ptx::cuda_cu_ctx_destroy_func_t gpu::Ptx::_cuda_cu_ctx_destroy; gpu::Ptx::cuda_cu_ctx_synchronize_func_t gpu::Ptx::_cuda_cu_ctx_synchronize; +gpu::Ptx::cuda_cu_ctx_get_current_func_t gpu::Ptx::_cuda_cu_ctx_get_current; gpu::Ptx::cuda_cu_ctx_set_current_func_t gpu::Ptx::_cuda_cu_ctx_set_current; gpu::Ptx::cuda_cu_device_get_count_func_t gpu::Ptx::_cuda_cu_device_get_count; gpu::Ptx::cuda_cu_device_get_name_func_t gpu::Ptx::_cuda_cu_device_get_name; @@ -337,123 +338,189 @@ return cu_function; } +// A PtxCall is used to manage executing a GPU kernel. In addition to launching +// the kernel, this class releases resources allocated for the execution. +class PtxCall: StackObj { + private: + JavaThread* _thread; // the thread on which this call is made + address _buffer; // buffer containing parameters and _return_value + int _buffer_size; // size (in bytes) of _buffer + oop* _pinned; // objects that have been pinned with cuMemHostRegister + int _pinned_length; // length of _pinned + gpu::Ptx::CUdeviceptr _ret_value; // pointer to slot in GPU memory holding the return value + int _ret_type_size; // size of the return type value + bool _ret_is_object; // specifies if the return type is Object + + bool check(int status, const char *action) { + if (status != GRAAL_CUDA_SUCCESS) { + Thread* THREAD = _thread; + char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, O_BUFLEN + 1); + jio_snprintf(message, O_BUFLEN, "[CUDA] *** Error (status=%d): %s", status, action); + if (TraceGPUInteraction || HAS_PENDING_EXCEPTION) { + tty->print_cr(message); + } + if (!HAS_PENDING_EXCEPTION) { + SharedRuntime::throw_and_post_jvmti_exception(_thread, vmSymbols::java_lang_RuntimeException(), message); + } + return false; + } + if (TraceGPUInteraction) { + tty->print_cr("[CUDA] Success: %s", action); + } + return true; + } + + public: + PtxCall(JavaThread* thread, address buffer, int buffer_size, oop* pinned, int encodedReturnTypeSize) : _thread(thread), + _buffer(buffer), _buffer_size(buffer_size), _pinned(pinned), _pinned_length(0), _ret_value(0), _ret_is_object(encodedReturnTypeSize < 0) { + _ret_type_size = _ret_is_object ? -encodedReturnTypeSize : encodedReturnTypeSize; + } + + bool is_object_return() { return _ret_is_object; } + + void alloc_return_value() { + if (_ret_type_size != 0) { + if (check(gpu::Ptx::_cuda_cu_memalloc(&_ret_value, _ret_type_size), "Allocate device memory for return value")) { + gpu::Ptx::CUdeviceptr* retValuePtr = (gpu::Ptx::CUdeviceptr*) ((_buffer + _buffer_size) - sizeof(_ret_value)); + *retValuePtr = _ret_value; + } + } + } + + void pin_objects(int count, int* objectOffsets) { + if (count == 0) { + return; + } + for (int i = 0; i < count; i++) { + int offset = objectOffsets[i]; + oop* argPtr = (oop*) (_buffer + offset); + oop obj = *argPtr; + if (obj != NULL) { + // Size (in bytes) of object + int objSize = obj->size() * HeapWordSize; + //tty->print_cr("Pinning object %d at offset %d: %p", i, offset, obj); + if (!check(gpu::Ptx::_cuda_cu_mem_host_register(obj, objSize, GRAAL_CU_MEMHOSTREGISTER_DEVICEMAP), "Pin object")) { + return; + } + + // Record original oop so that its memory can be unpinned + _pinned[_pinned_length++] = obj; + + // Replace host pointer to object with device pointer + // to object in kernel parameters buffer + if (!check(gpu::Ptx::_cuda_cu_mem_host_get_device_pointer((gpu::Ptx::CUdeviceptr*) argPtr, obj, 0), "Get device pointer for pinned object")) { + return; + } + } + } + } + + void launch(address kernel, jint dimX, jint dimY, jint dimZ) { + // grid dimensionality + unsigned int gridX = 1; + unsigned int gridY = 1; + unsigned int gridZ = 1; + void * config[] = { + GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER, (char*) (address) _buffer, + GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE, &_buffer_size, + GRAAL_CU_LAUNCH_PARAM_END + }; + if (check(gpu::Ptx::_cuda_cu_launch_kernel((struct CUfunc_st*) (address) kernel, + gridX, gridY, gridZ, + dimX, dimY, dimZ, + 0, NULL, NULL, (void**) &config), "Launch kernel")) { + } + } + + void synchronize() { + check(gpu::Ptx::_cuda_cu_ctx_synchronize(), "Synchronize kernel"); + } + + void unpin_objects() { + while (_pinned_length > 0) { + oop obj = _pinned[--_pinned_length]; + assert(obj != NULL, "npe"); + //tty->print_cr("Unpinning object %d: %p", _pinned_length, obj); + if (!check(gpu::Ptx::_cuda_cu_mem_host_unregister(obj), "Unpin object")) { + return; + } + } + } + + oop get_object_return_value() { + oop return_val; + check(gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, _ret_value, T_OBJECT_BYTE_SIZE), "Copy return value from device"); + return return_val; + } + + jlong get_primitive_return_value() { + jlong return_val; + check(gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, _ret_value, _ret_type_size), "Copy return value from device"); + return return_val; + } + + void free_return_value() { + if (_ret_value != 0) { + check(gpu::Ptx::_cuda_cu_memfree(_ret_value), "Free device memory"); + _ret_value = 0; + } + } + + void destroy_context() { + if (gpu::Ptx::_device_context != NULL) { + check(gpu::Ptx::_cuda_cu_ctx_destroy(gpu::Ptx::_device_context), "Destroy context"); + gpu::Ptx::_device_context = NULL; + } + } + + ~PtxCall() { + unpin_objects(); + free_return_value(); + destroy_context(); + } +}; + + JRT_ENTRY(jlong, gpu::Ptx::execute_kernel_from_vm(JavaThread* thread, jlong kernel, jint dimX, jint dimY, jint dimZ, - jlong parametersAndReturnValueBuffer, - jint parametersAndReturnValueBufferSize, + jlong buffer, + jint bufferSize, + jint objectParametersCount, + jlong objectParametersOffsets, + jlong pinnedObjects, int encodedReturnTypeSize)) if (kernel == 0L) { SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException(), NULL); return 0L; } - // grid dimensionality - unsigned int gridX = 1; - unsigned int gridY = 1; - unsigned int gridZ = 1; - - struct CUfunc_st* cu_function = (struct CUfunc_st*) (address) kernel; + PtxCall call(thread, (address) buffer, bufferSize, (oop*) (address) pinnedObjects, encodedReturnTypeSize); - void * config[5] = { - GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER, (char*) (address) parametersAndReturnValueBuffer, - GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE, ¶metersAndReturnValueBufferSize, - GRAAL_CU_LAUNCH_PARAM_END - }; +#define TRY(action) do { \ + action; \ + if (HAS_PENDING_EXCEPTION) return 0L; \ +} while (0) - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] launching kernel"); - } + TRY(call.alloc_return_value()); - bool isObjectReturn = encodedReturnTypeSize < 0; - int returnTypeSize = encodedReturnTypeSize < 0 ? -encodedReturnTypeSize : encodedReturnTypeSize; - gpu::Ptx::CUdeviceptr device_return_value; - int status; - if (returnTypeSize != 0) { - status = _cuda_cu_memalloc(&device_return_value, returnTypeSize); - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] *** Error (%d) Failed to allocate memory for return value pointer on device", status); - SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_RuntimeException(), "[CUDA] Failed to allocate memory for return value pointer on device"); - return 0L; - } - // Push device_return_value to kernelParams - gpu::Ptx::CUdeviceptr* returnValuePtr = (gpu::Ptx::CUdeviceptr*) - ((address) parametersAndReturnValueBuffer + - parametersAndReturnValueBufferSize - sizeof(device_return_value)); - *returnValuePtr = device_return_value; - } + TRY(call.pin_objects(objectParametersCount, (int*) (address) objectParametersOffsets)); + + TRY(call.launch((address) kernel, dimX, dimY, dimZ)); - status = _cuda_cu_launch_kernel(cu_function, - gridX, gridY, gridZ, - dimX, dimY, dimZ, - 0, NULL, NULL, (void **) &config); + TRY(call.synchronize()); - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to launch kernel"); - SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_RuntimeException(), "[CUDA] Failed to launch kernel"); + if (call.is_object_return()) { + oop return_val; + TRY(return_val = call.get_object_return_value()); + thread->set_vm_result(return_val); return 0L; } - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Success: Kernel Launch: X: %d Y: %d Z: %d", dimX, dimY, dimZ); - } - - status = _cuda_cu_ctx_synchronize(); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to synchronize launched kernel (%d)", status); - SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_RuntimeException(), "[CUDA] Failed to synchronize launched kernel"); - return 0L; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Success: Synchronized launch kernel"); - } + jlong return_val; + TRY(return_val = call.get_primitive_return_value()); + return return_val; - jlong primitiveReturnValue = 0L; - if (isObjectReturn) { - oop return_val; - status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&return_val, device_return_value, T_OBJECT_BYTE_SIZE); - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] *** Error (%d) Failed to copy value from device argument", status); - SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to copy value from device argument"); - return 0L; - } - thread->set_vm_result(return_val); - } else if (returnTypeSize > 0) { - status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&primitiveReturnValue, device_return_value, returnTypeSize); - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] *** Error (%d) Failed to copy value from device argument", status); - SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to copy value from device argument"); - return 0L; - } - } +#undef TRY - // Free device memory allocated for result - if (returnTypeSize != 0) { - status = gpu::Ptx::_cuda_cu_memfree(device_return_value); - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] *** Error (%d) Failed to free device memory of return value", status); - SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to free device memory of return value"); - return 0L; - } - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Success: Freed device memory of return value"); - } - - // Destroy context - status = gpu::Ptx::_cuda_cu_ctx_destroy(_device_context); - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] *** Error (%d) Failed to destroy context", status); - SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to destroy context"); - return 0L; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Success: Destroy context"); - } - - return primitiveReturnValue; JRT_END bool gpu::Ptx::execute_kernel(address kernel, PTXKernelArguments &ptxka, JavaValue &ret) { @@ -620,6 +687,7 @@ if (handle != NULL) { LOOKUP_CUDA_FUNCTION(cuInit, cuda_cu_init); LOOKUP_CUDA_FUNCTION(cuCtxSynchronize, cuda_cu_ctx_synchronize); + LOOKUP_CUDA_FUNCTION(cuCtxGetCurrent, cuda_cu_ctx_get_current); LOOKUP_CUDA_FUNCTION(cuCtxSetCurrent, cuda_cu_ctx_set_current); LOOKUP_CUDA_FUNCTION(cuDeviceGetCount, cuda_cu_device_get_count); LOOKUP_CUDA_FUNCTION(cuDeviceGetName, cuda_cu_device_get_name); diff -r 3840d61e0e68 -r 739194d1e813 src/gpu/ptx/vm/gpu_ptx.hpp --- a/src/gpu/ptx/vm/gpu_ptx.hpp Tue Jan 28 12:52:57 2014 +0100 +++ b/src/gpu/ptx/vm/gpu_ptx.hpp Tue Jan 28 12:55:06 2014 +0100 @@ -84,16 +84,19 @@ * Context creation flags */ -#define GRAAL_CU_CTX_MAP_HOST 0x08 +#define GRAAL_CU_CTX_MAP_HOST 0x08 +#define GRAAL_CU_CTX_SCHED_BLOCKING_SYNC 0x04 class Ptx { friend class gpu; + friend class PtxCall; protected: static bool probe_linkage(); static bool initialize_gpu(); static unsigned int total_cores(); - static void * generate_kernel(unsigned char *code, int code_len, const char *name); + static void* get_context(); + static void* generate_kernel(unsigned char *code, int code_len, const char *name); static bool execute_warp(int dimX, int dimY, int dimZ, address kernel, PTXKernelArguments & ka, JavaValue &ret); static bool execute_kernel(address kernel, PTXKernelArguments & ka, JavaValue &ret); public: @@ -106,8 +109,11 @@ typedef int CUdevice; /* CUDA device */ static jlong execute_kernel_from_vm(JavaThread* thread, jlong kernel, jint dimX, jint dimY, jint dimZ, - jlong parametersAndReturnValueBuffer, - jint parametersAndReturnValueBufferSize, + jlong buffer, + jint bufferSize, + jint objectParametersCount, + jlong objectParametersOffsets, + jlong pinnedObjects, int encodedReturnTypeSize); private: @@ -115,6 +121,7 @@ typedef int (*cuda_cu_ctx_create_func_t)(void*, unsigned int, CUdevice); typedef int (*cuda_cu_ctx_destroy_func_t)(void*); typedef int (*cuda_cu_ctx_synchronize_func_t)(void); + typedef int (*cuda_cu_ctx_get_current_func_t)(void*); typedef int (*cuda_cu_ctx_set_current_func_t)(void*); typedef int (*cuda_cu_device_get_count_func_t)(int*); typedef int (*cuda_cu_device_get_name_func_t)(char*, int, int); @@ -152,6 +159,7 @@ static cuda_cu_memfree_func_t _cuda_cu_memfree; static cuda_cu_memcpy_htod_func_t _cuda_cu_memcpy_htod; static cuda_cu_memcpy_dtoh_func_t _cuda_cu_memcpy_dtoh; + static cuda_cu_ctx_get_current_func_t _cuda_cu_ctx_get_current; static cuda_cu_ctx_set_current_func_t _cuda_cu_ctx_set_current; static cuda_cu_mem_host_register_func_t _cuda_cu_mem_host_register; static cuda_cu_mem_host_get_device_pointer_func_t _cuda_cu_mem_host_get_device_pointer; diff -r 3840d61e0e68 -r 739194d1e813 src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java --- a/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java Tue Jan 28 12:52:57 2014 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/BinaryParser.java Tue Jan 28 12:55:06 2014 +0100 @@ -35,6 +35,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.SwingUtilities; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; public class BinaryParser implements GraphParser { private static final int BEGIN_GROUP = 0x00; @@ -72,7 +74,10 @@ private final ReadableByteChannel channel; private final GraphDocument rootDocument; private final Deque folderStack; + private final Deque hashStack; private final ParseMonitor monitor; + + private MessageDigest digest; private enum Length { S, @@ -259,7 +264,12 @@ this.channel = channel; this.rootDocument = rootDocument; folderStack = new LinkedList<>(); + hashStack = new LinkedList<>(); this.monitor = monitor; + try { + this.digest = MessageDigest.getInstance("SHA-256"); + } catch (NoSuchAlgorithmException e) { + } } private void fill() throws IOException { @@ -274,6 +284,11 @@ while (buffer.remaining() < i) { fill(); } + buffer.mark(); + byte[] result = new byte[i]; + buffer.get(result); + digest.update(result); + buffer.reset(); } private int readByte() throws IOException { @@ -547,6 +562,7 @@ @Override public GraphDocument parse() throws IOException { folderStack.push(rootDocument); + hashStack.push(null); if (monitor != null) { monitor.setState("Starting parsing"); } @@ -589,6 +605,7 @@ }); } folderStack.push(group); + hashStack.push(null); if (callback != null && parent instanceof GraphDocument) { callback.started(group); } @@ -599,6 +616,7 @@ throw new IOException("Unbalanced groups"); } folderStack.pop(); + hashStack.pop(); break; } default: @@ -629,7 +647,17 @@ monitor.updateProgress(); } String title = readPoolObject(String.class); - return parseGraph(title); + digest.reset(); + InputGraph graph = parseGraph(title); + byte[] d = digest.digest(); + byte[] hash = hashStack.peek(); + if (hash != null && Arrays.equals(hash, d)) { + graph.getProperties().setProperty("_isDuplicate", "true"); + } else { + hashStack.pop(); + hashStack.push(d); + } + return graph; } private InputGraph parseGraph(String title) throws IOException { diff -r 3840d61e0e68 -r 739194d1e813 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java Tue Jan 28 12:52:57 2014 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/DiagramViewModel.java Tue Jan 28 12:55:06 2014 +0100 @@ -43,6 +43,7 @@ // Warning: Update setData method if fields are added private Group group; + private ArrayList graphs; private Set hiddenNodes; private Set onScreenNodes; private Set selectedNodes; @@ -56,6 +57,7 @@ private ChangedEvent hiddenNodesChangedEvent; private ChangedEvent viewPropertiesChangedEvent; private boolean showNodeHull; + private boolean hideDuplicates; private ChangedListener filterChainChangedListener = new ChangedListener() { @Override @@ -83,6 +85,10 @@ boolean groupChanged = (group == newModel.group); this.group = newModel.group; + if (groupChanged) { + filterGraphs(); + } + diagramChanged |= (filterChain != newModel.filterChain); this.filterChain = newModel.filterChain; diagramChanged |= (sequenceFilterChain != newModel.sequenceFilterChain); @@ -122,11 +128,33 @@ viewPropertiesChangedEvent.fire(); } + public boolean getHideDuplicates() { + return hideDuplicates; + } + + public void setHideDuplicates(boolean b) { + System.err.println("setHideDuplicates: " + b); + hideDuplicates = b; + InputGraph currentGraph = getFirstGraph(); + if (hideDuplicates) { + // Back up to the unhidden equivalent graph + int index = graphs.indexOf(currentGraph); + while (graphs.get(index).getProperties().get("_isDuplicate") != null) { + index--; + } + currentGraph = graphs.get(index); + } + filterGraphs(); + selectGraph(currentGraph); + viewPropertiesChangedEvent.fire(); + } + public DiagramViewModel(Group g, FilterChain filterChain, FilterChain sequenceFilterChain) { - super(calculateStringList(g)); + super(Arrays.asList("default")); this.showNodeHull = true; this.group = g; + filterGraphs(); assert filterChain != null; this.filterChain = filterChain; assert sequenceFilterChain != null; @@ -165,7 +193,7 @@ @Override public void changed(Group source) { assert source == group; - setPositions(calculateStringList(source)); + filterGraphs(); setSelectedNodes(selectedNodes); } }; @@ -211,7 +239,7 @@ } InputNode last = null; int index = 0; - for (InputGraph g : group.getGraphs()) { + for (InputGraph g : graphs) { Color curColor = colors.get(index); InputNode cur = g.getNode(id); if (cur != null) { @@ -316,16 +344,24 @@ diagramChanged(); } - private static List calculateStringList(Group g) { - List result = new ArrayList<>(); - for (InputGraph graph : g.getGraphs()) { - result.add(graph.getName()); + /* + * Select the set of graphs to be presented. + */ + private void filterGraphs() { + ArrayList result = new ArrayList<>(); + List positions = new ArrayList<>(); + for (InputGraph graph : group.getGraphs()) { + String duplicate = graph.getProperties().get("_isDuplicate"); + if (duplicate == null || !hideDuplicates) { + result.add(graph); + positions.add(graph.getName()); + } } - return result; + this.graphs = result; + setPositions(positions); } public InputGraph getFirstGraph() { - List graphs = group.getGraphs(); if (getFirstPosition() < graphs.size()) { return graphs.get(getFirstPosition()); } @@ -333,7 +369,6 @@ } public InputGraph getSecondGraph() { - List graphs = group.getGraphs(); if (getSecondPosition() < graphs.size()) { return graphs.get(getSecondPosition()); } @@ -341,7 +376,12 @@ } public void selectGraph(InputGraph g) { - int index = group.getGraphs().indexOf(g); + int index = graphs.indexOf(g); + if (index == -1 && hideDuplicates) { + // A graph was selected that's currently hidden, so unhide and select it. + setHideDuplicates(false); + index = graphs.indexOf(g); + } assert index != -1; setPositions(index, index); } diff -r 3840d61e0e68 -r 739194d1e813 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java Tue Jan 28 12:52:57 2014 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java Tue Jan 28 12:55:06 2014 +0100 @@ -78,6 +78,7 @@ private InstanceContent content; private InstanceContent graphContent; private OverviewAction overviewAction; + private HideDuplicatesAction hideDuplicatesAction; private PredSuccAction predSuccAction; private SelectionModeAction selectionModeAction; private PanModeAction panModeAction; @@ -87,6 +88,7 @@ private CardLayout cardLayout; private RangeSlider rangeSlider; private JToggleButton overviewButton; + private JToggleButton hideDuplicatesButton; private static final String PREFERRED_ID = "EditorTopComponent"; private static final String SATELLITE_STRING = "satellite"; private static final String SCENE_STRING = "scene"; @@ -207,6 +209,14 @@ rangeSliderModel.getDiagramChangedEvent().addListener(diagramChangedListener); rangeSliderModel.selectGraph(diagram.getGraph()); + rangeSliderModel.getViewPropertiesChangedEvent().addListener(new ChangedListener() { + @Override + public void changed(DiagramViewModel source) { + hideDuplicatesButton.setSelected(getModel().getHideDuplicates()); + hideDuplicatesAction.setState(getModel().getHideDuplicates()); + } + }); + toolBar.add(NextDiagramAction.get(NextDiagramAction.class)); toolBar.add(PrevDiagramAction.get(PrevDiagramAction.class)); @@ -230,6 +240,12 @@ toolBar.add(button); predSuccAction.addPropertyChangeListener(this); + hideDuplicatesAction = new HideDuplicatesAction(); + hideDuplicatesButton = new JToggleButton(hideDuplicatesAction); + hideDuplicatesButton.setSelected(false); + toolBar.add(hideDuplicatesButton); + hideDuplicatesAction.addPropertyChangeListener(this); + toolBar.addSeparator(); toolBar.add(UndoAction.get(UndoAction.class)); toolBar.add(RedoAction.get(RedoAction.class)); @@ -477,6 +493,9 @@ } else { showScene(); } + } else if (evt.getSource() == this.hideDuplicatesAction) { + boolean b = (Boolean) hideDuplicatesAction.getValue(HideDuplicatesAction.STATE); + this.getModel().setHideDuplicates(b); } else if (evt.getSource() == this.selectionModeAction || evt.getSource() == this.panModeAction) { if (panModeAction.isSelected()) { scene.setInteractionMode(DiagramViewer.InteractionMode.PANNING); diff -r 3840d61e0e68 -r 739194d1e813 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideDuplicatesAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/actions/HideDuplicatesAction.java Tue Jan 28 12:55:06 2014 +0100 @@ -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.sun.hotspot.igv.view.actions; + +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ImageIcon; +import org.openide.util.ImageUtilities; + +/** + * + * @author Tom Rodriguez + */ +public class HideDuplicatesAction extends AbstractAction { + + private boolean state; + public static final String STATE = "state"; + + public HideDuplicatesAction() { + putValue(AbstractAction.SMALL_ICON, new ImageIcon(ImageUtilities.loadImage(iconResource()))); + putValue(Action.SHORT_DESCRIPTION, "Hide graphs which are the same as the previous graph"); + setState(false); + } + + @Override + public void actionPerformed(ActionEvent ev) { + setState(!state); + } + + public void setState(boolean b) { + this.putValue(STATE, b); + this.state = b; + } + + protected String iconResource() { + return "com/sun/hotspot/igv/view/images/hideDuplicates.png"; + } +} diff -r 3840d61e0e68 -r 739194d1e813 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/hideDuplicates.png Binary file src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/images/hideDuplicates.png has changed diff -r 3840d61e0e68 -r 739194d1e813 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Tue Jan 28 12:52:57 2014 +0100 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Tue Jan 28 12:55:06 2014 +0100 @@ -669,6 +669,9 @@ } else { Disassembler::decode(cb, &st); } + if (st.size() <= 0) { + return NULL; + } Handle result = java_lang_String::create_from_platform_dependent_str(st.as_string(), CHECK_NULL); return JNIHandles::make_local(result()); @@ -827,6 +830,11 @@ C2V_END +C2V_VMENTRY(jboolean, isMature, (JNIEnv *env, jobject, jlong metaspace_method_data)) + MethodData* mdo = asMethodData(metaspace_method_data); + return mdo != NULL && mdo->is_mature(); +C2V_END + #define CC (char*) /*cast a literal from (const char*)*/ #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f)) @@ -846,6 +854,7 @@ #define HS_INSTALLED_CODE "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;" #define METASPACE_KLASS "J" #define METASPACE_METHOD "J" +#define METASPACE_METHOD_DATA "J" #define METASPACE_CONSTANT_POOL "J" JNINativeMethod CompilerToVM_methods[] = { @@ -889,6 +898,7 @@ {CC"readUnsafeKlassPointer", CC"("OBJECT")J", FN_PTR(readUnsafeKlassPointer)}, {CC"collectCounters", CC"()[J", FN_PTR(collectCounters)}, {CC"allocateCompileId", CC"("HS_RESOLVED_METHOD"I)I", FN_PTR(allocateCompileId)}, + {CC"isMature", CC"("METASPACE_METHOD_DATA")Z", FN_PTR(isMature)}, }; int CompilerToVM_methods_count() { diff -r 3840d61e0e68 -r 739194d1e813 src/share/vm/runtime/deoptimization.cpp --- a/src/share/vm/runtime/deoptimization.cpp Tue Jan 28 12:52:57 2014 +0100 +++ b/src/share/vm/runtime/deoptimization.cpp Tue Jan 28 12:55:06 2014 +0100 @@ -1359,7 +1359,7 @@ ScopeDesc* trap_scope = cvf->scope(); if (TraceDeoptimization) { - tty->print_cr(" bci=%d pc=%d, relative_pc=%d, method=%s" GRAAL_ONLY(", debug_id=%d"), trap_scope->bci(), fr.pc(), fr.pc() - nm->code_begin(), trap_scope->method()->name()->as_C_string() + tty->print_cr(" bci=%d pc=%d, relative_pc=%d, method=%s" GRAAL_ONLY(", debug_id=%d"), trap_scope->bci(), fr.pc(), fr.pc() - nm->code_begin(), trap_scope->method()->name_and_sig_as_C_string() #ifdef GRAAL , debug_id #endif