From 031e7ef56ed40e369c855acdcaefa0ec36fc6caa Mon Sep 17 00:00:00 2001 From: Siuming <2457944792@qq.com> Date: Sat, 6 Nov 2021 16:24:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix=20vt=20to=20object=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E8=B5=8B=E5=80=BC=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ILRuntime/Runtime/Intepreter/ILIntepreter.cs | 100 +++++-------------- TestCases/TestValueTypeBinding.cs | 24 +++++ 2 files changed, 48 insertions(+), 76 deletions(-) diff --git a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs index 8236b494..ea6a4c64 100644 --- a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs +++ b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs @@ -265,8 +265,6 @@ public object Run(ILMethod method, object instance, object[] p) bool returned = false; while (!returned) { - try - { #if DEBUG && !DISABLE_ILRUNTIME_DEBUG if (ShouldBreak) Break(); @@ -2231,14 +2229,14 @@ public object Run(ILMethod method, object instance, object[] p) if (obj != null) { if (obj is ILTypeInstance) - { - ILTypeInstance instance = obj as ILTypeInstance; - instance.PushToStack((int)ip->TokenLong, ret, this, mStack); - } - else - { - //var t = obj.GetType(); - type = AppDomain.GetType((int)(ip->TokenLong >> 32)); + { + ILTypeInstance instance = obj as ILTypeInstance; + instance.PushToStack((int)ip->TokenLong, ret, this, mStack); + } + else + { + //var t = obj.GetType(); + type = AppDomain.GetType((int)(ip->TokenLong >> 32)); if (type != null) { var token = (int)ip->TokenLong; @@ -4437,72 +4435,7 @@ public object Run(ILMethod method, object instance, object[] p) throw new NotSupportedException("Not supported opcode " + code); } ip++; - } - catch (Exception ex) - { - if (ehs != null) - { - int addr = (int)(ip - ptr); - var eh = GetCorrespondingExceptionHandler(ehs, ex, addr, ExceptionHandlerType.Catch, true); - if (eh == null) - { - eh = GetCorrespondingExceptionHandler(ehs, ex, addr, ExceptionHandlerType.Catch, false); - } - if (eh != null) - { - if (ex is ILRuntimeException) - { - ILRuntimeException ire = (ILRuntimeException)ex; - var inner = ire.InnerException; - inner.Data["ThisInfo"] = ire.ThisInfo; - inner.Data["StackTrace"] = ire.StackTrace; - inner.Data["LocalInfo"] = ire.LocalInfo; - ex = inner; - } - else - { - var debugger = AppDomain.DebugService; - if (method.HasThis) - ex.Data["ThisInfo"] = debugger.GetThisInfo(this); - else - ex.Data["ThisInfo"] = ""; - ex.Data["StackTrace"] = debugger.GetStackTrace(this); - ex.Data["LocalInfo"] = debugger.GetLocalVariableInfo(this); - } - //Clear call stack - while (stack.Frames.Peek().BasePointer != frame.BasePointer) - { - var f = stack.Frames.Peek(); - esp = stack.PopFrame(ref f, esp); - if (f.Method.ReturnType != AppDomain.VoidType) - { - Free(esp - 1); - esp--; - } - } - lastCaughtEx = ex; - esp = PushObject(esp, mStack, ex); - unhandledException = false; - ip = ptr + eh.HandlerStart; - continue; - } - } - if (unhandledException) - { - throw ex; - } - - unhandledException = true; - returned = true; -#if DEBUG && !DISABLE_ILRUNTIME_DEBUG - if (!AppDomain.DebugService.Break(this, ex)) -#endif - { - var newEx = new ILRuntimeException(ex.Message, this, method, ex); - throw newEx; - } - } } } #if DEBUG && !NO_PROFILER @@ -4736,10 +4669,25 @@ void StLocSub(StackObject* esp, StackObject* v, int idx, IList mStack) if (v->ObjectType == ObjectTypes.ValueTypeObjectReference) { CopyStackValueType(esp, v, mStack); + FreeStackValueType(esp); + } + else if(v->ObjectType == ObjectTypes.Object) + { + //直接把地址给到新的变量,所以并不释放esp空间 + var dst = ILIntepreter.ResolveReference(esp); + if(dst != null) + { + var ct = domain.GetTypeByIndex(dst->Value) as CLRType; + var binder = ct.ValueTypeBinder; + v->ObjectType = ObjectTypes.ValueTypeObjectReference; + int addr = ((IntPtr)dst).ToInt32(); + v->Value = addr; + } + else + throw new NotImplementedException(); } else throw new NotImplementedException(); - FreeStackValueType(esp); break; default: *v = *esp; diff --git a/TestCases/TestValueTypeBinding.cs b/TestCases/TestValueTypeBinding.cs index 548f17fb..52efe223 100644 --- a/TestCases/TestValueTypeBinding.cs +++ b/TestCases/TestValueTypeBinding.cs @@ -477,5 +477,29 @@ public static void UnitTest_10047() if(Math.Abs(arr2[0].X - 1244)>0.001f) throw new Exception(); } + + public static void UnitTest_10048() + { + var pos = new TestVector3(0f, 0.8f, 0.5f); + var obj = pos as object; + UnitTest_10048Sub(obj); + } + + static void UnitTest_10048Sub(object param = null) + { + var context = new UnitTest_10048Context( param); + object data = context.data; + Console.WriteLine("data:" + data.ToString()); + } + + public class UnitTest_10048Context + { + public object data; + + public UnitTest_10048Context(object data = null) + { + this.data = data; + } + } } } \ No newline at end of file From 47c6ab0f051e8f3aa38e5b87195f753a565c035c Mon Sep 17 00:00:00 2001 From: Siuming <2457944792@qq.com> Date: Sat, 6 Nov 2021 21:11:50 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"fix=20vt=20to=20object=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=B5=8B=E5=80=BC=E7=9A=84=E9=94=99=E8=AF=AF"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 031e7ef56ed40e369c855acdcaefa0ec36fc6caa. --- ILRuntime/Runtime/Intepreter/ILIntepreter.cs | 100 ++++++++++++++----- TestCases/TestValueTypeBinding.cs | 24 ----- 2 files changed, 76 insertions(+), 48 deletions(-) diff --git a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs index ea6a4c64..8236b494 100644 --- a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs +++ b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs @@ -265,6 +265,8 @@ public object Run(ILMethod method, object instance, object[] p) bool returned = false; while (!returned) { + try + { #if DEBUG && !DISABLE_ILRUNTIME_DEBUG if (ShouldBreak) Break(); @@ -2229,14 +2231,14 @@ public object Run(ILMethod method, object instance, object[] p) if (obj != null) { if (obj is ILTypeInstance) - { - ILTypeInstance instance = obj as ILTypeInstance; - instance.PushToStack((int)ip->TokenLong, ret, this, mStack); - } - else - { - //var t = obj.GetType(); - type = AppDomain.GetType((int)(ip->TokenLong >> 32)); + { + ILTypeInstance instance = obj as ILTypeInstance; + instance.PushToStack((int)ip->TokenLong, ret, this, mStack); + } + else + { + //var t = obj.GetType(); + type = AppDomain.GetType((int)(ip->TokenLong >> 32)); if (type != null) { var token = (int)ip->TokenLong; @@ -4435,7 +4437,72 @@ public object Run(ILMethod method, object instance, object[] p) throw new NotSupportedException("Not supported opcode " + code); } ip++; + } + catch (Exception ex) + { + if (ehs != null) + { + int addr = (int)(ip - ptr); + var eh = GetCorrespondingExceptionHandler(ehs, ex, addr, ExceptionHandlerType.Catch, true); + if (eh == null) + { + eh = GetCorrespondingExceptionHandler(ehs, ex, addr, ExceptionHandlerType.Catch, false); + } + if (eh != null) + { + if (ex is ILRuntimeException) + { + ILRuntimeException ire = (ILRuntimeException)ex; + var inner = ire.InnerException; + inner.Data["ThisInfo"] = ire.ThisInfo; + inner.Data["StackTrace"] = ire.StackTrace; + inner.Data["LocalInfo"] = ire.LocalInfo; + ex = inner; + } + else + { + var debugger = AppDomain.DebugService; + if (method.HasThis) + ex.Data["ThisInfo"] = debugger.GetThisInfo(this); + else + ex.Data["ThisInfo"] = ""; + ex.Data["StackTrace"] = debugger.GetStackTrace(this); + ex.Data["LocalInfo"] = debugger.GetLocalVariableInfo(this); + } + //Clear call stack + while (stack.Frames.Peek().BasePointer != frame.BasePointer) + { + var f = stack.Frames.Peek(); + esp = stack.PopFrame(ref f, esp); + if (f.Method.ReturnType != AppDomain.VoidType) + { + Free(esp - 1); + esp--; + } + } + lastCaughtEx = ex; + esp = PushObject(esp, mStack, ex); + unhandledException = false; + ip = ptr + eh.HandlerStart; + continue; + } + } + if (unhandledException) + { + throw ex; + } + + unhandledException = true; + returned = true; +#if DEBUG && !DISABLE_ILRUNTIME_DEBUG + if (!AppDomain.DebugService.Break(this, ex)) +#endif + { + var newEx = new ILRuntimeException(ex.Message, this, method, ex); + throw newEx; + } + } } } #if DEBUG && !NO_PROFILER @@ -4669,25 +4736,10 @@ void StLocSub(StackObject* esp, StackObject* v, int idx, IList mStack) if (v->ObjectType == ObjectTypes.ValueTypeObjectReference) { CopyStackValueType(esp, v, mStack); - FreeStackValueType(esp); - } - else if(v->ObjectType == ObjectTypes.Object) - { - //直接把地址给到新的变量,所以并不释放esp空间 - var dst = ILIntepreter.ResolveReference(esp); - if(dst != null) - { - var ct = domain.GetTypeByIndex(dst->Value) as CLRType; - var binder = ct.ValueTypeBinder; - v->ObjectType = ObjectTypes.ValueTypeObjectReference; - int addr = ((IntPtr)dst).ToInt32(); - v->Value = addr; - } - else - throw new NotImplementedException(); } else throw new NotImplementedException(); + FreeStackValueType(esp); break; default: *v = *esp; diff --git a/TestCases/TestValueTypeBinding.cs b/TestCases/TestValueTypeBinding.cs index 52efe223..548f17fb 100644 --- a/TestCases/TestValueTypeBinding.cs +++ b/TestCases/TestValueTypeBinding.cs @@ -477,29 +477,5 @@ public static void UnitTest_10047() if(Math.Abs(arr2[0].X - 1244)>0.001f) throw new Exception(); } - - public static void UnitTest_10048() - { - var pos = new TestVector3(0f, 0.8f, 0.5f); - var obj = pos as object; - UnitTest_10048Sub(obj); - } - - static void UnitTest_10048Sub(object param = null) - { - var context = new UnitTest_10048Context( param); - object data = context.data; - Console.WriteLine("data:" + data.ToString()); - } - - public class UnitTest_10048Context - { - public object data; - - public UnitTest_10048Context(object data = null) - { - this.data = data; - } - } } } \ No newline at end of file From d71a150da7ac9ed50b73995023fb9f9a7620c4b7 Mon Sep 17 00:00:00 2001 From: Siuming <2457944792@qq.com> Date: Sat, 6 Nov 2021 21:13:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8DValueTypeObjectReference?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=80=BC=E8=B5=8B=E5=80=BC=E7=BB=99Object?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=80=BC=E6=97=B6=E6=8A=9B=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ILRuntime/Runtime/Intepreter/ILIntepreter.cs | 16 ++++++++++++- TestCases/TestValueTypeBinding.cs | 24 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs index 8236b494..a9edfc87 100644 --- a/ILRuntime/Runtime/Intepreter/ILIntepreter.cs +++ b/ILRuntime/Runtime/Intepreter/ILIntepreter.cs @@ -4736,10 +4736,24 @@ void StLocSub(StackObject* esp, StackObject* v, int idx, IList mStack) if (v->ObjectType == ObjectTypes.ValueTypeObjectReference) { CopyStackValueType(esp, v, mStack); + FreeStackValueType(esp); + } + else if(v->ObjectType == ObjectTypes.Object) + { + var dst = ILIntepreter.ResolveReference(esp); + if(dst != null) + { + var ct = domain.GetTypeByIndex(dst->Value) as CLRType; + var binder = ct.ValueTypeBinder; + v->ObjectType = ObjectTypes.ValueTypeObjectReference; + int addr = ((IntPtr)dst).ToInt32(); + v->Value = addr; + } + else + throw new NotImplementedException(); } else throw new NotImplementedException(); - FreeStackValueType(esp); break; default: *v = *esp; diff --git a/TestCases/TestValueTypeBinding.cs b/TestCases/TestValueTypeBinding.cs index 548f17fb..52efe223 100644 --- a/TestCases/TestValueTypeBinding.cs +++ b/TestCases/TestValueTypeBinding.cs @@ -477,5 +477,29 @@ public static void UnitTest_10047() if(Math.Abs(arr2[0].X - 1244)>0.001f) throw new Exception(); } + + public static void UnitTest_10048() + { + var pos = new TestVector3(0f, 0.8f, 0.5f); + var obj = pos as object; + UnitTest_10048Sub(obj); + } + + static void UnitTest_10048Sub(object param = null) + { + var context = new UnitTest_10048Context( param); + object data = context.data; + Console.WriteLine("data:" + data.ToString()); + } + + public class UnitTest_10048Context + { + public object data; + + public UnitTest_10048Context(object data = null) + { + this.data = data; + } + } } } \ No newline at end of file