Search in sources :

Example 1 with Assumption

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

the class HotSpotCompiledCodeBuilder method createCompiledCode.

public static HotSpotCompiledCode createCompiledCode(CodeCacheProvider codeCache, ResolvedJavaMethod method, HotSpotCompilationRequest compRequest, CompilationResult compResult) {
    String name = compResult.getName();
    byte[] targetCode = compResult.getTargetCode();
    int targetCodeSize = compResult.getTargetCodeSize();
    Site[] sites = getSortedSites(codeCache, compResult);
    Assumption[] assumptions = compResult.getAssumptions();
    ResolvedJavaMethod[] methods = compResult.getMethods();
    List<CodeAnnotation> annotations = compResult.getAnnotations();
    Comment[] comments = new Comment[annotations.size()];
    if (!annotations.isEmpty()) {
        for (int i = 0; i < comments.length; i++) {
            CodeAnnotation annotation = annotations.get(i);
            String text;
            if (annotation instanceof CodeComment) {
                CodeComment codeComment = (CodeComment) annotation;
                text = codeComment.value;
            } else if (annotation instanceof JumpTable) {
                JumpTable jumpTable = (JumpTable) annotation;
                text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]";
            } else {
                text = annotation.toString();
            }
            comments[i] = new Comment(annotation.position, text);
        }
    }
    DataSection data = compResult.getDataSection();
    byte[] dataSection = new byte[data.getSectionSize()];
    ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder());
    Builder<DataPatch> patchBuilder = Stream.builder();
    data.buildDataSection(buffer, (position, vmConstant) -> {
        patchBuilder.accept(new DataPatch(position, new ConstantReference(vmConstant)));
    });
    int dataSectionAlignment = data.getSectionAlignment();
    DataPatch[] dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]);
    int totalFrameSize = compResult.getTotalFrameSize();
    StackSlot customStackArea = compResult.getCustomStackArea();
    boolean isImmutablePIC = compResult.isImmutablePIC();
    if (method instanceof HotSpotResolvedJavaMethod) {
        HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method;
        int entryBCI = compResult.getEntryBCI();
        boolean hasUnsafeAccess = compResult.hasUnsafeAccess();
        int id;
        long jvmciEnv;
        if (compRequest != null) {
            id = compRequest.getId();
            jvmciEnv = compRequest.getJvmciEnv();
        } else {
            id = hsMethod.allocateCompileId(entryBCI);
            jvmciEnv = 0L;
        }
        return new HotSpotCompiledNmethod(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC, totalFrameSize, customStackArea, hsMethod, entryBCI, id, jvmciEnv, hasUnsafeAccess);
    } else {
        return new HotSpotCompiledCode(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC, totalFrameSize, customStackArea);
    }
}
Also used : Site(jdk.vm.ci.code.site.Site) CodeAnnotation(org.graalvm.compiler.code.CompilationResult.CodeAnnotation) HotSpotCompiledCode(jdk.vm.ci.hotspot.HotSpotCompiledCode) ConstantReference(jdk.vm.ci.code.site.ConstantReference) JumpTable(org.graalvm.compiler.code.CompilationResult.JumpTable) Assumption(jdk.vm.ci.meta.Assumptions.Assumption) CodeComment(org.graalvm.compiler.code.CompilationResult.CodeComment) Comment(jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) StackSlot(jdk.vm.ci.code.StackSlot) ByteBuffer(java.nio.ByteBuffer) Infopoint(jdk.vm.ci.code.site.Infopoint) CodeComment(org.graalvm.compiler.code.CompilationResult.CodeComment) DataPatch(jdk.vm.ci.code.site.DataPatch) DataSection(org.graalvm.compiler.code.DataSection) HotSpotCompiledNmethod(jdk.vm.ci.hotspot.HotSpotCompiledNmethod) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with Assumption

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

the class GraalCompilerAssumptionsTest method checkGraph.

protected void checkGraph(Assumption expectedAssumption, StructuredGraph graph) {
    boolean found = false;
    for (Assumption a : graph.getAssumptions()) {
        if (expectedAssumption.equals(a)) {
            found = true;
        }
    }
    assertTrue(found, "Can't find assumption %s", expectedAssumption);
}
Also used : Assumption(jdk.vm.ci.meta.Assumptions.Assumption)

Example 3 with Assumption

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

the class FinalizableSubclassTest method checkForRegisterFinalizeNode.

