more changes on YEngine scripts heap usage

0.9.1.1
UbitUmarov 2019-11-22 04:09:05 +00:00
parent 647622bb02
commit 9b7ad30ee1
6 changed files with 54 additions and 45 deletions

View File

@ -69,15 +69,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine
{ {
this.inst = inst; this.inst = inst;
dnary = new SortedDictionary<object, object>(XMRArrayKeyComparer.singleton); dnary = new SortedDictionary<object, object>(XMRArrayKeyComparer.singleton);
heapUse = inst.UpdateHeapUse(0, EMPTYHEAP); heapUse = inst.UpdateArraysHeapUse(0, EMPTYHEAP);
} }
/*
~XMR_Array() ~XMR_Array()
{ {
heapUse = inst.UpdateHeapUse(heapUse, 0); heapUse = inst.UpdateLocalsHeapUse(heapUse, 0);
} }
*/
public static TokenType GetRValType(TokenName name) public static TokenType GetRValType(TokenName name)
{ {
@ -123,7 +122,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
{ {
newheapuse += keysize + HeapTrackerObject.Size(value); newheapuse += keysize + HeapTrackerObject.Size(value);
} }
heapUse = inst.UpdateHeapUse(heapUse, newheapuse); heapUse = inst.UpdateArraysHeapUse(heapUse, newheapuse);
// Save new value in array, replacing one of same key if there. // Save new value in array, replacing one of same key if there.
// null means remove the value, ie, script did array[key] = undef. // null means remove the value, ie, script did array[key] = undef.
@ -185,7 +184,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
*/ */
public void __pub_clear() public void __pub_clear()
{ {
heapUse = inst.UpdateHeapUse(heapUse, EMPTYHEAP); heapUse = inst.UpdateArraysHeapUse(heapUse, EMPTYHEAP);
dnary.Clear(); dnary.Clear();
enumrValid = false; enumrValid = false;
arrayValid = 0; arrayValid = 0;
@ -286,7 +285,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public delegate object RecvArrayObjDelegate(); public delegate object RecvArrayObjDelegate();
public void RecvArrayObj(RecvArrayObjDelegate recvObj) public void RecvArrayObj(RecvArrayObjDelegate recvObj)
{ {
heapUse = inst.UpdateHeapUse(heapUse, EMPTYHEAP); heapUse = inst.UpdateArraysHeapUse(heapUse, EMPTYHEAP);
// Cause any enumeration to refill the array from the sorted dictionary. // Cause any enumeration to refill the array from the sorted dictionary.
// Since it is a sorted dictionary, any enumerations will be in the same // Since it is a sorted dictionary, any enumerations will be in the same
// order as on the sending side. // order as on the sending side.
@ -301,7 +300,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
object key = FixKey(recvObj()); object key = FixKey(recvObj());
object val = recvObj(); object val = recvObj();
int htuse = HeapTrackerObject.Size(key) + HeapTrackerObject.Size(val); int htuse = HeapTrackerObject.Size(key) + HeapTrackerObject.Size(val);
heapUse = inst.UpdateHeapUse(heapUse, heapUse + htuse); heapUse = inst.UpdateArraysHeapUse(heapUse, heapUse + htuse);
dnary.Add(key, val); dnary.Add(key, val);
} }
} }

View File

@ -106,9 +106,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public void Save(LSL_List lis) public void Save(LSL_List lis)
{ {
if (lis == null) if (lis == null)
usage = instance.UpdateHeapUse(usage, 0); usage = instance.UpdateLocalsHeapUse(usage, 0);
else else
usage = instance.UpdateHeapUse(usage, Size(lis)); usage = instance.UpdateLocalsHeapUse(usage, Size(lis));
value = lis; value = lis;
} }
@ -190,8 +190,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public void Save(object obj) public void Save(object obj)
{ {
int newuse = Size(obj); usage = instance.UpdateLocalsHeapUse(usage, Size(obj));
usage = instance.UpdateHeapUse(usage, newuse);
value = obj; value = obj;
} }
@ -305,8 +304,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public void Save(string str) public void Save(string str)
{ {
int newuse = Size(str); usage = instance.UpdateLocalsHeapUse(usage, Size(str));
usage = instance.UpdateHeapUse(usage, newuse);
value = str; value = str;
} }
@ -318,7 +316,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public static int Size(string str) public static int Size(string str)
{ {
return (str == null) ? 0 : str.Length * HeapTrackerObject.HT_CHAR; return string.IsNullOrWhiteSpace(str) ? 0 : str.Length * HeapTrackerObject.HT_CHAR;
} }
} }
} }

View File

