com.oracle.truffle.api.profiles.ConditionProfile Java Examples

The following examples show how to use com.oracle.truffle.api.profiles.ConditionProfile. 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: IOPrimitives.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization
protected final PointersObject doCursor(final PointersObject receiver, final PointersObject maskObject,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image,
                @Cached("createBinaryProfile()") final ConditionProfile depthProfile) {
    if (image.hasDisplay()) {
        final int[] words = receiver.getFormBits(cursorReadNode);
        final int depth = receiver.getFormDepth(cursorReadNode);
        final int height = receiver.getFormHeight(cursorReadNode);
        final int width = receiver.getFormWidth(cursorReadNode);
        final PointersObject offset = receiver.getFormOffset(cursorReadNode);
        final int offsetX = Math.abs(offsetReadNode.executeInt(offset, POINT.X));
        final int offsetY = Math.abs(offsetReadNode.executeInt(offset, POINT.Y));
        if (depthProfile.profile(depth == 1)) {
            final int[] mask = cursorReadNode.executeNative(maskObject, FORM.BITS).getIntStorage();
            image.getDisplay().setCursor(words, mask, width, height, 2, offsetX, offsetY);
        } else {
            image.getDisplay().setCursor(words, null, width, height, depth, offsetX, offsetY);
        }
    }
    return receiver;
}
 
Example #2
Source File: DispatchSendFromStackNode.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = {"!isCompiledMethodObject(targetObject)"})
protected static final Object doObjectAsMethod(final VirtualFrame frame, final NativeObject selector, final Object targetObject, final Object receiver,
                @SuppressWarnings("unused") final ClassObject rcvrClass,
                @Cached final SqueakObjectClassNode classNode,
                @Shared("writeNode") @Cached final AbstractPointersObjectWriteNode writeNode,
                @Cached final LookupMethodNode lookupNode,
                @Cached("create(argumentCount)") final FrameStackPopNNode popArguments,
                @Cached final FrameStackPopNode popReceiver,
                @Cached("createBinaryProfile()") final ConditionProfile isDoesNotUnderstandProfile,
                @Cached("create()") final DispatchEagerlyNode dispatchNode,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final Object[] arguments = popArguments.execute(frame);
    final Object poppedReceiver = popReceiver.execute(frame);
    assert receiver == poppedReceiver;
    final ClassObject targetClass = classNode.executeLookup(targetObject);
    final Object newLookupResult = lookupNode.executeLookup(targetClass, image.runWithInSelector);
    if (isDoesNotUnderstandProfile.profile(newLookupResult == null)) {
        final Object doesNotUnderstandMethod = lookupNode.executeLookup(targetClass, image.doesNotUnderstand);
        return dispatchNode.executeDispatch(frame, (CompiledMethodObject) doesNotUnderstandMethod,
                        new Object[]{targetObject, image.newMessage(writeNode, selector, targetClass, arguments)});
    } else {
        return dispatchNode.executeDispatch(frame, (CompiledMethodObject) newLookupResult, new Object[]{targetObject, selector, image.asArrayOfObjects(arguments), receiver});
    }
}
 
Example #3
Source File: MaterializeContextOnMethodExitNode.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = {"image.lastSeenContext != null"})
protected static final void doMaterialize(final VirtualFrame frame,
                @Cached("createBinaryProfile()") final ConditionProfile isNotLastSeenContextProfile,
                @Cached("createBinaryProfile()") final ConditionProfile continueProfile,
                @Cached("create(true)") final GetOrCreateContextNode getOrCreateContextNode,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final ContextObject lastSeenContext = image.lastSeenContext;
    final ContextObject context = getOrCreateContextNode.executeGet(frame);
    if (isNotLastSeenContextProfile.profile(context != lastSeenContext)) {
        assert context.hasTruffleFrame();
        if (lastSeenContext != null && !lastSeenContext.hasMaterializedSender()) {
            lastSeenContext.setSender(context);
        }
        if (continueProfile.profile(!context.isTerminated() && context.hasEscaped())) {
            // Materialization needs to continue in parent frame.
            image.lastSeenContext = context;
        } else {
            // If context has not escaped, materialization can terminate here.
            image.lastSeenContext = null;
        }
    }
}
 
