Search in sources :

Example 11 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.

the class TypeFlowIterator method add.

private void add(TypeFlow<?> flow, WorkListEntry reason) {
    if (processed.contains(flow)) {
        return;
    }
    processed.add(flow);
    WorkListEntry entry = new WorkListEntry(flow, reason);
    worklist.add(entry);
    if (!flow.isClone() && flow.getSource() instanceof ValueNode) {
        AnalysisMethod method = (AnalysisMethod) ((ValueNode) flow.getSource()).graph().method();
        for (MethodFlowsGraph methodFlow : method.getTypeFlow().getMethodContextFlows().values()) {
            TypeFlow<?> curClone = methodFlow.lookupCloneOf(bb, flow);
            add(curClone, entry);
        }
    }
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) MethodFlowsGraph(com.oracle.graal.pointsto.flow.MethodFlowsGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 12 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.

the class JNIFunctionTablesFeature method prepareCallTrampoline.

private static CFunctionPointer prepareCallTrampoline(CompilationAccessImpl access, CallVariant variant, boolean nonVirtual) {
    JNICallTrampolineMethod trampolineMethod = JNIAccessFeature.singleton().getCallTrampolineMethod(variant, nonVirtual);
    AnalysisMethod analysisTrampoline = access.getUniverse().getBigBang().getUniverse().lookup(trampolineMethod);
    HostedMethod hostedTrampoline = access.getUniverse().lookup(analysisTrampoline);
    hostedTrampoline.compilationInfo.setCustomParseFunction(trampolineMethod.createCustomParseFunction());
    hostedTrampoline.compilationInfo.setCustomCompileFunction(trampolineMethod.createCustomCompileFunction());
    return MethodPointer.factory(hostedTrampoline);
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) JNICallTrampolineMethod(com.oracle.svm.jni.hosted.JNICallTrampolineMethod)

Example 13 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.

the class JNIFunctionTablesFeature method buildFunctionsInitializer.

private JNIStructFunctionsInitializer<JNINativeInterface> buildFunctionsInitializer(CompilationAccessImpl access, CFunctionPointer unimplemented) {
    Class<JNIFunctions> clazz = JNIFunctions.class;
    HostedType functions = access.getMetaAccess().lookupJavaType(clazz);
    HostedMethod[] methods = functions.getDeclaredMethods();
    int index = 0;
    int count = methods.length + generatedMethods.length;
    // Call, CallStatic, CallNonvirtual: for each return value kind: array, va_list, varargs
    // NewObject: array, va_list, varargs
    count += (jniKinds.size() * 3 + 1) * 3;
    int[] offsets = new int[count];
    CFunctionPointer[] pointers = new CFunctionPointer[offsets.length];
    for (HostedMethod method : methods) {
        StructFieldInfo field = findFieldFor(functionTableMetadata, method.getName());
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = getStubFunctionPointer(access, method);
        index++;
    }
    for (ResolvedJavaMethod accessor : generatedMethods) {
        StructFieldInfo field = findFieldFor(functionTableMetadata, accessor.getName());
        AnalysisUniverse analysisUniverse = access.getUniverse().getBigBang().getUniverse();
        AnalysisMethod analysisMethod = analysisUniverse.lookup(accessor);
        HostedMethod hostedMethod = access.getUniverse().lookup(analysisMethod);
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = MethodPointer.factory(hostedMethod);
        index++;
    }
    for (CallVariant variant : CallVariant.values()) {
        CFunctionPointer trampoline = prepareCallTrampoline(access, variant, false);
        String suffix = (variant == CallVariant.ARRAY) ? "A" : ((variant == CallVariant.VA_LIST) ? "V" : "");
        CFunctionPointer nonvirtualTrampoline = prepareCallTrampoline(access, variant, true);
        for (JavaKind kind : jniKinds) {
            String[] prefixes = { "Call", "CallStatic" };
            for (String prefix : prefixes) {
                StructFieldInfo field = findFieldFor(functionTableMetadata, prefix + kind.name() + "Method" + suffix);
                offsets[index] = field.getOffsetInfo().getProperty();
                pointers[index] = trampoline;
                index++;
            }
            StructFieldInfo field = findFieldFor(functionTableMetadata, "CallNonvirtual" + kind.name() + "Method" + suffix);
            offsets[index] = field.getOffsetInfo().getProperty();
            pointers[index] = nonvirtualTrampoline;
            index++;
        }
        StructFieldInfo field = findFieldFor(functionTableMetadata, "NewObject" + suffix);
        offsets[index] = field.getOffsetInfo().getProperty();
        pointers[index] = trampoline;
        index++;
    }
    VMError.guarantee(index == offsets.length && index == pointers.length);
    return new JNIStructFunctionsInitializer<>(JNINativeInterface.class, offsets, pointers, unimplemented);
}
Also used : CallVariant(com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod.CallVariant) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) HostedType(com.oracle.svm.hosted.meta.HostedType) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 14 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.

