use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class FlatNodeGenFactory method createCheckForPolymorphicSpecialize.
private Element createCheckForPolymorphicSpecialize() {
final boolean requiresExclude = requiresExclude();
final boolean requiresCacheCheck = requiresCacheCheck();
TypeMirror returnType = getType(void.class);
CodeExecutableElement executable = new CodeExecutableElement(modifiers(PRIVATE), returnType, CHECK_FOR_POLYMORPHIC_SPECIALIZE);
executable.addParameter(new CodeVariableElement(state.bitSetType, OLD_STATE));
if (requiresExclude) {
executable.addParameter(new CodeVariableElement(exclude.bitSetType, OLD_EXCLUDE));
}
if (requiresCacheCheck) {
executable.addParameter(new CodeVariableElement(getType(int.class), OLD_CACHE_COUNT));
}
CodeTreeBuilder builder = executable.createBuilder();
builder.declaration(state.bitSetType, NEW_STATE, state.createMaskedReference(FrameState.load(this), reachableSpecializations.toArray()));
if (requiresExclude) {
builder.declaration(exclude.bitSetType, NEW_EXCLUDE, exclude.createReference(FrameState.load(this)));
}
builder.startIf().string("(" + OLD_STATE + " ^ " + NEW_STATE + ") != 0");
if (requiresExclude) {
builder.string(" || ");
builder.string("(" + OLD_EXCLUDE + " ^ " + NEW_EXCLUDE + ") != 0");
}
if (requiresCacheCheck) {
builder.string(" || " + OLD_CACHE_COUNT + " < " + COUNT_CACHES + "()");
}
// if
builder.end();
builder.startBlock().startStatement().startCall("this", REPORT_POLYMORPHIC_SPECIALIZE).end(2);
// true block
builder.end();
return executable;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class FlatNodeGenFactory method createIsValid.
private Element createIsValid(TypeMirror assumptionType) {
CodeExecutableElement isValid = new CodeExecutableElement(modifiers(PRIVATE, STATIC), getType(boolean.class), "isValid_");
CodeTreeBuilder builder = isValid.createBuilder();
if (assumptionType.getKind() == TypeKind.ARRAY) {
isValid.addAnnotationMirror(new CodeAnnotationMirror(context.getDeclaredType(ExplodeLoop.class)));
isValid.addParameter(new CodeVariableElement(getType(Assumption[].class), "assumptions"));
builder.startIf().string("assumptions == null").end().startBlock().returnFalse().end();
builder.startFor().startGroup().type(((ArrayType) assumptionType).getComponentType()).string(" assumption : assumptions").end().end();
builder.startBlock();
builder.startIf().string("assumption == null || !assumption.isValid()").end();
builder.startBlock();
builder.returnFalse();
builder.end();
builder.end();
builder.returnTrue();
} else {
isValid.addParameter(new CodeVariableElement(getType(Assumption.class), "assumption"));
builder.startReturn().string("assumption != null && assumption.isValid()").end();
}
return isValid;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class FlatNodeGenFactory method createExecuteAndSpecialize.
private CodeExecutableElement createExecuteAndSpecialize() {
if (!node.needsRewrites(context)) {
return null;
}
final FrameState frameState = FrameState.load(this);
String frame = null;
if (needsFrameToExecute(reachableSpecializations)) {
frame = FRAME_VALUE;
}
TypeMirror returnType = executeAndSpecializeType.getReturnType();
CodeExecutableElement method = frameState.createMethod(modifiers(PRIVATE), returnType, "executeAndSpecialize", frame);
final CodeTreeBuilder builder = method.createBuilder();
builder.declaration(context.getType(Lock.class), "lock", "getLock()");
builder.declaration(context.getType(boolean.class), "hasLock", "true");
builder.statement("lock.lock()");
builder.tree(state.createLoad(frameState));
if (requiresExclude()) {
builder.tree(exclude.createLoad(frameState));
}
if (shouldReportPolymorphism(node, reachableSpecializations)) {
generateSaveOldPolymorphismState(builder, frameState);
}
builder.startTryBlock();
FrameState originalFrameState = frameState.copy();
SpecializationGroup group = createSpecializationGroups();
CodeTree execution = visitSpecializationGroup(builder, group, executeAndSpecializeType, frameState, null, NodeExecutionMode.SLOW_PATH);
builder.tree(execution);
if (group.hasFallthrough()) {
builder.tree(createTransferToInterpreterAndInvalidate());
builder.tree(createThrowUnsupported(builder, originalFrameState));
}
builder.end().startFinallyBlock();
if (shouldReportPolymorphism(node, reachableSpecializations)) {
generateCheckNewPolymorphismState(builder);
}
builder.startIf().string("hasLock").end().startBlock();
builder.statement("lock.unlock()");
builder.end();
builder.end();
return method;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class FlatNodeGenFactory method createFallbackGuard.
private Element createFallbackGuard() {
boolean frameUsed = false;
FrameState frameState = FrameState.load(this);
List<SpecializationData> specializations = new ArrayList<>(reachableSpecializations);
for (ListIterator<SpecializationData> iterator = specializations.listIterator(); iterator.hasNext(); ) {
SpecializationData specialization = iterator.next();
if (specialization.isFallback()) {
iterator.remove();
} else if (!specialization.isReachesFallback()) {
iterator.remove();
} else {
if (specialization.isFrameUsedByGuard()) {
frameUsed = true;
}
}
}
SpecializationGroup group = SpecializationGroup.create(specializations);
ExecutableTypeData executableType = node.findAnyGenericExecutableType(context, -1);
if (!frameUsed) {
frameState.removeValue(FRAME_VALUE);
}
fallbackNeedsState = false;
fallbackNeedsFrame = frameUsed;
state.createLoad(frameState);
CodeExecutableElement method = frameState.createMethod(modifiers(PRIVATE), getType(boolean.class), METHOD_FALLBACK_GUARD, FRAME_VALUE, STATE_VALUE);
CodeTree result = visitSpecializationGroup(CodeTreeBuilder.createBuilder(), group, executableType, frameState, null, NodeExecutionMode.FALLBACK_GUARD);
if (!fallbackNeedsState) {
VariableElement toRemove = null;
for (VariableElement v : method.getParameters()) {
if (v.getSimpleName().toString().equals(STATE_VALUE)) {
toRemove = v;
break;
}
}
if (toRemove != null) {
method.getParameters().remove(toRemove);
}
}
final CodeTreeBuilder builder = method.createBuilder();
for (SpecializationData implemented : specializations) {
if (implemented.getMaximumNumberOfInstances() > 1) {
method.getAnnotationMirrors().add(createExplodeLoop());
break;
}
}
builder.tree(result);
builder.returnTrue();
if (!accessesCachedState(specializations)) {
method.getModifiers().add(STATIC);
}
return method;
}
use of com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement in project graal by oracle.
the class FlatNodeGenFactory method createRemoveThis.
private CodeTree createRemoveThis(CodeTreeBuilder parent, FrameState frameState, ExecutableTypeData forType, SpecializationData specialization) {
CodeExecutableElement method = removeThisMethods.get(specialization);
String specializationLocalName = createSpecializationLocalName(specialization);
boolean useSpecializationClass = useSpecializationClass(specialization);
if (method == null) {
method = new CodeExecutableElement(context.getType(void.class), "remove" + specialization.getId() + "_");
if (useSpecializationClass) {
method.addParameter(new CodeVariableElement(context.getType(Object.class), specializationLocalName));
}
CodeTreeBuilder builder = method.createBuilder();
builder.declaration(context.getType(Lock.class), "lock", "getLock()");
builder.statement("lock.lock()");
builder.startTryBlock();
String fieldName = createSpecializationFieldName(specialization);
if (!useSpecializationClass || specialization.getMaximumNumberOfInstances() == 1) {
// single instance remove
builder.tree((state.createSet(null, new Object[] { specialization }, false, true)));
if (useSpecializationClass) {
builder.statement("this." + fieldName + " = null");
}
} else {
// multi instance remove
String typeName = createSpecializationTypeName(specialization);
boolean specializedIsNode = specializationClassIsNode(specialization);
builder.declaration(typeName, "prev", "null");
builder.declaration(typeName, "cur", "this." + fieldName);
builder.startWhile();
builder.string("cur != null");
builder.end().startBlock();
builder.startIf().string("cur == ").string(specializationLocalName).end().startBlock();
builder.startIf().string("prev == null").end().startBlock();
builder.statement("this." + fieldName + " = cur.next_");
if (specializedIsNode) {
builder.statement("this.adoptChildren()");
}
builder.end().startElseBlock();
builder.statement("prev.next_ = cur.next_");
if (specializedIsNode) {
builder.statement("prev.adoptChildren()");
}
builder.end();
builder.statement("break");
// if block
builder.end();
builder.statement("prev = cur");
builder.statement("cur = cur.next_");
// while block
builder.end();
builder.startIf().string("this." + fieldName).string(" == null").end().startBlock();
builder.tree((state.createSet(null, Arrays.asList(specialization).toArray(new SpecializationData[0]), false, true)));
builder.end();
}
builder.end().startFinallyBlock();
builder.statement("lock.unlock()");
builder.end();
removeThisMethods.put(specialization, method);
}
CodeTreeBuilder builder = parent.create();
builder.startStatement().startCall(method.getSimpleName().toString());
if (useSpecializationClass) {
builder.string(specializationLocalName);
}
builder.end().end();
builder.tree(createCallExecuteAndSpecialize(forType, frameState));
return builder.build();
}
Aggregations