From 33448e4ba83b590e0e7e340faf3d7f2cef80c611 Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Mon, 26 Oct 2009 07:50:25 -0700 Subject: Optimizations --- .../Region/ScriptEngine/Interfaces/ICompiler.cs | 4 +- .../ScriptEngine/Shared/Api/Runtime/ScriptBase.cs | 2 +- .../ScriptEngine/Shared/CodeTools/Compiler.cs | 156 ++++++++++----------- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 28 ++-- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 51 ++++--- 5 files changed, 123 insertions(+), 118 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Interfaces/ICompiler.cs b/OpenSim/Region/ScriptEngine/Interfaces/ICompiler.cs index f8af902..e4ca635 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/ICompiler.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/ICompiler.cs @@ -34,9 +34,7 @@ namespace OpenSim.Region.ScriptEngine.Interfaces { public interface ICompiler { - object PerformScriptCompile(string source, string asset, UUID ownerID); + void PerformScriptCompile(string source, string asset, UUID ownerID, out string assembly, out Dictionary, KeyValuePair> linemap); string[] GetWarnings(); - Dictionary, KeyValuePair> - LineMap(); } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs index 917ca44..121159c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs @@ -113,7 +113,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return; //ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject); - RemotingServices.GetLifetimeService(data as MarshalByRefObject); + //RemotingServices.GetLifetimeService(data as MarshalByRefObject); // lease.Register(m_sponser); MethodInfo mi = inits[api]; diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index fe26429..d781a1a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs @@ -74,7 +74,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools private string FilePrefix; private string ScriptEnginesPath = "ScriptEngines"; // mapping between LSL and C# line/column numbers - private Dictionary, KeyValuePair> m_positionMap; private ICodeConverter LSL_Converter; private List m_warnings = new List(); @@ -91,6 +90,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools private static UInt64 scriptCompileCounter = 0; // And a counter public IScriptEngine m_scriptEngine; + private Dictionary, KeyValuePair>> m_lineMaps = + new Dictionary, KeyValuePair>>(); + public Compiler(IScriptEngine scriptEngine) { m_scriptEngine = scriptEngine; @@ -271,16 +273,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools /// /// LSL script /// Filename to .dll assembly - public object PerformScriptCompile(string Script, string asset, UUID ownerUUID) + public void PerformScriptCompile(string Script, string asset, UUID ownerUUID, + out string assembly, out Dictionary, KeyValuePair> linemap) { - m_positionMap = null; + linemap = null; m_warnings.Clear(); - - string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine( + + assembly = Path.Combine(ScriptEnginesPath, Path.Combine( m_scriptEngine.World.RegionInfo.RegionID.ToString(), FilePrefix + "_compiled_" + asset + ".dll")); -// string OutFile = Path.Combine(ScriptEnginesPath, -// FilePrefix + "_compiled_" + asset + ".dll"); if (!Directory.Exists(ScriptEnginesPath)) { @@ -305,51 +306,53 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools } } - if (Script == String.Empty) + // Don't recompile if we already have it + // Performing 3 file exists tests for every script can still be slow + if (File.Exists(assembly) && File.Exists(assembly + ".text") && File.Exists(assembly + ".map")) { - if (File.Exists(OutFile)) - return OutFile; - - throw new Exception("Cannot find script assembly and no script text present"); + // If we have already read this linemap file, then it will be in our dictionary. + // Don't build another copy of the dictionary (saves memory) and certainly + // don't keep reading the same file from disk multiple times. + if (!m_lineMaps.ContainsKey(assembly)) + m_lineMaps[assembly] = ReadMapFile(assembly + ".map"); + linemap = m_lineMaps[assembly]; + return; } - // Don't recompile if we already have it - // - if (File.Exists(OutFile) && File.Exists(OutFile+".text") && File.Exists(OutFile+".map")) + if (Script == String.Empty) { - ReadMapFile(OutFile+".map"); - return OutFile; + throw new Exception("Cannot find script assembly and no script text present"); } - enumCompileType l = DefaultCompileLanguage; + enumCompileType language = DefaultCompileLanguage; if (Script.StartsWith("//c#", true, CultureInfo.InvariantCulture)) - l = enumCompileType.cs; + language = enumCompileType.cs; if (Script.StartsWith("//vb", true, CultureInfo.InvariantCulture)) { - l = enumCompileType.vb; + language = enumCompileType.vb; // We need to remove //vb, it won't compile with that Script = Script.Substring(4, Script.Length - 4); } if (Script.StartsWith("//lsl", true, CultureInfo.InvariantCulture)) - l = enumCompileType.lsl; + language = enumCompileType.lsl; if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture)) - l = enumCompileType.js; + language = enumCompileType.js; if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture)) - l = enumCompileType.yp; + language = enumCompileType.yp; - if (!AllowedCompilers.ContainsKey(l.ToString())) + if (!AllowedCompilers.ContainsKey(language.ToString())) { // Not allowed to compile to this language! string errtext = String.Empty; - errtext += "The compiler for language \"" + l.ToString() + "\" is not in list of allowed compilers. Script will not be executed!"; + errtext += "The compiler for language \"" + language.ToString() + "\" is not in list of allowed compilers. Script will not be executed!"; throw new Exception(errtext); } - if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)l) == false) { + if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)language) == false) { // Not allowed to compile to this language! string errtext = String.Empty; errtext += ownerUUID + " is not in list of allowed users for this scripting language. Script will not be executed!"; @@ -358,7 +361,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools string compileScript = Script; - if (l == enumCompileType.lsl) + if (language == enumCompileType.lsl) { // Its LSL, convert it to C# LSL_Converter = (ICodeConverter)new CSCodeGenerator(); @@ -370,16 +373,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools AddWarning(warning); } - m_positionMap = ((CSCodeGenerator) LSL_Converter).PositionMap; + linemap = ((CSCodeGenerator) LSL_Converter).PositionMap; + // Write the linemap to a file and save it in our dictionary for next time. + m_lineMaps[assembly] = linemap; + WriteMapFile(assembly + ".map", linemap); } - if (l == enumCompileType.yp) + if (language == enumCompileType.yp) { // Its YP, convert it to C# compileScript = YP_Converter.Convert(Script); } - switch (l) + switch (language) { case enumCompileType.cs: case enumCompileType.lsl: @@ -396,7 +402,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools break; } - return CompileFromDotNetText(compileScript, l, asset); + assembly = CompileFromDotNetText(compileScript, language, asset, assembly); + return; } public string[] GetWarnings() @@ -468,18 +475,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools /// /// CS script /// Filename to .dll assembly - internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset) + internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset, string assembly) { string ext = "." + lang.ToString(); // Output assembly name scriptCompileCounter++; - string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine( - m_scriptEngine.World.RegionInfo.RegionID.ToString(), - FilePrefix + "_compiled_" + asset + ".dll")); try { - File.Delete(OutFile); + File.Delete(assembly); } catch (Exception e) // NOTLEGIT - Should be just FileIOException { @@ -492,7 +496,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools if (WriteScriptSourceToDebugFile) { string srcFileName = FilePrefix + "_source_" + - Path.GetFileNameWithoutExtension(OutFile) + ext; + Path.GetFileNameWithoutExtension(assembly) + ext; try { File.WriteAllText(Path.Combine(Path.Combine( @@ -528,7 +532,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools } parameters.GenerateExecutable = false; - parameters.OutputAssembly = OutFile; + parameters.OutputAssembly = assembly; parameters.IncludeDebugInformation = CompileWithDebugInformation; //parameters.WarningLevel = 1; // Should be 4? parameters.TreatWarningsAsErrors = false; @@ -609,7 +613,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools if (severity == "Error") { - lslPos = FindErrorPosition(CompErr.Line, CompErr.Column); + lslPos = FindErrorPosition(CompErr.Line, CompErr.Column, m_lineMaps[assembly]); string text = CompErr.ErrorText; // Use LSL type names @@ -635,14 +639,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools // the compile may not be immediately apparent. Wait a // reasonable amount of time before giving up on it. - if (!File.Exists(OutFile)) + if (!File.Exists(assembly)) { - for (int i=0; i<20 && !File.Exists(OutFile); i++) + for (int i=0; i<20 && !File.Exists(assembly); i++) { System.Threading.Thread.Sleep(250); } // One final chance... - if (!File.Exists(OutFile)) + if (!File.Exists(assembly)) { errtext = String.Empty; errtext += "No compile error. But not able to locate compiled file."; @@ -658,7 +662,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools // // Read the binary file into a buffer // - FileInfo fi = new FileInfo(OutFile); + FileInfo fi = new FileInfo(assembly); if (fi == null) { @@ -671,7 +675,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools try { - FileStream fs = File.Open(OutFile, FileMode.Open, FileAccess.Read); + FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read); fs.Read(data, 0, data.Length); fs.Close(); } @@ -690,34 +694,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools Byte[] buf = enc.GetBytes(filetext); - FileStream sfs = File.Create(OutFile+".text"); + FileStream sfs = File.Create(assembly+".text"); sfs.Write(buf, 0, buf.Length); sfs.Close(); - string posmap = String.Empty; - if (m_positionMap != null) - { - foreach (KeyValuePair, KeyValuePair> kvp in m_positionMap) - { - KeyValuePair k = kvp.Key; - KeyValuePair v = kvp.Value; - posmap += String.Format("{0},{1},{2},{3}\n", - k.Key, k.Value, v.Key, v.Value); - } - } - - buf = enc.GetBytes(posmap); - - FileStream mfs = File.Create(OutFile+".map"); - mfs.Write(buf, 0, buf.Length); - mfs.Close(); - - return OutFile; - } - - public KeyValuePair FindErrorPosition(int line, int col) - { - return FindErrorPosition(line, col, m_positionMap); + return assembly; } private class kvpSorter : IComparer> @@ -791,27 +772,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools return message; } - public Dictionary, KeyValuePair> LineMap() + + private static void WriteMapFile(string filename, Dictionary, KeyValuePair> linemap) { - if (m_positionMap == null) - return null; - - Dictionary, KeyValuePair> ret = - new Dictionary, KeyValuePair>(); - - foreach (KeyValuePair kvp in m_positionMap.Keys) - ret.Add(kvp, m_positionMap[kvp]); - - return ret; + string mapstring = String.Empty; + foreach (KeyValuePair, KeyValuePair> kvp in linemap) + { + KeyValuePair k = kvp.Key; + KeyValuePair v = kvp.Value; + mapstring += String.Format("{0},{1},{2},{3}\n", k.Key, k.Value, v.Key, v.Value); + } + + System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); + Byte[] mapbytes = enc.GetBytes(mapstring); + FileStream mfs = File.Create(filename); + mfs.Write(mapbytes, 0, mapbytes.Length); + mfs.Close(); } - private void ReadMapFile(string filename) + + private static Dictionary, KeyValuePair> ReadMapFile(string filename) { + Dictionary, KeyValuePair> linemap; try { StreamReader r = File.OpenText(filename); - - m_positionMap = new Dictionary, KeyValuePair>(); + linemap = new Dictionary, KeyValuePair>(); string line; while ((line = r.ReadLine()) != null) @@ -825,12 +811,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools KeyValuePair k = new KeyValuePair(kk, kv); KeyValuePair v = new KeyValuePair(vk, vv); - m_positionMap[k] = v; + linemap[k] = v; } } catch { + linemap = new Dictionary, KeyValuePair>(); } + return linemap; } } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 2b858ec..37ec5df 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -93,7 +93,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private StateSource m_stateSource; private bool m_postOnRez; private bool m_startedFromSavedState = false; - private string m_CurrentState = String.Empty; + private int m_CurrentStateHash; private UUID m_RegionID = UUID.Zero; private Dictionary, KeyValuePair> @@ -252,16 +252,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance { m_Apis[api] = am.CreateApi(api); m_Apis[api].Initialize(engine, part, m_LocalID, itemID); - } + } + + try + { + if (dom != System.AppDomain.CurrentDomain) + m_Script = (IScript)dom.CreateInstanceAndUnwrap( + Path.GetFileNameWithoutExtension(assembly), + "SecondLife.Script"); + else + m_Script = (IScript)Assembly.Load( + Path.GetFileNameWithoutExtension(assembly)).CreateInstance( + "SecondLife.Script"); - try - { - m_Script = (IScript)dom.CreateInstanceAndUnwrap( - Path.GetFileNameWithoutExtension(assembly), - "SecondLife.Script"); //ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass); - RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass); + //RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass); // lease.Register(this); } catch (Exception) @@ -893,7 +899,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance string xml = ScriptSerializer.Serialize(this); - if (m_CurrentState != xml) + // Compare hash of the state we just just created with the state last written to disk + // If the state is different, update the disk file. + if(xml.GetHashCode() != m_CurrentStateHash) { try { @@ -911,7 +919,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance //{ // throw new Exception("Completed persistence save, but no file was created"); //} - m_CurrentState = xml; + m_CurrentStateHash = xml.GetHashCode(); } } diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 7b19ce3..57042e9 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -73,9 +73,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine private bool m_InitialStartup = true; private int m_ScriptFailCount; // Number of script fails since compile queue was last empty private string m_ScriptErrorMessage; + private Dictionary m_uniqueScripts = new Dictionary(); + private bool m_AppDomainLoading; -// disable warning: need to keep a reference to XEngine.EventManager -// alive to avoid it being garbage collected + // disable warning: need to keep a reference to XEngine.EventManager + // alive to avoid it being garbage collected #pragma warning disable 414 private EventManager m_EventManager; #pragma warning restore 414 @@ -201,6 +203,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine m_MaxScriptQueue = m_ScriptConfig.GetInt("MaxScriptEventQueue",300); m_StackSize = m_ScriptConfig.GetInt("ThreadStackSize", 262144); m_SleepTime = m_ScriptConfig.GetInt("MaintenanceInterval", 10) * 1000; + m_AppDomainLoading = m_ScriptConfig.GetBoolean("AppDomainLoading", true); m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30); m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false); @@ -470,6 +473,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (engine != ScriptEngineName) return; + // If we've seen this exact script text before, use that reference instead + if (m_uniqueScripts.ContainsKey(script)) + script = m_uniqueScripts[script]; + else + m_uniqueScripts[script] = script; + Object[] parms = new Object[]{localID, itemID, script, startParam, postOnRez, (StateSource)stateSource}; if (stateSource == (int)StateSource.ScriptedRez) @@ -590,14 +599,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine { lock (m_AddingAssemblies) { - assembly = (string)m_Compiler.PerformScriptCompile(script, - assetID.ToString(), item.OwnerID); + m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assembly, out linemap); if (!m_AddingAssemblies.ContainsKey(assembly)) { m_AddingAssemblies[assembly] = 1; } else { m_AddingAssemblies[assembly]++; } - linemap = m_Compiler.LineMap(); } string[] warnings = m_Compiler.GetWarnings(); @@ -696,19 +703,22 @@ namespace OpenSim.Region.ScriptEngine.XEngine Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; Evidence evidence = new Evidence(baseEvidence); - AppDomain sandbox = - AppDomain.CreateDomain( - m_Scene.RegionInfo.RegionID.ToString(), - evidence, appSetup); -/* - PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); - AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); - PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); - PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); - CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); - sandboxPolicy.RootCodeGroup = sandboxCodeGroup; - sandbox.SetAppDomainPolicy(sandboxPolicy); -*/ + AppDomain sandbox; + if (m_AppDomainLoading) + sandbox = AppDomain.CreateDomain( + m_Scene.RegionInfo.RegionID.ToString(), + evidence, appSetup); + else + sandbox = AppDomain.CurrentDomain; + /* + PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); + AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); + PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); + PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); + CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); + sandboxPolicy.RootCodeGroup = sandboxCodeGroup; + sandbox.SetAppDomainPolicy(sandboxPolicy); + */ m_AppDomains[appDomain] = sandbox; m_AppDomains[appDomain].AssemblyResolve += @@ -905,9 +915,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine AppDomain domain = m_AppDomains[id]; m_AppDomains.Remove(id); - AppDomain.Unload(domain); + if (domain != AppDomain.CurrentDomain) + AppDomain.Unload(domain); domain = null; -// m_log.DebugFormat("[XEngine] Unloaded app domain {0}", id.ToString()); + // m_log.DebugFormat("[XEngine] Unloaded app domain {0}", id.ToString()); } } -- cgit v1.1 From dd13fa361b12fa2fb1c91c9f74379a305935a87d Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 29 Oct 2009 05:56:37 -0700 Subject: * Misc. formatting cleanup for the previous patch * Added the new AppDomainLoading variable to the [XEngine] section in the example config --- .../ScriptEngine/Shared/CodeTools/Compiler.cs | 51 +++++++++++----------- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 8 ++-- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 18 ++++---- 3 files changed, 40 insertions(+), 37 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index d781a1a..3080c71 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs @@ -174,8 +174,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools else { #if DEBUG -// m_log.Debug("[Compiler]: " + -// "Config OK. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is recognized as a valid language."); + // m_log.Debug("[Compiler]: " + + // "Config OK. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is recognized as a valid language."); #endif // LANGUAGE IS IN ALLOW-LIST DefaultCompileLanguage = LanguageMapping[defaultCompileLanguage]; @@ -214,12 +214,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools catch (Exception ex) { m_log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + Path.Combine(ScriptEnginesPath, - m_scriptEngine.World.RegionInfo.RegionID.ToString())+ "\": " + ex.ToString()); + m_scriptEngine.World.RegionInfo.RegionID.ToString()) + "\": " + ex.ToString()); } } foreach (string file in Directory.GetFiles(Path.Combine(ScriptEnginesPath, - m_scriptEngine.World.RegionInfo.RegionID.ToString()),FilePrefix + "_compiled*")) + m_scriptEngine.World.RegionInfo.RegionID.ToString()), FilePrefix + "_compiled*")) { try { @@ -273,8 +273,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools /// /// LSL script /// Filename to .dll assembly - public void PerformScriptCompile(string Script, string asset, UUID ownerUUID, - out string assembly, out Dictionary, KeyValuePair> linemap) + public void PerformScriptCompile(string Script, string asset, UUID ownerUUID, + out string assembly, out Dictionary, KeyValuePair> linemap) { linemap = null; m_warnings.Clear(); @@ -352,13 +352,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools throw new Exception(errtext); } - if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)language) == false) { + if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)language) == false) + { // Not allowed to compile to this language! string errtext = String.Empty; errtext += ownerUUID + " is not in list of allowed users for this scripting language. Script will not be executed!"; throw new Exception(errtext); } - + string compileScript = Script; if (language == enumCompileType.lsl) @@ -373,7 +374,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools AddWarning(warning); } - linemap = ((CSCodeGenerator) LSL_Converter).PositionMap; + linemap = ((CSCodeGenerator)LSL_Converter).PositionMap; // Write the linemap to a file and save it in our dictionary for next time. m_lineMaps[assembly] = linemap; WriteMapFile(assembly + ".map", linemap); @@ -487,7 +488,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools } catch (Exception e) // NOTLEGIT - Should be just FileIOException { - throw new Exception("Unable to delete old existing "+ + throw new Exception("Unable to delete old existing " + "script-file before writing new. Compile aborted: " + e.ToString()); } @@ -506,7 +507,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools } catch (Exception ex) //NOTLEGIT - Should be just FileIOException { - m_log.Error("[Compiler]: Exception while "+ + m_log.Error("[Compiler]: Exception while " + "trying to write script source to file \"" + srcFileName + "\": " + ex.ToString()); } @@ -547,7 +548,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools case enumCompileType.cs: case enumCompileType.lsl: bool complete = false; - bool retried = false; + bool retried = false; do { lock (CScodeProvider) @@ -588,7 +589,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools parameters, Script); break; default: - throw new Exception("Compiler is not able to recongnize "+ + throw new Exception("Compiler is not able to recongnize " + "language type \"" + lang.ToString() + "\""); } @@ -641,7 +642,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools if (!File.Exists(assembly)) { - for (int i=0; i<20 && !File.Exists(assembly); i++) + for (int i = 0; i < 20 && !File.Exists(assembly); i++) { System.Threading.Thread.Sleep(250); } @@ -654,8 +655,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools } } -// m_log.DebugFormat("[Compiler] Compiled new assembly "+ -// "for {0}", asset); + // m_log.DebugFormat("[Compiler] Compiled new assembly "+ + // "for {0}", asset); // Because windows likes to perform exclusive locks, we simply // write out a textual representation of the file here @@ -694,17 +695,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools Byte[] buf = enc.GetBytes(filetext); - FileStream sfs = File.Create(assembly+".text"); + FileStream sfs = File.Create(assembly + ".text"); sfs.Write(buf, 0, buf.Length); sfs.Close(); return assembly; } - private class kvpSorter : IComparer> + private class kvpSorter : IComparer> { - public int Compare(KeyValuePair a, - KeyValuePair b) + public int Compare(KeyValuePair a, + KeyValuePair b) { return a.Key.CompareTo(b.Key); } @@ -723,8 +724,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools out ret)) return ret; - List> sorted = - new List>(positionMap.Keys); + List> sorted = + new List>(positionMap.Keys); sorted.Sort(new kvpSorter()); @@ -791,18 +792,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools } - private static Dictionary, KeyValuePair> ReadMapFile(string filename) + private static Dictionary, KeyValuePair> ReadMapFile(string filename) { Dictionary, KeyValuePair> linemap; try { StreamReader r = File.OpenText(filename); linemap = new Dictionary, KeyValuePair>(); - + string line; while ((line = r.ReadLine()) != null) { - String[] parts = line.Split(new Char[] {','}); + String[] parts = line.Split(new Char[] { ',' }); int kk = System.Convert.ToInt32(parts[0]); int kv = System.Convert.ToInt32(parts[1]); int vk = System.Convert.ToInt32(parts[2]); diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 37ec5df..f16aefc 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -93,7 +93,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private StateSource m_stateSource; private bool m_postOnRez; private bool m_startedFromSavedState = false; - private int m_CurrentStateHash; + private UUID m_CurrentStateHash; private UUID m_RegionID = UUID.Zero; private Dictionary, KeyValuePair> @@ -901,7 +901,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance // Compare hash of the state we just just created with the state last written to disk // If the state is different, update the disk file. - if(xml.GetHashCode() != m_CurrentStateHash) + UUID hash = UUID.Parse(Utils.MD5String(xml)); + + if(hash != m_CurrentStateHash) { try { @@ -919,7 +921,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance //{ // throw new Exception("Completed persistence save, but no file was created"); //} - m_CurrentStateHash = xml.GetHashCode(); + m_CurrentStateHash = hash; } } diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 57042e9..b13e0de 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -710,15 +710,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine evidence, appSetup); else sandbox = AppDomain.CurrentDomain; - /* - PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); - AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); - PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); - PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); - CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); - sandboxPolicy.RootCodeGroup = sandboxCodeGroup; - sandbox.SetAppDomainPolicy(sandboxPolicy); - */ + + //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); + //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); + //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); + //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); + //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); + //sandboxPolicy.RootCodeGroup = sandboxCodeGroup; + //sandbox.SetAppDomainPolicy(sandboxPolicy); + m_AppDomains[appDomain] = sandbox; m_AppDomains[appDomain].AssemblyResolve += -- cgit v1.1 From ec7fd8b1f810a13e7f78448e9ef81113ed3c5bf0 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 29 Oct 2009 06:42:40 -0700 Subject: More performance improvements to XEngine script loading --- .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 24 ++++---- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 67 ++++++++-------------- 2 files changed, 37 insertions(+), 54 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index f16aefc..549c038 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -74,27 +74,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance private string m_PrimName; private string m_ScriptName; private string m_Assembly; - private int m_StartParam = 0; + private int m_StartParam; private string m_CurrentEvent = String.Empty; - private bool m_InSelfDelete = false; + private bool m_InSelfDelete; private int m_MaxScriptQueue; private bool m_SaveState = true; - private bool m_ShuttingDown = false; - private int m_ControlEventsInQueue = 0; - private int m_LastControlLevel = 0; - private bool m_CollisionInQueue = false; + private bool m_ShuttingDown; + private int m_ControlEventsInQueue; + private int m_LastControlLevel; + private bool m_CollisionInQueue; private TaskInventoryItem m_thisScriptTask; // The following is for setting a minimum delay between events - private double m_minEventDelay = 0; - private long m_eventDelayTicks = 0; - private long m_nextEventTimeTicks = 0; + private double m_minEventDelay; + private long m_eventDelayTicks; + private long m_nextEventTimeTicks; private bool m_startOnInit = true; - private UUID m_AttachedAvatar = UUID.Zero; + private UUID m_AttachedAvatar; private StateSource m_stateSource; private bool m_postOnRez; - private bool m_startedFromSavedState = false; + private bool m_startedFromSavedState; private UUID m_CurrentStateHash; - private UUID m_RegionID = UUID.Zero; + private UUID m_RegionID; private Dictionary, KeyValuePair> m_LineMap; diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index b13e0de..b0fce75 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -50,6 +50,9 @@ using OpenSim.Region.ScriptEngine.Shared.CodeTools; using OpenSim.Region.ScriptEngine.Shared.Instance; using OpenSim.Region.ScriptEngine.Interfaces; +using ScriptCompileQueue = OpenSim.Framework.LocklessQueue; +using Parallel = OpenSim.Framework.Parallel; + namespace OpenSim.Region.ScriptEngine.XEngine { public class XEngine : INonSharedRegionModule, IScriptModule, IScriptEngine @@ -116,7 +119,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine private Dictionary > m_DomainScripts = new Dictionary >(); - private Queue m_CompileQueue = new Queue(100); + private ScriptCompileQueue m_CompileQueue = new ScriptCompileQueue(); IWorkItemResult m_CurrentCompile = null; public string ScriptEngineName @@ -487,16 +490,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine } else { - lock (m_CompileQueue) - { - m_CompileQueue.Enqueue(parms); + m_CompileQueue.Enqueue(parms); - if (m_CurrentCompile == null) - { - m_CurrentCompile = m_ThreadPool.QueueWorkItem( - new WorkItemCallback(this.DoOnRezScriptQueue), - new Object[0]); - } + if (m_CurrentCompile == null) + { + m_CurrentCompile = m_ThreadPool.QueueWorkItem(DoOnRezScriptQueue, null); } } } @@ -507,50 +505,35 @@ namespace OpenSim.Region.ScriptEngine.XEngine { m_InitialStartup = false; System.Threading.Thread.Sleep(15000); - lock (m_CompileQueue) + + if (m_CompileQueue.Count == 0) { - if (m_CompileQueue.Count==0) - // No scripts on region, so won't get triggered later - // by the queue becoming empty so we trigger it here - m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty); + // No scripts on region, so won't get triggered later + // by the queue becoming empty so we trigger it here + m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty); } } - Object o; - lock (m_CompileQueue) + List compiles = new List(); + object[] o; + while (m_CompileQueue.Dequeue(out o)) { - o = m_CompileQueue.Dequeue(); - if (o == null) - { - m_CurrentCompile = null; - return null; - } + compiles.Add(o); } - DoOnRezScript(o); + Parallel.For(0, compiles.Count, delegate(int i) { DoOnRezScript(compiles[i]); }); + + m_CurrentCompile = null; + m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount, + m_ScriptErrorMessage); + m_ScriptFailCount = 0; - lock (m_CompileQueue) - { - if (m_CompileQueue.Count > 0) - { - m_CurrentCompile = m_ThreadPool.QueueWorkItem( - new WorkItemCallback(this.DoOnRezScriptQueue), - new Object[0]); - } - else - { - m_CurrentCompile = null; - m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount, - m_ScriptErrorMessage); - m_ScriptFailCount = 0; - } - } return null; } - private bool DoOnRezScript(object parm) + private bool DoOnRezScript(object[] parms) { - Object[] p = (Object[])parm; + Object[] p = parms; uint localID = (uint)p[0]; UUID itemID = (UUID)p[1]; string script =(string)p[2]; -- cgit v1.1 From 7f4d646aeacef5e82a4f8df1494e3752afc3372f Mon Sep 17 00:00:00 2001 From: Douglas R. Miles Date: Sat, 31 Oct 2009 19:24:14 -0800 Subject: http://opensimulator.org/mantis/view.php?id=4337 --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 3849558..c9221b8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3817,7 +3817,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { case 1: // DATA_ONLINE (0|1) // TODO: implement fetching of this information - if (userProfile.CurrentAgent.AgentOnline) + if (userProfile.CurrentAgent!=null && userProfile.CurrentAgent.AgentOnline) reply = "1"; else reply = "0"; -- cgit v1.1 From 58c260140ccd15846700f01cceb7b08d87df144e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 31 Oct 2009 19:10:33 -0700 Subject: Patch + minor formatting fixes. --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index c9221b8..64f7c8d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3817,7 +3817,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { case 1: // DATA_ONLINE (0|1) // TODO: implement fetching of this information - if (userProfile.CurrentAgent!=null && userProfile.CurrentAgent.AgentOnline) + if (userProfile.CurrentAgent!=null && userProfile.CurrentAgent.AgentOnline) reply = "1"; else reply = "0"; -- cgit v1.1 From 67ac9881faf2034facfe92613538938695c2cda9 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 2 Nov 2009 11:28:35 -0800 Subject: Removing duplicate SceneObjectPart.RotationalVelocity property --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 64f7c8d..0ea62d7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -2163,7 +2163,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Vector llGetOmega() { m_host.AddScriptLPS(1); - return new LSL_Vector(m_host.RotationalVelocity.X, m_host.RotationalVelocity.Y, m_host.RotationalVelocity.Z); + return new LSL_Vector(m_host.AngularVelocity.X, m_host.AngularVelocity.Y, m_host.AngularVelocity.Z); } public LSL_Float llGetTimeOfDay() @@ -3159,7 +3159,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llTargetOmega(LSL_Vector axis, double spinrate, double gain) { m_host.AddScriptLPS(1); - m_host.RotationalVelocity = new Vector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate)); m_host.AngularVelocity = new Vector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate)); m_host.ScheduleTerseUpdate(); m_host.SendTerseUpdateToAllClients(); -- cgit v1.1