Search in sources :

Example 6 with HostedField

use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.

the class ComputedValueField method translateFieldOffset.

private JavaConstant translateFieldOffset(JavaConstant receiver, Class<?> tclass) {
    long searchOffset = ReadableJavaField.readFieldValue(GraalAccess.getOriginalProviders().getConstantReflection(), original, receiver).asLong();
    // search the declared fields for a field with a matching offset
    for (Field f : tclass.getDeclaredFields()) {
        if (!Modifier.isStatic(f.getModifiers())) {
            long fieldOffset = UnsafeAccess.UNSAFE.objectFieldOffset(f);
            if (fieldOffset == searchOffset) {
                HostedField sf = hMetaAccess.lookupJavaField(f);
                guarantee(sf.isAccessed() && sf.getLocation() > 0, "Field not marked as accessed: " + sf.format("%H.%n"));
                return JavaConstant.forLong(sf.getLocation());
            }
        }
    }
    throw shouldNotReachHere("unknown field offset class: " + tclass + ", offset = " + searchOffset);
}
Also used : ReadableJavaField(com.oracle.svm.core.meta.ReadableJavaField) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Field(java.lang.reflect.Field) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) HostedField(com.oracle.svm.hosted.meta.HostedField) HostedField(com.oracle.svm.hosted.meta.HostedField)

Example 7 with HostedField

use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.

the class JNICallTrampolineMethod method getFieldOffset.

private int getFieldOffset(HostedProviders providers) {
    HostedMetaAccess metaAccess = (HostedMetaAccess) providers.getMetaAccess();
    HostedUniverse universe = (HostedUniverse) metaAccess.getUniverse();
    AnalysisUniverse analysisUniverse = universe.getBigBang().getUniverse();
    HostedField hostedField = universe.lookup(analysisUniverse.lookup(callWrapperField));
    assert hostedField.hasLocation();
    return hostedField.getLocation();
}
Also used : HostedField(com.oracle.svm.hosted.meta.HostedField) HostedUniverse(com.oracle.svm.hosted.meta.HostedUniverse) HostedMetaAccess(com.oracle.svm.hosted.meta.HostedMetaAccess) AnalysisUniverse(com.oracle.graal.pointsto.meta.AnalysisUniverse)

Example 8 with HostedField

use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.

the class JNIAccessibleField method fillOffset.

void fillOffset(CompilationAccessImpl access) {
    assert id.equal(0);
    try {
        Field reflField = declaringClass.getClassObject().getDeclaredField(name);
        HostedField field = access.getMetaAccess().lookupJavaField(reflField);
        assert field.hasLocation();
        int offset = field.getLocation();
        assert ID_OFFSET_MASK.and(offset).equal(offset);
        this.id = flags.or(offset);
    } catch (NoSuchFieldException e) {
        throw new RuntimeException(e);
    }
}
Also used : HostedField(com.oracle.svm.hosted.meta.HostedField) Field(java.lang.reflect.Field) HostedField(com.oracle.svm.hosted.meta.HostedField)

Example 9 with HostedField

use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.

the class NativeImageHeap method addTrailingObjects.

public void addTrailingObjects(DebugContext debug) {
    // Process any remaining objects on the worklist, especially that might intern strings.
    processAddObjectWorklist(debug);
    HostedField internedStringsField = (HostedField) StringInternFeature.getInternedStringsField(metaAccess);
    boolean usesInternedStrings = internedStringsField.wrapped.isAccessed();
    if (usesInternedStrings) {
        /*
             * Ensure that the hub of the String[] array (used for the interned objects) is written.
             */
        addObject(debug, getMetaAccess().lookupJavaType(String[].class).getHub(), false, false, "internedStrings table");
        /*
             * We are no longer allowed to add new interned strings, because that would modify the
             * table we are about to write.
             */
        internStringsPhase.disallow();
        /*
             * By now, all interned Strings have been added to our internal interning table.
             * Populate the VM configuration with this table, and ensure it is part of the heap.
             */
        String[] imageInternedStrings = internedStrings.keySet().toArray(new String[0]);
        Arrays.sort(imageInternedStrings);
        ImageSingletons.lookup(StringInternSupport.class).setImageInternedStrings(imageInternedStrings);
        addObject(debug, imageInternedStrings, true, true, "internedStrings table");
        // Process any objects that were transitively added to the heap.
        processAddObjectWorklist(debug);
    } else {
        internStringsPhase.disallow();
    }
    addObjectsPhase.disallow();
    assert addObjectWorklist.isEmpty();
}
Also used : HostedField(com.oracle.svm.hosted.meta.HostedField) StringInternSupport(com.oracle.svm.core.jdk.StringInternSupport)

