Search in sources :

Example 1 with UnsignedWord

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

the class PosixJavaNIOSubstitutions method toByteArray.

// Checkstyle: resume
protected static byte[] toByteArray(CCharPointer cstr) {
    UnsignedWord len = SubstrateUtil.strlen(cstr);
    byte[] result = new byte[(int) len.rawValue()];
    for (int i = 0; i < result.length; i++) {
        result[i] = cstr.read(i);
    }
    return result;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 2 with UnsignedWord

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

the class NativeImage method getXmxValue.

protected String getXmxValue(int maxInstances) {
    UnsignedWord memMax = PhysicalMemory.size().unsignedDivide(10).multiply(8).unsignedDivide(maxInstances);
    String maxXmx = "14g";
    if (memMax.aboveOrEqual(Word.unsigned(SubstrateOptionsParser.parseLong(maxXmx)))) {
        return maxXmx;
    }
    return Long.toUnsignedString(memMax.rawValue());
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord)

Example 3 with UnsignedWord

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

the class JavaLangSubstitutions method identityHashCode.

@Substitute
private static int identityHashCode(Object obj) {
    if (obj == null) {
        return 0;
    }
    DynamicHub hub = KnownIntrinsics.readHub(obj);
    int hashCodeOffset = hub.getHashCodeOffset();
    if (hashCodeOffset == 0) {
        throw VMError.shouldNotReachHere("identityHashCode called on illegal object");
    }
    UnsignedWord hashCodeOffsetWord = WordFactory.unsigned(hashCodeOffset);
    int hashCode = ObjectAccess.readInt(obj, hashCodeOffsetWord);
    if (hashCode != 0) {
        return hashCode;
    }
    /* On the first invocation for an object create a new hash code. */
    hashCode = IdentityHashCodeSupport.generateHashCode();
    if (!UnsafeAccess.UNSAFE.compareAndSwapInt(obj, hashCodeOffset, 0, hashCode)) {
        /* We lost the race, so there now must be a hash code installed from another thread. */
        hashCode = ObjectAccess.readInt(obj, hashCodeOffsetWord);
    }
    VMError.guarantee(hashCode != 0, "Missing identity hash code");
    return hashCode;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) DynamicHub(com.oracle.svm.core.hub.DynamicHub) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 4 with UnsignedWord

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

the class ReferenceMapDecoder method walkOffsetsFromPointer.

/**
 * Walk the reference map encoding from a Pointer, applying a visitor to each Object reference.
 *
 * @param baseAddress A Pointer to a collections of primitives and Object references.
 * @param referenceMapEncoding The encoding for the Object references in the collection.
 * @param referenceMapIndex The start index for the particular reference map in the encoding.
 * @param visitor The ObjectRefernceVisitor to be applied to each Object reference.
 * @return false if any of the visits returned false, true otherwise.
 */
@AlwaysInline("de-virtualize calls to ObjectReferenceVisitor")
public static boolean walkOffsetsFromPointer(PointerBase baseAddress, byte[] referenceMapEncoding, long referenceMapIndex, ObjectReferenceVisitor visitor) {
    assert referenceMapIndex != CodeInfoQueryResult.NO_REFERENCE_MAP;
    assert referenceMapEncoding != null;
    UnsignedWord uncompressedSize = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getReferenceSize());
    UnsignedWord compressedSize = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getCompressedReferenceSize());
    UnsignedWord slotSize = WordFactory.unsigned(SubstrateReferenceMap.getSlotSizeInBytes());
    Pointer objRef = (Pointer) baseAddress;
    long idx = referenceMapIndex;
    while (true) {
        int gap = ByteArrayReader.getU1(referenceMapEncoding, idx);
        if (gap == GAP_END_OF_TABLE) {
            break;
        }
        int count = ByteArrayReader.getS1(referenceMapEncoding, idx + 1);
        // Skip a gap.
        objRef = objRef.add(slotSize.multiply(gap));
        // Visit the offsets.
        boolean compressed = (count < 0);
        UnsignedWord refSize = compressed ? compressedSize : uncompressedSize;
        count = (count < 0) ? -count : count;
        for (int c = 0; c < count; c += 1) {
            final boolean visitResult = visitor.visitObjectReferenceInline(objRef, compressed);
            if (!visitResult) {
                return false;
            }
            objRef = objRef.add(refSize);
        }
        idx += 2;
    }
    return true;
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) Pointer(org.graalvm.word.Pointer) AlwaysInline(com.oracle.svm.core.annotate.AlwaysInline)

Example 5 with UnsignedWord

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

the class CInterfaceTutorial method javaEntryPoint4.

@CEntryPoint(name = "java_entry_point4")
protected static void javaEntryPoint4(@SuppressWarnings("unused") IsolateThread thread, SUData sudata) {
    int i = 0;
    UnsignedWord u = sudata.getUB1Unsigned();
    SignedWord s = sudata.getSB1Signed();
    i = sudata.getUB1();
    System.out.println(" getUB1() = " + i + (i < 0 ? "<" : ">=") + " 0");
    System.out.println(" getUB1Unsigned() = " + u.rawValue() + (u.rawValue() < 0 ? "<" : ">=") + " 0");
    i = sudata.getSB1();
    System.out.println(" getSB1() = " + i + (i < 0 ? "<" : ">=") + " 0");
    System.out.println(" getSB1Signed() = " + s.rawValue() + (s.rawValue() < 0 ? "<" : ">=") + " 0");
    System.out.println("(byte) 245        = " + ((byte) 245));
    System.out.println("(byte) 245 & 0xFF = " + (((byte) 245) & 0xFF));
    System.out.println("sudata.getUB1Unsigned().aboveOrEqual(220) = " + sudata.getUB1Unsigned().aboveOrEqual(220));
    System.out.println("sudata.getUB1Unsigned().aboveOrEqual(245) = " + sudata.getUB1Unsigned().aboveOrEqual(245));
    System.out.println("sudata.getUB1Unsigned().aboveOrEqual((byte)220) = " + sudata.getUB1Unsigned().aboveOrEqual((byte) 220));
    System.out.println("sudata.getUB1Unsigned().aboveOrEqual((byte)245) = " + sudata.getUB1Unsigned().aboveOrEqual((byte) 245));
    System.out.println("sudata.getUB1() && 0xFF >  220 = " + ((sudata.getUB1() & 0xFF) > 220));
    System.out.println("sudata.getUB1() && 0xFF >  245 = " + ((sudata.getUB1() & 0xFF) > 245));
}
Also used : UnsignedWord(org.graalvm.word.UnsignedWord) SignedWord(org.graalvm.word.SignedWord) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

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