Search in sources :

Example 31 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class TraceLocalMoveResolver method addMapping.

public void addMapping(TraceInterval fromInterval, TraceInterval toInterval) {
    if (isIllegal(toInterval.location()) && toInterval.canMaterialize()) {
        if (debug.isLogEnabled()) {
            debug.log("no store to rematerializable interval %s needed", toInterval);
        }
        return;
    }
    if (isIllegal(fromInterval.location()) && fromInterval.canMaterialize()) {
        // Instead of a reload, re-materialize the value
        JavaConstant rematValue = fromInterval.getMaterializedValue();
        addMapping(rematValue, toInterval);
        return;
    }
    if (debug.isLogEnabled()) {
        debug.log("add move mapping from %s to %s", fromInterval, toInterval);
    }
    assert fromInterval.operandNumber != toInterval.operandNumber : "from and to interval equal: " + fromInterval;
    assert LIRKind.verifyMoveKinds(allocator.getKind(toInterval), allocator.getKind(fromInterval), allocator.getRegisterAllocationConfig()) : String.format("Kind mismatch: %s vs. %s, from=%s, to=%s", allocator.getKind(fromInterval), allocator.getKind(toInterval), fromInterval, toInterval);
    mappingFrom.add(fromInterval);
    mappingFromOpr.add(null);
    mappingTo.add(toInterval);
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 32 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class BytecodeParser method genDynamicInvokeHelper.

private boolean genDynamicInvokeHelper(ResolvedJavaMethod target, int cpi, int opcode) {
    assert opcode == INVOKEDYNAMIC || opcode == INVOKEVIRTUAL;
    InvokeDynamicPlugin invokeDynamicPlugin = graphBuilderConfig.getPlugins().getInvokeDynamicPlugin();
    if (opcode == INVOKEVIRTUAL && invokeDynamicPlugin != null && !invokeDynamicPlugin.isResolvedDynamicInvoke(this, cpi, opcode)) {
        // regular invokevirtual, let caller handle it
        return false;
    }
    if (GeneratePIC.getValue(options) && (invokeDynamicPlugin == null || !invokeDynamicPlugin.supportsDynamicInvoke(this, cpi, opcode))) {
        // bail out if static compiler and no dynamic type support
        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
        return true;
    }
    JavaConstant appendix = constantPool.lookupAppendix(cpi, opcode);
    ValueNode appendixNode = null;
    if (appendix != null) {
        if (invokeDynamicPlugin != null) {
            invokeDynamicPlugin.recordDynamicMethod(this, cpi, opcode, target);
            // Will perform runtime type checks and static initialization
            FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
            appendixNode = invokeDynamicPlugin.genAppendixNode(this, cpi, opcode, appendix, stateBefore);
        } else {
            appendixNode = ConstantNode.forConstant(appendix, metaAccess, graph);
        }
        frameState.push(JavaKind.Object, appendixNode);
    } else if (GeneratePIC.getValue(options)) {
        // Need to emit runtime guard and perform static initialization.
        // Not implemented yet.
        append(new DeoptimizeNode(InvalidateRecompile, Unresolved));
        return true;
    }
    boolean hasReceiver = (opcode == INVOKEDYNAMIC) ? false : !target.isStatic();
    ValueNode[] args = frameState.popArguments(target.getSignature().getParameterCount(hasReceiver));
    if (hasReceiver) {
        appendInvoke(InvokeKind.Virtual, target, args);
    } else {
        appendInvoke(InvokeKind.Static, target, args);
    }
    return true;
}
Also used : InvokeDynamicPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvokeDynamicPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) FrameState(org.graalvm.compiler.nodes.FrameState)

Example 33 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class BytecodeParser method genIntegerSwitch.

protected void genIntegerSwitch(ValueNode value, ArrayList<BciBlock> actualSuccessors, int[] keys, double[] keyProbabilities, int[] keySuccessors) {
    if (value.isConstant()) {
        JavaConstant constant = (JavaConstant) value.asConstant();
        int constantValue = constant.asInt();
        for (int i = 0; i < keys.length; ++i) {
            if (keys[i] == constantValue) {
                appendGoto(actualSuccessors.get(keySuccessors[i]));
                return;
            }
        }
        appendGoto(actualSuccessors.get(keySuccessors[keys.length]));
    } else {
        this.controlFlowSplit = true;
        double[] successorProbabilities = successorProbabilites(actualSuccessors.size(), keySuccessors, keyProbabilities);
        IntegerSwitchNode switchNode = append(new IntegerSwitchNode(value, actualSuccessors.size(), keys, keyProbabilities, keySuccessors));
        for (int i = 0; i < actualSuccessors.size(); i++) {
            switchNode.setBlockSuccessor(i, createBlockTarget(successorProbabilities[i], actualSuccessors.get(i), frameState));
        }
    }
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode)

