com.oracle.truffle.api.nodes.ExplodeLoop Java Examples

The following examples show how to use com.oracle.truffle.api.nodes.ExplodeLoop. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HashemInvokeNode.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExplodeLoop
@Override
public Object executeGeneric(VirtualFrame frame) {
    Object function = functionNode.executeGeneric(frame);

    /*
     * The number of arguments is constant for one invoke node. During compilation, the loop is
     * unrolled and the execute methods of all arguments are inlined. This is triggered by the
     * ExplodeLoop annotation on the method. The compiler assertion below illustrates that the
     * array length is really constant.
     */
    CompilerAsserts.compilationConstant(argumentNodes.length);

    Object[] argumentValues = new Object[argumentNodes.length];
    for (int i = 0; i < argumentNodes.length; i++) {
        argumentValues[i] = argumentNodes[i].executeGeneric(frame);
    }

    try {
        return library.execute(function, argumentValues);
    } catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {
        /* Execute was not successful. */
        throw HashemUndefinedNameException.undefinedBebin(this, function);
    }
}
 
Example #2
Source File: SqueakImageContext.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExplodeLoop
public MethodCacheEntry findMethodCacheEntry(final ClassObject classObject, final NativeObject selector) {
    methodCacheRandomish = methodCacheRandomish + 1 & 3;
    final int selectorHash = System.identityHashCode(selector);
    int firstProbe = (System.identityHashCode(classObject) ^ selectorHash) & METHOD_CACHE_MASK;
    int probe = firstProbe;
    for (int i = 0; i < METHOD_CACHE_REPROBES; i++) {
        final MethodCacheEntry entry = methodCache[probe];
        if (entry.getClassObject() == classObject && entry.getSelector() == selector) {
            return entry;
        }
        if (i == methodCacheRandomish) {
            firstProbe = probe;
        }
        probe = probe + selectorHash & METHOD_CACHE_MASK;
    }
    return methodCache[firstProbe].reuseFor(classObject, selector);
}
 
Example #3
Source File: FrameAccess.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExplodeLoop
public static Object[] newWith(final VirtualFrame frame, final CompiledMethodObject method, final Object sender, final BlockClosureObject closure,
                final FrameSlotReadNode[] receiverAndArgumentsNodes) {
    final int receiverAndArgumentsLength = receiverAndArgumentsNodes.length;
    final Object[] frameArguments = new Object[ArgumentIndicies.RECEIVER.ordinal() + receiverAndArgumentsLength];
    assert method != null : "Method should never be null";
    assert sender != null : "Sender should never be null";
    assert receiverAndArgumentsLength > 0 : "At least a receiver must be provided";
    frameArguments[ArgumentIndicies.METHOD.ordinal()] = method;
    frameArguments[ArgumentIndicies.SENDER_OR_SENDER_MARKER.ordinal()] = sender;
    frameArguments[ArgumentIndicies.CLOSURE_OR_NULL.ordinal()] = closure;
    for (int i = 0; i < receiverAndArgumentsNodes.length; i++) {
        frameArguments[ArgumentIndicies.RECEIVER.ordinal() + i] = receiverAndArgumentsNodes[i].executeRead(frame);
    }
    return frameArguments;
}
 
Example #4
Source File: FrameStackPopNNode.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Override
@ExplodeLoop
public Object[] execute(final VirtualFrame frame) {
    if (stackPointerSlot == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        stackPointerSlot = FrameAccess.getStackPointerSlot(frame);
        stackPointer = FrameAccess.getStackPointer(frame, stackPointerSlot) - readNodes.length;
        assert stackPointer >= 0 : "Bad stack pointer";
        for (int i = 0; i < readNodes.length; i++) {
            readNodes[i] = insert(FrameSlotReadNode.create(frame, stackPointer + i));
        }
    }
    FrameAccess.setStackPointer(frame, stackPointerSlot, stackPointer);
    final Object[] result = new Object[readNodes.length];
    for (int i = 0; i < readNodes.length; i++) {
        result[i] = readNodes[i].executeRead(frame);
    }
    return result;
}
 
Example #5
Source File: ClosureSymbolNode.java    From mumbler with GNU General Public License v3.0 5 votes vote down vote up
@ExplodeLoop
public <T> T readUpStack(FrameGet<T> getter, Frame frame)
        throws FrameSlotTypeException {

    Frame lookupFrame = frame;
    for (int i = 0; i < this.getDepth(); i++) {
        lookupFrame = getLexicalScope(lookupFrame);
    }
    return getter.get(lookupFrame, this.getSlot());
}
 
