Yengine: a few more changes on the global variables nulls

This commit is contained in:
UbitUmarov
2021-07-23 16:18:11 +01:00
parent ae49b540c1
commit b1051417e0
2 changed files with 114 additions and 102 deletions

View File

@@ -62,17 +62,17 @@ namespace OpenSim.Region.ScriptEngine.Yengine
private XMRInstAbstract instance;
public int arraysHeapUse;
private static readonly XMR_Array[] noArrays = new XMR_Array[0];
private static readonly char[] noChars = new char[0];
private static readonly double[] noFloats = new double[0];
private static readonly int[] noIntegers = new int[0];
private static readonly LSL_List[] noLists = new LSL_List[0];
private static readonly object[] noObjects = new object[0];
private static readonly LSL_Rotation[] noRotations = new LSL_Rotation[0];
private static readonly string[] noStrings = new string[0];
private static readonly LSL_Vector[] noVectors = new LSL_Vector[0];
private static readonly XMRSDTypeClObj[] noSDTClObjs = new XMRSDTypeClObj[0];
private static readonly Delegate[][] noSDTIntfObjs = new Delegate[0][];
public static readonly XMR_Array[] noArrays = new XMR_Array[0];
public static readonly char[] noChars = new char[0];
public static readonly double[] noFloats = new double[0];
public static readonly int[] noIntegers = new int[0];
public static readonly LSL_List[] noLists = new LSL_List[0];
public static readonly object[] noObjects = new object[0];
public static readonly LSL_Rotation[] noRotations = new LSL_Rotation[0];
public static readonly string[] noStrings = new string[0];
public static readonly LSL_Vector[] noVectors = new LSL_Vector[0];
public static readonly XMRSDTypeClObj[] noSDTClObjs = new XMRSDTypeClObj[0];
public static readonly Delegate[][] noSDTIntfObjs = new Delegate[0][];
public XMRInstArrays(XMRInstAbstract inst)
{
@@ -201,83 +201,102 @@ namespace OpenSim.Region.ScriptEngine.Yengine
ClearOldArrays();
iarArrays = (XMR_Array[])recver();
char[] chrs = (char[])recver();
double[] flts = (double[])recver();
int[] ints = (int[])recver();
LSL_List[] liss = (LSL_List[])recver();
object[] objs = (object[])recver();
LSL_Rotation[] rots = (LSL_Rotation[])recver();
string[] strs = (string[])recver();
LSL_Vector[] vecs = (LSL_Vector[])recver();
iarSDTClObjs = (XMRSDTypeClObj[])recver();
Delegate[][] dels = (Delegate[][])recver();
if(iarArrays == null)
iarArrays = noArrays;
int newheapuse = arraysHeapUse;
// value types simply are the size of the value * number of values
if(chrs!=null)
char[] chrs = (char[])recver();
if (chrs != null)
{
newheapuse += chrs.Length * HeapTrackerObject.HT_CHAR;
iarChars = chrs;
}
else
chrs = noChars;
if(flts != null)
iarChars = noChars;
double[] flts = (double[])recver();
if (flts != null)
{
newheapuse += flts.Length * HeapTrackerObject.HT_DOUB;
iarFloats = flts;
}
else
flts = noFloats;
if(ints != null)
iarFloats = noFloats;
int[] ints = (int[])recver();
if (ints != null)
{
newheapuse += ints.Length * HeapTrackerObject.HT_INT;
iarIntegers = ints;
}
else
ints = noIntegers;
if(rots!=null)
newheapuse += rots.Length * HeapTrackerObject.HT_ROT;
else
rots = noRotations;
if(vecs != null)
newheapuse += vecs.Length * HeapTrackerObject.HT_VEC;
else
vecs = noVectors;
if(dels != null)
newheapuse += dels.Length * HeapTrackerObject.HT_DELE;
else
dels = noSDTIntfObjs;
iarIntegers = noIntegers;
// lists, objects, strings are the sum of the size of each element
if(liss != null)
LSL_List[] liss = (LSL_List[])recver();
if (liss != null)
{
foreach(LSL_List lis in liss)
foreach (LSL_List lis in liss)
newheapuse += HeapTrackerList.Size(lis);
iarLists = liss;
}
else
liss = noLists;
iarLists = noLists;
if(objs != null)
object[] objs = (object[])recver();
if (objs != null)
{
foreach(object obj in objs)
foreach (object obj in objs)
newheapuse += HeapTrackerObject.Size(obj);
iarObjects = objs;
}
else
objs = noObjects;
if(strs != null)
{
foreach(string str in strs)
newheapuse += HeapTrackerString.Size(str);
}
else
strs = noStrings;
iarObjects = noObjects;
// others (XMR_Array, XMRSDTypeClObj) keep track of their own heap usage
LSL_Rotation[] rots = (LSL_Rotation[])recver();
if (rots != null)
{
newheapuse += rots.Length * HeapTrackerObject.HT_ROT;
iarRotations = rots;
}
else
iarRotations = noRotations;
string[] strs = (string[])recver();
if (strs != null)
{
foreach (string str in strs)
newheapuse += HeapTrackerString.Size(str);
iarStrings = strs;
}
else
iarStrings = noStrings;
LSL_Vector[] vecs = (LSL_Vector[])recver();
if (vecs != null)
{
newheapuse += vecs.Length * HeapTrackerObject.HT_VEC;
iarVectors = vecs;
}
else
iarVectors = noVectors;
iarSDTClObjs = (XMRSDTypeClObj[])recver();
if(iarSDTClObjs == null)
iarSDTClObjs = noSDTClObjs;
Delegate[][] dels = (Delegate[][])recver();
if(dels != null)
{
newheapuse += dels.Length * HeapTrackerObject.HT_DELE;
iarSDTIntfObjs = dels;
}
else
iarSDTIntfObjs = noSDTIntfObjs;
// update script heap usage, throwing an exception before finalizing changes
arraysHeapUse = instance.UpdateArraysHeapUse(arraysHeapUse, newheapuse);
iarChars = chrs;
iarFloats = flts;
iarIntegers = ints;
iarLists = liss;
iarObjects = objs;
iarRotations = rots;
iarStrings = strs;
iarVectors = vecs;
iarSDTIntfObjs = dels;
}
private void ClearOldArrays()

View File

@@ -619,7 +619,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine
Dictionary<string, int> rotationNames = new Dictionary<string, int>();
Dictionary<string, int> listNames = new Dictionary<string, int>();
int nn = m_ObjCode.globalVarNames.Count;
int[] ints = null;
double[] doubles = null;
string[] strings = null;
@@ -627,53 +626,42 @@ namespace OpenSim.Region.ScriptEngine.Yengine
LSL_Rotation[] rotations = null;
LSL_List[] lists = null;
int nn = m_ObjCode.globalVarNames.Count;
if (nn > 0)
{
if (m_ObjCode.globalVarNames.ContainsKey("iarIntegers"))
Dictionary<int, string> tmpVars;
if (m_ObjCode.globalVarNames.TryGetValue("iarIntegers", out tmpVars))
{
getvarNames(m_ObjCode.globalVarNames["iarIntegers"], intNames);
ints = new int[m_ObjCode.globalVarNames["iarIntegers"].Count];
getvarNames(tmpVars, intNames);
ints = new int[tmpVars.Count];
}
if (m_ObjCode.globalVarNames.ContainsKey("iarFloats"))
if (m_ObjCode.globalVarNames.TryGetValue("iarFloats", out tmpVars))
{
getvarNames(m_ObjCode.globalVarNames["iarFloats"], doubleNames);
doubles = new double[m_ObjCode.globalVarNames["iarFloats"].Count];
getvarNames(tmpVars, doubleNames);
doubles = new double[tmpVars.Count];
}
if (m_ObjCode.globalVarNames.ContainsKey("iarVectors"))
if (m_ObjCode.globalVarNames.TryGetValue("iarVectors", out tmpVars))
{
getvarNames(m_ObjCode.globalVarNames["iarVectors"], vectorNames);
vectors = new LSL_Vector[m_ObjCode.globalVarNames["iarVectors"].Count];
getvarNames(tmpVars, vectorNames);
vectors = new LSL_Vector[tmpVars.Count];
}
if (m_ObjCode.globalVarNames.ContainsKey("iarRotations"))
if (m_ObjCode.globalVarNames.TryGetValue("iarRotations", out tmpVars))
{
getvarNames(m_ObjCode.globalVarNames["iarRotations"], rotationNames);
rotations = new LSL_Rotation[m_ObjCode.globalVarNames["iarRotations"].Count];
getvarNames(tmpVars, rotationNames);
rotations = new LSL_Rotation[tmpVars.Count];
}
if (m_ObjCode.globalVarNames.ContainsKey("iarStrings"))
if (m_ObjCode.globalVarNames.TryGetValue("iarStrings", out tmpVars))
{
getvarNames(m_ObjCode.globalVarNames["iarStrings"], stringNames);
strings = new string[m_ObjCode.globalVarNames["iarStrings"].Count];
getvarNames(tmpVars, stringNames);
strings = new string[tmpVars.Count];
}
if (m_ObjCode.globalVarNames.ContainsKey("iarLists"))
if (m_ObjCode.globalVarNames.TryGetValue("iarLists", out tmpVars))
{
getvarNames(m_ObjCode.globalVarNames["iarLists"], listNames);
lists = new LSL_List[m_ObjCode.globalVarNames["iarLists"].Count];
getvarNames(tmpVars, listNames);
lists = new LSL_List[tmpVars.Count];
}
}
if(ints == null)
ints = new int[0];
if(doubles == null)
doubles = new double[0];
if(strings == null)
strings = new string[0];
if(vectors == null)
vectors = new LSL_Vector[0];
if(rotations == null)
rotations = new LSL_Rotation[0];
if(lists == null)
lists = new LSL_List[0];
int heapsz = 0;
try
@@ -915,12 +903,17 @@ namespace OpenSim.Region.ScriptEngine.Yengine
lock (m_RunLock)
{
glblVars.iarIntegers = ints;
glblVars.iarFloats = doubles;
glblVars.iarVectors = vectors;
glblVars.iarRotations = rotations;
glblVars.iarStrings = strings;
glblVars.iarLists = lists;
glblVars.iarIntegers = (ints != null) ? ints : XMRInstArrays.noIntegers;
glblVars.iarFloats = (doubles != null) ? doubles : XMRInstArrays.noFloats;
glblVars.iarStrings = (strings != null) ? strings : XMRInstArrays.noStrings;
glblVars.iarVectors = (vectors != null) ? vectors : XMRInstArrays.noVectors;
glblVars.iarRotations = (rotations != null) ? rotations : XMRInstArrays.noRotations;
glblVars.iarLists = (lists != null) ? lists : XMRInstArrays.noLists;
glblVars.iarChars = XMRInstArrays.noChars;
glblVars.iarArrays = XMRInstArrays.noArrays;
glblVars.iarObjects = XMRInstArrays.noObjects;
glblVars.iarSDTClObjs = XMRInstArrays.noSDTClObjs;
glblVars.iarSDTIntfObjs = XMRInstArrays.noSDTIntfObjs;
AddArraysHeapUse(heapsz);
CheckRunLockInvariants(true);