public static ShadowIAsyncStateMachine CLRInvoke( ShadowIAsyncStateMachine that ) { var xAsyncStateMachineTypeName = that.TypeName; Console.WriteLine(typeof(object) + " CLRInvoke " //+ typeof(SharedProgram) + new { Thread.CurrentThread.ManagedThreadId, that.TypeName, that.state }); // do we have the type mentioned loaded? //var NewStateMachine = Activator.CreateInstance(AsyncStateMachineType); //var NewStateMachineI = NewStateMachine as IAsyncStateMachine; //// this will take step into next await. ////NewStateMachineI.MoveNext(); //java.lang.Object Program prep for JVMCLRSwitchToCLRContextAsync.SharedProgram{ ManagedThreadId = 1 } //java.lang.Object enter JVMCLRSwitchToCLRContextAsync.SharedProgram{ ManagedThreadId = 1 } //java.lang.Object enter HopToCLR { ManagedThreadId = 1 } //{ continuation = ScriptCoreLib.Shared.BCLImplementation.System.__Action@123ec81 } //{ Method = void _AwaitUnsafeOnCompleted_b__1() } //{ Target = ScriptCoreLib.Shared.BCLImplementation.System.Runtime.CompilerServices.__AsyncTaskMethodBuilder___c__DisplayClass2_2@f87f48 } //{ SourceField = ScriptCoreLib.Shared.BCLImplementation.System.Runtime.CompilerServices.__IAsyncStateMachine zstateMachine, value = JVMCLRSwitchToCLRContextAsync.SharedProgram__Invoke_d__0@1405ef7 } //{ AsyncStateMachineSourceField = java.lang.String e, value = hi } //{ AsyncStateMachineSourceField = ScriptCoreLib.Shared.BCLImplementation.System.Runtime.CompilerServices.__AsyncTaskMethodBuilder __t__builder, value = ScriptCoreLib.Shared.BCLImplementation.System.Runtime.CompilerServices.__AsyncTaskMethodBuilder@1bba400 } //{ AsyncStateMachineSourceField = int __1__state, value = 0 } //{ AsyncStateMachineSourceField = JVMCLRSwitchToCLRContextAsync.HopToCLR __u___awaiter1, value = JVMCLRSwitchToCLRContextAsync.HopToCLR@19d3b25 } //{ AsyncStateMachineSourceField = java.lang.Object __t__stack, value = } //{ AsyncStateMachineSourceField = JVMCLRSwitchToCLRContextAsync.HopToThreadPoolAwaitable __u___awaiter2, value = } //{ SourceField = ScriptCoreLib.Shared.BCLImplementation.System.__Action yield, value = ScriptCoreLib.Shared.BCLImplementation.System.__Action@14989ff } //System.Object CLRInvoke { ManagedThreadId = 3, AsyncStateMachineTypeName = JVMCLRSwitchToCLRContextAsync.SharedProgram__Invoke_d__0 } //{ SourceField = System.Runtime.CompilerServices.IAsyncStateMachine m_stateMachine, value = JVMCLRSwitchToCLRContextAsync.SharedProgram+<Invoke>d__0 } // should java keep the actual type name as an attribute, like we have displayName Console.WriteLine("looking for the type..."); var xAsyncStateMachineType = typeof(CLRProgram).Assembly.GetTypes().FirstOrDefault( x => { //Console.WriteLine(new { x.FullName }); return x.FullName.Replace("+", "_").Replace("<", "_").Replace(">", "_") == xAsyncStateMachineTypeName.Replace("+", "_").Replace("<", "_").Replace(">", "_"); } ); //looking for the type... //{ FullName = JVMCLRSwitchToCLRContextAsync.Program } //{ FullName = <module>.SHA12fc19b38aba0098236ba7fd654b62facbfa4969b@1331799119 } //{ FullName = ScriptCoreLib.Desktop.JVM.JVMLauncher } //{ FullName = <module>.SHA1e4eb4631b3cf3610d48914d2f4deba4581c74282@275784628$00000006 } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = ScriptCoreLib.Desktop.JVM.__JVMLauncherInvoke } //{ FullName = ScriptCoreLib.Desktop.JVM.__InternalGetEntryPoint } //{ FullName = ScriptCoreLib.Desktop.JVM.__InternalGetEntryPoint+ } //{ FullName = . } //{ FullName = . } //{ FullName = .? } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = .? } //{ FullName = . } //{ FullName = . } //{ FullName = JVMCLRSwitchToCLRContextAsync__i.<02000018>\\\\\\\+export } //{ FullName = <module>.SHA14908e43b60b15906983f15d5126d55d794b08a03@516876350$0000001e } //{ FullName = JVMCLRSwitchToCLRContextAsync.<02000006>\\\\\\\\\\\\\\\+<interfaceexport> } //{ FullName = JVMCLRSwitchToCLRContextAsync.CLRProgram } //{ FullName = JVMCLRSwitchToCLRContextAsync.CLRProgram+<>c__DisplayClass1 } //{ FullName = <>f__AnonymousType$34$$30$$29$$28$7`1 } //{ FullName = ScriptCoreLib.Desktop.AppDomainAssemblyResolve } //{ FullName = <module>.SHA1ece49800bcc87751341b0db5b5d43bab4e1973d0@1209331862$00000025 } //{ FullName = ScriptCoreLib.Library.StringConversions } //{ FullName = <module>.SHA17c927d0ef51414d5913d986a2a0ad52032747944@1023654678$00000027 } //{ FullName = ScriptCoreLib.Interop.IntPtrInfo } //{ FullName = <module>.SHA19ab5a45e1768fb14172603268fe7f44ab10839ae@1329949876$0000002a$0000002e$00000029 } //{ FullName = <>f__AnonymousType$42$$53$$67$$65$6`2 } //{ FullName = <>f__AnonymousType$45$$65$$70$$68$8`2 } //{ FullName = <module>.SHA111aec3ca07ebcd71f8efa6a7eb37c94e05d294eb@2139898218$00000047$00000030 } //{ FullName = <module>.SHA1d04c4f386a94a00ca9ac06112eefc7d4456dc8c4@30829592 } //{ FullName = <ExportDirectoryBridge> } Console.WriteLine(typeof(object) + " CLRInvoke " + new { Thread.CurrentThread.ManagedThreadId, xAsyncStateMachineType }); // how can we send the type ref over the wire? encypt it? var NewStateMachine = Activator.CreateInstance(xAsyncStateMachineType); var NewStateMachineI = NewStateMachine as IAsyncStateMachine; #region 1__state xAsyncStateMachineType.GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).WithEach( AsyncStateMachineSourceField => { if (AsyncStateMachineSourceField.Name.EndsWith("1__state")) { AsyncStateMachineSourceField.SetValue( NewStateMachineI, that.state ); } } ); #endregion var ShadowIAsyncStateMachine = new ShadowIAsyncStateMachine(); var reset = new AutoResetEvent(false); HopToJVM.VirtualOnCompleted = (Action continuation) => { Console.WriteLine("time to jump back? yes"); Console.WriteLine(new { continuation }); Console.WriteLine(new { continuation.Method }); Console.WriteLine(new { continuation.Target }); // inspect target. can we reactivate it? //0001 0200000e JVMCLRSwitchToCLRContextAsync__i__d.jvm::JVMCLRSwitchToCLRContextAsync.SharedProgram+<Invoke>d__0 var f = continuation.Target.GetType().GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ); var AsyncStateMachineSource = default(IAsyncStateMachine); var AsyncStateMachineType = default(Type); var AsyncStateMachineFields = default(FieldInfo[]); // { AsyncStateMachineSourceField = Int32 <>1__state, value = 1 } f.WithEach( SourceField => { var SourceField_value = SourceField.GetValue(continuation.Target); Console.WriteLine(new { SourceField, value = SourceField_value }); var m_stateMachine = SourceField_value as IAsyncStateMachine; if (m_stateMachine != null) { AsyncStateMachineSource = m_stateMachine; AsyncStateMachineType = m_stateMachine.GetType(); AsyncStateMachineFields = AsyncStateMachineType.GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ); AsyncStateMachineFields.WithEach( AsyncStateMachineSourceField => { var value = AsyncStateMachineSourceField.GetValue(m_stateMachine); if (AsyncStateMachineSourceField.Name.EndsWith("1__state")) { ShadowIAsyncStateMachine.state = (int)value; } Console.WriteLine(new { AsyncStateMachineSourceField, value }); } ); } } ); reset.Set(); }; new Thread( delegate() { // this will take step into next await. NewStateMachineI.MoveNext(); } ).Start(); reset.WaitOne(); Console.WriteLine("time to jump back? " + new { ShadowIAsyncStateMachine.state }); return ShadowIAsyncStateMachine; }
public static ShadowIAsyncStateMachine CLRInvoke( ShadowIAsyncStateMachine that ) { var xAsyncStateMachineTypeName = that.TypeName; Console.WriteLine(typeof(object) + " CLRInvoke " //+ typeof(SharedProgram) + new { Thread.CurrentThread.ManagedThreadId, that.TypeName, that.state }); // do we have the type mentioned loaded? //var NewStateMachine = Activator.CreateInstance(AsyncStateMachineType); //var NewStateMachineI = NewStateMachine as IAsyncStateMachine; //// this will take step into next await. ////NewStateMachineI.MoveNext(); //java.lang.Object Program prep for JVMCLRSwitchToCLRContextAsync.SharedProgram{ ManagedThreadId = 1 } //java.lang.Object enter JVMCLRSwitchToCLRContextAsync.SharedProgram{ ManagedThreadId = 1 } //java.lang.Object enter HopToCLR { ManagedThreadId = 1 } //{ continuation = ScriptCoreLib.Shared.BCLImplementation.System.__Action@123ec81 } //{ Method = void _AwaitUnsafeOnCompleted_b__1() } //{ Target = ScriptCoreLib.Shared.BCLImplementation.System.Runtime.CompilerServices.__AsyncTaskMethodBuilder___c__DisplayClass2_2@f87f48 } //{ SourceField = ScriptCoreLib.Shared.BCLImplementation.System.Runtime.CompilerServices.__IAsyncStateMachine zstateMachine, value = JVMCLRSwitchToCLRContextAsync.SharedProgram__Invoke_d__0@1405ef7 } //{ AsyncStateMachineSourceField = java.lang.String e, value = hi } //{ AsyncStateMachineSourceField = ScriptCoreLib.Shared.BCLImplementation.System.Runtime.CompilerServices.__AsyncTaskMethodBuilder __t__builder, value = ScriptCoreLib.Shared.BCLImplementation.System.Runtime.CompilerServices.__AsyncTaskMethodBuilder@1bba400 } //{ AsyncStateMachineSourceField = int __1__state, value = 0 } //{ AsyncStateMachineSourceField = JVMCLRSwitchToCLRContextAsync.HopToCLR __u___awaiter1, value = JVMCLRSwitchToCLRContextAsync.HopToCLR@19d3b25 } //{ AsyncStateMachineSourceField = java.lang.Object __t__stack, value = } //{ AsyncStateMachineSourceField = JVMCLRSwitchToCLRContextAsync.HopToThreadPoolAwaitable __u___awaiter2, value = } //{ SourceField = ScriptCoreLib.Shared.BCLImplementation.System.__Action yield, value = ScriptCoreLib.Shared.BCLImplementation.System.__Action@14989ff } //System.Object CLRInvoke { ManagedThreadId = 3, AsyncStateMachineTypeName = JVMCLRSwitchToCLRContextAsync.SharedProgram__Invoke_d__0 } //{ SourceField = System.Runtime.CompilerServices.IAsyncStateMachine m_stateMachine, value = JVMCLRSwitchToCLRContextAsync.SharedProgram+<Invoke>d__0 } // should java keep the actual type name as an attribute, like we have displayName Console.WriteLine("looking for the type..."); var xAsyncStateMachineType = typeof(CLRProgram).Assembly.GetTypes().FirstOrDefault( x => { //Console.WriteLine(new { x.FullName }); return(x.FullName.Replace("+", "_").Replace("<", "_").Replace(">", "_") == xAsyncStateMachineTypeName.Replace("+", "_").Replace("<", "_").Replace(">", "_")); } ); //looking for the type... //{ FullName = JVMCLRSwitchToCLRContextAsync.Program } //{ FullName = <module>.SHA12fc19b38aba0098236ba7fd654b62facbfa4969b@1331799119 } //{ FullName = ScriptCoreLib.Desktop.JVM.JVMLauncher } //{ FullName = <module>.SHA1e4eb4631b3cf3610d48914d2f4deba4581c74282@275784628$00000006 } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = ScriptCoreLib.Desktop.JVM.__JVMLauncherInvoke } //{ FullName = ScriptCoreLib.Desktop.JVM.__InternalGetEntryPoint } //{ FullName = ScriptCoreLib.Desktop.JVM.__InternalGetEntryPoint+ } //{ FullName = . } //{ FullName = . } //{ FullName = .? } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = . } //{ FullName = .? } //{ FullName = . } //{ FullName = . } //{ FullName = JVMCLRSwitchToCLRContextAsync__i.<02000018>\\\\\\\+export } //{ FullName = <module>.SHA14908e43b60b15906983f15d5126d55d794b08a03@516876350$0000001e } //{ FullName = JVMCLRSwitchToCLRContextAsync.<02000006>\\\\\\\\\\\\\\\+<interfaceexport> } //{ FullName = JVMCLRSwitchToCLRContextAsync.CLRProgram } //{ FullName = JVMCLRSwitchToCLRContextAsync.CLRProgram+<>c__DisplayClass1 } //{ FullName = <>f__AnonymousType$34$$30$$29$$28$7`1 } //{ FullName = ScriptCoreLib.Desktop.AppDomainAssemblyResolve } //{ FullName = <module>.SHA1ece49800bcc87751341b0db5b5d43bab4e1973d0@1209331862$00000025 } //{ FullName = ScriptCoreLib.Library.StringConversions } //{ FullName = <module>.SHA17c927d0ef51414d5913d986a2a0ad52032747944@1023654678$00000027 } //{ FullName = ScriptCoreLib.Interop.IntPtrInfo } //{ FullName = <module>.SHA19ab5a45e1768fb14172603268fe7f44ab10839ae@1329949876$0000002a$0000002e$00000029 } //{ FullName = <>f__AnonymousType$42$$53$$67$$65$6`2 } //{ FullName = <>f__AnonymousType$45$$65$$70$$68$8`2 } //{ FullName = <module>.SHA111aec3ca07ebcd71f8efa6a7eb37c94e05d294eb@2139898218$00000047$00000030 } //{ FullName = <module>.SHA1d04c4f386a94a00ca9ac06112eefc7d4456dc8c4@30829592 } //{ FullName = <ExportDirectoryBridge> } Console.WriteLine(typeof(object) + " CLRInvoke " + new { Thread.CurrentThread.ManagedThreadId, xAsyncStateMachineType }); // how can we send the type ref over the wire? encypt it? var NewStateMachine = Activator.CreateInstance(xAsyncStateMachineType); var NewStateMachineI = NewStateMachine as IAsyncStateMachine; #region 1__state xAsyncStateMachineType.GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).WithEach( AsyncStateMachineSourceField => { if (AsyncStateMachineSourceField.Name.EndsWith("1__state")) { AsyncStateMachineSourceField.SetValue( NewStateMachineI, that.state ); } } ); #endregion var ShadowIAsyncStateMachine = new ShadowIAsyncStateMachine(); var reset = new AutoResetEvent(false); HopToJVM.VirtualOnCompleted = (Action continuation) => { Console.WriteLine("time to jump back? yes"); Console.WriteLine(new { continuation }); Console.WriteLine(new { continuation.Method }); Console.WriteLine(new { continuation.Target }); // inspect target. can we reactivate it? //0001 0200000e JVMCLRSwitchToCLRContextAsync__i__d.jvm::JVMCLRSwitchToCLRContextAsync.SharedProgram+<Invoke>d__0 var f = continuation.Target.GetType().GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ); var AsyncStateMachineSource = default(IAsyncStateMachine); var AsyncStateMachineType = default(Type); var AsyncStateMachineFields = default(FieldInfo[]); // { AsyncStateMachineSourceField = Int32 <>1__state, value = 1 } f.WithEach( SourceField => { var SourceField_value = SourceField.GetValue(continuation.Target); Console.WriteLine(new { SourceField, value = SourceField_value }); var m_stateMachine = SourceField_value as IAsyncStateMachine; if (m_stateMachine != null) { AsyncStateMachineSource = m_stateMachine; AsyncStateMachineType = m_stateMachine.GetType(); AsyncStateMachineFields = AsyncStateMachineType.GetFields( System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ); AsyncStateMachineFields.WithEach( AsyncStateMachineSourceField => { var value = AsyncStateMachineSourceField.GetValue(m_stateMachine); if (AsyncStateMachineSourceField.Name.EndsWith("1__state")) { ShadowIAsyncStateMachine.state = (int)value; } Console.WriteLine(new { AsyncStateMachineSourceField, value }); } ); } } ); reset.Set(); }; new Thread( delegate() { // this will take step into next await. NewStateMachineI.MoveNext(); } ).Start(); reset.WaitOne(); Console.WriteLine("time to jump back? " + new { ShadowIAsyncStateMachine.state }); return(ShadowIAsyncStateMachine); }
public static ShadowIAsyncStateMachine CLRInvoke(ShadowIAsyncStateMachine e) { // 23e8:02:01 RewriteToAssembly error: System.IO.FileLoadException: Could not load file or assembly 'JVMCLRSwitchToCLRContextAsync.dll' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A) return CLRProgram.CLRInvoke(e); }
public static ShadowIAsyncStateMachine CLRInvoke(ShadowIAsyncStateMachine e) { // 23e8:02:01 RewriteToAssembly error: System.IO.FileLoadException: Could not load file or assembly 'JVMCLRSwitchToCLRContextAsync.dll' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A) return(CLRProgram.CLRInvoke(e)); }