private static jthread alloc_thread(JNIEnvHandle jniEnv)
        {
            jniNativeInterface nativeInterface = (jniNativeInterface)Marshal.PtrToStructure(Marshal.ReadIntPtr(jniEnv.Handle), typeof(jniNativeInterface));

            jclass @class = nativeInterface.FindClass(jniEnv, "java/lang/Thread");

            if (@class == jclass.Null)
            {
                throw new Exception("ERROR: JNI: Cannot find %s with FindClass.");
            }

            nativeInterface.ExceptionClear(jniEnv);

            jmethodID method = nativeInterface.GetMethodID(jniEnv, @class, "<init>", "()V");

            if (method == jmethodID.Null)
            {
                throw new Exception("Cannot find Thread constructor method.");
            }

            nativeInterface.ExceptionClear(jniEnv);
            jthread result = (jthread)nativeInterface.NewObject(jniEnv, @class, method);

            if (result == jthread.Null)
            {
                throw new Exception("Cannot create new Thread object");
            }

            nativeInterface.ExceptionClear(jniEnv);
            return(result);
        }
        internal JvmNativeEnvironment(JvmEnvironment environment, JNIEnvHandle nativeEnvironmentHandle, jniNativeInterface nativeInterface)
        {
            Contract.Requires <ArgumentNullException>(environment != null, "environment");
            Contract.Requires <ArgumentException>(nativeEnvironmentHandle != JNIEnvHandle.Null);

            _environment             = environment;
            _nativeEnvironmentHandle = nativeEnvironmentHandle;
            _nativeInterface         = nativeInterface;
        }
Beispiel #3
0
        internal JvmNativeEnvironment GetNativeFunctionTable(JNIEnvHandle nativeEnvironmentHandle)
        {
            IntPtr functionTable;

            ThrowOnFailure(_rawInterface.GetJNIFunctionTable(_env, out functionTable));
            try
            {
                jniNativeInterface nativeInterface = (jniNativeInterface)Marshal.PtrToStructure(functionTable, typeof(jniNativeInterface));
                return(new JvmNativeEnvironment(this, nativeEnvironmentHandle, nativeInterface));
            }
            finally
            {
                if (functionTable != IntPtr.Zero)
                {
                    Deallocate(functionTable);
                }
            }
        }
Beispiel #4
0
 public JniEnvironment(JNIEnvHandle handle)
 {
     _handle = handle;
     _rawInterface = (jniNativeInterface)Marshal.PtrToStructure(Marshal.ReadIntPtr(handle.Handle), typeof(jniNativeInterface));
 }