Example #4
Source File: DispatchSendNode.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = {"!isCompiledMethodObject(targetObject)"})
protected final Object doObjectAsMethod(final VirtualFrame frame, final NativeObject selector, final Object targetObject, @SuppressWarnings("unused") final ClassObject rcvrClass,
                final Object[] rcvrAndArgs,
                @Cached final SqueakObjectClassNode classNode,
                @Shared("writeNode") @Cached final AbstractPointersObjectWriteNode writeNode,
                @Cached final LookupMethodNode lookupNode,
                @Cached("createBinaryProfile()") final ConditionProfile isDoesNotUnderstandProfile,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final Object[] arguments = ArrayUtils.allButFirst(rcvrAndArgs);
    final ClassObject targetClass = classNode.executeLookup(targetObject);
    final Object newLookupResult = lookupNode.executeLookup(targetClass, image.runWithInSelector);
    if (isDoesNotUnderstandProfile.profile(newLookupResult == null)) {
        final Object doesNotUnderstandMethod = lookupNode.executeLookup(targetClass, image.doesNotUnderstand);
        return dispatchNode.executeDispatch(frame, (CompiledMethodObject) doesNotUnderstandMethod,
                        new Object[]{targetObject, image.newMessage(writeNode, selector, targetClass, arguments)});
    } else {
        return dispatchNode.executeDispatch(frame, (CompiledMethodObject) newLookupResult, new Object[]{targetObject, selector, image.asArrayOfObjects(arguments), rcvrAndArgs[0]});
    }
}
 
Example #5
Source File: SocketPlugin.java    From trufflesqueak with MIT License 6 votes vote down vote up
@SuppressWarnings("unused")
@Specialization
protected static final PointersObject doWork(final PointersObject receiver,
                final long netType,
                final long socketType,
                final long rcvBufSize,
                final long semaphoreIndex,
                final long aReadSemaphore,
                final long aWriteSemaphore,
                @Cached("createBinaryProfile()") final ConditionProfile socketTypeProfile,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {

    final SqueakSocket socket;
    try {
        if (socketTypeProfile.profile(socketType == 1)) {
            socket = new SqueakUDPSocket();
        } else {
            assert socketType == 0;
            socket = new SqueakTCPSocket();
        }
    } catch (final IOException e) {
        throw PrimitiveFailed.andTransferToInterpreter();
    }
    return PointersObject.newHandleWithHiddenObject(image, socket);
}
 
Example #6
Source File: ContextObject.java    From trufflesqueak with MIT License 6 votes vote down vote up
@TruffleBoundary
public boolean pointsTo(final Object thang) {
    // TODO: make sure this works correctly
    if (truffleFrame != null) {
        if (getSender() == thang || thang.equals(getInstructionPointer(ConditionProfile.getUncached())) || thang.equals(getStackPointer()) || getMethod() == thang || getClosure() == thang ||
                        getReceiver() == thang) {
            return true;
        }
        for (int i = 0; i < getBlockOrMethod().getNumStackSlots(); i++) {
            if (atTemp(i) == thang) {
                return true;
            }
        }
    }
    return false;
}
 
Example #7
Source File: MiscPrimitivePlugin.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization
protected static final long doFind(@SuppressWarnings("unused") final Object receiver, final NativeObject string, final NativeObject inclusionMap, final long start,
                @Cached("createBinaryProfile()") final ConditionProfile notFoundProfile) {
    if (start < 1 || !string.isByteType() || !inclusionMap.isByteType()) {
        CompilerDirectives.transferToInterpreter();
        throw PrimitiveFailed.BAD_ARGUMENT;
    }
    if (inclusionMap.getByteLength() != 256) {
        CompilerDirectives.transferToInterpreter();
        return 0L;
    }
    final int stringSize = string.getByteLength();
    long index = start - 1;
    while (index < stringSize && inclusionMap.getByte(string.getByteUnsigned(index)) == 0) {
        index++;
    }
    return notFoundProfile.profile(index >= stringSize) ? 0L : index + 1;
}
 
Example #8
Source File: AbstractSqueakObject.java    From trufflesqueak with MIT License 6 votes vote down vote up
@ExportMessage
public Object readMember(final String member,
                @Shared("lookupNode") @Cached final LookupMethodByStringNode lookupNode,
                @Shared("classNode") @Cached final SqueakObjectClassNode classNode,
                @Exclusive @Cached("createBinaryProfile()") final ConditionProfile alternativeProfile) throws UnknownIdentifierException {
    final ClassObject classObject = classNode.executeLookup(this);
    final String selectorString = toSelector(member);
    final Object methodObject = lookupNode.executeLookup(classObject, selectorString);
    if (alternativeProfile.profile(methodObject instanceof CompiledMethodObject)) {
        return new BoundMethod((CompiledMethodObject) methodObject, this);
    } else {
        final Object methodObjectAlternative = lookupNode.executeLookup(classObject, toAlternativeSelector(selectorString));
        if (methodObjectAlternative instanceof CompiledMethodObject) {
            return new BoundMethod((CompiledMethodObject) methodObjectAlternative, this);
        } else {
            throw UnknownIdentifierException.create(member);
        }
    }
}
 
Example #9
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"obj.isLongType()", "isLongNilTag(value)"})
protected static final void doArrayOfLongsNilTagClash(final ArrayObject obj, final long index, final long value,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    /** `value` happens to be long nil tag, need to despecialize to be able store it. */
    obj.transitionFromLongsToObjects(isNilTagProfile);
    doArrayOfObjects(obj, index, value);
}
 
