Search in sources :

Example 71 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class SubstrateGraphBuilderPlugins method registerSizeOfPlugins.

private static void registerSizeOfPlugins(SnippetReflectionProvider snippetReflection, InvocationPlugins plugins) {
    Registration r = new Registration(plugins, SizeOf.class);
    r.register1("get", Class.class, new InvocationPlugin() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode classNode) {
            Class<? extends PointerBase> clazz = constantObjectParameter(b, snippetReflection, targetMethod, 0, Class.class, classNode);
            int result = SizeOf.get(clazz);
            b.notifyReplacedCall(targetMethod, b.addPush(JavaKind.Int, ConstantNode.forInt(result)));
            return true;
        }
    });
    r.register1("unsigned", Class.class, new InvocationPlugin() {

        @SuppressWarnings("unchecked")
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode classNode) {
            Class<? extends PointerBase> clazz = constantObjectParameter(b, snippetReflection, targetMethod, 0, Class.class, classNode);
            UnsignedWord result = SizeOf.unsigned(clazz);
            b.notifyReplacedCall(targetMethod, b.addPush(JavaKind.Object, ConstantNode.forConstant(snippetReflection.forObject(result), b.getMetaAccess())));
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) UnsignedWord(org.graalvm.word.UnsignedWord) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) PointerBase(org.graalvm.word.PointerBase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 72 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class WriteBarrierSnippets method g1PostWriteBarrier.

@Snippet
public static void g1PostWriteBarrier(Address address, Object object, Object value, @ConstantParameter boolean usePrecise, @ConstantParameter Register threadRegister, @ConstantParameter boolean trace, @ConstantParameter Counters counters) {
    Word thread = registerAsWord(threadRegister);
    Object fixedValue = FixedValueAnchorNode.getObject(value);
    verifyOop(object);
    verifyOop(fixedValue);
    validateObject(object, fixedValue);
    Pointer oop;
    if (usePrecise) {
        oop = Word.fromAddress(address);
    } else {
        oop = Word.objectToTrackedPointer(object);
    }
    int gcCycle = 0;
    if (trace) {
        Pointer gcTotalCollectionsAddress = WordFactory.pointer(HotSpotReplacementsUtil.gcTotalCollectionsAddress(INJECTED_VMCONFIG));
        gcCycle = (int) gcTotalCollectionsAddress.readLong(0);
        log(trace, "[%d] G1-Post Thread: %p Object: %p\n", gcCycle, thread.rawValue(), Word.objectToTrackedPointer(object).rawValue());
        log(trace, "[%d] G1-Post Thread: %p Field: %p\n", gcCycle, thread.rawValue(), oop.rawValue());
    }
    Pointer writtenValue = Word.objectToTrackedPointer(fixedValue);
    // The result of the xor reveals whether the installed pointer crosses heap regions.
    // In case it does the write barrier has to be issued.
    final int logOfHeapRegionGrainBytes = GraalHotSpotVMConfigNode.logOfHeapRegionGrainBytes();
    UnsignedWord xorResult = (oop.xor(writtenValue)).unsignedShiftRight(logOfHeapRegionGrainBytes);
    // Calculate the address of the card to be enqueued to the
    // thread local card queue.
    UnsignedWord cardBase = oop.unsignedShiftRight(cardTableShift(INJECTED_VMCONFIG));
    final long startAddress = GraalHotSpotVMConfigNode.cardTableAddress();
    int displacement = 0;
    if (((int) startAddress) == startAddress && GraalHotSpotVMConfigNode.isCardTableAddressConstant()) {
        displacement = (int) startAddress;
    } else {
        cardBase = cardBase.add(WordFactory.unsigned(startAddress));
    }
    Word cardAddress = (Word) cardBase.add(displacement);
    counters.g1AttemptedPostWriteBarrierCounter.inc();
    if (probability(FREQUENT_PROBABILITY, xorResult.notEqual(0))) {
        counters.g1EffectiveAfterXORPostWriteBarrierCounter.inc();
        // If the written value is not null continue with the barrier addition.
        if (probability(FREQUENT_PROBABILITY, writtenValue.notEqual(0))) {
            byte cardByte = cardAddress.readByte(0, GC_CARD_LOCATION);
            counters.g1EffectiveAfterNullPostWriteBarrierCounter.inc();
            // If the card is already dirty, (hence already enqueued) skip the insertion.
            if (probability(NOT_FREQUENT_PROBABILITY, cardByte != g1YoungCardValue(INJECTED_VMCONFIG))) {
                MembarNode.memoryBarrier(STORE_LOAD, GC_CARD_LOCATION);
                byte cardByteReload = cardAddress.readByte(0, GC_CARD_LOCATION);
                if (probability(NOT_FREQUENT_PROBABILITY, cardByteReload != dirtyCardValue(INJECTED_VMCONFIG))) {
                    log(trace, "[%d] G1-Post Thread: %p Card: %p \n", gcCycle, thread.rawValue(), WordFactory.unsigned((int) cardByte).rawValue());
                    cardAddress.writeByte(0, (byte) 0, GC_CARD_LOCATION);
                    counters.g1ExecutedPostWriteBarrierCounter.inc();
                    // If the thread local card queue is full, issue a native call which will
                    // initialize a new one and add the card entry.
                    Word indexAddress = thread.add(g1CardQueueIndexOffset(INJECTED_VMCONFIG));
                    Word indexValue = thread.readWord(g1CardQueueIndexOffset(INJECTED_VMCONFIG));
                    if (probability(FREQUENT_PROBABILITY, indexValue.notEqual(0))) {
                        Word bufferAddress = thread.readWord(g1CardQueueBufferOffset(INJECTED_VMCONFIG));
                        Word nextIndex = indexValue.subtract(wordSize());
                        Word logAddress = bufferAddress.add(nextIndex);
                        // Log the object to be scanned as well as update
                        // the card queue's next index.
                        logAddress.writeWord(0, cardAddress, GC_LOG_LOCATION);
                        indexAddress.writeWord(0, nextIndex, GC_INDEX_LOCATION);
                    } else {
                        g1PostBarrierStub(G1WBPOSTCALL, cardAddress);
                    }
                }
            }
        }
    }
}
Also used : Word(org.graalvm.compiler.word.Word) UnsignedWord(org.graalvm.word.UnsignedWord) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord) UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 73 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class ArraycopySnippets method objectCopyBackward.