@ -60,7 +60,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public Delegate[][] iarSDTIntfObjs; public Delegate[][] iarSDTIntfObjs;
private XMRInstAbstract instance; private XMRInstAbstract instance;
private int arraysHeapUse; public int arraysHeapUse;
private static readonly XMR_Array[] noArrays = new XMR_Array[0]; private static readonly XMR_Array[] noArrays = new XMR_Array[0];
private static readonly char[] noChars = new char[0]; private static readonly char[] noChars = new char[0];
@ -79,10 +79,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine
instance = inst; instance = inst;
} }
/*
~XMRInstArrays() ~XMRInstArrays()
{ {
arraysHeapUse = instance.UpdateHeapUse(arraysHeapUse, 0); arraysHeapUse = instance.UpdateArraysHeapUse(arraysHeapUse, 0);
} }
*/
public void Clear() public void Clear()
{ {
@ -109,7 +111,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
if (iarVectors != null) if (iarVectors != null)
newheapUse += iarVectors.Length * HeapTrackerObject.HT_VEC; newheapUse += iarVectors.Length * HeapTrackerObject.HT_VEC;
arraysHeapUse = instance.UpdateHeapUse(0, newheapUse); arraysHeapUse = instance.UpdateArraysHeapUse(0, newheapUse);
} }
public void AllocVarArrays(XMRInstArSizes ars) public void AllocVarArrays(XMRInstArSizes ars)
@ -117,13 +119,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine
ClearOldArrays(); ClearOldArrays();
int newuse = arraysHeapUse + int newuse = arraysHeapUse +
ars.iasChars* HeapTrackerObject.HT_CHAR + ars.iasChars* HeapTrackerObject.HT_CHAR +
ars.iasFloats * HeapTrackerObject.HT_SFLT + ars.iasFloats * HeapTrackerObject.HT_DOUB +
ars.iasIntegers * HeapTrackerObject.HT_INT + ars.iasIntegers * HeapTrackerObject.HT_INT +
ars.iasRotations * HeapTrackerObject.HT_ROT + ars.iasRotations * HeapTrackerObject.HT_ROT +
ars.iasVectors * HeapTrackerObject.HT_VEC + ars.iasVectors * HeapTrackerObject.HT_VEC +
ars.iasSDTIntfObjs * HeapTrackerObject.HT_DELE; ars.iasSDTIntfObjs * HeapTrackerObject.HT_DELE;
arraysHeapUse = instance.UpdateHeapUse(arraysHeapUse, newuse); arraysHeapUse = instance.UpdateArraysHeapUse(arraysHeapUse, newuse);
iarArrays = (ars.iasArrays > 0) ? new XMR_Array[ars.iasArrays] : noArrays; iarArrays = (ars.iasArrays > 0) ? new XMR_Array[ars.iasArrays] : noArrays;
iarChars = (ars.iasChars > 0) ? new char[ars.iasChars] : noChars; iarChars = (ars.iasChars > 0) ? new char[ars.iasChars] : noChars;
@ -144,7 +146,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public void PopList(int index, LSL_List lis) public void PopList(int index, LSL_List lis)
{ {
int delta = HeapTrackerObject.Size(lis) - HeapTrackerObject.Size(iarLists[index]); int delta = HeapTrackerObject.Size(lis) - HeapTrackerObject.Size(iarLists[index]);
instance.UpdateHeapUse(0, delta); instance.UpdateArraysHeapUse(0, delta);
Interlocked.Add(ref arraysHeapUse, delta); Interlocked.Add(ref arraysHeapUse, delta);
iarLists[index] = lis; iarLists[index] = lis;
} }
@ -155,7 +157,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public void PopObject(int index, object obj) public void PopObject(int index, object obj)
{ {
int delta = HeapTrackerObject.Size(obj) - HeapTrackerObject.Size(iarObjects[index]); int delta = HeapTrackerObject.Size(obj) - HeapTrackerObject.Size(iarObjects[index]);
instance.UpdateHeapUse(0, delta); instance.UpdateArraysHeapUse(0, delta);
Interlocked.Add(ref arraysHeapUse, delta); Interlocked.Add(ref arraysHeapUse, delta);
iarObjects[index] = obj; iarObjects[index] = obj;
} }
@ -166,7 +168,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public void PopString(int index, string str) public void PopString(int index, string str)
{ {
int delta = HeapTrackerString.Size(str) - HeapTrackerString.Size(iarStrings[index]); int delta = HeapTrackerString.Size(str) - HeapTrackerString.Size(iarStrings[index]);
instance.UpdateHeapUse(0, delta); instance.UpdateArraysHeapUse(0, delta);
Interlocked.Add(ref arraysHeapUse, delta); Interlocked.Add(ref arraysHeapUse, delta);
iarStrings[index] = str; iarStrings[index] = str;
} }
@ -233,7 +235,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
// others (XMR_Array, XMRSDTypeClObj) keep track of their own heap usage // others (XMR_Array, XMRSDTypeClObj) keep track of their own heap usage
// update script heap usage, throwing an exception before finalizing changes // update script heap usage, throwing an exception before finalizing changes
arraysHeapUse = instance.UpdateHeapUse(arraysHeapUse, newheapuse); arraysHeapUse = instance.UpdateArraysHeapUse(arraysHeapUse, newheapuse);
iarChars = chrs; iarChars = chrs;
iarFloats = flts; iarFloats = flts;
@ -258,7 +260,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
} }
if(iarFloats != null) if(iarFloats != null)
{ {
newheapuse -= iarFloats.Length * HeapTrackerObject.HT_SFLT; newheapuse -= iarFloats.Length * HeapTrackerObject.HT_DOUB;
iarFloats = null; iarFloats = null;
} }
if(iarIntegers != null) if(iarIntegers != null)
@ -301,7 +303,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
iarSDTIntfObjs = null; iarSDTIntfObjs = null;
} }
arraysHeapUse = instance.UpdateHeapUse(arraysHeapUse, newheapuse); arraysHeapUse = instance.UpdateArraysHeapUse(arraysHeapUse, newheapuse);
} }
} }
@ -453,35 +455,43 @@ namespace OpenSim.Region.ScriptEngine.Yengine
\**************************************************/ \**************************************************/
protected int heapLimit; protected int heapLimit;
public int m_heapUsed; public int m_localsHeapUsed;
public int m_arraysHeapUsed;
public virtual int UpdateHeapUse(int olduse, int newuse) public virtual int UpdateLocalsHeapUse(int olduse, int newuse)
{ {
if (m_heapUsed < 0) int newtotal = Interlocked.Add(ref m_localsHeapUsed, newuse - olduse);
m_heapUsed = 0; if (newtotal + glblVars.arraysHeapUse > heapLimit)
int newtotal = Interlocked.Add(ref m_heapUsed, newuse - olduse); throw new OutOfHeapException(m_arraysHeapUsed + newtotal + olduse - newuse, newtotal, heapLimit);
if(newtotal > heapLimit) return newuse;
throw new OutOfHeapException(newtotal + olduse - newuse, newtotal, heapLimit); }
// not in use
public virtual int UpdateArraysHeapUse(int olduse, int newuse)
{
//int newtotal = Interlocked.Add(ref m_arraysheapUsed, newuse - olduse);
if(newuse + glblVars.arraysHeapUse > heapLimit)
throw new OutOfHeapException(m_arraysHeapUsed + newuse + olduse - newuse, newuse, heapLimit);
return newuse; return newuse;
} }
public virtual void AddHeapUse(int delta) public virtual void AddLocalsHeapUse(int delta)
{ {
Interlocked.Add(ref m_heapUsed, delta); Interlocked.Add(ref m_localsHeapUsed, delta);
}
public virtual void AddArraysHeapUse(int delta)
{
Interlocked.Add(ref m_arraysHeapUsed, delta);
} }
public int xmrHeapLeft() public int xmrHeapLeft()
{ {
if (m_heapUsed < 0) return heapLimit - m_localsHeapUsed - glblVars.arraysHeapUse;
m_heapUsed = 0;
return heapLimit - m_heapUsed;
} }
public int xmrHeapUsed() public int xmrHeapUsed()
{ {
if(m_heapUsed < 0) return m_localsHeapUsed + glblVars.arraysHeapUse;
m_heapUsed = 0;
return m_heapUsed;
} }
/** /**

View File

@ -86,7 +86,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
m_StackSize = stackSize; m_StackSize = stackSize;
m_StackLeft = stackSize; m_StackLeft = stackSize;
m_HeapSize = heapSize; m_HeapSize = heapSize;
m_heapUsed = 0; m_localsHeapUsed = 0;
m_arraysHeapUsed = 0;
m_CompilerErrors = errors; m_CompilerErrors = errors;
m_StateFileName = GetStateFileName(scriptBasePath, m_ItemID); m_StateFileName = GetStateFileName(scriptBasePath, m_ItemID);
@ -904,7 +905,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
glblVars.iarStrings = strings; glblVars.iarStrings = strings;
glblVars.iarLists = lists; glblVars.iarLists = lists;
AddHeapUse(heapsz); AddArraysHeapUse(heapsz);
CheckRunLockInvariants(true); CheckRunLockInvariants(true);
} }

View File

@ -888,7 +888,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
m_SleepUntil = DateTime.MinValue; // not doing llSleep() m_SleepUntil = DateTime.MinValue; // not doing llSleep()
m_ResetCount++; // has been reset once more m_ResetCount++; // has been reset once more
m_heapUsed = 0; m_localsHeapUsed = 0;
m_arraysHeapUsed = 0;
glblVars.Clear(); glblVars.Clear();
// Tell next call to 'default state_entry()' to reset all global // Tell next call to 'default state_entry()' to reset all global

View File

@ -60,7 +60,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
public Delegate[][] sdtcITable; public Delegate[][] sdtcITable;
/* /*
* These arrays hold the insance variable values. * These arrays hold the instance variable values.
* The array lengths are determined by the script compilation, * The array lengths are determined by the script compilation,
* and are found in TokenDeclSDTypeClass.instSizes. * and are found in TokenDeclSDTypeClass.instSizes.
*/ */