Example #10
Source File: SocketPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
/**
 * Return the host address found by the last host name lookup. Returns nil if the last
 * lookup was unsuccessful.
 */
@Specialization
protected static final AbstractSqueakObject doWork(@SuppressWarnings("unused") final Object receiver,
                @Cached("createBinaryProfile()") final ConditionProfile hasResultProfile,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final byte[] lastNameLookup = Resolver.lastHostNameLookupResult();
    LogUtils.SOCKET.finer(() -> "Name Lookup Result: " + Resolver.addressBytesToString(lastNameLookup));
    return hasResultProfile.profile(lastNameLookup == null) ? NilObject.SINGLETON : image.asByteArray(lastNameLookup);
}
 
Example #11
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"obj.isDoubleType()", "isDoubleNilTag(value)"})
protected static final void doArrayOfDoublesNilTagClash(final ArrayObject obj, final long index, final double value,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    // `value` happens to be double nil tag, need to despecialize to be able store it.
    obj.transitionFromDoublesToObjects(isNilTagProfile);
    doArrayOfObjects(obj, index, value);
}
 
Example #12
Source File: LargeIntegers.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization
protected static final Object doLargeInteger(final LargeIntegerObject receiver, final long arg,
                @Cached("createBinaryProfile()") final ConditionProfile positiveProfile) {
    if (positiveProfile.profile(arg >= 0)) {
        return receiver.longValue() & arg;
    } else {
        return receiver.and(arg);
    }
}
 
Example #13
Source File: ContextObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
@Specialization(guards = {"index >= TEMP_FRAME_START", "context == cachedContext", "index == cachedIndex"}, limit = "4")
protected static final Object doTempCached(final ContextObject context, final long index,
                @Cached("context") final ContextObject cachedContext,
                @Cached("index") final long cachedIndex,
                @Cached("createReadNode(cachedContext, cachedIndex)") final FrameSlotReadNode readNode,
                @Cached("createBinaryProfile()") final ConditionProfile isNullProfile) {
    return NilObject.nullToNil(readNode.executeReadUnsafe(cachedContext.getTruffleFrame()), isNullProfile);
}
 
Example #14
Source File: LargeIntegers.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(replaces = "doLong")
protected static final Object doLongWithOverflow(final long lhs, final long rhs,
                @Cached("createBinaryProfile()") final ConditionProfile differentSignProfile,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    if (differentSignProfile.profile(differentSign(lhs, rhs))) {
        return LargeIntegerObject.subtract(image, lhs, rhs);
    } else {
        return LargeIntegerObject.add(image, lhs, rhs);
    }
}
 