Example #6
Source File: InvokeNode.java    From mumbler with GNU General Public License v3.0 5 votes vote down vote up
@Override
@ExplodeLoop
public Object execute(VirtualFrame virtualFrame) {
    MumblerFunction function = this.evaluateFunction(virtualFrame);
    CompilerAsserts.compilationConstant(this.argumentNodes.length);
    CompilerAsserts.compilationConstant(this.isTail());

    Object[] argumentValues = new Object[this.argumentNodes.length + 1];
    argumentValues[0] = function.getLexicalScope();
    for (int i=0; i<this.argumentNodes.length; i++) {
        argumentValues[i+1] = this.argumentNodes[i].execute(virtualFrame);
    }

    return call(virtualFrame, function.callTarget, argumentValues);
}
 
Example #7
Source File: MumblerRootNode.java    From mumbler with GNU General Public License v3.0 5 votes vote down vote up
@Override
@ExplodeLoop
public Object execute(VirtualFrame virtualFrame) {
    int last = this.bodyNodes.length - 1;
    CompilerAsserts.compilationConstant(last);
    for (int i=0; i<last; i++) {
        this.bodyNodes[i].execute(virtualFrame);
    }
    return this.bodyNodes[last].execute(virtualFrame);
}
 
Example #8
Source File: SqueakFFIPrims.java    From trufflesqueak with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
@Specialization(guards = {"byteArray.isByteType()", "byteOffsetLong > 0", "byteSize == 8", "!isSigned", "inUnsignedBounds(value)"})
@ExplodeLoop
protected static final Object doAtPut8UnsignedLarge(final NativeObject byteArray, final long byteOffsetLong, final LargeIntegerObject value, final long byteSize, final boolean isSigned) {
    final int byteOffset = (int) byteOffsetLong - 1;
    final byte[] targetBytes = byteArray.getByteStorage();
    final byte[] sourceBytes = value.getBytes();
    final int numSourceBytes = sourceBytes.length;
    for (int i = 0; i < 8; i++) {
        targetBytes[byteOffset + i] = i < numSourceBytes ? sourceBytes[i] : 0;
    }
    return value;
}
 
Example #9
Source File: SqueakFFIPrims.java    From trufflesqueak with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
@Specialization(guards = {"byteArray.isByteType()", "byteOffsetLong > 0", "byteSize == 4", "!isSigned", "value.fitsIntoLong()",
                "inUnsignedBounds(value.longValueExact(), MAX_VALUE_UNSIGNED_4)"})
@ExplodeLoop
protected static final Object doAtPut4UnsignedLarge(final NativeObject byteArray, final long byteOffsetLong, final LargeIntegerObject value, final long byteSize, final boolean isSigned) {
    final int byteOffset = (int) byteOffsetLong - 1;
    final byte[] targetBytes = byteArray.getByteStorage();
    final byte[] sourceBytes = value.getBytes();
    final int numSourceBytes = sourceBytes.length;
    for (int i = 0; i < 4; i++) {
        targetBytes[byteOffset + i] = i < numSourceBytes ? sourceBytes[i] : 0;
    }
    return value;
}
 
Example #10
Source File: Matrix2x3Plugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExplodeLoop
protected final float[] loadMatrixAsFloat(final NativeObject object) {
    final int[] ints = loadMatrix(object);
    final float[] floats = new float[MATRIX_SIZE];
    for (int i = 0; i < MATRIX_SIZE; i++) {
        floats[i] = Float.intBitsToFloat(ints[i]);
    }
    return floats;
}
 
Example #11
Source File: ControlPrimitives.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExplodeLoop
@Specialization(guards = "sizeNode.execute(argArray) == cachedNumArgs", limit = "3")
protected final Object doExecuteCached(final VirtualFrame frame, @SuppressWarnings("unused") final ClassObject compiledMethodClass, final Object receiver, final ArrayObject argArray,
                final CompiledMethodObject methodObject,
                @Cached("sizeNode.execute(argArray)") final int cachedNumArgs,
                @Cached("create()") final DispatchEagerlyNode dispatchNode) {
    final Object[] dispatchRcvrAndArgs = new Object[1 + cachedNumArgs];
    dispatchRcvrAndArgs[0] = receiver;
    for (int i = 0; i < cachedNumArgs; i++) {
        dispatchRcvrAndArgs[1 + i] = readNode.execute(argArray, i);
    }
    return dispatchNode.executeDispatch(frame, methodObject, dispatchRcvrAndArgs);
}
 
