aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorTedd Hansen2007-08-19 10:28:27 +0000
committerTedd Hansen2007-08-19 10:28:27 +0000
commite70cdbc5accc5025ed4e6262ff01ce50bf553141 (patch)
treeb8b74de490ae4d8a03d63458f1ad06730a5e6635
parentMoved script loading from ScriptManager to AppDomainManager. Now increases sc... (diff)
downloadopensim-SC_OLD-e70cdbc5accc5025ed4e6262ff01ce50bf553141.zip
opensim-SC_OLD-e70cdbc5accc5025ed4e6262ff01ce50bf553141.tar.gz
opensim-SC_OLD-e70cdbc5accc5025ed4e6262ff01ce50bf553141.tar.bz2
opensim-SC_OLD-e70cdbc5accc5025ed4e6262ff01ce50bf553141.tar.xz
Added event method invoke cache to Executor. "Bind once, Invoke multiple times". Will speed up script event execution considerable. But at the cost of some memory (will be optimized later with RuntimeXHandle).
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/Executor.cs44
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs51
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs14
3 files changed, 70 insertions, 39 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs
index ca6459b..dedf00d 100644
--- a/OpenSim/Region/ScriptEngine/Common/Executor.cs
+++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs
@@ -5,7 +5,7 @@ using System.Reflection;
5 5
6namespace OpenSim.Region.ScriptEngine.Common 6namespace OpenSim.Region.ScriptEngine.Common
7{ 7{
8 public class Executor: MarshalByRefObject 8 public class Executor : MarshalByRefObject
9 { 9 {
10 /* TODO: 10 /* TODO:
11 * 11 *
@@ -16,10 +16,12 @@ namespace OpenSim.Region.ScriptEngine.Common
16 */ 16 */
17 17
18 private IScript m_Script; 18 private IScript m_Script;
19 private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>();
19 20
20 public Executor(IScript Script) 21 public Executor(IScript Script)
21 { 22 {
22 m_Script = Script; 23 m_Script = Script;
24
23 } 25 }
24 public void ExecuteEvent(string FunctionName, object[] args) 26 public void ExecuteEvent(string FunctionName, object[] args)
25 { 27 {
@@ -34,23 +36,51 @@ namespace OpenSim.Region.ScriptEngine.Common
34 //} 36 //}
35 //} 37 //}
36 38
37 Type type = m_Script.GetType();
38 39
39 Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + m_Script.State() + "_event_" + FunctionName + "\"");
40 40
41 string EventName = m_Script.State() + "_event_" + FunctionName;
42
43 //type.InvokeMember(EventName, BindingFlags.InvokeMethod, null, m_Script, args);
44
45 Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + EventName + "\"");
46
47 if (Events.ContainsKey(EventName) == false)
48 {
49 // Not found, create
50 Type type = m_Script.GetType();
51 try
52 {
53 MethodInfo mi = type.GetMethod(EventName);
54 Events.Add(EventName, mi);
55 }
56 catch (Exception e)
57 {
58 // Event name not found, cache it as not found
59 Events.Add(EventName, null);
60 }
61 }
62
63 // Get event
64 MethodInfo ev = null;
65 Events.TryGetValue(EventName, out ev);
66
67 if (ev == null) // No event by that name!
68 return;
69
70 // Found
41 try 71 try
42 { 72 {
43 type.InvokeMember(m_Script.State() + "_event_" + FunctionName, BindingFlags.InvokeMethod, null, m_Script, args); 73 // Invoke it
74 ev.Invoke(m_Script, args);
75
44 } 76 }
45 catch (Exception e) 77 catch (Exception e)
46 { 78 {
47 // TODO: Send to correct place 79 // TODO: Send to correct place
48 Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString()); 80 Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString());
49 } 81 }
50
51
52 } 82 }
53 83
54
55 } 84 }
85
56} 86}
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
index 77c859f..1218b19 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs
@@ -14,7 +14,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
14{ 14{
15 public class AppDomainManager 15 public class AppDomainManager
16 { 16 {
17 private int MaxScriptsPerAppDomain = 1; 17 private int MaxScriptsPerAppDomain = 3;
18 /// <summary> 18 /// <summary>
19 /// Internal list of all AppDomains 19 /// Internal list of all AppDomains
20 /// </summary> 20 /// </summary>
@@ -22,7 +22,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
22 /// <summary> 22 /// <summary>
23 /// Structure to keep track of data around AppDomain 23 /// Structure to keep track of data around AppDomain
24 /// </summary> 24 /// </summary>
25 private struct AppDomainStructure 25 private class AppDomainStructure
26 { 26 {
27 /// <summary> 27 /// <summary>
28 /// The AppDomain itself 28 /// The AppDomain itself
@@ -57,33 +57,25 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
57 /// <returns>Free AppDomain</returns> 57 /// <returns>Free AppDomain</returns>
58 private AppDomainStructure GetFreeAppDomain() 58 private AppDomainStructure GetFreeAppDomain()
59 { 59 {
60 FreeAppDomains(); 60 FreeAppDomains(); // Outsite lock, has its own GetLock
61 lock(GetLock) { 61 lock (GetLock)
62 {
62 // Current full? 63 // Current full?
63 if (CurrentAD.ScriptsLoaded >= MaxScriptsPerAppDomain) 64 if (CurrentAD != null && CurrentAD.ScriptsLoaded >= MaxScriptsPerAppDomain)
64 { 65 {
65 // Add it to AppDomains list and empty current 66 // Add it to AppDomains list and empty current
66 AppDomains.Add(CurrentAD); 67 AppDomains.Add(CurrentAD);
67 CurrentAD = new AppDomainStructure(); 68 CurrentAD = null;
68 } 69 }
69 // No current 70 // No current
70 if (CurrentAD.CurrentAppDomain == null) 71 if (CurrentAD == null)
71 { 72 {
72 // Create a new current AppDomain 73 // Create a new current AppDomain
73 CurrentAD = new AppDomainStructure(); 74 CurrentAD = new AppDomainStructure();
74 CurrentAD.ScriptsWaitingUnload = 0; // to avoid compile warning for not in use 75 CurrentAD.CurrentAppDomain = PrepareNewAppDomain();
75 CurrentAD.CurrentAppDomain = PrepareNewAppDomain();
76
77
78 } 76 }
79 77
80 // Increase number of scripts loaded into this 78 Console.WriteLine("Scripts loaded in this Appdomain: " + CurrentAD.ScriptsLoaded);
81 // TODO:
82 // - We assume that every time someone wants an AppDomain they will load into it
83 // if this assumption is wrong we end up with a miscount and will never unload it.
84 //
85
86 // Return AppDomain
87 return CurrentAD; 79 return CurrentAD;
88 } // lock 80 } // lock
89 } 81 }
@@ -143,19 +135,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
143 135
144 136
145 137
146 public OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadScript(string FileName, IScriptHost host) 138 public OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadScript(string FileName)
147 { 139 {
148 //LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CreateInstanceAndUnwrap(FileName, "SecondLife.Script"); 140 // Find next available AppDomain to put it in
149 //Console.WriteLine("Base directory: " + AppDomain.CurrentDomain.BaseDirectory);
150 // * Find next available AppDomain to put it in
151 AppDomainStructure FreeAppDomain = GetFreeAppDomain(); 141 AppDomainStructure FreeAppDomain = GetFreeAppDomain();
152 142
153 143 if (FreeAppDomain == null) Console.WriteLine("FreeAppDomain == null");
144 if (FreeAppDomain.CurrentAppDomain == null) Console.WriteLine("FreeAppDomain.CurrentAppDomain == null");
154 LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script"); 145 LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script");
155 //LSL_BuiltIn_Commands_Interface mbrt = (LSL_BuiltIn_Commands_Interface)FreeAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script");
156 //Type mytype = mbrt.GetType(); 146 //Type mytype = mbrt.GetType();
157 //Console.WriteLine("is proxy={0}", RemotingServices.IsTransparentProxy(mbrt)); 147 Console.WriteLine("ScriptEngine AppDomainManager: is proxy={0}", RemotingServices.IsTransparentProxy(mbrt));
158 148
149 // Increase script count in tihs AppDomain
159 FreeAppDomain.ScriptsLoaded++; 150 FreeAppDomain.ScriptsLoaded++;
160 151
161 //mbrt.Start(); 152 //mbrt.Start();
@@ -169,7 +160,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
169 /// Increase "dead script" counter for an AppDomain 160 /// Increase "dead script" counter for an AppDomain
170 /// </summary> 161 /// </summary>
171 /// <param name="ad"></param> 162 /// <param name="ad"></param>
172 [Obsolete("Needs fixing!!!")] 163 [Obsolete("Needs fixing, needs a real purpose in life!!!")]
173 public void StopScript(AppDomain ad) 164 public void StopScript(AppDomain ad)
174 { 165 {
175 lock (FreeLock) 166 lock (FreeLock)
@@ -188,10 +179,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
188 if (ads.CurrentAppDomain == ad) 179 if (ads.CurrentAppDomain == ad)
189 { 180 {
190 // Found it - messy code to increase structure 181 // Found it - messy code to increase structure
191 AppDomainStructure ads2 = ads; 182 //AppDomainStructure ads2 = ads;
192 ads2.ScriptsWaitingUnload++; 183 ads.ScriptsWaitingUnload++;
193 AppDomains.Remove(ads); 184 //AppDomains.Remove(ads);
194 AppDomains.Add(ads2); 185 //AppDomains.Add(ads2);
195 return; 186 return;
196 } 187 }
197 } // foreach 188 } // foreach
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
index 9a65b5c..4879fb2 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
@@ -34,6 +34,7 @@ using System.Reflection;
34using System.Runtime.Remoting; 34using System.Runtime.Remoting;
35using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
36using OpenSim.Region.Environment.Scenes.Scripting; 36using OpenSim.Region.Environment.Scenes.Scripting;
37using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler;
37using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL; 38using OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL;
38using OpenSim.Region.ScriptEngine.Common; 39using OpenSim.Region.ScriptEngine.Common;
39 40
@@ -176,7 +177,16 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
176 //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); 177 //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName);
177 178
178 //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID); 179 //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, ObjectID);
179 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName, ObjectID); 180 long before;
181 before = GC.GetTotalMemory(true);
182 LSL_BaseClass Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName);
183 Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before);
184 before = GC.GetTotalMemory(true);
185 Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName);
186 Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before);
187 before = GC.GetTotalMemory(true);
188 Script = m_scriptEngine.myAppDomainManager.LoadScript(FileName);
189 Console.WriteLine("Script occupies {0} bytes", GC.GetTotalMemory(true) - before);
180 190
181 191
182 // Add it to our temporary active script keeper 192 // Add it to our temporary active script keeper
@@ -184,7 +194,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
184 SetScript(ObjectID, ScriptID, Script); 194 SetScript(ObjectID, ScriptID, Script);
185 // We need to give (untrusted) assembly a private instance of BuiltIns 195 // We need to give (untrusted) assembly a private instance of BuiltIns
186 // this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed. 196 // this private copy will contain Read-Only FullScriptID so that it can bring that on to the server whenever needed.
187 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands LSLB = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL_BuiltIn_Commands(this, ObjectID); 197 LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(this, ObjectID);
188 198
189 // Start the script - giving it BuiltIns 199 // Start the script - giving it BuiltIns
190 Script.Start(LSLB); 200 Script.Start(LSLB);