public JavaVmWrapper(IntPtr javaVmPtr) { this.javaVmPtr = javaVmPtr; var vm = (JavaVm)Marshal.PtrToStructure(javaVmPtr, typeof(JavaVm)); functions = (JniInvokeInterface)Marshal.PtrToStructure(vm.Functions, typeof(JniInvokeInterface)); }
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); } }