Search in sources :

Example 31 with CodeTreeBuilder

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;
}
Also used : CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 32 with CodeTreeBuilder

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();
}
Also used : CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 33 with CodeTreeBuilder

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();
}
Also used : DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) SlowPathException(com.oracle.truffle.api.nodes.SlowPathException) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 34 with CodeTreeBuilder

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;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) ArrayType(javax.lang.model.type.ArrayType) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) Assumption(com.oracle.truffle.api.Assumption)

Example 35 with CodeTreeBuilder

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;
}
Also used : CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) SpecializationGroup(com.oracle.truffle.dsl.processor.parser.SpecializationGroup) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) Lock(java.util.concurrent.locks.Lock)

Aggregations

CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)64 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)23 TypeMirror (javax.lang.model.type.TypeMirror)23 CodeTree (com.oracle.truffle.dsl.processor.java.model.CodeTree)21 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)20 ArrayList (java.util.ArrayList)18 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)17 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)16 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)13 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)12 NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)8 VariableElement (javax.lang.model.element.VariableElement)8 ElementUtils.isObject (com.oracle.truffle.dsl.processor.java.ElementUtils.isObject)7 ExecutableElement (javax.lang.model.element.ExecutableElement)7 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)5 ExecutableTypeData (com.oracle.truffle.dsl.processor.model.ExecutableTypeData)5 Arrays (java.util.Arrays)5 UnexpectedResultException (com.oracle.truffle.api.nodes.UnexpectedResultException)4 AssumptionExpression (com.oracle.truffle.dsl.processor.model.AssumptionExpression)4 SpecializationGroup (com.oracle.truffle.dsl.processor.parser.SpecializationGroup)4