Example #15
Source File: LargeIntegers.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization
protected static final Object doLongLargeInteger(final long lhs, final LargeIntegerObject rhs,
                @Cached("createBinaryProfile()") final ConditionProfile differentSignProfile) {
    if (differentSignProfile.profile(rhs.differentSign(lhs))) {
        return rhs.add(lhs);
    } else {
        return LargeIntegerObject.subtract(lhs, rhs);
    }
}
 
Example #16
Source File: LargeIntegers.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization
protected static final Object doLargeInteger(final LargeIntegerObject lhs, final LargeIntegerObject rhs,
                @Cached("createBinaryProfile()") final ConditionProfile sameSignProfile) {
    if (sameSignProfile.profile(lhs.sameSign(rhs))) {
        return lhs.subtract(rhs);
    } else {
        return lhs.add(rhs);
    }
}
 
Example #17
Source File: LargeIntegers.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(rewriteOn = ArithmeticException.class)
protected static final long doLong(final long lhs, final long rhs,
                @Cached("createBinaryProfile()") final ConditionProfile differentSignProfile) {
    if (differentSignProfile.profile(differentSign(lhs, rhs))) {
        return Math.subtractExact(lhs, rhs);
    } else {
        return Math.addExact(lhs, rhs);
    }
}
 
Example #18
Source File: LargeIntegers.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(replaces = "doLong")
protected static final Object doLongWithOverflow(final long lhs, final long rhs,
                @Cached("createBinaryProfile()") final ConditionProfile differentSignProfile,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    if (differentSignProfile.profile(differentSign(lhs, rhs))) {
        return LargeIntegerObject.add(image, lhs, rhs);
    } else {
        return LargeIntegerObject.subtract(image, lhs, rhs);
    }
}
 
Example #19
Source File: LargeIntegers.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization
protected static final Object doLargeIntegerLong(final LargeIntegerObject lhs, final long rhs,
                @Cached("createBinaryProfile()") final ConditionProfile differentSignProfile) {
    if (differentSignProfile.profile(lhs.differentSign(rhs))) {
        return lhs.subtract(rhs);
    } else {
        return lhs.add(rhs);
    }
}
 
Example #20
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"obj.isCharType()", "isCharNilTag(value)"})
protected static final void doArrayOfCharsNilTagClash(final ArrayObject obj, final long index, final char value,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    /** `value` happens to be char nil tag, need to despecialize to be able store it. */
    obj.transitionFromCharsToObjects(isNilTagProfile);
    doArrayOfObjects(obj, index, value);
}
 
Example #21
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "obj.isDoubleType()")
protected final void doArrayOfDoubles(final Object[] target, final ArrayObject obj,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    final double[] doubles = obj.getDoubleStorage();
    for (int i = 0; i < doubles.length; i++) {
        target[offset + i] = ArrayObject.toObjectFromDouble(doubles[i], isNilTagProfile);
    }
}
 
Example #22
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "obj.isLongType()")
protected final void doArrayOfLongs(final Object[] target, final ArrayObject obj,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    final long[] longs = obj.getLongStorage();
    for (int i = 0; i < longs.length; i++) {
        target[offset + i] = ArrayObject.toObjectFromLong(longs[i], isNilTagProfile);
    }
}
 
Example #23
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "obj.isCharType()")
protected final void doArrayOfChars(final Object[] target, final ArrayObject obj,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    final char[] chars = obj.getCharStorage();
    for (int i = 0; i < chars.length; i++) {
        target[offset + i] = ArrayObject.toObjectFromChar(chars[i], isNilTagProfile);
    }
}
 
Example #24
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "obj.isDoubleType()")
protected static final Object[] doArrayOfDoubles(final Object first, final ArrayObject obj,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    final double[] doubles = obj.getDoubleStorage();
    final int length = doubles.length;
    final Object[] objects = new Object[1 + length];
    objects[0] = first;
    for (int i = 0; i < length; i++) {
        objects[1 + i] = ArrayObject.toObjectFromDouble(doubles[i], isNilTagProfile);
    }
    return objects;
}
 