private void checkForRegisterFinalizeNode(Class<?> cl, boolean shouldContainFinalizer, AllowAssumptions allowAssumptions) {
    StructuredGraph graph = parseAndProcess(cl, allowAssumptions);
    Assert.assertTrue(graph.getNodes().filter(RegisterFinalizerNode.class).count() == (shouldContainFinalizer ? 1 : 0));
    int noFinalizerAssumption = 0;
    Assumptions assumptions = graph.getAssumptions();
    if (assumptions != null) {
        for (Assumption a : assumptions) {
            if (a instanceof NoFinalizableSubclass) {
                noFinalizerAssumption++;
            } else if (a instanceof LeafType) {
                // Need to also allow leaf type assumption instead of no finalizable subclass
                // assumption.
                noFinalizerAssumption++;
            }
        }
    }
    Assert.assertTrue(noFinalizerAssumption == (shouldContainFinalizer ? 0 : 1));
}
Also used : LeafType(jdk.vm.ci.meta.Assumptions.LeafType) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assumptions(jdk.vm.ci.meta.Assumptions) NoFinalizableSubclass(jdk.vm.ci.meta.Assumptions.NoFinalizableSubclass) RegisterFinalizerNode(org.graalvm.compiler.nodes.java.RegisterFinalizerNode) Assumption(jdk.vm.ci.meta.Assumptions.Assumption)

Example 4 with Assumption

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

the class TruffleCompilationResultBuilderFactory method createBuilder.

@Override
public CompilationResultBuilder createBuilder(CodeCacheProvider codeCache, ForeignCallsProvider foreignCalls, FrameMap frameMap, Assembler asm, DataBuilder dataBuilder, FrameContext frameContext, OptionValues options, DebugContext debug, CompilationResult compilationResult) {
    return new CompilationResultBuilder(codeCache, foreignCalls, frameMap, asm, dataBuilder, frameContext, options, debug, compilationResult) {

        @Override
        protected void closeCompilationResult() {
            CompilationResult result = this.compilationResult;
            result.setMethods(graph.method(), graph.getMethods());
            result.setBytecodeSize(graph.getBytecodeSize());
            Set<Assumption> newAssumptions = new HashSet<>();
            for (Assumption assumption : graph.getAssumptions()) {
                TruffleCompilationResultBuilderFactory.processAssumption(newAssumptions, assumption, validAssumptions);
            }
            if (result.getAssumptions() != null) {
                for (Assumption assumption : result.getAssumptions()) {
                    TruffleCompilationResultBuilderFactory.processAssumption(newAssumptions, assumption, validAssumptions);
                }
            }
            result.setAssumptions(newAssumptions.toArray(new Assumption[newAssumptions.size()]));
            super.closeCompilationResult();
        }
    };
}
Also used : CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) CompilationResult(org.graalvm.compiler.code.CompilationResult) TruffleAssumption(org.graalvm.compiler.truffle.compiler.nodes.TruffleAssumption) Assumption(jdk.vm.ci.meta.Assumptions.Assumption) HashSet(java.util.HashSet)

Aggregations

Assumption (jdk.vm.ci.meta.Assumptions.Assumption)4 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 StackSlot (jdk.vm.ci.code.StackSlot)1 ConstantReference (jdk.vm.ci.code.site.ConstantReference)1 DataPatch (jdk.vm.ci.code.site.DataPatch)1 Infopoint (jdk.vm.ci.code.site.Infopoint)1 Site (jdk.vm.ci.code.site.Site)1 HotSpotCompiledCode (jdk.vm.ci.hotspot.HotSpotCompiledCode)1 Comment (jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment)1 HotSpotCompiledNmethod (jdk.vm.ci.hotspot.HotSpotCompiledNmethod)1 HotSpotResolvedJavaMethod (jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod)1 Assumptions (jdk.vm.ci.meta.Assumptions)1 LeafType (jdk.vm.ci.meta.Assumptions.LeafType)1 NoFinalizableSubclass (jdk.vm.ci.meta.Assumptions.NoFinalizableSubclass)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 CompilationResult (org.graalvm.compiler.code.CompilationResult)1 CodeAnnotation (org.graalvm.compiler.code.CompilationResult.CodeAnnotation)1 CodeComment (org.graalvm.compiler.code.CompilationResult.CodeComment)1 JumpTable (org.graalvm.compiler.code.CompilationResult.JumpTable)1