Search in sources :

Example 36 with Word

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

the class NewObjectSnippets method allocateInstanceHelper.

public static Object allocateInstanceHelper(int size, KlassPointer hub, Word prototypeMarkWord, boolean fillContents, Register threadRegister, boolean constantSize, String typeContext, OptionValues options, Counters counters) {
    Object result;
    Word thread = registerAsWord(threadRegister);
    Word top = readTlabTop(thread);
    Word end = readTlabEnd(thread);
    Word newTop = top.add(size);
    if (useTLAB(INJECTED_VMCONFIG) && probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) {
        writeTlabTop(thread, newTop);
        emitPrefetchAllocate(newTop, false);
        result = formatObject(hub, size, top, prototypeMarkWord, fillContents, constantSize, counters);
    } else {
        if (counters != null && counters.stub != null) {
            counters.stub.inc();
        }
        result = newInstance(HotSpotBackend.NEW_INSTANCE, hub);
    }
    profileAllocation("instance", size, typeContext, options);
    return verifyOop(result);
}
Also used : Word(org.graalvm.compiler.word.Word) HotSpotReplacementsUtil.registerAsWord(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord) HotSpotReplacementsUtil.loadKlassFromObject(org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.loadKlassFromObject)

Example 37 with Word

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

the class SHA5Substitutions method implCompress0.

@MethodSubstitution(isStatic = false)
static void implCompress0(Object receiver, byte[] buf, int ofs) {
    Object realReceiver = PiNode.piCastNonNull(receiver, shaClass);
    Object state = RawLoadNode.load(realReceiver, stateOffset, JavaKind.Object, LocationIdentity.any());
    Word bufAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(buf, getArrayBaseOffset(JavaKind.Byte) + ofs));
    Word stateAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(state, getArrayBaseOffset(JavaKind.Int)));
    HotSpotBackend.sha5ImplCompressStub(bufAddr, stateAddr);
}
Also used : Word(org.graalvm.compiler.word.Word) MethodSubstitution(org.graalvm.compiler.api.replacements.MethodSubstitution)

Example 38 with Word

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

the class NewInstanceStub method refillAllocate.

/**
 * Attempts to refill the current thread's TLAB and retries the allocation.
 *
 * @param intArrayHub the hub for {@code int[].class}
 * @param sizeInBytes the size of the allocation
 * @param log specifies if logging is enabled
 *
 * @return the newly allocated, uninitialized chunk of memory, or {@link WordFactory#zero()} if
 *         the operation was unsuccessful
 */
static Word refillAllocate(Word thread, KlassPointer intArrayHub, int sizeInBytes, boolean log) {
    // and therefore we have to go to slowpath to allocate a new TLAB.
    if (useG1GC(INJECTED_VMCONFIG)) {
        return WordFactory.zero();
    }
    if (!useTLAB(INJECTED_VMCONFIG)) {
        return edenAllocate(WordFactory.unsigned(sizeInBytes), log);
    }
    Word intArrayMarkWord = WordFactory.unsigned(tlabIntArrayMarkWord(INJECTED_VMCONFIG));
    int alignmentReserveInBytes = tlabAlignmentReserveInHeapWords(INJECTED_VMCONFIG) * wordSize();
    Word top = readTlabTop(thread);
    Word end = readTlabEnd(thread);
    // calculate amount of free space
    long tlabFreeSpaceInBytes = end.subtract(top).rawValue();
    if (log) {
        printf("refillTLAB: thread=%p\n", thread.rawValue());
        printf("refillTLAB: top=%p\n", top.rawValue());
        printf("refillTLAB: end=%p\n", end.rawValue());
        printf("refillTLAB: tlabFreeSpaceInBytes=%ld\n", tlabFreeSpaceInBytes);
    }
    long tlabFreeSpaceInWords = tlabFreeSpaceInBytes >>> log2WordSize();
    // Retain TLAB and allocate object in shared space if
    // the amount free in the TLAB is too large to discard.
    Word refillWasteLimit = thread.readWord(tlabRefillWasteLimitOffset(INJECTED_VMCONFIG), TLAB_REFILL_WASTE_LIMIT_LOCATION);
    if (tlabFreeSpaceInWords <= refillWasteLimit.rawValue()) {
        if (tlabStats(INJECTED_VMCONFIG)) {
            // increment number of refills
            thread.writeInt(tlabNumberOfRefillsOffset(INJECTED_VMCONFIG), thread.readInt(tlabNumberOfRefillsOffset(INJECTED_VMCONFIG), TLAB_NOF_REFILLS_LOCATION) + 1, TLAB_NOF_REFILLS_LOCATION);
            if (log) {
                printf("thread: %p -- number_of_refills %d\n", thread.rawValue(), thread.readInt(tlabNumberOfRefillsOffset(INJECTED_VMCONFIG), TLAB_NOF_REFILLS_LOCATION));
            }
            // accumulate wastage
            int wastage = thread.readInt(tlabFastRefillWasteOffset(INJECTED_VMCONFIG), TLAB_FAST_REFILL_WASTE_LOCATION) + (int) tlabFreeSpaceInWords;
            if (log) {
                printf("thread: %p -- accumulated wastage %d\n", thread.rawValue(), wastage);
            }
            thread.writeInt(tlabFastRefillWasteOffset(INJECTED_VMCONFIG), wastage, TLAB_FAST_REFILL_WASTE_LOCATION);
        }
        // fill [top, end + alignment_reserve) with array object
        if (top.notEqual(0)) {
            int headerSize = arrayBaseOffset(JavaKind.Int);
            // just like the HotSpot assembler stubs, assumes that tlabFreeSpaceInInts fits in
            // an int
            int tlabFreeSpaceInInts = (int) tlabFreeSpaceInBytes >>> 2;
            int length = ((alignmentReserveInBytes - headerSize) >>> 2) + tlabFreeSpaceInInts;
            NewObjectSnippets.formatArray(intArrayHub, 0, length, headerSize, top, intArrayMarkWord, false, false, null);
            long allocated = thread.readLong(threadAllocatedBytesOffset(INJECTED_VMCONFIG), TLAB_THREAD_ALLOCATED_BYTES_LOCATION);
            allocated = allocated + top.subtract(readTlabStart(thread)).rawValue();
            thread.writeLong(threadAllocatedBytesOffset(INJECTED_VMCONFIG), allocated, TLAB_THREAD_ALLOCATED_BYTES_LOCATION);
        }
        // refill the TLAB with an eden allocation
        Word tlabRefillSizeInWords = thread.readWord(threadTlabSizeOffset(INJECTED_VMCONFIG), TLAB_SIZE_LOCATION);
        Word tlabRefillSizeInBytes = tlabRefillSizeInWords.multiply(wordSize());
        // allocate new TLAB, address returned in top
        top = edenAllocate(tlabRefillSizeInBytes, log);
        if (top.notEqual(0)) {
            end = top.add(tlabRefillSizeInBytes.subtract(alignmentReserveInBytes));
            initializeTlab(thread, top, end);
            return NewInstanceStub.allocate(thread, sizeInBytes);
        } else {
            return WordFactory.zero();
        }
    } else {
        // Retain TLAB
        Word newRefillWasteLimit = refillWasteLimit.add(tlabRefillWasteIncrement(INJECTED_VMCONFIG));
        thread.writeWord(tlabRefillWasteLimitOffset(INJECTED_VMCONFIG), newRefillWasteLimit, TLAB_REFILL_WASTE_LIMIT_LOCATION);
        if (log) {
            printf("refillTLAB: retaining TLAB - newRefillWasteLimit=%p\n", newRefillWasteLimit.rawValue());
        }
        if (tlabStats(INJECTED_VMCONFIG)) {
            thread.writeInt(tlabSlowAllocationsOffset(INJECTED_VMCONFIG), thread.readInt(tlabSlowAllocationsOffset(INJECTED_VMCONFIG), TLAB_SLOW_ALLOCATIONS_LOCATION) + 1, TLAB_SLOW_ALLOCATIONS_LOCATION);
        }
        return edenAllocate(WordFactory.unsigned(sizeInBytes), log);
    }
}
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 39 with Word

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

