use of com.oracle.truffle.api.dsl.Specialization in project graal by oracle.
the class NodeParser method initializeFallbackReachability.
private static void initializeFallbackReachability(NodeData node) {
List<SpecializationData> specializations = node.getSpecializations();
SpecializationData fallback = null;
for (int i = specializations.size() - 1; i >= 0; i--) {
SpecializationData specialization = specializations.get(i);
if (specialization.isFallback() && specialization.getMethod() != null) {
fallback = specialization;
break;
}
}
if (fallback == null) {
// no need to compute reachability
return;
}
for (int index = 0; index < specializations.size(); index++) {
SpecializationData specialization = specializations.get(index);
SpecializationData lastReachable = specialization;
for (int searchIndex = index + 1; searchIndex < specializations.size(); searchIndex++) {
SpecializationData search = specializations.get(searchIndex);
if (search == fallback) {
// reached the end of the specialization
break;
}
assert lastReachable != search;
if (!lastReachable.isReachableAfter(search)) {
lastReachable = search;
} else if (search.getReplaces().contains(specialization)) {
lastReachable = search;
}
}
specialization.setReachesFallback(lastReachable == specialization);
List<SpecializationData> failedSpecializations = null;
if (specialization.isReachesFallback() && !specialization.getCaches().isEmpty() && !specialization.getGuards().isEmpty()) {
boolean guardBoundByCache = false;
for (GuardExpression guard : specialization.getGuards()) {
if (specialization.isGuardBoundWithCache(guard)) {
guardBoundByCache = true;
break;
}
}
if (guardBoundByCache && specialization.getMaximumNumberOfInstances() > 1) {
if (failedSpecializations == null) {
failedSpecializations = new ArrayList<>();
}
failedSpecializations.add(specialization);
}
}
if (failedSpecializations != null) {
List<String> specializationIds = failedSpecializations.stream().map((e) -> e.getId()).collect(Collectors.toList());
fallback.addError("Some guards for the following specializations could not be negated for the @%s specialization: %s. " + "Guards cannot be negated for the @%s when they bind @%s parameters and the specialization may consist of multiple instances. " + "To fix this limit the number of instances to '1' or " + "introduce a more generic specialization declared between this specialization and the fallback. " + "Alternatively the use of @%s can be avoided by declaring a @%s with manually specified negated guards.", Fallback.class.getSimpleName(), specializationIds, Fallback.class.getSimpleName(), Cached.class.getSimpleName(), Fallback.class.getSimpleName(), Specialization.class.getSimpleName());
}
}
}
use of com.oracle.truffle.api.dsl.Specialization in project graal by oracle.
the class SlowPathSerializeArgumentNode method genericWithPrepare.
@Specialization(replaces = "cacheType", guards = { "value != null" })
protected Object genericWithPrepare(NativeArgumentBuffer buffer, LibFFIType type, TruffleObject value, @Cached("createUnbox()") Node unbox, @Cached("createIsExecutable()") Node isExecutable, @Cached("createAsPointer()") AsPointerNode asPointer, @Cached("createRecursive()") SlowPathSerializeArgumentNode recursive) {
Object prepared = type.slowpathPrepareArgument(value);
if (prepared == PrepareArgument.EXECUTABLE) {
if (ForeignAccess.sendIsExecutable(isExecutable, value)) {
prepared = value;
} else {
prepared = PrepareArgument.POINTER;
}
}
if (prepared == PrepareArgument.POINTER) {
prepared = asPointer.execute(value);
} else if (prepared == PrepareArgument.UNBOX) {
Object unboxed;
try {
unboxed = ForeignAccess.sendUnbox(unbox, value);
} catch (UnsupportedMessageException ex) {
throw UnsupportedTypeException.raise(ex, new Object[] { value });
}
return recursive.execute(buffer, type, unboxed);
}
slowPathSerialize(buffer, type, prepared);
return null;
}
use of com.oracle.truffle.api.dsl.Specialization in project graal by oracle.
the class SLDefineFunctionBuiltin method defineFunction.
@TruffleBoundary
@Specialization
public String defineFunction(String code) {
// @formatter:off
Source source = Source.newBuilder(code).name("[defineFunction]").mimeType(SLLanguage.MIME_TYPE).build();
// @formatter:on
/* The same parsing code as for parsing the initial source. */
getContext().getFunctionRegistry().register(source);
return code;
}
use of com.oracle.truffle.api.dsl.Specialization in project graal by oracle.
the class SLHelloEqualsWorldBuiltin method change.
@Specialization
@TruffleBoundary
public String change() {
FrameInstance frameInstance = Truffle.getRuntime().getCallerFrame();
Frame frame = frameInstance.getFrame(FrameAccess.READ_WRITE);
FrameSlot slot = frame.getFrameDescriptor().findOrAddFrameSlot("hello");
frame.setObject(slot, "world");
return "world";
}
use of com.oracle.truffle.api.dsl.Specialization in project graal by oracle.
the class SLCallFunctionsWithBuiltin method runTests.
@Specialization
public SLNull runTests(String startsWith, SLFunction harness) {
boolean found = false;
for (SLFunction function : getContext().getFunctionRegistry().getFunctions()) {
if (function.getName().startsWith(startsWith) && getSource(function) == getSource(harness) && getSource(function) != null) {
indirectCall.call(harness.getCallTarget(), new Object[] { function });
found = true;
}
}
if (!found) {
throw new SLAssertionError("No tests found to execute.", this);
}
return SLNull.SINGLETON;
}
Aggregations