use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder 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.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createSpecializationFieldReference.
private CodeTree createSpecializationFieldReference(FrameState frameState, SpecializationData s, String fieldName) {
CodeTreeBuilder builder = new CodeTreeBuilder(null);
if (useSpecializationClass(s)) {
String localName = createSpecializationLocalName(s);
LocalVariable var = frameState.get(localName);
if (var != null) {
builder.string(localName);
} else {
builder.string("this.", createSpecializationFieldName(s));
}
} else {
builder.string("this");
}
if (fieldName != null) {
builder.string(".");
builder.string(fieldName);
}
return builder.build();
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder in project graal by oracle.
the class FlatNodeGenFactory method createCatchRewriteException.
private CodeTree createCatchRewriteException(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData forType, FrameState frameState, CodeTree execution, NodeExecutionMode mode) {
if (specialization.getExceptions().isEmpty()) {
return execution;
}
CodeTreeBuilder builder = parent.create();
builder.startTryBlock();
builder.tree(execution);
boolean nonSlowPath = false;
TypeMirror[] exceptionTypes = new TypeMirror[specialization.getExceptions().size()];
for (int i = 0; i < exceptionTypes.length; i++) {
TypeMirror type = specialization.getExceptions().get(i).getJavaClass();
if (!ElementUtils.isAssignable(type, context.getType(SlowPathException.class)) && !ElementUtils.isAssignable(type, context.getType(ArithmeticException.class))) {
nonSlowPath = true;
}
exceptionTypes[i] = type;
}
builder.end().startCatchBlock(exceptionTypes, "ex");
if (nonSlowPath) {
builder.tree(createTransferToInterpreterAndInvalidate());
} else {
builder.lineComment("implicit transferToInterpreterAndInvalidate()");
}
builder.tree(createExcludeThis(builder, frameState, forType, specialization, mode));
builder.end();
return builder.build();
}
use of com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder 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.CodeTreeBuilder 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;
}
Aggregations