the class UniverseBuilder method collectHashCodeFieldInfo.

@SuppressWarnings("try")
private void collectHashCodeFieldInfo(BigBang bb) {
    AnalysisMethod method;
    try {
        method = aMetaAccess.lookupJavaMethod(System.class.getMethod("identityHashCode", Object.class));
    } catch (NoSuchMethodException | SecurityException e) {
        throw shouldNotReachHere();
    }
    if (method == null) {
        return;
    }
    DebugContext debug = bb.getDebug();
    try (Indent ignore = debug.logAndIndent("check types for which identityHashCode is invoked")) {
        // Check which types may be a parameter of System.identityHashCode (which is invoked by
        // Object.hashCode).
        TypeState thisParamState = method.getTypeFlow().getParameterTypeState(bb, 0);
        assert thisParamState != null;
        Iterable<AnalysisType> typesNeedHashCode = thisParamState.types();
        if (typesNeedHashCode == null || thisParamState.isUnknown()) {
            // This is the case if the identityHashCode parameter type is unknown. So all
            // classes get the hashCode field.
            // But this is only a fail-safe, because it cannot happen in the current
            // implementation of the analysis pass.
            debug.log("all types need a hashCode field");
            for (HostedType hType : hUniverse.getTypes()) {
                if (hType.isInstanceClass()) {
                    ((HostedInstanceClass) hType).setNeedHashCodeField();
                }
            }
            hUniverse.getObjectClass().setNeedHashCodeField();
        } else {
            for (AnalysisType type : typesNeedHashCode) {
                debug.log("type %s is argument to identityHashCode", type);
                /*
                     * Array types get a hash-code field by default. So we only have to deal with
                     * instance types here.
                     */
                if (type.isInstanceClass()) {
                    HostedInstanceClass hType = (HostedInstanceClass) hUniverse.lookup(type);
                    hType.setNeedHashCodeField();
                }
            }
        }
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) Indent(org.graalvm.compiler.debug.Indent) TypeState(com.oracle.graal.pointsto.typestate.TypeState) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 15 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.

the class HostedType method wrappedResolveMethod.

private ResolvedJavaMethod wrappedResolveMethod(HostedMethod method, HostedType callerType) {
    AnalysisMethod orig = wrapped.resolveConcreteMethod(method.wrapped, callerType.wrapped);
    ResolvedJavaMethod result = orig == null ? null : universe.lookup(orig);
    if (result != null && !isWordType() && !Arrays.asList(method.getImplementations()).contains(result)) {
        /* Our static analysis found out that this method is not reachable. */
        result = null;
    }
    return result;
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)31 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)7 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)6 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)5 Map (java.util.Map)5 JavaKind (jdk.vm.ci.meta.JavaKind)5 TypeState (com.oracle.graal.pointsto.typestate.TypeState)4 SubstrateMethod (com.oracle.svm.graal.meta.SubstrateMethod)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)2 InvokeTypeFlow (com.oracle.graal.pointsto.flow.InvokeTypeFlow)2 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)2 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)2 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 SubstrateForeignCallsProvider (com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider)2