Search in sources :

Example 6 with ObjectLayout

use of com.oracle.svm.core.config.ObjectLayout in project graal by oracle.

the class PthreadVMCondition method beforeCompilation.

@Override
public void beforeCompilation(BeforeCompilationAccess access) {
    ObjectLayout layout = ConfigurationValues.getObjectLayout();
    int nextIndex = 0;
    PthreadVMMutex[] mutexes = mutexReplacer.getReplacements().toArray(new PthreadVMMutex[0]);
    int mutexSize = NumUtil.roundUp(SizeOf.get(Pthread.pthread_mutex_t.class), 8);
    for (PthreadVMMutex mutex : mutexes) {
        mutex.structOffset = WordFactory.unsigned(layout.getArrayElementOffset(JavaKind.Byte, nextIndex));
        nextIndex += mutexSize;
    }
    PthreadVMCondition[] conditions = conditionReplacer.getReplacements().toArray(new PthreadVMCondition[0]);
    int conditionSize = NumUtil.roundUp(SizeOf.get(Pthread.pthread_cond_t.class), 8);
    for (PthreadVMCondition condition : conditions) {
        condition.structOffset = WordFactory.unsigned(layout.getArrayElementOffset(JavaKind.Byte, nextIndex));
        nextIndex += conditionSize;
    }
    PthreadVMLockSupport lockSupport = ImageSingletons.lookup(PthreadVMLockSupport.class);
    lockSupport.mutexes = mutexes;
    lockSupport.conditions = conditions;
    lockSupport.pthreadStructs = new byte[nextIndex];
}
Also used : ObjectLayout(com.oracle.svm.core.config.ObjectLayout)

Example 7 with ObjectLayout

use of com.oracle.svm.core.config.ObjectLayout in project graal by oracle.

the class CollectingObjectReferenceVisitor method verifyVirtualObject.

private void verifyVirtualObject(CompilationResult compilation, VirtualObject expectedObject, ValueInfo[] actualObject, FrameInfoQueryResult actualFrame, BitSet visitedVirtualObjects) {
    if (visitedVirtualObjects.get(expectedObject.getId())) {
        return;
    }
    visitedVirtualObjects.set(expectedObject.getId());
    ObjectLayout objectLayout = ConfigurationValues.getObjectLayout();
    SharedType expectedType = (SharedType) expectedObject.getType();
    if (expectedType.isArray()) {
        JavaKind kind = expectedType.getComponentType().getJavaKind();
        int expectedLength = 0;
        for (int i = 0; i < expectedObject.getValues().length; i++) {
            JavaValue expectedValue = expectedObject.getValues()[i];
            UnsignedWord expectedOffset = WordFactory.unsigned(objectLayout.getArrayElementOffset(expectedType.getComponentType().getJavaKind(), expectedLength));
            ValueInfo actualValue = findActualArrayElement(actualObject, expectedOffset);
            verifyValue(compilation, expectedValue, actualValue, actualFrame, visitedVirtualObjects);
            JavaKind valueKind = expectedObject.getSlotKind(i);
            if (objectLayout.sizeInBytes(kind) == 4 && objectLayout.sizeInBytes(valueKind) == 8) {
                /*
                     * Truffle uses arrays in a non-standard way: it declares an int[] array and
                     * uses it to also store long and double values. These values span two array
                     * elements - so we have to add 2 to the length.
                     */
                expectedLength += 2;
            } else {
                expectedLength++;
            }
        }
        int actualLength = actualObject[1].value.asInt();
        assert expectedLength == actualLength;
    } else {
        SharedField[] expectedFields = (SharedField[]) expectedType.getInstanceFields(true);
        int fieldIdx = 0;
        int valueIdx = 0;
        while (valueIdx < expectedObject.getValues().length) {
            SharedField expectedField = expectedFields[fieldIdx];
            fieldIdx += 1;
            JavaValue expectedValue = expectedObject.getValues()[valueIdx];
            JavaKind valueKind = expectedObject.getSlotKind(valueIdx);
            valueIdx += 1;
            JavaKind kind = expectedField.getStorageKind();
            if (objectLayout.sizeInBytes(kind) == 4 && objectLayout.sizeInBytes(valueKind) == 8) {
                /*
                     * Truffle uses fields in a non-standard way: it declares a couple of
                     * (consecutive) int fields, and uses them to also store long and double values.
                     * These values span two fields - so we have to ignore a field.
                     */
                fieldIdx++;
            }
            UnsignedWord expectedOffset = WordFactory.unsigned(expectedField.getLocation());
            ValueInfo actualValue = findActualField(actualObject, expectedOffset);
            verifyValue(compilation, expectedValue, actualValue, actualFrame, visitedVirtualObjects);
        }
    }
}
Also used : SharedField(com.oracle.svm.core.meta.SharedField) UnsignedWord(org.graalvm.word.UnsignedWord) JavaValue(jdk.vm.ci.meta.JavaValue) ValueInfo(com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo) ObjectLayout(com.oracle.svm.core.config.ObjectLayout) SharedType(com.oracle.svm.core.meta.SharedType) Infopoint(jdk.vm.ci.code.site.Infopoint) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 8 with ObjectLayout

