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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations