public static string FindPath(JavaVMConfiguration configuration) { int strategyCount = configuration.DiscoveryStrategyCount; for (int i = 0; i < strategyCount; i++) { JavaVMDiscoveryStrategy strategy = configuration.GetDiscoveryStrategyAtIndex(i); JavaVMDiscoveryType discoveryType = strategy.DiscoveryType; string discoverySpec = strategy.Specification; string workingSpec = discoverySpec == null ? string.Empty : discoverySpec; ReadOnlyCollection<String> hints = strategy.Hints; workingSpec = workingSpec.Trim(); string outputPath = null; if (discoveryType == JavaVMDiscoveryType.Path) { outputPath = PlatformFactory.Platform.FindJvmLibraryWithPath(workingSpec); } else if (discoveryType == JavaVMDiscoveryType.Lookup) { outputPath = PlatformFactory.Platform.LookupJvmLibrary(workingSpec); } if (outputPath != null) { return outputPath; } } throw new JniException("Failed to find JVM Path."); }
public JavaVMLoader(JavaVMConfiguration configuration) { mJavaVMConfiguration = configuration; mJavaVMPath = JavaVMPathFinder.FindPath(configuration); mJavaVMModuleHandle = PlatformFactory.Platform.LoadDynamicLibrary(mJavaVMPath); if (JavaVM.IsLoggingEnabled) { JavaVM.Log("Loaded JVM DLL: " + mJavaVMPath); } }
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); } }
private static void StaticInitializeCore(JavaVMConfiguration configuration, IJavaVMCallbackHandler hookHandler) { if (Instance != null) { throw new JniException(JniResourceManager.Instance.GetString("jvmCoreInitOnlyOnce")); } mInstance = new JavaVM(); Instance.InitializeCore(configuration, hookHandler); }
private static JavaVMConfiguration InitializeConfiguration(JavaVMConfiguration configuration) { if (configuration == null) { configuration = JavaVMConfiguration.FromAppConfiguration(); if (configuration == null) { configuration = JavaVMConfiguration.CreateDefault(); // use all defaults } } return configuration; }
public static void Initialize(JavaVMConfiguration configuration) { StaticInitializeCore(configuration, null); }
public static void Initialize(JavaVMConfiguration configuration, IJavaVMCallbackHandler hookHandler) { StaticInitializeCore(configuration, hookHandler); }
internal JavaNativeMethodRegistrar(JavaVMConfiguration configuration, JniEnvironment environment) { LoadCounterpartAssemblies(configuration); RegisterCounterpart(environment, this.GetType()); }
private void LoadCounterpartAssemblies(JavaVMConfiguration configuration) { mCounterpartMap.Clear(); List<string> paths = configuration.CounterpartPaths; foreach (string path in paths) { string fullPath = path; if (!fullPath.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { fullPath += ".dll"; } Assembly asm = Assembly.LoadFile(Path.GetFullPath(fullPath)); Type[] types = asm.GetTypes(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; string peer = FindJavaPeerClassName(type); if (peer != null) { mCounterpartMap[peer] = type; } } } }
private static void ParsePlatform(XmlNode section, JavaVMConfiguration configuration) { JniPlatformId platformId = PlatformFactory.PlatformId; XmlNode platformNode = section.SelectSingleNode("platform[@id=\'" + platformId.ToString() + "\']"); configuration.CrtLib = GetAttribute(platformNode, "crtLib", configuration.CrtLib); XmlNodeList kids = platformNode.ChildNodes; foreach (XmlNode kid in kids) { if (kid.NodeType != XmlNodeType.Element) { continue; } if (kid.Name == "vmDiscovery") { JavaVMDiscoveryType discoveryType = (JavaVMDiscoveryType)Enum.Parse(typeof(JavaVMDiscoveryType), GetAttribute(kid, "type", JavaVMDiscoveryType.Path.ToString())); string discoverySpec = GetNodeValue(kid, string.Empty); JavaVMDiscoveryStrategy strategy = new JavaVMDiscoveryStrategy(discoveryType, discoverySpec, null); configuration.AddDiscoveryStrategy(strategy); } else { throw new JniException(JniResourceManager.Instance.GetString("jvmCfgInvalidNode") + kid.Name); } } }
private static void ParseCounterparts(XmlNode section, JavaVMConfiguration configuration) { XmlNodeList kids = section.SelectSingleNode("javaToNative").ChildNodes; foreach (XmlNode kid in kids) { if (kid.NodeType != XmlNodeType.Element) { continue; } if (kid.Name == "counterpartAssembly") { configuration.AddCounterpartPathPart(GetNodeValue(kid, string.Empty)); } else { throw new JniException(JniResourceManager.Instance.GetString("jvmCfgInvalidNode") + kid.Name); } } }
protected override void DeserializeSection(XmlReader reader) { try { XmlDocument doc = new XmlDocument(); doc.Load(reader); mCfg = CreateFromXml(doc.DocumentElement); } catch (Exception ex) { throw new JniException(JniResourceManager.Instance.GetString("jvmConfigParseError"), ex); } }