the class NewInstanceStub method newInstance.

/**
 * Re-attempts allocation after an initial TLAB allocation failed or was skipped (e.g., due to
 * -XX:-UseTLAB).
 *
 * @param hub the hub of the object to be allocated
 * @param intArrayHub the hub for {@code int[].class}
 */
@Snippet
private static Object newInstance(KlassPointer hub, @ConstantParameter KlassPointer intArrayHub, @ConstantParameter Register threadRegister, @ConstantParameter OptionValues options) {
    /*
         * The type is known to be an instance so Klass::_layout_helper is the instance size as a
         * raw number
         */
    Word thread = registerAsWord(threadRegister);
    boolean inlineContiguousAllocationSupported = GraalHotSpotVMConfigNode.inlineContiguousAllocationSupported();
    if (!forceSlowPath(options) && inlineContiguousAllocationSupported && !useCMSIncrementalMode(INJECTED_VMCONFIG)) {
        if (isInstanceKlassFullyInitialized(hub)) {
            int sizeInBytes = readLayoutHelper(hub);
            Word memory = refillAllocate(thread, intArrayHub, sizeInBytes, logging(options));
            if (memory.notEqual(0)) {
                Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset(INJECTED_VMCONFIG), PROTOTYPE_MARK_WORD_LOCATION);
                NewObjectSnippets.formatObjectForStub(hub, sizeInBytes, memory, prototypeMarkWord);
                return verifyObject(memory.toObject());
            }
        }
    }
    if (logging(options)) {
        printf("newInstance: calling new_instance_c\n");
    }
    newInstanceC(NEW_INSTANCE_C, thread, hub);
    handlePendingException(thread, true);
    return verifyObject(getAndClearObjectResult(thread));
}
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) Snippet(org.graalvm.compiler.api.replacements.Snippet)

Example 40 with Word

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

the class OutOfBoundsExceptionStub method createOutOfBoundsException.

@Snippet
private static Object createOutOfBoundsException(int idx, @ConstantParameter Register threadRegister, @ConstantParameter int bufferSizeInWords) {
    Word buffer = AllocaNode.alloca(bufferSizeInWords);
    long number = idx;
    if (number < 0) {
        number = -number;
    }
    Word ptr = buffer.add(MAX_INT_STRING_SIZE);
    ptr.writeByte(0, (byte) 0);
    do {
        long digit = number % 10;
        number /= 10;
        ptr = ptr.subtract(1);
        ptr.writeByte(0, (byte) ('0' + digit));
    } while (number > 0);
    if (idx < 0) {
        ptr = ptr.subtract(1);
        ptr.writeByte(0, (byte) '-');
    }
    return createException(threadRegister, ArrayIndexOutOfBoundsException.class, ptr);
}
Also used : Word(org.graalvm.compiler.word.Word) Snippet(org.graalvm.compiler.api.replacements.Snippet)

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