Search in sources :

Example 11 with PinnedObject

use of org.graalvm.nativeimage.PinnedObject in project graal by oracle.

the class JavaUtilZipSubstitutions method setDictionary.

// Inflater.c-Java_java_util_zip_Inflater_setDictionary(JNIEnv *env, jclass cls, jlong addr,
@Substitute
private static void setDictionary(long addr, byte[] b, int off, int len) {
    try (PinnedObject pinned = PinnedObject.create(b)) {
        CCharPointer bufPlusOff = pinned.addressOfArrayElement(off);
        int res = ZLib.inflateSetDictionary(WordFactory.pointer(addr), bufPlusOff, len);
        if (res == ZLib.Z_OK()) {
            return;
        } else if (res == ZLib.Z_STREAM_ERROR() || res == ZLib.Z_DATA_ERROR()) {
            throw new IllegalArgumentException();
        } else {
            throw new InternalError();
        }
    }
}
Also used : PinnedObject(org.graalvm.nativeimage.PinnedObject) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 12 with PinnedObject

use of org.graalvm.nativeimage.PinnedObject in project graal by oracle.

the class JavaUtilZipSubstitutions method deflateBytes.

// Deflater.c-Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
@SuppressWarnings("hiding")
@Substitute
private int deflateBytes(long addr, byte[] b, int off, int len, int flush) {
    z_stream strm = WordFactory.pointer(addr);
    try (PinnedObject pinned_in_buf = PinnedObject.create(this.buf);
        PinnedObject pinned_out_buf = PinnedObject.create(b)) {
        strm.set_next_in(pinned_in_buf.addressOfArrayElement(this.off));
        strm.set_next_out(pinned_out_buf.addressOfArrayElement(off));
        strm.set_avail_in(this.len);
        strm.set_avail_out(len);
        if (this.setParams) {
            int res = ZLib.deflateParams(strm, level, strategy);
            this.setParams = false;
            if (res == ZLib.Z_OK()) {
                return Util_java_util_zip_Deflater.update(this, len, strm);
            } else if (res == ZLib.Z_BUF_ERROR()) {
                return 0;
            } else {
                throw new InternalError();
            }
        } else {
            int res = ZLib.deflate(strm, this.finish ? ZLib.Z_FINISH() : flush);
            if (res == ZLib.Z_STREAM_END()) {
                this.finished = true;
                return Util_java_util_zip_Deflater.update(this, len, strm);
            } else if (res == ZLib.Z_OK()) {
                return Util_java_util_zip_Deflater.update(this, len, strm);
            } else if (res == ZLib.Z_BUF_ERROR()) {
                return 0;
            } else {
                throw new InternalError();
            }
        }
    }
}
Also used : ZLib.z_stream(com.oracle.svm.core.posix.headers.ZLib.z_stream) PinnedObject(org.graalvm.nativeimage.PinnedObject) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

PinnedObject (org.graalvm.nativeimage.PinnedObject)12 Substitute (com.oracle.svm.core.annotate.Substitute)7 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)7 ZLib.z_stream (com.oracle.svm.core.posix.headers.ZLib.z_stream)2 IOException (java.io.IOException)2 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)2 SignedWord (org.graalvm.word.SignedWord)2 NoAllocationVerifier (com.oracle.svm.core.heap.NoAllocationVerifier)1 NetinetIn (com.oracle.svm.core.posix.headers.NetinetIn)1 Pwd.passwd (com.oracle.svm.core.posix.headers.Pwd.passwd)1 Pwd.passwdPointer (com.oracle.svm.core.posix.headers.Pwd.passwdPointer)1 Socket (com.oracle.svm.core.posix.headers.Socket)1 NativeTruffleContext (com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext)1 LibFFI.ffi_cif (com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif)1 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 ServerSocket (java.net.ServerSocket)1 UnknownHostException (java.net.UnknownHostException)1 DataFormatException (java.util.zip.DataFormatException)1 Word (org.graalvm.compiler.word.Word)1 Platform (org.graalvm.nativeimage.Platform)1