Search in sources :

Example 26 with JavaKind

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

the class GraalCompilerTest method checkArgs.

protected void checkArgs(ResolvedJavaMethod method, Object[] args) {
    JavaType[] sig = method.toParameterTypes();
    Assert.assertEquals(sig.length, args.length);
    for (int i = 0; i < args.length; i++) {
        JavaType javaType = sig[i];
        JavaKind kind = javaType.getJavaKind();
        Object arg = args[i];
        if (kind == JavaKind.Object) {
            if (arg != null && javaType instanceof ResolvedJavaType) {
                ResolvedJavaType resolvedJavaType = (ResolvedJavaType) javaType;
                Assert.assertTrue(resolvedJavaType + " from " + getMetaAccess().lookupJavaType(arg.getClass()), resolvedJavaType.isAssignableFrom(getMetaAccess().lookupJavaType(arg.getClass())));
            }
        } else {
            Assert.assertNotNull(arg);
            Assert.assertEquals(kind.toBoxedJavaClass(), arg.getClass());
        }
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 27 with JavaKind

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

the class PEReadEliminationClosure method processStoreIndexed.

private boolean processStoreIndexed(StoreIndexedNode store, PEReadEliminationBlockState state, GraphEffectList effects) {
    int index = store.index().isConstant() ? ((JavaConstant) store.index().asConstant()).asInt() : -1;
    // BASTORE (with elementKind being Byte) can be used to store values in boolean arrays.
    JavaKind elementKind = store.elementKind();
    if (elementKind == JavaKind.Byte) {
        elementKind = getElementKindFromStamp(store.array());
        if (elementKind == JavaKind.Illegal) {
            // Could not determine the actual access kind from stamp. Hence kill both.
            state.killReadCache(NamedLocationIdentity.getArrayLocation(JavaKind.Boolean), index);
            state.killReadCache(NamedLocationIdentity.getArrayLocation(JavaKind.Byte), index);
            return false;
        }
    }
    LocationIdentity arrayLocation = NamedLocationIdentity.getArrayLocation(elementKind);
    if (index != -1) {
        return processStore(store, store.array(), arrayLocation, index, elementKind, false, store.value(), state, effects);
    } else {
        state.killReadCache(arrayLocation, -1);
    }
    return false;
}
Also used : LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 28 with JavaKind

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

the class PEReadEliminationClosure method processUnsafeLoad.

private boolean processUnsafeLoad(RawLoadNode load, PEReadEliminationBlockState state, GraphEffectList effects) {
    if (load.offset().isConstant()) {
        ResolvedJavaType type = StampTool.typeOrNull(load.object());
        if (type != null && type.isArray()) {
            JavaKind accessKind = load.accessKind();
            JavaKind componentKind = type.getComponentType().getJavaKind();
            long offset = load.offset().asJavaConstant().asLong();
            int index = VirtualArrayNode.entryIndexForOffset(tool.getArrayOffsetProvider(), offset, accessKind, type.getComponentType(), Integer.MAX_VALUE);
            ValueNode object = GraphUtil.unproxify(load.object());
            LocationIdentity location = NamedLocationIdentity.getArrayLocation(componentKind);
            ValueNode cachedValue = state.getReadCache(object, location, index, accessKind, this);
            assert cachedValue == null || load.stamp(NodeView.DEFAULT).isCompatible(cachedValue.stamp(NodeView.DEFAULT)) : "The RawLoadNode's stamp is not compatible with the cached value.";
            if (cachedValue != null) {
                effects.replaceAtUsages(load, cachedValue, load);
                addScalarAlias(load, cachedValue);
                return true;
            } else {
                state.addReadCache(object, location, index, accessKind, isOverflowAccess(accessKind, componentKind), load, this);
            }
        }
    }
    return false;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 29 with JavaKind

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

the class NativeImageHeap method writeObject.

private void writeObject(ObjectInfo info, final RelocatableBuffer roBuffer, final RelocatableBuffer rwBuffer) {
    /*
         * Write a reference from the object to its hub. This lives at layout.getHubOffset() from
         * the object base.
         */
    final RelocatableBuffer buffer = bufferForPartition(info, roBuffer, rwBuffer);
    final int indexInSection = info.getIntIndexInSection(layout.getHubOffset());
    assert layout.isReferenceAligned(info.getOffsetInPartition());
    assert layout.isReferenceAligned(indexInSection);
    final HostedClass clazz = info.getClazz();
    final DynamicHub hub = clazz.getHub();
    final long objectHeaderBits = Heap.getHeap().getObjectHeader().setBootImageOnLong(0L);
    writeDynamicHub(buffer, indexInSection, hub, objectHeaderBits);
    if (clazz.isInstanceClass()) {
        JavaConstant con = SubstrateObjectConstant.forObject(info.getObject());
        HybridLayout<?> hybridLayout = hybridLayouts.get(clazz);
        HostedField hybridArrayField = null;
        HostedField hybridBitsetField = null;
        int maxBitIndex = -1;
        Object hybridArray = null;
        if (hybridLayout != null) {
            hybridArrayField = hybridLayout.getArrayField();
            hybridArray = SubstrateObjectConstant.asObject(hybridArrayField.readStorageValue(con));
            hybridBitsetField = hybridLayout.getBitsetField();
            if (hybridBitsetField != null) {
                BitSet bitSet = (BitSet) SubstrateObjectConstant.asObject(hybridBitsetField.readStorageValue(con));
                if (bitSet != null) {
                    /*
                         * Write the bits of the hybrid bit field. The bits are located between the
                         * array length and the instance fields.
                         */
                    int bitsPerByte = Byte.SIZE;
                    for (int bit = bitSet.nextSetBit(0); bit >= 0; bit = bitSet.nextSetBit(bit + 1)) {
                        final int index = info.getIntIndexInSection(hybridLayout.getBitFieldOffset()) + bit / bitsPerByte;
                        if (index > maxBitIndex) {
                            maxBitIndex = index;
                        }
                        int mask = 1 << (bit % bitsPerByte);
                        assert mask < (1 << bitsPerByte);
                        buffer.putByte(index, (byte) (buffer.getByte(index) | mask));
                    }
                }
            }
        }
        /*
             * Write the regular instance fields.
             */
        for (HostedField field : clazz.getInstanceFields(true)) {
            if (!field.equals(hybridArrayField) && !field.equals(hybridBitsetField) && field.isAccessed()) {
                assert field.getLocation() >= 0;
                assert info.getIntIndexInSection(field.getLocation()) > maxBitIndex;
                writeField(buffer, info, field, con, info);
            }
        }
        if (hub.getHashCodeOffset() != 0) {
            buffer.putInt(info.getIntIndexInSection(hub.getHashCodeOffset()), info.getIdentityHashCode());
        }
        if (hybridArray != null) {
            /*
                 * Write the hybrid array length and the array elements.
                 */
            int length = Array.getLength(hybridArray);
            buffer.putInt(info.getIntIndexInSection(layout.getArrayLengthOffset()), length);
            for (int i = 0; i < length; i++) {
                final int elementIndex = info.getIntIndexInSection(hybridLayout.getArrayElementOffset(i));
                final JavaKind elementKind = hybridLayout.getArrayElementKind();
                final Object array = Array.get(hybridArray, i);
                writeConstant(buffer, elementIndex, elementKind, array, info);
            }
        }
    } else if (clazz.isArray()) {
        JavaKind kind = clazz.getComponentType().getJavaKind();
        Object array = info.getObject();
        int length = Array.getLength(array);
        buffer.putInt(info.getIntIndexInSection(layout.getArrayLengthOffset()), length);
        buffer.putInt(info.getIntIndexInSection(layout.getArrayHashCodeOffset()), info.getIdentityHashCode());
        if (array instanceof Object[]) {
            Object[] oarray = (Object[]) array;
            assert oarray.length == length;
            for (int i = 0; i < length; i++) {
                final int elementIndex = info.getIntIndexInSection(layout.getArrayElementOffset(kind, i));
                final Object element = aUniverse.replaceObject(oarray[i]);
                writeConstant(buffer, elementIndex, kind, element, info);
            }
        } else {
            for (int i = 0; i < length; i++) {
                final int elementIndex = info.getIntIndexInSection(layout.getArrayElementOffset(kind, i));
                final Object element = Array.get(array, i);
                writeConstant(buffer, elementIndex, kind, element, info);
            }
        }
    } else {
        throw shouldNotReachHere();
    }
}
Also used : HostedField(com.oracle.svm.hosted.meta.HostedField) DynamicHub(com.oracle.svm.core.hub.DynamicHub) BitSet(java.util.BitSet) JavaConstant(jdk.vm.ci.meta.JavaConstant) HostedClass(com.oracle.svm.hosted.meta.HostedClass) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 30 with JavaKind

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

the class NativeImageHeap method addObjectToBootImageHeap.

/**
 * It has been determined that an object should be added to the model of the native image heap.
 * This is the mechanics of recursively adding the object and all its fields and array elements
 * to the model of the native image heap.
 */
private void addObjectToBootImageHeap(final Object original, final Object canonicalObj, final boolean canonicalizable, boolean immutableFromParent, final int identityHashCode, final Object reason) {
    final Optional<HostedType> optionalType = getMetaAccess().optionalLookupJavaType(canonicalObj.getClass());
    if (!optionalType.isPresent() || !optionalType.get().isInstantiated()) {
        throw UserError.abort("Image heap writing found an object whose class was not seen as instantiated during static analysis. " + "Did a static field or an object referenced from a static field changed during native image generation? " + "For example, a lazily initialized cache could have been initialized during image generation, " + "in which case you need to force eager initialization of the cache before static analysis or reset the cache using a field value recomputation.\n" + "  object: " + original + "  of class: " + original.getClass().getTypeName() + "\n" + "  reachable through:\n" + fillReasonStack(new StringBuilder(), reason));
    }
    final HostedType type = optionalType.get();
    if (type.isInstanceClass()) {
        final HostedInstanceClass clazz = (HostedInstanceClass) type;
        final JavaConstant con = SubstrateObjectConstant.forObject(canonicalObj);
        final Object hybridArray;
        final long size;
        if (HybridLayout.isHybrid(clazz)) {
            HybridLayout<?> hybridLayout = hybridLayouts.get(clazz);
            if (hybridLayout == null) {
                hybridLayout = new HybridLayout<>(clazz, layout);
                hybridLayouts.put(clazz, hybridLayout);
            }
            /*
                 * The hybrid array and bit set are written within the hybrid object. So they may
                 * not be written as separate objects. We use the blacklist to check that.
                 */
            HostedField bitsetField = hybridLayout.getBitsetField();
            if (bitsetField != null) {
                BitSet bitSet = (BitSet) SubstrateObjectConstant.asObject(bitsetField.readStorageValue(con));
                if (bitSet != null) {
                    blacklist.put(bitSet, Boolean.TRUE);
                }
            }
            hybridArray = SubstrateObjectConstant.asObject(hybridLayout.getArrayField().readStorageValue(con));
            blacklist.put(hybridArray, Boolean.TRUE);
            size = hybridLayout.getTotalSize(Array.getLength(hybridArray));
        } else {
            hybridArray = null;
            size = LayoutEncoding.getInstanceSize(clazz.getHub().getLayoutEncoding()).rawValue();
        }
        // All canonicalizable objects are immutable,
        // as are instances of known immutable classes.
        final ObjectInfo info = addToHeapPartition(original, canonicalObj, clazz, size, identityHashCode, canonicalizable, immutableFromParent, reason);
        recursiveAddObject(clazz.getHub(), canonicalizable, false, info);
        // Recursively add all the fields of the object.
        // Even if the parent is not canonicalizable, the fields may be canonicalizable.
        final boolean fieldsAreImmutable = canonicalObj instanceof String;
        for (HostedField field : clazz.getInstanceFields(true)) {
            if (field.getType().getStorageKind() == JavaKind.Object && !HybridLayout.isHybridField(field) && field.isAccessed()) {
                assert field.getLocation() >= 0;
                recursiveAddObject(SubstrateObjectConstant.asObject(field.readStorageValue(con)), canonicalizable, fieldsAreImmutable, info);
            }
        }
        if (hybridArray instanceof Object[]) {
            addArrayElements((Object[]) hybridArray, canonicalizable, info);
        }
    } else if (type.isArray()) {
        HostedArrayClass clazz = (HostedArrayClass) type;
        int length = Array.getLength(canonicalObj);
        JavaKind kind = type.getComponentType().getJavaKind();
        final long size = layout.getArraySize(kind, length);
        final ObjectInfo info = addToHeapPartition(original, canonicalObj, clazz, size, identityHashCode, canonicalizable, immutableFromParent, reason);
        recursiveAddObject(clazz.getHub(), canonicalizable, false, info);
        if (kind == JavaKind.Object) {
            addArrayElements((Object[]) canonicalObj, canonicalizable, info);
        }
    } else {
        throw shouldNotReachHere();
    }
}
Also used : HostedField(com.oracle.svm.hosted.meta.HostedField) BitSet(java.util.BitSet) JavaConstant(jdk.vm.ci.meta.JavaConstant) HostedInstanceClass(com.oracle.svm.hosted.meta.HostedInstanceClass) HostedType(com.oracle.svm.hosted.meta.HostedType) HostedArrayClass(com.oracle.svm.hosted.meta.HostedArrayClass) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

JavaKind (jdk.vm.ci.meta.JavaKind)90 ValueNode (org.graalvm.compiler.nodes.ValueNode)44 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)24 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)17 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)16 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)13 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)12 JavaType (jdk.vm.ci.meta.JavaType)11 Stamp (org.graalvm.compiler.core.common.type.Stamp)10 LocationIdentity (org.graalvm.word.LocationIdentity)10 ArrayList (java.util.ArrayList)9 JavaConstant (jdk.vm.ci.meta.JavaConstant)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)8 FrameState (org.graalvm.compiler.nodes.FrameState)8 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)8 Signature (jdk.vm.ci.meta.Signature)7 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)6 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)6 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)6