Example #12
Source File: FrameStackInitializationNode.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExplodeLoop
public void executeInitialize(final VirtualFrame frame) {
    if (stackPointerSlot == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        stackPointerSlot = FrameAccess.getStackPointerSlot(frame);
        final CompiledCodeObject code;
        final int initialSP;
        final BlockClosureObject closure = FrameAccess.getClosure(frame);
        if (closure == null) {
            code = FrameAccess.getMethod(frame);
            initialSP = code.getNumTemps();
        } else {
            code = closure.getCompiledBlock();
            initialSP = code.getNumArgsAndCopied();
        }
        numArgs = code.getNumArgsAndCopied();
        writeNodes = new FrameSlotWriteNode[initialSP];
        for (int i = 0; i < writeNodes.length; i++) {
            writeNodes[i] = insert(FrameSlotWriteNode.create(code.getStackSlot(i)));
        }
    }
    CompilerAsserts.partialEvaluationConstant(writeNodes.length);
    final Object[] arguments = frame.getArguments();
    assert arguments.length == FrameAccess.expectedArgumentSize(numArgs);
    for (int i = 0; i < numArgs; i++) {
        writeNodes[i].executeWrite(frame, arguments[FrameAccess.getArgumentStartIndex() + i]);
    }
    // Initialize remaining temporary variables with nil in newContext.
    for (int i = numArgs; i < writeNodes.length; i++) {
        writeNodes[i].executeWrite(frame, NilObject.SINGLETON);
    }
    FrameAccess.setStackPointer(frame, stackPointerSlot, writeNodes.length);
}
 
Example #13
Source File: MultiEventHandler.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@ExplodeLoop
@Override
public Object onUnwind(VirtualFrame frame, Object info) {
    Object res = null;
    for (BaseEventHandlerNode handler : handlers) {
        res = handler.onUnwind(frame, info);
        if (res != null) {
            return res;
        }
    }
    return null;
}
 
Example #14
Source File: MultiEventHandler.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
@ExplodeLoop
public void executeExceptionalCtrlFlow(VirtualFrame frame, Throwable exception, Object[] inputs) throws Exception {
    for (BaseEventHandlerNode handler : handlers) {
        handler.executeExceptionalCtrlFlow(frame, exception, inputs);
    }
}
 
Example #15
Source File: MultiEventHandler.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@ExplodeLoop
@Override
public void executeExceptional(VirtualFrame frame, Throwable exception) throws Exception {
    for (BaseEventHandlerNode handler : handlers) {
        handler.executeExceptional(frame, exception);
    }
}
 
Example #16
Source File: MultiEventHandler.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
@ExplodeLoop
public void executePost(VirtualFrame frame, Object result, Object[] inputs) throws Exception {
    for (BaseEventHandlerNode handler : handlers) {
        handler.executePost(frame, result, inputs);
        noChildHandlerUpdate = noChildHandlerUpdate && (handler.wantsToUpdateHandler() == handler);
    }
}
 
Example #17
Source File: MultiEventHandler.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@Override
@ExplodeLoop
public void executePre(VirtualFrame frame, Object[] inputs) throws Exception {
    for (BaseEventHandlerNode handler : handlers) {
        handler.executePre(frame, inputs);
        noChildHandlerUpdate = noChildHandlerUpdate && (handler.wantsToUpdateHandler() == handler);
    }
}
 
Example #18
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExplodeLoop
private static Object[] createShredded(int[] shreddedArguments, Object[] arguments) {
    Object[] result = new Object[shreddedArguments.length];
    for (int i = 0; i < shreddedArguments.length; i++) {
        result[i] = new ShreddedObject(arguments[shreddedArguments[i]]);
    }
    return result;
}
 
Example #19
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExplodeLoop
private static Object[] mapArguments(InteropLibrary[] valueInterop, MappedFunction receiver, ArgumentArray arguments, ArgumentArray shredded, ArgumentArray values) {
    Object[] result = new Object[valueInterop.length];
    for (int i = 0; i < valueInterop.length; i++) {
        try {
            result[i] = valueInterop[i].execute(receiver.values[i], arguments, shredded, values);
        } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
            CompilerDirectives.transferToInterpreter();
            throw new MapException("cannot map parameter " + i + ": " + e.getMessage());
        }
    }
    return result;
}
 