Example 10 with HostedField

use of com.oracle.svm.hosted.meta.HostedField in project graal by oracle.

the class NativeImageHeap method choosePartition.

/**
 * Choose a partition of the native image heap for the given object.
 */
private HeapPartition choosePartition(final Object candidate, final boolean immutableArg) {
    final HostedType type = getMetaAccess().lookupJavaType(candidate.getClass());
    assert type.getWrapped().isInstantiated() : type;
    boolean written = false;
    boolean references = false;
    boolean immutable = immutableArg;
    if (type.isInstanceClass()) {
        final HostedInstanceClass clazz = (HostedInstanceClass) type;
        if (HybridLayout.isHybrid(clazz)) {
            final HybridLayout<?> hybridLayout = new HybridLayout<>(clazz, layout);
            final HostedField arrayField = hybridLayout.getArrayField();
            written |= arrayField.isWritten();
            final JavaKind arrayKind = hybridLayout.getArrayElementKind();
            references |= arrayKind.isObject();
        }
        // Aggregate over all the fields of the instance.
        for (HostedField field : clazz.getInstanceFields(true)) {
            /*
                 * Any field that is written says the instance is written. Except that if the field
                 * is final, it will only be written during initialization during native image
                 * construction, but will not be written in the running image.
                 */
            written |= field.isWritten() && !field.isFinal();
            references |= field.getType().getStorageKind().isObject();
        }
        // If the type has a monitor field, it has a reference field that is written.
        if (clazz.getMonitorFieldOffset() != 0) {
            written = true;
            references = true;
            immutable = false;
        }
    } else if (type.isArray()) {
        HostedArrayClass clazz = (HostedArrayClass) type;
        // TODO: How to know if any of the array elements are written?
        written = true;
        JavaKind kind = clazz.getComponentType().getJavaKind();
        references = kind.isObject();
    } else {
        throw shouldNotReachHere();
    }
    if (SubstrateOptions.UseOnlyWritableBootImageHeap.getValue()) {
        assert !spawnIsolates();
        // Emergency use only! Alarms will sound!
        return writableReference;
    }
    if (!written || immutable) {
        return references ? readOnlyReference : readOnlyPrimitive;
    } else {
        return references ? writableReference : writablePrimitive;
    }
}
Also used : HostedType(com.oracle.svm.hosted.meta.HostedType) HostedArrayClass(com.oracle.svm.hosted.meta.HostedArrayClass) HostedField(com.oracle.svm.hosted.meta.HostedField) HybridLayout(com.oracle.svm.hosted.config.HybridLayout) HostedInstanceClass(com.oracle.svm.hosted.meta.HostedInstanceClass) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

HostedField (com.oracle.svm.hosted.meta.HostedField)13 HostedType (com.oracle.svm.hosted.meta.HostedType)4 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)3 JavaKind (jdk.vm.ci.meta.JavaKind)3 DynamicHub (com.oracle.svm.core.hub.DynamicHub)2 SubstrateField (com.oracle.svm.graal.meta.SubstrateField)2 HostedArrayClass (com.oracle.svm.hosted.meta.HostedArrayClass)2 HostedInstanceClass (com.oracle.svm.hosted.meta.HostedInstanceClass)2 Field (java.lang.reflect.Field)2 BitSet (java.util.BitSet)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)1 NativeImageInfo (com.oracle.svm.core.heap.NativeImageInfo)1 StringInternSupport (com.oracle.svm.core.jdk.StringInternSupport)1 ReadableJavaField (com.oracle.svm.core.meta.ReadableJavaField)1 SubstrateType (com.oracle.svm.graal.meta.SubstrateType)1 HybridLayout (com.oracle.svm.hosted.config.HybridLayout)1 HostedClass (com.oracle.svm.hosted.meta.HostedClass)1 HostedInterface (com.oracle.svm.hosted.meta.HostedInterface)1