Search in sources :

Example 46 with Specialization

use of com.oracle.truffle.api.dsl.Specialization in project TrufflePascal by Aspect26.

the class GetDateNode method getDate.

@Specialization
void getDate(Reference yearReference, Reference monthReference, Reference dayReference, Reference weekDayReference) {
    LocalDateTime now = LocalDateTime.now();
    this.setLongValue(yearReference, now.getYear());
    this.setLongValue(monthReference, now.getMonthValue());
    this.setLongValue(dayReference, now.getDayOfMonth());
    // by specification, Sunday shall be 0, not 7 in Pascal
    this.setLongValue(weekDayReference, now.getDayOfWeek().getValue() % 7);
}
Also used : LocalDateTime(java.time.LocalDateTime) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 47 with Specialization

use of com.oracle.truffle.api.dsl.Specialization in project graal by oracle.

the class SLCallUntilOptimizedBuiltin method callUntilCompiled.

@Specialization
public SLFunction callUntilCompiled(SLFunction function, boolean checkTarget) {
    OptimizedCallTarget target = ((OptimizedCallTarget) function.getCallTarget());
    for (int i = 0; i < MAX_CALLS; i++) {
        if (isCompiling(target)) {
            break;
        } else {
            indirectCall.call(target, EMPTY_ARGS);
        }
    }
    // call one more in compiled
    indirectCall.call(target, EMPTY_ARGS);
    if (checkTarget) {
        checkTarget(target);
    }
    return function;
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 48 with Specialization

use of com.oracle.truffle.api.dsl.Specialization in project graal by oracle.

the class SLCallWithOptionOverrideBuiltin method callWithOptionOverride.

@Specialization
public SLFunction callWithOptionOverride(SLFunction function, String name, Object value) {
    TruffleOptionsOverrideScope scope = override(name, value);
    OptimizedCallTarget target = ((OptimizedCallTarget) function.getCallTarget());
    indirectCall.call(target, EMPTY_ARGS);
    close(scope);
    return function;
}
Also used : TruffleOptionsOverrideScope(org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 49 with Specialization

use of com.oracle.truffle.api.dsl.Specialization in project graal by oracle.

the class SLWaitForOptimizationBuiltin method waitForOptimization.

@Specialization
public SLFunction waitForOptimization(SLFunction function, long timeout) {
    OptimizedCallTarget target = (OptimizedCallTarget) function.getCallTarget();
    GraalTruffleRuntime runtime = ((GraalTruffleRuntime) Truffle.getRuntime());
    try {
        runtime.waitForCompilation(target, timeout);
    } catch (ExecutionException | TimeoutException e) {
        throw new RuntimeException(e);
    }
    return function;
}
Also used : GraalTruffleRuntime(org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 50 with Specialization

use of com.oracle.truffle.api.dsl.Specialization in project graal by oracle.

the class SpecializationMethodParser method parseSpecialization.

private SpecializationData parseSpecialization(TemplateMethod method) {
    List<SpecializationThrowsData> exceptionData = new ArrayList<>();
    boolean unexpectedResultRewrite = false;
    if (method.getMethod() != null) {
        AnnotationValue rewriteValue = ElementUtils.getAnnotationValue(method.getMarkerAnnotation(), "rewriteOn");
        List<TypeMirror> exceptionTypes = ElementUtils.getAnnotationValueList(TypeMirror.class, method.getMarkerAnnotation(), "rewriteOn");
        List<TypeMirror> rewriteOnTypes = new ArrayList<>();
        for (TypeMirror exceptionType : exceptionTypes) {
            SpecializationThrowsData throwsData = new SpecializationThrowsData(method.getMarkerAnnotation(), rewriteValue, exceptionType);
            if (!ElementUtils.canThrowType(method.getMethod().getThrownTypes(), exceptionType)) {
                method.addError("A rewriteOn checked exception was specified but not thrown in the method's throws clause. The @%s method must specify a throws clause with the exception type '%s'.", Specialization.class.getSimpleName(), ElementUtils.getQualifiedName(exceptionType));
            }
            if (ElementUtils.typeEquals(exceptionType, getContext().getType(UnexpectedResultException.class))) {
                if (ElementUtils.typeEquals(method.getMethod().getReturnType(), getContext().getType(Object.class))) {
                    method.addError("A specialization with return type 'Object' cannot throw UnexpectedResultException.");
                }
                unexpectedResultRewrite = true;
            }
            rewriteOnTypes.add(throwsData.getJavaClass());
            exceptionData.add(throwsData);
        }
        for (TypeMirror typeMirror : method.getMethod().getThrownTypes()) {
            if (!ElementUtils.canThrowType(rewriteOnTypes, typeMirror)) {
                method.addError(rewriteValue, "A checked exception '%s' is thrown but is not specified using the rewriteOn property. " + "Checked exceptions that are not used for rewriting are not handled by the DSL. Use RuntimeExceptions for this purpose instead.", ElementUtils.getQualifiedName(typeMirror));
            }
        }
        Collections.sort(exceptionData, new Comparator<SpecializationThrowsData>() {

            @Override
            public int compare(SpecializationThrowsData o1, SpecializationThrowsData o2) {
                return ElementUtils.compareByTypeHierarchy(o1.getJavaClass(), o2.getJavaClass());
            }
        });
    }
    SpecializationData specialization = new SpecializationData(getNode(), method, SpecializationKind.SPECIALIZED, exceptionData, unexpectedResultRewrite);
    if (method.getMethod() != null) {
        String insertBeforeName = ElementUtils.getAnnotationValue(String.class, method.getMarkerAnnotation(), "insertBefore");
        if (!insertBeforeName.equals("")) {
            specialization.setInsertBeforeName(insertBeforeName);
        }
        List<String> replacesDefs = new ArrayList<>();
        replacesDefs.addAll(ElementUtils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "replaces"));
        // TODO remove if deprecated contains api is removed.
        replacesDefs.addAll(ElementUtils.getAnnotationValueList(String.class, specialization.getMarkerAnnotation(), "contains"));
        Set<String> containsNames = specialization.getReplacesNames();
        containsNames.clear();
        if (replacesDefs != null) {
            for (String include : replacesDefs) {
                if (!containsNames.contains(include)) {
                    specialization.getReplacesNames().add(include);
                } else {
                    AnnotationValue value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "replaces");
                    if (value == null) {
                        // TODO remove if deprecated api was removed.
                        value = ElementUtils.getAnnotationValue(specialization.getMarkerAnnotation(), "contains");
                    }
                    specialization.addError(value, "Duplicate replace declaration '%s'.", include);
                }
            }
        }
    }
    return specialization;
}
Also used : ArrayList(java.util.ArrayList) SpecializationData(com.oracle.truffle.dsl.processor.model.SpecializationData) Specialization(com.oracle.truffle.api.dsl.Specialization) UnexpectedResultException(com.oracle.truffle.api.nodes.UnexpectedResultException) TypeMirror(javax.lang.model.type.TypeMirror) SpecializationThrowsData(com.oracle.truffle.dsl.processor.model.SpecializationThrowsData) AnnotationValue(javax.lang.model.element.AnnotationValue)

Aggregations

Specialization (com.oracle.truffle.api.dsl.Specialization)73 LLVMTruffleObject (com.oracle.truffle.llvm.runtime.LLVMTruffleObject)35 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)27 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)16 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)6 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)6 LLVMAddress (com.oracle.truffle.llvm.runtime.LLVMAddress)6 StackPointer (com.oracle.truffle.llvm.runtime.memory.LLVMStack.StackPointer)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5 FileValue (cz.cuni.mff.d3s.trupple.language.runtime.customvalues.FileValue)3 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)3 Frame (com.oracle.truffle.api.frame.Frame)2 InteropException (com.oracle.truffle.api.interop.InteropException)2 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)2 LLVMFunctionDescriptor (com.oracle.truffle.llvm.runtime.LLVMFunctionDescriptor)2 LLVM80BitFloat (com.oracle.truffle.llvm.runtime.floating.LLVM80BitFloat)2 SLRootNode (com.oracle.truffle.sl.nodes.SLRootNode)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 Type (java.lang.reflect.Type)2 Assumption (com.oracle.truffle.api.Assumption)1