Example #20
Source File: ExecuteContextNode.java    From trufflesqueak with MIT License 4 votes vote down vote up
@ExplodeLoop(kind = ExplodeLoop.LoopExplosionKind.MERGE_EXPLODE)
private Object startBytecode(final VirtualFrame frame) {
    CompilerAsserts.partialEvaluationConstant(bytecodeNodes.length);
    int pc = 0;
    int backJumpCounter = 0;
    Object returnValue = null;
    bytecode_loop: while (pc != LOCAL_RETURN_PC) {
        CompilerAsserts.partialEvaluationConstant(pc);
        final AbstractBytecodeNode node = fetchNextBytecodeNode(pc);
        if (node instanceof CallPrimitiveNode) {
            final CallPrimitiveNode callPrimitiveNode = (CallPrimitiveNode) node;
            if (callPrimitiveNode.primitiveNode != null) {
                try {
                    returnValue = callPrimitiveNode.primitiveNode.executePrimitive(frame);
                    pc = LOCAL_RETURN_PC;
                    continue bytecode_loop;
                } catch (final PrimitiveFailed e) {
                    /* getHandlePrimitiveFailedNode() also acts as a BranchProfile. */
                    getHandlePrimitiveFailedNode().executeHandle(frame, e.getReasonCode());
                    /*
                     * Same toString() methods may throw compilation warnings, this is expected
                     * and ok for primitive failure logging purposes. Note that primitives that
                     * are not implemented are also not logged.
                     */
                    LogUtils.PRIMITIVES.fine(() -> callPrimitiveNode.primitiveNode.getClass().getSimpleName() + " failed (arguments: " +
                                    ArrayUtils.toJoinedString(", ", FrameAccess.getReceiverAndArguments(frame)) + ")");
                    /* continue with fallback code. */
                }
            }
            pc = callPrimitiveNode.getSuccessorIndex();
            assert pc == CallPrimitiveNode.NUM_BYTECODES;
            continue;
        } else if (node instanceof AbstractSendNode) {
            pc = node.getSuccessorIndex();
            FrameAccess.setInstructionPointer(frame, code, pc);
            node.executeVoid(frame);
            final int actualNextPc = FrameAccess.getInstructionPointer(frame, code);
            if (pc != actualNextPc) {
                /*
                 * pc has changed, which can happen if a context is restarted (e.g. as part of
                 * Exception>>retry). For now, we continue in the interpreter to avoid confusing
                 * the Graal compiler.
                 */
                CompilerDirectives.transferToInterpreter();
                pc = actualNextPc;
            }
            continue bytecode_loop;
        } else if (node instanceof ConditionalJumpNode) {
            final ConditionalJumpNode jumpNode = (ConditionalJumpNode) node;
            if (jumpNode.executeCondition(frame)) {
                final int successor = jumpNode.getJumpSuccessorIndex();
                if (CompilerDirectives.inInterpreter() && successor <= pc) {
                    backJumpCounter++;
                }
                pc = successor;
                continue bytecode_loop;
            } else {
                final int successor = jumpNode.getSuccessorIndex();
                if (CompilerDirectives.inInterpreter() && successor <= pc) {
                    backJumpCounter++;
                }
                pc = successor;
                continue bytecode_loop;
            }
        } else if (node instanceof UnconditionalJumpNode) {
            final int successor = ((UnconditionalJumpNode) node).getJumpSuccessor();
            if (CompilerDirectives.inInterpreter() && successor <= pc) {
                backJumpCounter++;
            }
            pc = successor;
            continue bytecode_loop;
        } else if (node instanceof AbstractReturnNode) {
            returnValue = ((AbstractReturnNode) node).executeReturn(frame);
            pc = LOCAL_RETURN_PC;
            continue bytecode_loop;
        } else if (node instanceof PushClosureNode) {
            final PushClosureNode pushClosureNode = (PushClosureNode) node;
            pushClosureNode.executePush(frame);
            pc = pushClosureNode.getClosureSuccessorIndex();
            continue bytecode_loop;
        } else {
            /* All other bytecode nodes. */
            node.executeVoid(frame);
            pc = node.getSuccessorIndex();
            continue bytecode_loop;
        }
    }
    assert returnValue != null && !hasModifiedSender(frame);
    FrameAccess.terminate(frame, code.getInstructionPointerSlot());
    assert backJumpCounter >= 0;
    LoopNode.reportLoopCount(this, backJumpCounter);
    return returnValue;
}