aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/YEngine/XMRHeapTracker.cs
diff options
context:
space:
mode:
authorUbitUmarov2018-02-23 14:52:34 +0000
committerUbitUmarov2018-02-23 14:52:34 +0000
commit2129d941acbc5f83aca4dc4c30a62d3226888136 (patch)
treee12f2391978c923ef780f558ee5a32d857ee9124 /OpenSim/Region/ScriptEngine/YEngine/XMRHeapTracker.cs
parentMerge branch 'master' into httptests (diff)
downloadopensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.zip
opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.gz
opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.bz2
opensim-SC-2129d941acbc5f83aca4dc4c30a62d3226888136.tar.xz
rename XMREngine as Yengine (still not all done), big mess source formating changes, move state files to proper folder, fix a source file locking on errors, more changes for cross platform including from Mike,... yes yes i know a messy commit
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMRHeapTracker.cs (renamed from OpenSim/Region/ScriptEngine/XMREngine/XMRHeapTracker.cs)174
1 files changed, 101 insertions, 73 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRHeapTracker.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRHeapTracker.cs
index 0e7d303..33eb8bf 100644
--- a/OpenSim/Region/ScriptEngine/XMREngine/XMRHeapTracker.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRHeapTracker.cs
@@ -37,7 +37,7 @@ using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
37using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 37using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
38using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; 38using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
39 39
40namespace OpenSim.Region.ScriptEngine.XMREngine 40namespace OpenSim.Region.ScriptEngine.Yengine
41{ 41{
42 /** 42 /**
43 * One instance of this class for lsl base objects that take a variable 43 * One instance of this class for lsl base objects that take a variable
@@ -48,32 +48,35 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
48 * Note that the xmr arrays and script-defined objects have their own 48 * Note that the xmr arrays and script-defined objects have their own
49 * heap tracking built in so do not need any of this stuff. 49 * heap tracking built in so do not need any of this stuff.
50 */ 50 */
51 public class HeapTrackerBase { 51 public class HeapTrackerBase
52 {
52 protected int usage; // num bytes used by object 53 protected int usage; // num bytes used by object
53 protected XMRInstAbstract instance; // what script it is in 54 protected XMRInstAbstract instance; // what script it is in
54 55
55 public HeapTrackerBase (XMRInstAbstract inst) 56 public HeapTrackerBase(XMRInstAbstract inst)
56 { 57 {
57 if (inst == null) throw new ArgumentNullException ("inst"); 58 if(inst == null)
59 throw new ArgumentNullException("inst");
58 instance = inst; 60 instance = inst;
59 } 61 }
60 62
61 ~HeapTrackerBase () 63 ~HeapTrackerBase()
62 { 64 {
63 usage = instance.UpdateHeapUse (usage, 0); 65 usage = instance.UpdateHeapUse(usage, 0);
64 } 66 }
65 } 67 }
66 68
67 /** 69 /**
68 * Wrapper around lists to keep track of how much memory they use. 70 * Wrapper around lists to keep track of how much memory they use.
69 */ 71 */
70 public class HeapTrackerList : HeapTrackerBase { 72 public class HeapTrackerList: HeapTrackerBase
71 private static FieldInfo listValueField = typeof (HeapTrackerList).GetField ("value"); 73 {
72 private static MethodInfo listSaveMethod = typeof (HeapTrackerList).GetMethod ("Save"); 74 private static FieldInfo listValueField = typeof(HeapTrackerList).GetField("value");
75 private static MethodInfo listSaveMethod = typeof(HeapTrackerList).GetMethod("Save");
73 76
74 public LSL_List value; 77 public LSL_List value;
75 78
76 public HeapTrackerList (XMRInstAbstract inst) : base (inst) { } 79 public HeapTrackerList(XMRInstAbstract inst) : base(inst) { }
77 80
78 // generate CIL code to pop the value from the CIL stack 81 // generate CIL code to pop the value from the CIL stack
79 // input: 82 // input:
@@ -83,7 +86,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
83 // 'this' pointer popped from stack 86 // 'this' pointer popped from stack
84 // new value popped from CIL stack 87 // new value popped from CIL stack
85 // heap usage updated 88 // heap usage updated
86 public static void GenPop (Token errorAt, ScriptMyILGen ilGen) 89 public static void GenPop(Token errorAt, ScriptMyILGen ilGen)
87 { 90 {
88 ilGen.Emit(errorAt, OpCodes.Call, listSaveMethod); 91 ilGen.Emit(errorAt, OpCodes.Call, listSaveMethod);
89 } 92 }
@@ -95,21 +98,21 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
95 // 'this' pointer popped from stack 98 // 'this' pointer popped from stack
96 // value pushed on CIL stack replacing 'this' pointer 99 // value pushed on CIL stack replacing 'this' pointer
97 // returns typeof value pushed on stack 100 // returns typeof value pushed on stack
98 public static Type GenPush (Token errorAt, ScriptMyILGen ilGen) 101 public static Type GenPush(Token errorAt, ScriptMyILGen ilGen)
99 { 102 {
100 ilGen.Emit (errorAt, OpCodes.Ldfld, listValueField); 103 ilGen.Emit(errorAt, OpCodes.Ldfld, listValueField);
101 return typeof (LSL_List); 104 return typeof(LSL_List);
102 } 105 }
103 106
104 public void Save (LSL_List lis) 107 public void Save(LSL_List lis)
105 { 108 {
106 int newuse = Size (lis); 109 int newuse = Size(lis);
107 usage = instance.UpdateHeapUse (usage, newuse); 110 usage = instance.UpdateHeapUse(usage, newuse);
108 value = lis; 111 value = lis;
109 } 112 }
110 113
111 //private static int counter = 5; 114 //private static int counter = 5;
112 public static int Size (LSL_List lis) 115 public static int Size(LSL_List lis)
113 { 116 {
114 // VS2017 in debug mode seems to have a problem running this statement quickly: 117 // VS2017 in debug mode seems to have a problem running this statement quickly:
115 //SLOW: return (!typeof(LSL_List).IsValueType && (lis == null)) ? 0 : lis.Size; 118 //SLOW: return (!typeof(LSL_List).IsValueType && (lis == null)) ? 0 : lis.Size;
@@ -120,9 +123,12 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
120 123
121 // VS2017 in debug mode seems content to run this quickly though: 124 // VS2017 in debug mode seems content to run this quickly though:
122 125
123 try { 126 try
127 {
124 return lis.Size; 128 return lis.Size;
125 } catch { 129 }
130 catch
131 {
126 return 0; 132 return 0;
127 } 133 }
128 } 134 }
@@ -131,22 +137,23 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
131 /** 137 /**
132 * Wrapper around objects to keep track of how much memory they use. 138 * Wrapper around objects to keep track of how much memory they use.
133 */ 139 */
134 public class HeapTrackerObject : HeapTrackerBase { 140 public class HeapTrackerObject: HeapTrackerBase
135 private static FieldInfo objectValueField = typeof (HeapTrackerObject).GetField ("value"); 141 {
136 private static MethodInfo objectSaveMethod = typeof (HeapTrackerObject).GetMethod ("Save"); 142 private static FieldInfo objectValueField = typeof(HeapTrackerObject).GetField("value");
143 private static MethodInfo objectSaveMethod = typeof(HeapTrackerObject).GetMethod("Save");
137 144
138 public const int HT_CHAR = 2; 145 public const int HT_CHAR = 2;
139 public const int HT_DELE = 8; 146 public const int HT_DELE = 8;
140 public const int HT_DOUB = 8; 147 public const int HT_DOUB = 8;
141 public const int HT_SING = 4; 148 public const int HT_SING = 4;
142 public const int HT_SFLT = 4; 149 public const int HT_SFLT = 4;
143 public const int HT_INT = 4; 150 public const int HT_INT = 4;
144 public const int HT_VEC = HT_DOUB * 3; 151 public const int HT_VEC = HT_DOUB * 3;
145 public const int HT_ROT = HT_DOUB * 4; 152 public const int HT_ROT = HT_DOUB * 4;
146 153
147 public object value; 154 public object value;
148 155
149 public HeapTrackerObject (XMRInstAbstract inst) : base (inst) { } 156 public HeapTrackerObject(XMRInstAbstract inst) : base(inst) { }
150 157
151 // generate CIL code to pop the value from the CIL stack 158 // generate CIL code to pop the value from the CIL stack
152 // input: 159 // input:
@@ -156,7 +163,7 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
156 // 'this' pointer popped from stack 163 // 'this' pointer popped from stack
157 // new value popped from CIL stack 164 // new value popped from CIL stack
158 // heap usage updated 165 // heap usage updated
159 public static void GenPop (Token errorAt, ScriptMyILGen ilGen) 166 public static void GenPop(Token errorAt, ScriptMyILGen ilGen)
160 { 167 {
161 ilGen.Emit(errorAt, OpCodes.Call, objectSaveMethod); 168 ilGen.Emit(errorAt, OpCodes.Call, objectSaveMethod);
162 } 169 }
@@ -168,67 +175,88 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
168 // 'this' pointer popped from stack 175 // 'this' pointer popped from stack
169 // value pushed on CIL stack replacing 'this' pointer 176 // value pushed on CIL stack replacing 'this' pointer
170 // returns typeof value pushed on stack 177 // returns typeof value pushed on stack
171 public static Type GenPush (Token errorAt, ScriptMyILGen ilGen) 178 public static Type GenPush(Token errorAt, ScriptMyILGen ilGen)
172 { 179 {
173 ilGen.Emit (errorAt, OpCodes.Ldfld, objectValueField); 180 ilGen.Emit(errorAt, OpCodes.Ldfld, objectValueField);
174 return typeof (object); 181 return typeof(object);
175 } 182 }
176 183
177 public void Save (object obj) 184 public void Save(object obj)
178 { 185 {
179 int newuse = Size (obj); 186 int newuse = Size(obj);
180 usage = instance.UpdateHeapUse (usage, newuse); 187 usage = instance.UpdateHeapUse(usage, newuse);
181 value = obj; 188 value = obj;
182 } 189 }
183 190
184 // public so it can be used by XMRArray 191 // public so it can be used by XMRArray
185 public static int Size (object obj) 192 public static int Size(object obj)
186 { 193 {
187 if (obj == null) return 0; 194 if(obj == null)
188 195 return 0;
189 if (obj is char) return HT_CHAR; 196
190 if (obj is Delegate) return HT_DELE; 197 if(obj is char)
191 if (obj is double) return HT_DOUB; 198 return HT_CHAR;
192 if (obj is float) return HT_SING; 199 if(obj is Delegate)
193 if (obj is int) return HT_INT; 200 return HT_DELE;
194 if (obj is LSL_Float) return HT_SFLT; 201 if(obj is double)
195 if (obj is LSL_Integer) return HT_INT; 202 return HT_DOUB;
196 if (obj is LSL_List) return ((LSL_List)obj).Size; 203 if(obj is float)
197 if (obj is LSL_Rotation) return HT_ROT; 204 return HT_SING;
198 if (obj is LSL_String) return ((LSL_String)obj).m_string.Length * HT_CHAR; 205 if(obj is int)
199 if (obj is LSL_Vector) return HT_VEC; 206 return HT_INT;
200 if (obj is string) return ((string)obj).Length * HT_CHAR; 207 if(obj is LSL_Float)
201 if (obj is XMR_Array) return 0; 208 return HT_SFLT;
202 if (obj is XMRArrayListKey) return ((XMRArrayListKey)obj).Size; 209 if(obj is LSL_Integer)
203 if (obj is XMRSDTypeClObj) return 0; 210 return HT_INT;
204 211 if(obj is LSL_List)
205 if (obj is Array) { 212 return ((LSL_List)obj).Size;
213 if(obj is LSL_Rotation)
214 return HT_ROT;
215 if(obj is LSL_String)
216 return ((LSL_String)obj).m_string.Length * HT_CHAR;
217 if(obj is LSL_Vector)
218 return HT_VEC;
219 if(obj is string)
220 return ((string)obj).Length * HT_CHAR;
221 if(obj is XMR_Array)
222 return 0;
223 if(obj is XMRArrayListKey)
224 return ((XMRArrayListKey)obj).Size;
225 if(obj is XMRSDTypeClObj)
226 return 0;
227
228 if(obj is Array)
229 {
206 Array ar = (Array)obj; 230 Array ar = (Array)obj;
207 int len = ar.Length; 231 int len = ar.Length;
208 if (len == 0) return 0; 232 if(len == 0)
209 Type et = ar.GetType ().GetElementType (); 233 return 0;
210 if (et.IsValueType) return Size (ar.GetValue (0)) * len; 234 Type et = ar.GetType().GetElementType();
235 if(et.IsValueType)
236 return Size(ar.GetValue(0)) * len;
211 int size = 0; 237 int size = 0;
212 for (int i = 0; i < len; i ++) { 238 for(int i = 0; i < len; i++)
213 size += Size (ar.GetValue (i)); 239 {
240 size += Size(ar.GetValue(i));
214 } 241 }
215 return size; 242 return size;
216 } 243 }
217 244
218 throw new Exception ("unknown size of type " + obj.GetType ().Name); 245 throw new Exception("unknown size of type " + obj.GetType().Name);
219 } 246 }
220 } 247 }
221 248
222 /** 249 /**
223 * Wrapper around strings to keep track of how much memory they use. 250 * Wrapper around strings to keep track of how much memory they use.
224 */ 251 */
225 public class HeapTrackerString : HeapTrackerBase { 252 public class HeapTrackerString: HeapTrackerBase
226 private static FieldInfo stringValueField = typeof (HeapTrackerString).GetField ("value"); 253 {
227 private static MethodInfo stringSaveMethod = typeof (HeapTrackerString).GetMethod ("Save"); 254 private static FieldInfo stringValueField = typeof(HeapTrackerString).GetField("value");
255 private static MethodInfo stringSaveMethod = typeof(HeapTrackerString).GetMethod("Save");
228 256
229 public string value; 257 public string value;
230 258
231 public HeapTrackerString (XMRInstAbstract inst) : base (inst) { } 259 public HeapTrackerString(XMRInstAbstract inst) : base(inst) { }
232 260
233 // generate CIL code to pop the value from the CIL stack 261 // generate CIL code to pop the value from the CIL stack
234 // input: 262 // input:
@@ -238,9 +266,9 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
238 // 'this' pointer popped from stack 266 // 'this' pointer popped from stack
239 // new value popped from CIL stack 267 // new value popped from CIL stack
240 // heap usage updated 268 // heap usage updated
241 public static void GenPop (Token errorAt, ScriptMyILGen ilGen) 269 public static void GenPop(Token errorAt, ScriptMyILGen ilGen)
242 { 270 {
243 ilGen.Emit (errorAt, OpCodes.Call, stringSaveMethod); 271 ilGen.Emit(errorAt, OpCodes.Call, stringSaveMethod);
244 } 272 }
245 273
246 // generate CIL code to push the value on the CIL stack 274 // generate CIL code to push the value on the CIL stack
@@ -250,20 +278,20 @@ namespace OpenSim.Region.ScriptEngine.XMREngine
250 // 'this' pointer popped from stack 278 // 'this' pointer popped from stack
251 // value pushed on CIL stack replacing 'this' pointer 279 // value pushed on CIL stack replacing 'this' pointer
252 // returns typeof value pushed on stack 280 // returns typeof value pushed on stack
253 public static Type GenPush (Token errorAt, ScriptMyILGen ilGen) 281 public static Type GenPush(Token errorAt, ScriptMyILGen ilGen)
254 { 282 {
255 ilGen.Emit (errorAt, OpCodes.Ldfld, stringValueField); 283 ilGen.Emit(errorAt, OpCodes.Ldfld, stringValueField);
256 return typeof (string); 284 return typeof(string);
257 } 285 }
258 286
259 public void Save (string str) 287 public void Save(string str)
260 { 288 {
261 int newuse = Size (str); 289 int newuse = Size(str);
262 usage = instance.UpdateHeapUse (usage, newuse); 290 usage = instance.UpdateHeapUse(usage, newuse);
263 value = str; 291 value = str;
264 } 292 }
265 293
266 public static int Size (string str) 294 public static int Size(string str)
267 { 295 {
268 return (str == null) ? 0 : str.Length * HeapTrackerObject.HT_CHAR; 296 return (str == null) ? 0 : str.Length * HeapTrackerObject.HT_CHAR;
269 } 297 }