Example 34 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class GraalCompiler method emitCode.

@SuppressWarnings("try")
public static void emitCode(Backend backend, Assumptions assumptions, ResolvedJavaMethod rootMethod, Collection<ResolvedJavaMethod> inlinedMethods, EconomicSet<ResolvedJavaField> accessedFields, int bytecodeSize, LIRGenerationResult lirGenRes, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner, CompilationResultBuilderFactory factory) {
    DebugContext debug = lirGenRes.getLIR().getDebug();
    try (DebugCloseable a = EmitCode.start(debug)) {
        FrameMap frameMap = lirGenRes.getFrameMap();
        CompilationResultBuilder crb = backend.newCompilationResultBuilder(lirGenRes, frameMap, compilationResult, factory);
        backend.emitCode(crb, lirGenRes.getLIR(), installedCodeOwner);
        if (assumptions != null && !assumptions.isEmpty()) {
            compilationResult.setAssumptions(assumptions.toArray());
        }
        if (rootMethod != null) {
            compilationResult.setMethods(rootMethod, inlinedMethods);
            compilationResult.setFields(accessedFields);
            compilationResult.setBytecodeSize(bytecodeSize);
        }
        crb.finish();
        if (debug.isCountEnabled()) {
            List<DataPatch> ldp = compilationResult.getDataPatches();
            JavaKind[] kindValues = JavaKind.values();
            CounterKey[] dms = new CounterKey[kindValues.length];
            for (int i = 0; i < dms.length; i++) {
                dms[i] = DebugContext.counter("DataPatches-%s", kindValues[i]);
            }
            for (DataPatch dp : ldp) {
                JavaKind kind = JavaKind.Illegal;
                if (dp.reference instanceof ConstantReference) {
                    VMConstant constant = ((ConstantReference) dp.reference).getConstant();
                    if (constant instanceof JavaConstant) {
                        kind = ((JavaConstant) constant).getJavaKind();
                    }
                }
                dms[kind.ordinal()].add(debug, 1);
            }
            DebugContext.counter("CompilationResults").increment(debug);
            DebugContext.counter("CodeBytesEmitted").add(debug, compilationResult.getTargetCodeSize());
            DebugContext.counter("InfopointsEmitted").add(debug, compilationResult.getInfopoints().size());
            DebugContext.counter("DataPatches").add(debug, ldp.size());
            DebugContext.counter("ExceptionHandlersEmitted").add(debug, compilationResult.getExceptionHandlers().size());
        }
        debug.dump(DebugContext.BASIC_LEVEL, compilationResult, "After code generation");
    }
}
Also used : FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) ConstantReference(jdk.vm.ci.code.site.ConstantReference) JavaConstant(jdk.vm.ci.meta.JavaConstant) DebugContext(org.graalvm.compiler.debug.DebugContext) CounterKey(org.graalvm.compiler.debug.CounterKey) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) DataPatch(jdk.vm.ci.code.site.DataPatch) VMConstant(jdk.vm.ci.meta.VMConstant) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 35 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class BoxingSnippets method canonicalizeBoxing.

public static FloatingNode canonicalizeBoxing(BoxNode box, MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection) {
    ValueNode value = box.getValue();
    if (value.isConstant()) {
        JavaConstant sourceConstant = value.asJavaConstant();
        if (sourceConstant.getJavaKind() != box.getBoxingKind() && sourceConstant.getJavaKind().isNumericInteger()) {
            switch(box.getBoxingKind()) {
                case Boolean:
                    sourceConstant = JavaConstant.forBoolean(sourceConstant.asLong() != 0L);
                    break;
                case Byte:
                    sourceConstant = JavaConstant.forByte((byte) sourceConstant.asLong());
                    break;
                case Char:
                    sourceConstant = JavaConstant.forChar((char) sourceConstant.asLong());
                    break;
                case Short:
                    sourceConstant = JavaConstant.forShort((short) sourceConstant.asLong());
                    break;
            }
        }
        JavaConstant boxedConstant = constantReflection.boxPrimitive(sourceConstant);
        if (boxedConstant != null && sourceConstant.getJavaKind() == box.getBoxingKind()) {
            return ConstantNode.forConstant(boxedConstant, metaAccess, box.graph());
        }
    }
    return null;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5