use of com.oracle.svm.core.config.ObjectLayout in project graal by oracle.

the class CollectingObjectReferenceVisitor method findActualArrayElement.

private static ValueInfo findActualArrayElement(ValueInfo[] actualObject, UnsignedWord expectedOffset) {
    DynamicHub hub = KnownIntrinsics.convertUnknownValue(SubstrateObjectConstant.asObject(actualObject[0].getValue()), DynamicHub.class);
    ObjectLayout objectLayout = ConfigurationValues.getObjectLayout();
    assert LayoutEncoding.isArray(hub.getLayoutEncoding());
    return findActualValue(actualObject, expectedOffset, objectLayout, LayoutEncoding.getArrayBaseOffset(hub.getLayoutEncoding()), 2);
}
Also used : ObjectLayout(com.oracle.svm.core.config.ObjectLayout) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 9 with ObjectLayout

use of com.oracle.svm.core.config.ObjectLayout in project graal by oracle.

the class FrameInfoVerifier method makeVirtualObject.

private void makeVirtualObject(FrameData data, VirtualObject virtualObject) {
    int id = virtualObject.getId();
    if (data.virtualObjects[id] != null) {
        return;
    }
    /* Install a non-null value to support recursive VirtualObjects. */
    data.virtualObjects[id] = MARKER;
    /* Objects must contain only compressed references when compression is enabled */
    boolean compressedRefs = ReferenceAccess.singleton().haveCompressedReferences();
    List<ValueInfo> valueList = new ArrayList<>(virtualObject.getValues().length + 4);
    SharedType type = (SharedType) virtualObject.getType();
    /* The first element is the hub of the virtual object. */
    valueList.add(makeValueInfo(data, JavaKind.Object, SubstrateObjectConstant.forObject(type.getHub())));
    ObjectLayout objectLayout = ConfigurationValues.getObjectLayout();
    assert type.isArray() == LayoutEncoding.isArray(type.getHub().getLayoutEncoding()) : "deoptimization code uses layout encoding to determine if type is an array";
    if (type.isArray()) {
        /* We do not know the final length yet, so add a placeholder. */
        valueList.add(null);
        int length = 0;
        JavaKind kind = ((SharedType) type.getComponentType()).getStorageKind();
        for (int i = 0; i < virtualObject.getValues().length; i++) {
            JavaValue value = virtualObject.getValues()[i];
            JavaKind valueKind = virtualObject.getSlotKind(i);
            if (objectLayout.sizeInBytes(kind, compressedRefs) == 4 && objectLayout.sizeInBytes(valueKind, compressedRefs) == 8) {
                /*
                     * Truffle uses arrays in a non-standard way: it declares an int[] array and
                     * uses it to also store long and double values. These values span two array
                     * elements - so we have to write this element with the actual value kind and
                     * add 2 to the length.
                     */
                valueList.add(makeValueInfo(data, valueKind, value));
                length += 2;
            } else {
                assert objectLayout.sizeInBytes(valueKind.getStackKind(), compressedRefs) <= objectLayout.sizeInBytes(kind.getStackKind(), compressedRefs);
                valueList.add(makeValueInfo(data, kind, value));
                length++;
            }
            assert objectLayout.getArrayElementOffset(type.getComponentType().getJavaKind(), length) == objectLayout.getArrayBaseOffset(type.getComponentType().getJavaKind()) + computeOffset(valueList.subList(2, valueList.size()), compressedRefs);
        }
        assert valueList.get(1) == null;
        valueList.set(1, makeValueInfo(data, JavaKind.Int, JavaConstant.forInt(length)));
    } else {
        /*
             * We must add filling constants for padding, so that values are contiguous. The
             * deoptimization code does not have access to field information.
             */
        SharedField[] fields = (SharedField[]) type.getInstanceFields(true);
        long curOffset = objectLayout.getFirstFieldOffset();
        int fieldIdx = 0;
        int valueIdx = 0;
        while (valueIdx < virtualObject.getValues().length) {
            SharedField field = fields[fieldIdx];
            fieldIdx += 1;
            JavaValue value = virtualObject.getValues()[valueIdx];
            JavaKind valueKind = virtualObject.getSlotKind(valueIdx);
            valueIdx += 1;
            JavaKind kind = field.getStorageKind();
            if (objectLayout.sizeInBytes(kind, compressedRefs) == 4 && objectLayout.sizeInBytes(valueKind, compressedRefs) == 8) {
                /*
                     * Truffle uses fields in a non-standard way: it declares a couple of
                     * (consecutive) int fields, and uses them to also store long and double values.
                     * These values span two fields - so we have to ignore a field.
                     */
                kind = valueKind;
                assert fields[fieldIdx].getJavaKind() == field.getJavaKind();
                fieldIdx++;
            }
            if (field.getLocation() >= 0) {
                assert curOffset <= field.getLocation();
                while (curOffset + 7 < field.getLocation()) {
                    valueList.add(makeValueInfo(data, JavaKind.Long, JavaConstant.LONG_0));
                    curOffset += 8;
                }
                if (curOffset + 3 < field.getLocation()) {
                    valueList.add(makeValueInfo(data, JavaKind.Int, JavaConstant.INT_0));
                    curOffset += 4;
                }
                if (curOffset + 1 < field.getLocation()) {
                    valueList.add(makeValueInfo(data, JavaKind.Short, JavaConstant.forShort((short) 0)));
                    curOffset += 2;
                }
                if (curOffset < field.getLocation()) {
                    valueList.add(makeValueInfo(data, JavaKind.Byte, JavaConstant.forByte((byte) 0)));
                    curOffset += 1;
                }
                assert curOffset == field.getLocation();
                assert curOffset == computeOffset(valueList, compressedRefs);
                valueList.add(makeValueInfo(data, kind, value));
                curOffset += objectLayout.sizeInBytes(kind, compressedRefs);
            }
        }
    }
    data.virtualObjects[id] = valueList.toArray(new ValueInfo[valueList.size()]);
    ImageSingletons.lookup(Counters.class).virtualObjectsCount.inc();
}
Also used : SharedField(com.oracle.svm.core.meta.SharedField) ValueInfo(com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo) JavaValue(jdk.vm.ci.meta.JavaValue) ObjectLayout(com.oracle.svm.core.config.ObjectLayout) ArrayList(java.util.ArrayList) SharedType(com.oracle.svm.core.meta.SharedType) Infopoint(jdk.vm.ci.code.site.Infopoint) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 10 with ObjectLayout

