Search in sources :

Example 1 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint 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)

Example 2 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class CInterfaceTutorial method javaEntryPoint2.

@CEntryPoint(name = "java_entry_point2")
protected static void javaEntryPoint2(@SuppressWarnings("unused") IsolateThread thread, Substruct1 s1, Substruct2 s2) {
    System.out.println("*** In Java, demonstrating inheritance with @CStruct class");
    CCharPointer tp1 = s1.typePtr();
    CCharPointer tp2 = s2.header().typePtr();
    System.out.println("tp1 = 0x" + Long.toHexString(tp1.rawValue()) + " tp2 = 0x" + Long.toHexString(tp2.rawValue()));
    System.out.println("&s1.header = 0x" + Long.toHexString(s1.header().rawValue()) + " &s2.header = 0x" + Long.toHexString(s2.header().rawValue()));
    System.out.println("s1.f1 = " + s1.f1() + "  s2.f2 = " + s2.f1());
    System.out.println("&s1.f1 = 0x" + Long.toHexString(s1.addressOff1().rawValue()));
    System.out.println("*&s1.f1 = " + s1.addressOff1().read());
    System.out.println("offset_of(s1.f1) = " + s1.offsetOff1());
    System.out.println("s1.header.type = " + s1.type() + "  ((Header) s2).type = " + s2.header().type());
    System.out.println("*** In Java, demonstrating @CFieldOffset");
    System.out.println("offset_of(s1.header) = " + Substruct1.offsetOfHeader());
    System.out.println("offset_of(s2.header) = " + s2.offsetOfHeader());
    System.out.println("offset_of(s2.f1) = " + s2.offsetOff1().rawValue());
    /*
         * Accessing elements of an array of struct. Say that s1 is the first element of subdata_t
         * s[10].
         */
    // ps1 = &s[0]
    Substruct1 ps1 = s1.addressOf(0);
    // ps2 = &s[1]
    Substruct1 ps2 = s1.addressOf(1);
    long s = ps2.rawValue() - ps1.rawValue();
    System.out.print("sizeof(s1) =" + SizeOf.get(Substruct1.class));
    System.out.print(" s1 = 0x" + Long.toHexString(s1.rawValue()));
    System.out.print("  ps1 = 0x" + Long.toHexString(ps1.rawValue()));
    System.out.println("  ps2 = 0x" + Long.toHexString(ps2.rawValue()));
    System.out.println(" ps2 - ps1 " + (s == SizeOf.get(Substruct1.class) ? "=" : "!=") + " sizeof(substruct1)");
}
Also used : CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 3 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class PolyglotNativeAPI method polyglot_get_callback_info.

@CEntryPoint(name = "polyglot_get_callback_info")
public static PolyglotStatus polyglot_get_callback_info(IsolateThread isolate_thread, PolyglotCallbackInfo callback_info, SizeTPointer argc, PolyglotValuePointerPointer argv, WordPointer data) {
    return withHandledErrors(() -> {
        PolyglotCallbackInfoInternal callbackInfo = fetchHandle(callback_info);
        UnsignedWord numberOfArguments = WordFactory.unsigned(callbackInfo.arguments.length);
        UnsignedWord bufferSize = argc.read();
        UnsignedWord size = bufferSize.belowThan(numberOfArguments) ? bufferSize : numberOfArguments;
        argc.write(size);
        for (UnsignedWord i = WordFactory.zero(); i.belowThan(size); i = i.add(1)) {
            int index = (int) i.rawValue();
            ObjectHandle argument = callbackInfo.arguments[index];
            argv.write(index, argument);
        }
        data.write(callbackInfo.data);
    });
}
Also used : ObjectHandle(org.graalvm.nativeimage.ObjectHandle) UnsignedWord(org.graalvm.word.UnsignedWord) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 4 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class PolyglotNativeAPI method polyglot_value_as_int64.

@CEntryPoint(name = "polyglot_value_as_int64")
public static PolyglotStatus polyglot_value_as_int64(IsolateThread isolate_thread, PolyglotValuePointer value, CLongPointer result) {
    return withHandledErrors(() -> {
        Value valueObject = fetchHandle(value);
        result.write(valueObject.asLong());
    });
}
Also used : Value(org.graalvm.polyglot.Value) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Example 5 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class PolyglotNativeAPI method polyglot_value_as_float.

@CEntryPoint(name = "polyglot_value_as_float")
public static PolyglotStatus polyglot_value_as_float(IsolateThread isolate_thread, PolyglotValuePointer value, CFloatPointer result) {
    return withHandledErrors(() -> {
        Value dataObject = fetchHandle(value);
        result.write(dataObject.asFloat());
    });
}
Also used : Value(org.graalvm.polyglot.Value) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint)

Aggregations

CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)81 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)26 Value (org.graalvm.polyglot.Value)23 CEntryPointContext (org.graalvm.nativeimage.c.function.CEntryPointContext)19 Context (org.graalvm.polyglot.Context)19 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)7 ObjectHandle (org.graalvm.nativeimage.ObjectHandle)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)4 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)4 JNIObjectHandle (com.oracle.svm.jni.nativeapi.JNIObjectHandle)3 PinnedObject (org.graalvm.nativeimage.PinnedObject)3 Log (com.oracle.svm.core.log.Log)2 JNIAccessibleMethodDescriptor (com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor)2 JNINativeLinkage (com.oracle.svm.jni.access.JNINativeLinkage)2 JNIMethodId (com.oracle.svm.jni.nativeapi.JNIMethodId)2 JNINativeMethod (com.oracle.svm.jni.nativeapi.JNINativeMethod)2 Executable (java.lang.reflect.Executable)2 Method (java.lang.reflect.Method)2 ByteBuffer (java.nio.ByteBuffer)2