Search in sources :

Example 21 with ResolvedJavaField

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

the class UnsafeAutomaticSubstitutionProcessor method processUnsafeArrayBaseOffsetInvoke.

/**
 * Process call to {@link sun.misc.Unsafe#arrayBaseOffset(Class)}. The matching logic below
 * applies to the following code pattern:
 *
 * <code> static final long arrayBaseOffsets = Unsafe.getUnsafe().arrayBaseOffset(byte[].class); </code>
 */
private void processUnsafeArrayBaseOffsetInvoke(ResolvedJavaType type, Invoke unsafeArrayBaseOffsetInvoke) {
    SnippetReflectionProvider snippetReflectionProvider = GraalAccess.getOriginalSnippetReflection();
    List<String> unsuccessfulReasons = new ArrayList<>();
    Class<?> arrayClass = null;
    ValueNode arrayClassArgument = unsafeArrayBaseOffsetInvoke.callTarget().arguments().get(1);
    if (arrayClassArgument.isJavaConstant()) {
        arrayClass = snippetReflectionProvider.asObject(Class.class, arrayClassArgument.asJavaConstant());
    } else {
        unsuccessfulReasons.add("The first argument of the call to Unsafe.arrayBaseOffset() is not a constant.");
    }
    /*
         * If the value returned by the call to Unsafe.arrayBaseOffset() is stored into a field then
         * that must be the offset field.
         */
    ResolvedJavaField offsetField = extractValueStoreField(unsafeArrayBaseOffsetInvoke.asNode(), unsuccessfulReasons);
    if (arrayClass != null && offsetField != null) {
        Class<?> finalArrayClass = arrayClass;
        Supplier<ComputedValueField> supplier = () -> new ComputedValueField(offsetField, null, Kind.ArrayBaseOffset, finalArrayClass, null, true);
        if (tryAutomaticRecomputation(offsetField, Kind.ArrayBaseOffset, supplier)) {
            reportSuccessfulAutomaticRecomputation(Kind.ArrayBaseOffset, offsetField, arrayClass.getCanonicalName());
        }
    } else {
        reportUnsuccessfulAutomaticRecomputation(type, unsafeArrayBaseOffsetInvoke, Kind.ArrayBaseOffset, unsuccessfulReasons);
    }
}
Also used : SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) ArrayList(java.util.ArrayList) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 22 with ResolvedJavaField

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

the class VMThreadLocalCollector method sortThreadLocals.

public List<VMThreadLocalInfo> sortThreadLocals(Feature.CompilationAccess a, FastThreadLocal first) {
    CompilationAccessImpl config = (CompilationAccessImpl) a;
    sealed = true;
    /*
         * Find a unique static field for every VM thread local object. The field name is used to
         * make the layout of VMThread deterministic.
         */
    for (ResolvedJavaField f : config.getFields()) {
        SharedField field = (SharedField) f;
        if (field.isStatic() && field.getStorageKind() == JavaKind.Object) {
            Object fieldValue = SubstrateObjectConstant.asObject(((ReadableJavaField) field).readValue(null));
            if (fieldValue instanceof FastThreadLocal) {
                FastThreadLocal threadLocal = (FastThreadLocal) fieldValue;
                VMThreadLocalInfo info = threadLocals.get(threadLocal);
                String fieldName = field.format("%H.%n");
                if (!field.isFinal()) {
                    throw shouldNotReachHere("VMThreadLocal referenced from non-final field: " + fieldName);
                } else if (info.name != null) {
                    throw shouldNotReachHere("VMThreadLocal referenced from two static final fields: " + info.name + ", " + fieldName);
                }
                info.name = fieldName;
            }
        }
    }
    for (VMThreadLocalInfo info : threadLocals.values()) {
        if (info.name == null) {
            shouldNotReachHere("VMThreadLocal found that is not referenced from a static final field");
        }
        assert info.sizeInBytes == -1;
        if (info.sizeSupplier != null) {
            info.sizeInBytes = NumUtil.roundUp(info.sizeSupplier.getAsInt(), 8);
        } else {
            info.sizeInBytes = ConfigurationValues.getObjectLayout().sizeInBytes(info.storageKind);
        }
    }
    List<VMThreadLocalInfo> sortedThreadLocals = new ArrayList<>(threadLocals.values());
    sortedThreadLocals.sort(VMThreadLocalCollector::compareThreadLocal);
    if (first != null) {
        VMThreadLocalInfo info = threadLocals.get(first);
        assert info != null && sortedThreadLocals.contains(info);
        sortedThreadLocals.remove(info);
        sortedThreadLocals.add(0, info);
    }
    return sortedThreadLocals;
}
Also used : SharedField(com.oracle.svm.core.meta.SharedField) CompilationAccessImpl(com.oracle.svm.hosted.FeatureImpl.CompilationAccessImpl) ArrayList(java.util.ArrayList) FastThreadLocal(com.oracle.svm.core.threadlocal.FastThreadLocal) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) VMThreadLocalInfo(com.oracle.svm.core.threadlocal.VMThreadLocalInfo)

