Skip to content

Commit

Permalink
Fixed #764
Browse files Browse the repository at this point in the history
  • Loading branch information
liiir1985 committed Oct 23, 2023
1 parent e8d6a82 commit a961c81
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
34 changes: 28 additions & 6 deletions ILRuntime/Runtime/Intepreter/RegisterVM/ILIntepreter.Register.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,7 @@ public unsafe partial class ILIntepreter
{
bool isILMethod = m is ILMethod;
bool useRegister = isILMethod && ((ILMethod)m).ShouldUseRegisterVM;
int objCnt = 0;
if (ip->Operand4 == 0)
{
intVal = m.HasThis ? m.ParameterCount + 1 : m.ParameterCount;
Expand All @@ -2821,29 +2822,35 @@ public unsafe partial class ILIntepreter
{
reg1 = (r + ip->Register2);
CopyToStack(esp, reg1, mStack);
if (useRegister && reg1->ObjectType < ObjectTypes.Object)
if (reg1->ObjectType < ObjectTypes.Object)
{
mStack.Add(null);
objCnt++;
if (useRegister)
mStack.Add(null);
}
esp++;
}
if (intVal > 1)
{
reg1 = (r + ip->Register3);
CopyToStack(esp, reg1, mStack);
if (useRegister && reg1->ObjectType < ObjectTypes.Object)
if (reg1->ObjectType < ObjectTypes.Object)
{
mStack.Add(null);
objCnt++;
if (useRegister)
mStack.Add(null);
}
esp++;
}
if (intVal > 2)
{
reg1 = (r + ip->Register4);
CopyToStack(esp, reg1, mStack);
if (useRegister && reg1->ObjectType < ObjectTypes.Object)
if (reg1->ObjectType < ObjectTypes.Object)
{
mStack.Add(null);
objCnt++;
if (useRegister)
mStack.Add(null);
}
esp++;
}
Expand Down Expand Up @@ -2885,6 +2892,7 @@ public unsafe partial class ILIntepreter
}
if (!processed)
{
bool shouldFix = false;
if (code == OpCodeREnum.Callvirt)
{
objRef = GetObjectAndResolveReference(esp - (ilm.ParameterCount + 1));
Expand All @@ -2895,6 +2903,7 @@ public unsafe partial class ILIntepreter
dst = *(StackObject**)&objRef->Value;
var ft = domain.GetTypeByIndex(dst->Value) as ILType;
ilm = ft.GetVirtualMethod(ilm) as ILMethod;
shouldFix = useRegister != ilm.ShouldUseRegisterVM;
useRegister = ilm.ShouldUseRegisterVM;
}
else
Expand All @@ -2903,9 +2912,22 @@ public unsafe partial class ILIntepreter
if (obj == null)
throw new NullReferenceException();
ilm = ((ILTypeInstance)obj).Type.GetVirtualMethod(ilm) as ILMethod;
shouldFix = useRegister != ilm.ShouldUseRegisterVM;
useRegister = ilm.ShouldUseRegisterVM;
}
}
if (shouldFix)
{
if (useRegister)
{
for (intVal = 0; intVal < objCnt; intVal++)
{
mStack.Add(null);
}
}
else
mStack.RemoveRange(mStack.Count - objCnt, objCnt);
}
if (useRegister)
esp = ExecuteR(ilm, esp, out unhandledException);
else
Expand Down
21 changes: 21 additions & 0 deletions TestCases/InheritanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ public static void InheritanceTest24()
float res = list.Update(0, 1);
if (res < 10)
throw new Exception();
res = list.Update2(0, 1);
if (res < 10)
throw new Exception();
}
class ListSub : AbstractBase
{
Expand All @@ -358,6 +361,16 @@ public override float Update(float a, float b)
}
return baseVal;
}

public override float Update2(float a, float b)
{
float baseVal = a;
foreach (var i in children)
{
baseVal += i.Update2(baseVal, b);
}
return baseVal;
}
}

class ListSub2 : AbstractBase
Expand All @@ -366,11 +379,19 @@ public override float Update(float a, float b)
{
return a + b;
}

[ILRuntimeJIT(ILRuntimeJITFlags.NoJIT)]
public override float Update2(float a, float b)
{
return a + b;
}
}
abstract class AbstractBase
{
[ILRuntimeJIT(ILRuntimeJITFlags.NoJIT)]
public abstract float Update(float a, float b);

public abstract float Update2(float a, float b);
}

class TestExplicitInterface : IDisposable
Expand Down

0 comments on commit a961c81

Please sign in to comment.