Mercurial > hg > truffle
changeset 15236:c8d4ace5b78c
Merge.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 18 Apr 2014 14:14:48 +0200 |
parents | 27afd57655ba (diff) 5c9185d42a3a (current diff) |
children | d49a8fe10727 |
files | |
diffstat | 8 files changed, 160 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java Fri Apr 18 13:40:31 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/ArrayLengthNode.java Fri Apr 18 14:14:48 2014 +0200 @@ -28,6 +28,7 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; +import com.oracle.graal.nodes.util.*; /** * The {@code ArrayLength} instruction gets the length of an array. @@ -57,18 +58,25 @@ /** * Gets the length of an array if possible. * - * @param graph TODO - * @param array an array - * * @return a node representing the length of {@code array} or null if it is not available */ - public static ValueNode readArrayLength(StructuredGraph graph, ValueNode array, ConstantReflectionProvider constantReflection) { - if (array instanceof ArrayLengthProvider) { - ValueNode length = ((ArrayLengthProvider) array).length(); + public static ValueNode readArrayLength(StructuredGraph graph, ValueNode originalArray, ConstantReflectionProvider constantReflection) { + ArrayLengthProvider foundArrayLengthProvider = null; + ValueNode result = originalArray; + while (result instanceof ValueProxy) { + if (result instanceof ArrayLengthProvider) { + foundArrayLengthProvider = (ArrayLengthProvider) result; + } + result = ((ValueProxy) result).getOriginalNode(); + } + + if (foundArrayLengthProvider != null) { + ValueNode length = foundArrayLengthProvider.length(); if (length != null) { return length; } } + ValueNode array = GraphUtil.unproxify(originalArray); if (constantReflection != null && array.isConstant() && !array.isNullConstant()) { Constant constantValue = array.asConstant(); if (constantValue != null && constantValue.isNonNull()) {
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Fri Apr 18 13:40:31 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java Fri Apr 18 14:14:48 2014 +0200 @@ -51,6 +51,8 @@ protected final CompilationPolicy compilationPolicy; private OptimizedCallTarget splitSource; private final AtomicInteger callSitesKnown = new AtomicInteger(0); + @CompilationFinal private Class<?>[] profiledArgumentTypes; + @CompilationFinal private Assumption profiledArgumentTypesAssumption; @CompilationFinal private Class<?> profiledReturnType; @CompilationFinal private Assumption profiledReturnTypeAssumption; @@ -83,9 +85,21 @@ } public Object callDirect(Object... args) { + if (profiledArgumentTypesAssumption == null) { + CompilerDirectives.transferToInterpreter(); + profiledArgumentTypesAssumption = Truffle.getRuntime().createAssumption("Profiled Argument Types"); + profiledArgumentTypes = new Class<?>[args.length]; + } else if (profiledArgumentTypes != null) { + if (profiledArgumentTypes.length != args.length) { + CompilerDirectives.transferToInterpreter(); + profiledArgumentTypesAssumption.invalidate(); + profiledArgumentTypes = null; + } + } + Object result = callBoundary(args); Class<?> klass = profiledReturnType; - if (klass != null && profiledReturnTypeAssumption.isValid()) { + if (klass != null && CompilerDirectives.inCompiledCode() && profiledReturnTypeAssumption.isValid()) { result = CompilerDirectives.unsafeCast(result, klass, true, true); } return result; @@ -247,7 +261,13 @@ } } - public final Object callRoot(Object[] args) { + public final Object callRoot(Object[] originalArguments) { + + Object[] args = originalArguments; + if (this.profiledArgumentTypesAssumption != null && CompilerDirectives.inCompiledCode() && profiledArgumentTypesAssumption.isValid()) { + args = CompilerDirectives.unsafeCast(castArrayFixedLength(args, profiledArgumentTypes.length), Object[].class, true, true); + } + VirtualFrame frame = createFrame(getRootNode().getFrameDescriptor(), args); Object result = callProxy(frame); @@ -269,6 +289,10 @@ return result; } + private static Object castArrayFixedLength(Object[] args, @SuppressWarnings("unused") int length) { + return args; + } + public static FrameWithoutBoxing createFrame(FrameDescriptor descriptor, Object[] args) { return new FrameWithoutBoxing(descriptor, args); }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/CompilerDirectivesSubstitutions.java Fri Apr 18 13:40:31 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/CompilerDirectivesSubstitutions.java Fri Apr 18 14:14:48 2014 +0200 @@ -55,6 +55,11 @@ } @MethodSubstitution + public static boolean inCompiledCode() { + return true; + } + + @MethodSubstitution public static void interpreterOnly(@SuppressWarnings("unused") Runnable runnable) { }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/OptimizedCallTargetSubstitutions.java Fri Apr 18 13:40:31 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/OptimizedCallTargetSubstitutions.java Fri Apr 18 14:14:48 2014 +0200 @@ -23,6 +23,8 @@ package com.oracle.graal.truffle.substitutions; import com.oracle.graal.api.replacements.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.type.*; import com.oracle.graal.truffle.*; import com.oracle.graal.truffle.nodes.frame.*; import com.oracle.truffle.api.frame.*; @@ -34,4 +36,9 @@ private static FrameWithoutBoxing createFrame(FrameDescriptor descriptor, Object[] args) { return NewFrameNode.allocate(FrameWithoutBoxing.class, descriptor, args); } + + @MethodSubstitution + private static Object castArrayFixedLength(Object[] args, int length) { + return PiArrayNode.piArrayCast(args, length, StampFactory.forNodeIntrinsic()); + } }
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java Fri Apr 18 13:40:31 2014 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerDirectives.java Fri Apr 18 14:14:48 2014 +0200 @@ -84,6 +84,15 @@ } /** + * Returns a boolean value indicating whether the method is executed in the compiled code. + * + * @return {@code false} when executed in the interpreter, {@code true} in compiled code. + */ + public static boolean inCompiledCode() { + return false; + } + + /** * Directive for the compiler that the given runnable should only be executed in the interpreter * and ignored in the compiled code. *
--- a/graal/com.oracle.truffle.sl.test/tests/HelloEqualsWorld.output Fri Apr 18 13:40:31 2014 +0200 +++ b/graal/com.oracle.truffle.sl.test/tests/HelloEqualsWorld.output Fri Apr 18 14:14:48 2014 +0200 @@ -0,0 +1,90 @@ +Initial stack trace: +Frame: root doIt, a=0, hello=null +Frame: root main, i=0 +After 123 assignment: +Frame: root doIt, a=0, hello=123 +Frame: root main, i=0 +After hello assignment: +Frame: root doIt, a=0, hello=world +Frame: root main, i=0 +Initial stack trace: +Frame: root doIt, a=1, hello=null +Frame: root main, i=1 +After 123 assignment: +Frame: root doIt, a=1, hello=123 +Frame: root main, i=1 +After hello assignment: +Frame: root doIt, a=1, hello=world +Frame: root main, i=1 +Initial stack trace: +Frame: root doIt, a=2, hello=null +Frame: root main, i=2 +After 123 assignment: +Frame: root doIt, a=2, hello=123 +Frame: root main, i=2 +After hello assignment: +Frame: root doIt, a=2, hello=world +Frame: root main, i=2 +Initial stack trace: +Frame: root doIt, a=3, hello=null +Frame: root main, i=3 +After 123 assignment: +Frame: root doIt, a=3, hello=123 +Frame: root main, i=3 +After hello assignment: +Frame: root doIt, a=3, hello=world +Frame: root main, i=3 +Initial stack trace: +Frame: root doIt, a=4, hello=null +Frame: root main, i=4 +After 123 assignment: +Frame: root doIt, a=4, hello=123 +Frame: root main, i=4 +After hello assignment: +Frame: root doIt, a=4, hello=world +Frame: root main, i=4 +Initial stack trace: +Frame: root doIt, a=5, hello=null +Frame: root main, i=5 +After 123 assignment: +Frame: root doIt, a=5, hello=123 +Frame: root main, i=5 +After hello assignment: +Frame: root doIt, a=5, hello=world +Frame: root main, i=5 +Initial stack trace: +Frame: root doIt, a=6, hello=null +Frame: root main, i=6 +After 123 assignment: +Frame: root doIt, a=6, hello=123 +Frame: root main, i=6 +After hello assignment: +Frame: root doIt, a=6, hello=world +Frame: root main, i=6 +Initial stack trace: +Frame: root doIt, a=7, hello=null +Frame: root main, i=7 +After 123 assignment: +Frame: root doIt, a=7, hello=123 +Frame: root main, i=7 +After hello assignment: +Frame: root doIt, a=7, hello=world +Frame: root main, i=7 +Initial stack trace: +Frame: root doIt, a=8, hello=null +Frame: root main, i=8 +After 123 assignment: +Frame: root doIt, a=8, hello=123 +Frame: root main, i=8 +After hello assignment: +Frame: root doIt, a=8, hello=world +Frame: root main, i=8 +Initial stack trace: +Frame: root doIt, a=9, hello=null +Frame: root main, i=9 +After 123 assignment: +Frame: root doIt, a=9, hello=123 +Frame: root main, i=9 +After hello assignment: +Frame: root doIt, a=9, hello=world +Frame: root main, i=9 \ No newline at end of file
--- a/graal/com.oracle.truffle.sl.test/tests/HelloEqualsWorld.sl Fri Apr 18 13:40:31 2014 +0200 +++ b/graal/com.oracle.truffle.sl.test/tests/HelloEqualsWorld.sl Fri Apr 18 14:14:48 2014 +0200 @@ -1,14 +1,14 @@ function doIt(a) { -// println("Initial stack trace:"); -// println(stacktrace()); + println("Initial stack trace:"); + println(stacktrace()); hello = 123; -// println("After 123 assignment:"); -// println(stacktrace()); + println("After 123 assignment:"); + println(stacktrace()); -// helloEqualsWorld(); -// println("After hello assignment:"); -// println(stacktrace()); + helloEqualsWorld(); + println("After hello assignment:"); + println(stacktrace()); // readln(); }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLHelloEqualsWorldBuiltin.java Fri Apr 18 13:40:31 2014 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLHelloEqualsWorldBuiltin.java Fri Apr 18 14:14:48 2014 +0200 @@ -35,11 +35,11 @@ public abstract class SLHelloEqualsWorldBuiltin extends SLBuiltinNode { @Specialization - public Object change() { + public String change() { FrameInstance frameInstance = Truffle.getRuntime().getStackTrace().iterator().next(); Frame frame = frameInstance.getFrame(FrameAccess.READ_WRITE, false); FrameSlot slot = frame.getFrameDescriptor().findOrAddFrameSlot("hello"); frame.setObject(slot, "world"); - return null; + return "world"; } }