private static void objectCopyBackward(Object fromArray, int fromIndex, Object toArray, int toIndex, int length, int le) {
    UnsignedWord fromOffset = LayoutEncoding.getArrayElementOffset(le, fromIndex);
    UnsignedWord toOffset = LayoutEncoding.getArrayElementOffset(le, toIndex);
    UnsignedWord elementSize = WordFactory.unsigned(LayoutEncoding.getArrayIndexScale(le));
    UnsignedWord size = elementSize.multiply(length);
    objectCopyBackwardsUninterruptibly(fromArray, fromOffset, toArray, toOffset, elementSize, size);
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord)

Example 74 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class ArraycopySnippets method primitiveCopyBackward.

private static void primitiveCopyBackward(Object fromArray, int fromIndex, Object toArray, int toIndex, int length, int le) {
    UnsignedWord fromOffset = LayoutEncoding.getArrayElementOffset(le, fromIndex);
    UnsignedWord toOffset = LayoutEncoding.getArrayElementOffset(le, toIndex);
    UnsignedWord elementSize = WordFactory.unsigned(LayoutEncoding.getArrayIndexScale(le));
    UnsignedWord size = elementSize.multiply(length);
    if (size.and(1).notEqual(0)) {
        size = size.subtract(1);
        ObjectAccess.writeByte(toArray, toOffset.add(size), ObjectAccess.readByte(fromArray, fromOffset.add(size)));
    }
    if (size.and(3).notEqual(0)) {
        size = size.subtract(2);
        ObjectAccess.writeShort(toArray, toOffset.add(size), ObjectAccess.readShort(fromArray, fromOffset.add(size)));
    }
    if (size.and(7).notEqual(0)) {
        size = size.subtract(4);
        ObjectAccess.writeInt(toArray, toOffset.add(size), ObjectAccess.readInt(fromArray, fromOffset.add(size)));
    }
    while (size.aboveThan(0)) {
        size = size.subtract(8);
        ObjectAccess.writeLong(toArray, toOffset.add(size), ObjectAccess.readLong(fromArray, fromOffset.add(size)));
    }
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord)

Example 75 with UnsignedWord

use of org.graalvm.word.UnsignedWord in project graal by oracle.

the class ArraycopySnippets method objectCopyBackwardsUninterruptibly.

@Uninterruptible(reason = "Only the first writeObject has a write-barrier.")
private static void objectCopyBackwardsUninterruptibly(Object fromArray, UnsignedWord fromOffset, Object toArray, UnsignedWord toOffset, UnsignedWord elementSize, UnsignedWord size) {
    // Loop-peel the first iteration so I can use BarrieredAccess
    // to put a write barrier on the destination.
    // TODO: I am explicitly not making the first read have a read barrier.
    UnsignedWord remaining = size;
    if (remaining.aboveThan(0)) {
        remaining = remaining.subtract(elementSize);
        BarrieredAccess.writeObject(toArray, toOffset.add(remaining), ObjectAccess.readObject(fromArray, fromOffset.add(remaining)));
        while (remaining.aboveThan(0)) {
            remaining = remaining.subtract(elementSize);
            ObjectAccess.writeObject(toArray, toOffset.add(remaining), ObjectAccess.readObject(fromArray, fromOffset.add(remaining)));
        }
    }
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Aggregations

UnsignedWord (org.graalvm.word.UnsignedWord)137 Pointer (org.graalvm.word.Pointer)43 Log (com.oracle.svm.core.log.Log)30 DynamicHub (com.oracle.svm.core.hub.DynamicHub)11 Fold (org.graalvm.compiler.api.replacements.Fold)11 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)9 Snippet (org.graalvm.compiler.api.replacements.Snippet)9 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)6 AlignedHeader (com.oracle.svm.core.genscavenge.AlignedHeapChunk.AlignedHeader)4 WordBase (org.graalvm.word.WordBase)4 AlwaysInline (com.oracle.svm.core.annotate.AlwaysInline)3 ValueInfo (com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo)3 UnalignedHeader (com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader)3 XOptions (com.oracle.svm.core.option.XOptions)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)2 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)2 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)2 Infopoint (jdk.vm.ci.code.site.Infopoint)2 JavaKind (jdk.vm.ci.meta.JavaKind)2