Example #25
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"})
protected static final Object doAt8Unsigned(final NativeObject byteArray, final long byteOffsetLong, final long byteSize, final boolean isSigned,
                @Cached("createBinaryProfile()") final ConditionProfile positiveProfile,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
    final long signedLong = doAt8Signed(byteArray, byteOffsetLong, byteSize, isSigned);
    if (positiveProfile.profile(signedLong >= 0)) {
        return signedLong;
    } else {
        return LargeIntegerObject.toUnsigned(image, signedLong);
    }
}
 
Example #26
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "obj.isCharType()")
protected static final Object[] doArrayOfChars(final Object first, final ArrayObject obj,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    final char[] chars = obj.getCharStorage();
    final int length = chars.length;
    final Object[] objects = new Object[1 + length];
    objects[0] = first;
    for (int i = 0; i < length; i++) {
        final char value = chars[i];
        objects[1 + i] = ArrayObject.toObjectFromChar(value, isNilTagProfile);
    }
    return objects;
}
 
Example #27
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "obj.isDoubleType()")
protected static final Object[] doArrayOfDoubles(final ArrayObject obj,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    final double[] doubles = obj.getDoubleStorage();
    final int length = doubles.length;
    final Object[] objects = new Object[length];
    for (int i = 0; i < length; i++) {
        objects[i] = ArrayObject.toObjectFromDouble(doubles[i], isNilTagProfile);
    }
    return objects;
}
 
Example #28
Source File: ArrayObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = "obj.isLongType()")
protected static final Object[] doArrayOfLongs(final ArrayObject obj,
                @Cached("createBinaryProfile()") final ConditionProfile isNilTagProfile) {
    final long[] longs = obj.getLongStorage();
    final int length = longs.length;
    final Object[] objects = new Object[length];
    for (int i = 0; i < length; i++) {
        objects[i] = ArrayObject.toObjectFromLong(longs[i], isNilTagProfile);
    }
    return objects;
}
 
Example #29
Source File: MiscPrimitivePlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization
protected static final long doFind(@SuppressWarnings("unused") final Object receiver, final NativeObject key, final NativeObject body, final long start,
                final NativeObject matchTable,
                @Cached("createBinaryProfile()") final ConditionProfile quickReturnProfile,
                @Cached final BranchProfile foundProfile,
                @Cached final BranchProfile notFoundProfile) {
    if (!key.isByteType() || !body.isByteType() || !matchTable.isByteType() || matchTable.getByteLength() < 256) {
        CompilerDirectives.transferToInterpreter();
        throw PrimitiveFailed.BAD_ARGUMENT;
    }
    final int keyLength = key.getByteLength();
    if (quickReturnProfile.profile(keyLength == 0)) {
        return 0L;
    } else {
        final int bodyLength = body.getByteLength();
        for (long startIndex = Math.max(start - 1, 0); startIndex <= bodyLength - keyLength; startIndex++) {
            int index = 0;
            while (matchTable.getByte(body.getByteUnsigned(startIndex + index)) == matchTable.getByte(key.getByteUnsigned(index))) {
                if (index == keyLength - 1) {
                    foundProfile.enter();
                    return startIndex + 1;
                } else {
                    index++;
                }
            }
        }
        notFoundProfile.enter();
        return 0L;
    }
}
 
Example #30
Source File: AbstractPointersObjectNodes.java    From trufflesqueak with MIT License 5 votes vote down vote up
@Specialization(guards = {"cachedIndex == index", "object.getLayout() == cachedLayout", "cachedIndex >= cachedLayout.getInstSize()"}, limit = "VARIABLE_PART_INDEX_CACHE_LIMIT")
protected static final Object doReadFromVariablePartCachedIndex(final WeakVariablePointersObject object, @SuppressWarnings("unused") final int index,
                @Cached("index") final int cachedIndex,
                @Cached("object.getLayout()") final ObjectLayout cachedLayout,
                @Cached("createBinaryProfile()") final ConditionProfile nilProfile) {
    return object.getFromVariablePart(cachedIndex - cachedLayout.getInstSize(), nilProfile);
}