public static void Construct() { try { ModuleN.InitN(); JNIEnv env = JNIEnv.ThreadEnv; JniGlobalHandle hmHandle = env.NewGlobalRef((JniHandle)domain.GetData("hostManager")); JniGlobalHandle peerHandle = env.NewGlobalRef((JniHandle)domain.GetData("peer")); JniGlobalHandle itemHandle = env.NewGlobalRef((JniHandle)domain.GetData("item")); hostManager = Bridge.CreateProxy <IHostManager>(hmHandle); robotPeer = Bridge.CreateProxy <IRobotPeer>(peerHandle); specification = Bridge.CreateProxy <IRobotItem>(itemHandle); statics = ((RobotStatics)domain.GetData("statics")); CreateProxy(); Assembly assembly = Assembly.LoadFrom(robotAssemblyShadowFileName); Reflection.CheckAssembly(assembly); string robotFullName = specification.getFullClassName(); robotType = assembly.GetType(robotFullName, false); robotProxy.setRobotType(robotType); } catch (Exception ex) { LoggerN.logError(ex); throw; } }
public HostingShell(IRobotItem itemSpecification, IHostManager hostManager, IRobotPeer peer, IRobotStatics jstatics, string dllFileName) { robotPeer = peer; Init(true); Open(dllFileName); JniGlobalHandle hmHandle = ((IJvmProxy)hostManager).JvmHandle; JniGlobalHandle peerhandle = ((IJvmProxy)peer).JvmHandle; JniGlobalHandle itemHandle = ((IJvmProxy)itemSpecification).JvmHandle; domain.SetData("hostManager", hmHandle.DangerousGetHandle()); domain.SetData("peer", peerhandle.DangerousGetHandle()); domain.SetData("item", itemHandle.DangerousGetHandle()); var statics = serializer.ConvertJ2C <RobotStatics>(RbSerializerN.RobotStatics_TYPE, (Object)jstatics); domain.SetData("statics", statics); domain.SetData("robotName", statics.getName()); try { domain.DoCallBack(HostingSeed.Construct); } catch (Exception) { robotPeer.punishBadBehavior(BadBehavior.SECURITY_VIOLATION); } hmHandle.HoldThisHandle(); peerhandle.HoldThisHandle(); itemHandle.HoldThisHandle(); }
internal JniLocalHandle NewObjectArrayPtr(int len, JniGlobalHandle clazz, IJvmProxy init) { JniLocalHandle res = newObjectArray(envPtr, len, clazz, init == null ? JniGlobalHandle.Zero : init.JvmHandle); ExceptionTest(); return(res); }
public void DeleteGlobalRef(JniGlobalHandle gref) { if (JniGlobalHandle.IsNull(gref)) { throw new ArgumentNullException("gref"); } deleteGlobalRef(envPtr, gref); //optimized away ExceptionTest(); }
public void TypeCbyCLRProxy() { JInterfacesHelper h = new JInterfacesHelper(); CWithJavaInterface cwc = h.getCWithJavaInterfaceC(new CWithJavaInterface(0)); Object val = Bridge.WrapCLR(cwc); JniGlobalHandle jniGlobalHandle = ((IClrProxy)val).JvmHandle; RegistryRecord record = Registry.GetRecord(JNIEnv.ThreadEnv, jniGlobalHandle, val.getClass()); Assert.IsNotNull(record); jniGlobalHandle.HoldThisHandle(); }
public void WasJvmCrash() { String o = new String(); JniGlobalHandle handle = ((IJvmProxy)o).JvmHandle; for (int i = 0; i < 100; i++) { crash(i, handle); } // this solved the problem //((IJvmProxy)o).HoldThisHandle(); }
public static TRes CreateProxy <TRes>(JniGlobalHandle jvmHandle) { Type reqType = typeof(TRes); if (!reqType.IsInterface && !typeof(IObject).IsAssignableFrom(reqType)) { throw new JNIException("Can't create proxy to CLR class"); } RegistryRecord record = Registry.GetCLRRecord(reqType); JNIEnv env = JNIEnv.ThreadEnv; Class clazz = env.GetObjectClass(jvmHandle); if (!record.JVMInterface.isAssignableFrom(clazz)) { throw new InvalidCastException("Can't cast JVM instance of " + clazz + " to " + record.JVMInterface + "\n (" + clazz.getClassLoader() + "->" + record.JVMInterface.getClassLoader() + ")"); } IJvmProxy res = record.CopyCLRProxy(env, jvmHandle); return((TRes)res); }
public static void crash(int i, JniGlobalHandle handle) { //Console.WriteLine("a" + i); var sharedBuffer = new byte[10 * 1024 * 100]; //Console.WriteLine("b"); DirectByteBuffer execJavaBuffer = new DirectByteBuffer(sharedBuffer); //Console.WriteLine("c"); try { String duplicate = Bridge.CreateProxy <String>(handle); string s = duplicate.toString(); } catch (System.Exception) { Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); throw; } //Console.WriteLine("d"); GC.Collect(3, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); }
void IJvmProxy.Copy(JNIEnv env, JniGlobalHandle obj) { jvmHandle = obj; }
void IJvmProxy.Init(JNIEnv env, JniLocalHandle obj) { jvmHandle = env.NewGlobalRef(obj); env.DeleteLocalRef(obj); }