Ejemplo n.º 1
0
 private void ReleaseCore(bool appDomainUnloading)
 {
     lock (mLockingObject)
     {
         if (Instance == null)
         {
             return;
         }
         GC.WaitForPendingFinalizers();
         if (appDomainUnloading)
         {
             AppDomain.CurrentDomain.ProcessExit -= new EventHandler(CurrentDomain_ProcessExit);
             AppDomain.CurrentDomain.DomainUnload -= new EventHandler(CurrentDomain_DomainUnload);
         }
         if (appDomainUnloading && mPinnedDelegates != null)
         {
             foreach (DelegatePin pin in mPinnedDelegates.Values)
             {
                 ((IDisposable)pin).Dispose();
             }
             mPinnedDelegates.Clear();
             mPinnedDelegates = null;
         }
         mNativeMethodRegistrar = null;
         try
         {
             if (appDomainUnloading)
             {
                 DetachCurrentThread();
             }
             if (appDomainUnloading && !AllowReuseOfExistingVM && this.mJavaVM != IntPtr.Zero)
             {
                 //DestroyJavaVM();
             }
         }
         catch (JniException)
         {
         }
         finally
         {
             mJavaVM = IntPtr.Zero;
         }
         JniEnvironment.Release();
         mInstance = null;
         PlatformFactory.Platform.Release();
     }
 }
Ejemplo n.º 2
0
        private void InitializeCore(JavaVMConfiguration configuration, IJavaVMCallbackHandler hookHandler)
        {
            try
            {
                Log("32/64-bit: " + (IntPtr.Size * 8));

                AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
                AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_DomainUnload);

                mIJavaVMHookHandler = hookHandler;

                mJvmConfiguration = InitializeConfiguration(configuration);
                PlatformFactory.Create(mJvmConfiguration);
                mJvmConfiguration.CanonicalizePaths(PlatformFactory.Platform);

                mLoader = new JavaVMLoader(this.JvmConfiguration);

                InitializeHooks();

                IntPtr loadedVM = mLoader.GetFirstCreatedVM();
                IntPtr environmentHandle = IntPtr.Zero;
                if (loadedVM != IntPtr.Zero)
                {
                    if (!AllowReuseOfExistingVM)
                    {
                        throw new JniException("VM already exists.");
                    }
                    if (IsLoggingEnabled)
                    {
                        Log("Using existing VM.");
                    }
                    mJavaVM = loadedVM;
                }
                else
                {
                    mJavaVM = mLoader.Load(out environmentHandle);
                }
                mInvokeInterface = new JniInvokeInterface(this.mJavaVM, this.JvmConfiguration.Version);

                if (loadedVM != IntPtr.Zero)
                {
                    environmentHandle = JniEnvironmentCache.GetEnvironmentHandle();
                }

                mJniEnvironmentCache = new JniEnvironmentCache(environmentHandle);
                JniEnvironment environment = FindEnvironment();

                mNativeMethodRegistrar = new JavaNativeMethodRegistrar(mJvmConfiguration, environment);
                JavaStdStreamRedirector.Init(environment);

                if (IsLoggingEnabled)
                {
                    JavaSystemPropertiesHelper.LogBannerProperties(environment);
                }
            }
            catch (Exception ex)
            {
                throw new JniException(JniResourceManager.Instance.GetString("jvmCoreFailedToCreate"), ex);
            }
        }