use of com.oracle.svm.core.config.ObjectLayout in project graal by oracle.

the class RecomputedFields method compute.

@Override
public Object compute(ResolvedJavaField original, ResolvedJavaField annotated, Object receiver) {
    try {
        ObjectLayout layout = ImageSingletons.lookup(ObjectLayout.class);
        /*
             * ASHIFT is a hard-coded constant in the original implementation, so there is no need
             * to recompute it. It is a private field, so we need reflection to access it.
             */
        Field ashiftField = java.util.concurrent.Exchanger.class.getDeclaredField("ASHIFT");
        ashiftField.setAccessible(true);
        int ashift = ashiftField.getInt(null);
        /*
             * The original implementation uses Node[].class, but we know that all Object arrays
             * have the same kind and layout. The kind denotes the element type of the array.
             */
        JavaKind ak = JavaKind.Object;
        // ABASE absorbs padding in front of element 0
        int abase = layout.getArrayBaseOffset(ak) + (1 << ashift);
        /* Sanity check. */
        final int s = layout.getArrayIndexScale(ak);
        if ((s & (s - 1)) != 0 || s > (1 << ashift)) {
            throw VMError.shouldNotReachHere("Unsupported array scale");
        }
        return abase;
    } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException ex) {
        throw VMError.shouldNotReachHere(ex);
    }
}
Also used : ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Field(java.lang.reflect.Field) ObjectLayout(com.oracle.svm.core.config.ObjectLayout) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

ObjectLayout (com.oracle.svm.core.config.ObjectLayout)11 JavaKind (jdk.vm.ci.meta.JavaKind)6 DynamicHub (com.oracle.svm.core.hub.DynamicHub)4 ValueInfo (com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo)3 ArrayList (java.util.ArrayList)3 SharedField (com.oracle.svm.core.meta.SharedField)2 SharedType (com.oracle.svm.core.meta.SharedType)2 Infopoint (jdk.vm.ci.code.site.Infopoint)2 JavaValue (jdk.vm.ci.meta.JavaValue)2 UnsignedWord (org.graalvm.word.UnsignedWord)2 AnalysisPolicy (com.oracle.graal.pointsto.AnalysisPolicy)1 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)1 SubstitutionProcessor (com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor)1 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)1 AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)1 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)1 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 TypeState (com.oracle.graal.pointsto.typestate.TypeState)1 Timer (com.oracle.graal.pointsto.util.Timer)1