Example 23 with ResolvedJavaField

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

the class AnnotationSubstitutionProcessor method lookup.

@Override
public ResolvedJavaField lookup(ResolvedJavaField field) {
    Delete deleteAnnotation = deleteAnnotations.get(field);
    if (deleteAnnotation != null) {
        throw new UnsupportedFeatureException(deleteErrorMessage(field, deleteAnnotation, true));
    }
    ResolvedJavaField substitution = fieldSubstitutions.get(field);
    if (substitution != null) {
        return substitution;
    }
    return field;
}
Also used : Delete(com.oracle.svm.core.annotate.Delete) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 24 with ResolvedJavaField

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

the class AnnotationSubstitutionProcessor method handleDeletedClass.

private void handleDeletedClass(Class<?> originalClass, Delete deleteAnnotation) {
    if (NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
        /*
             * We register all methods and fields as deleted. That still allows usage of the type in
             * type checks.
             */
        for (Executable m : originalClass.getDeclaredMethods()) {
            ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
            registerAsDeleted(null, method, deleteAnnotation);
        }
        for (Executable m : originalClass.getDeclaredConstructors()) {
            ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
            registerAsDeleted(null, method, deleteAnnotation);
        }
        for (Field f : originalClass.getDeclaredFields()) {
            ResolvedJavaField field = metaAccess.lookupJavaField(f);
            registerAsDeleted(null, field, deleteAnnotation);
        }
    } else {
        deleteAnnotations.put(metaAccess.lookupJavaType(originalClass), deleteAnnotation);
    }
}
Also used : ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Field(java.lang.reflect.Field) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) Executable(java.lang.reflect.Executable) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 25 with ResolvedJavaField

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

the class AnnotationSubstitutionProcessor method findOriginalField.

private ResolvedJavaField findOriginalField(Field annotatedField, Class<?> originalClass, boolean forceOptional) {
    TargetElement targetElementAnnotation = lookupAnnotation(annotatedField, TargetElement.class);
    String originalName = "";
    boolean optional = false;
    if (targetElementAnnotation != null) {
        originalName = targetElementAnnotation.name();
        optional = targetElementAnnotation.optional();
    }
    if (originalName.length() == 0) {
        originalName = annotatedField.getName();
    }
    try {
        Field originalField = originalClass.getDeclaredField(originalName);
        guarantee(getTargetClass(annotatedField.getType()).equals(originalField.getType()), "Type mismatch:%n    %s %s%n    %s %s", annotatedField.getType(), annotatedField, originalField.getType(), originalField);
        return metaAccess.lookupJavaField(originalField);
    } catch (NoSuchFieldException ex) {
        /*
             * Some fields are hidden from reflection. Try to find the field via the
             * ResolvedJavaType.
             */
        for (ResolvedJavaField f : metaAccess.lookupJavaType(originalClass).getInstanceFields(true)) {
            if (f.getName().equals(originalName)) {
                return f;
            }
        }
        guarantee(optional || forceOptional, "could not find non-optional target field: %s", annotatedField);
        return null;
    }
}
Also used : ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Field(java.lang.reflect.Field) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) TargetElement(com.oracle.svm.core.annotate.TargetElement) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Aggregations

ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)45 ValueNode (org.graalvm.compiler.nodes.ValueNode)16 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)10 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)10 ArrayList (java.util.ArrayList)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)6 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)4 Field (java.lang.reflect.Field)4 JavaKind (jdk.vm.ci.meta.JavaKind)4 Invoke (org.graalvm.compiler.nodes.Invoke)4 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)4 SnippetReflectionProvider (org.graalvm.compiler.api.replacements.SnippetReflectionProvider)3 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)3 NodePlugin (org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin)3 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)3 LocationIdentity (org.graalvm.word.LocationIdentity)3 Delete (com.oracle.svm.core.annotate.Delete)2 Method (java.lang.reflect.Method)2 JavaField (jdk.vm.ci.meta.JavaField)2 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)2