Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with Ldind and with RefObj.Set, unrecycled VBox #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 57 additions & 43 deletions CLRSharp/CLRSharp/Execute/StackFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,19 @@ public void Init(CodeBody body)
}
public object Return()
{

if (_params != null)
{
foreach (var i in _params)
{
VBox box = i as VBox;
if (box != null)
ValueOnStack.UnUse(box);
}
}
this.slotVar.ClearVBox();
if (this.stackCalc.Count == 0) return null;
object ret = stackCalc.Pop();
this.stackCalc.ClearVBox();

return ret;
}
void FillArray(object array, byte[] bytes)
Expand Down Expand Up @@ -1013,15 +1020,33 @@ public void Set(object obj)
{
if (type == RefType.arg)
{
frame._params[pos] = obj;
var p = frame._params[pos];
if (p is VBox)
{
if (obj is VBox)
((VBox)p).Set((VBox)obj);
else
((VBox)p).SetDirect(obj);
}
else
frame._params[pos] = obj;
}
else if (type == RefType.loc)
{
while (frame.slotVar.Count <= pos)
{
frame.slotVar.Add(null);
}
frame.slotVar[pos] = obj;
var loc = frame.slotVar[pos];
if (loc is VBox)
{
if (obj is VBox)
((VBox)loc).Set((VBox)obj);
else
((VBox)loc).SetDirect(obj);
}
else
frame.slotVar[pos] = obj;
}
else if (type == RefType.field)
{
Expand Down Expand Up @@ -1242,15 +1267,22 @@ public VBox GetVBox(object obj)
}
return box;
}










public VBox GetVBoxCloned(object obj)
{
VBox box = null;
if (obj is VBox)
{
box = obj as VBox;
box = box.Clone();
}
else
{
box = ValueOnStack.MakeVBox(obj.GetType());
box.SetDirect(obj);
}
return box;
}

public void Sub()
{
Expand Down Expand Up @@ -2678,32 +2710,30 @@ public void Switch(ThreadContext context, int[] index)
//_pos = poss[pos];
}
}

public void Ldind_I1()
{
object obje = stackCalc.Pop();
if (obje is RefObj)
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
throw new Exception("not impl Ldind_I1:");
//_codepos++;
}

public void Ldind_U1()
{
object obje = stackCalc.Pop();
if (obje is RefObj)
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
Expand All @@ -2717,9 +2747,7 @@ public void Ldind_I2()
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
Expand All @@ -2733,9 +2761,7 @@ public void Ldind_U2()
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
Expand All @@ -2749,9 +2775,7 @@ public void Ldind_I4()
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
Expand All @@ -2765,9 +2789,7 @@ public void Ldind_U4()
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
Expand All @@ -2781,9 +2803,7 @@ public void Ldind_I8()
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
Expand All @@ -2797,9 +2817,7 @@ public void Ldind_I()
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
Expand All @@ -2813,9 +2831,7 @@ public void Ldind_R4()
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
Expand All @@ -2829,9 +2845,7 @@ public void Ldind_R8()
{
RefObj _ref = obje as RefObj;
object value = _ref.Get();
VBox box = ValueOnStack.MakeVBox(value.GetType());
box.SetDirect(value);
stackCalc.Push(box);
stackCalc.Push(GetVBoxCloned(value));
_codepos++;
return;
}
Expand Down