Search in sources :

Example 21 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class NewInstanceStub method edenAllocate.

/**
 * Attempts to allocate a chunk of memory from Eden space.
 *
 * @param sizeInBytes the size of the chunk to allocate
 * @param log specifies if logging is enabled
 * @return the allocated chunk or {@link WordFactory#zero()} if allocation fails
 */
public static Word edenAllocate(Word sizeInBytes, boolean log) {
    final long heapTopRawAddress = GraalHotSpotVMConfigNode.heapTopAddress();
    final long heapEndRawAddress = GraalHotSpotVMConfigNode.heapEndAddress();
    Word heapTopAddress = WordFactory.unsigned(heapTopRawAddress);
    Word heapEndAddress = WordFactory.unsigned(heapEndRawAddress);
    while (true) {
        Word heapTop = heapTopAddress.readWord(0, HEAP_TOP_LOCATION);
        Word newHeapTop = heapTop.add(sizeInBytes);
        if (newHeapTop.belowOrEqual(heapTop)) {
            return WordFactory.zero();
        }
        Word heapEnd = heapEndAddress.readWord(0, HEAP_END_LOCATION);
        if (newHeapTop.aboveThan(heapEnd)) {
            return WordFactory.zero();
        }
        if (heapTopAddress.logicCompareAndSwapWord(0, heapTop, newHeapTop, HEAP_TOP_LOCATION)) {
            return heapTop;
        }
    }
}
Also used : Word(org.graalvm.compiler.word.Word) HotSpotReplacementsUtil.tlabIntArrayMarkWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.tlabIntArrayMarkWord) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)

Example 22 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class NewInstanceStub method allocate.

private static Word allocate(Word thread, int size) {
    Word top = readTlabTop(thread);
    Word end = readTlabEnd(thread);
    Word newTop = top.add(size);
    /*
         * this check might lead to problems if the TLAB is within 16GB of the address space end
         * (checked in c++ code)
         */
    if (probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) {
        writeTlabTop(thread, newTop);
        return top;
    }
    return WordFactory.zero();
}
Also used : Word(org.graalvm.compiler.word.Word) HotSpotReplacementsUtil.tlabIntArrayMarkWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.tlabIntArrayMarkWord) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)

Example 23 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class StubUtil method verifyObject.

/**
 * Verifies that a given object value is well formed if {@code -XX:+VerifyOops} is enabled.
 */
public static Object verifyObject(Object object) {
    if (verifyOops(INJECTED_VMCONFIG)) {
        Word verifyOopCounter = WordFactory.unsigned(verifyOopCounterAddress(INJECTED_VMCONFIG));
        verifyOopCounter.writeInt(0, verifyOopCounter.readInt(0) + 1);
        Pointer oop = Word.objectToTrackedPointer(object);
        if (object != null) {
            GuardingNode anchorNode = SnippetAnchorNode.anchor();
            // make sure object is 'reasonable'
            if (!oop.and(WordFactory.unsigned(verifyOopMask(INJECTED_VMCONFIG))).equal(WordFactory.unsigned(verifyOopBits(INJECTED_VMCONFIG)))) {
                fatal("oop not in heap: %p", oop.rawValue());
            }
            KlassPointer klass = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
            if (klass.isNull()) {
                fatal("klass for oop %p is null", oop.rawValue());
            }
        }
    }
    return object;
}
Also used : Word(org.graalvm.compiler.word.Word) Pointer(org.graalvm.word.Pointer) KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) KlassPointer(org.graalvm.compiler.hotspot.word.KlassPointer) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Example 24 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class WordTest method cast.

@Snippet
public static long cast(long input) {
    WordBase base = WordFactory.signed(input);
    UnsignedWord unsigned = (UnsignedWord) base;
    Pointer pointer = (Pointer) unsigned;
    Word word = (Word) pointer;
    return word.rawValue();
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Word(org.graalvm.compiler.word.Word) UnsignedWord(org.graalvm.word.UnsignedWord) WordBase(org.graalvm.word.WordBase) Pointer(org.graalvm.word.Pointer) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 25 with Word

use of org.graalvm.compiler.word.Word in project graal by oracle.

the class MonitorSnippets method tryEnterInflated.

private static boolean tryEnterInflated(Object object, Word lock, Word mark, Register threadRegister, boolean trace, OptionValues options, Counters counters) {
    // write non-zero value to lock slot
    lock.writeWord(lockDisplacedMarkOffset(INJECTED_VMCONFIG), lock, DISPLACED_MARK_WORD_LOCATION);
    // mark is a pointer to the ObjectMonitor + monitorMask
    Word monitor = mark.subtract(monitorMask(INJECTED_VMCONFIG));
    int ownerOffset = objectMonitorOwnerOffset(INJECTED_VMCONFIG);
    Word owner = monitor.readWord(ownerOffset, OBJECT_MONITOR_OWNER_LOCATION);
    if (probability(FREQUENT_PROBABILITY, owner.equal(0))) {
        // it appears unlocked (owner == 0)
        if (probability(FREQUENT_PROBABILITY, monitor.logicCompareAndSwapWord(ownerOffset, owner, registerAsWord(threadRegister), OBJECT_MONITOR_OWNER_LOCATION))) {
            // success
            traceObject(trace, "+lock{inflated:cas}", object, true, options);
            counters.inflatedCas.inc();
            return true;
        } else {
            traceObject(trace, "+lock{stub:inflated:failed-cas}", object, true, options);
            counters.inflatedFailedCas.inc();
        }
    } else {
        traceObject(trace, "+lock{stub:inflated:owned}", object, true, options);
        counters.inflatedOwned.inc();
    }
    return false;
}
Also used : Word(org.graalvm.compiler.word.Word) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)

Aggregations

Word (org.graalvm.compiler.word.Word)53 HotSpotReplacementsUtil.registerAsWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord)32 Snippet (org.graalvm.compiler.api.replacements.Snippet)22 Pointer (org.graalvm.word.Pointer)12 UnsignedWord (org.graalvm.word.UnsignedWord)7 MethodSubstitution (org.graalvm.compiler.api.replacements.MethodSubstitution)5 KlassPointer (org.graalvm.compiler.hotspot.word.KlassPointer)5 HotSpotReplacementsUtil.tlabIntArrayMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.tlabIntArrayMarkWord)4 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)2 HotSpotReplacementsUtil.loadKlassFromObject (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.loadKlassFromObject)2 SignedWord (org.graalvm.word.SignedWord)2 Substitute (com.oracle.svm.core.annotate.Substitute)1 SubstrateObjectConstant (com.oracle.svm.core.meta.SubstrateObjectConstant)1 Pwd.passwd (com.oracle.svm.core.posix.headers.Pwd.passwd)1 Pwd.passwdPointer (com.oracle.svm.core.posix.headers.Pwd.passwdPointer)1 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)1 HotSpotReplacementsUtil.arrayPrototypeMarkWord (org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayPrototypeMarkWord)1 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)1 Isolate (org.graalvm.nativeimage.Isolate)1 PinnedObject (org.graalvm.nativeimage.PinnedObject)1