diff options
author | UbitUmarov | 2018-02-02 12:49:40 +0000 |
---|---|---|
committer | UbitUmarov | 2018-02-02 12:49:40 +0000 |
commit | 83e2fee71be695b78438e0c9dc50b649a539d0e3 (patch) | |
tree | af213fea5ebfa4e773af6942c753e7f3bba0d83f /OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs | |
parent | Merge branch 'master' into httptests (diff) | |
download | opensim-SC-83e2fee71be695b78438e0c9dc50b649a539d0e3.zip opensim-SC-83e2fee71be695b78438e0c9dc50b649a539d0e3.tar.gz opensim-SC-83e2fee71be695b78438e0c9dc50b649a539d0e3.tar.bz2 opensim-SC-83e2fee71be695b78438e0c9dc50b649a539d0e3.tar.xz |
add experimental script engine XMRengine donated by mrieker (DreamNation) And our Melanie. ***DANGER*** ***TESTONLY*** ***disable HG*** dont leave running when not looking... tp/crossing to Xengine will reset scripts. i do see a few issues but should be testable, so we can decide if we should invest more on it.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs | 230 |
1 files changed, 230 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs new file mode 100644 index 0000000..436434a --- /dev/null +++ b/OpenSim/Region/ScriptEngine/XMREngine/XMRInstMain.cs | |||
@@ -0,0 +1,230 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Threading; | ||
30 | using System.Reflection; | ||
31 | using System.Collections; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Runtime.Remoting.Lifetime; | ||
34 | using System.Security.Policy; | ||
35 | using System.IO; | ||
36 | using System.Xml; | ||
37 | using System.Text; | ||
38 | using OpenMetaverse; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
41 | using OpenSim.Region.ScriptEngine.Shared; | ||
42 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
43 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
44 | using OpenSim.Region.ScriptEngine.XMREngine; | ||
45 | using OpenSim.Region.Framework.Scenes; | ||
46 | using log4net; | ||
47 | |||
48 | using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; | ||
49 | using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; | ||
50 | using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
51 | using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list; | ||
52 | using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion; | ||
53 | using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; | ||
54 | using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3; | ||
55 | |||
56 | // This class exists in the main app domain | ||
57 | // | ||
58 | namespace OpenSim.Region.ScriptEngine.XMREngine | ||
59 | { | ||
60 | /** | ||
61 | * @brief Which queue it is in as far as running is concerned, | ||
62 | * ie, m_StartQueue, m_YieldQueue, m_SleepQueue, etc. | ||
63 | * Allowed transitions: | ||
64 | * Starts in CONSTRUCT when constructed | ||
65 | * CONSTRUCT->ONSTARTQ : only by thread that constructed and compiled it | ||
66 | * IDLE->ONSTARTQ,RESETTING : by any thread but must have m_QueueLock when transitioning | ||
67 | * ONSTARTQ->RUNNING,RESETTING : only by thread that removed it from m_StartQueue | ||
68 | * ONYIELDQ->RUNNING,RESETTING : only by thread that removed it from m_YieldQueue | ||
69 | * ONSLEEPQ->REMDFROMSLPQ : by any thread but must have m_SleepQueue when transitioning | ||
70 | * REMDFROMSLPQ->ONYIELDQ,RESETTING : only by thread that removed it from m_SleepQueue | ||
71 | * RUNNING->whatever1 : only by thread that transitioned it to RUNNING | ||
72 | * whatever1 = IDLE,ONSLEEPQ,ONYIELDQ,ONSTARTQ,SUSPENDED,FINISHED | ||
73 | * FINSHED->whatever2 : only by thread that transitioned it to FINISHED | ||
74 | * whatever2 = IDLE,ONSTARTQ,DISPOSED | ||
75 | * SUSPENDED->ONSTARTQ : by any thread (NOT YET IMPLEMENTED, should be under some kind of lock?) | ||
76 | * RESETTING->ONSTARTQ : only by the thread that transitioned it to RESETTING | ||
77 | */ | ||
78 | public enum XMRInstState { | ||
79 | CONSTRUCT, // it is being constructed | ||
80 | IDLE, // nothing happening (finished last event and m_EventQueue is empty) | ||
81 | ONSTARTQ, // inserted on m_Engine.m_StartQueue | ||
82 | RUNNING, // currently being executed by RunOne() | ||
83 | ONSLEEPQ, // inserted on m_Engine.m_SleepQueue | ||
84 | REMDFROMSLPQ, // removed from m_SleepQueue but not yet on m_YieldQueue | ||
85 | ONYIELDQ, // inserted on m_Engine.m_YieldQueue | ||
86 | FINISHED, // just finished handling an event | ||
87 | SUSPENDED, // m_SuspendCount > 0 | ||
88 | RESETTING, // being reset via external call | ||
89 | DISPOSED // has been disposed | ||
90 | } | ||
91 | |||
92 | public partial class XMRInstance : XMRInstAbstract, IDisposable | ||
93 | { | ||
94 | /******************************************************************\ | ||
95 | * This module contains the instance variables for XMRInstance. * | ||
96 | \******************************************************************/ | ||
97 | |||
98 | public const int MAXEVENTQUEUE = 64; | ||
99 | |||
100 | public static readonly DetectParams[] zeroDetectParams = new DetectParams[0]; | ||
101 | public static readonly object[] zeroObjectArray = new object[0]; | ||
102 | |||
103 | public static readonly ILog m_log = | ||
104 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
105 | |||
106 | // For a given m_Item.AssetID, do we have the compiled object code and where | ||
107 | // is it? | ||
108 | public static object m_CompileLock = new object(); | ||
109 | private static Dictionary<string,ScriptObjCode> m_CompiledScriptObjCode = new Dictionary<string,ScriptObjCode>(); | ||
110 | |||
111 | public XMRInstance m_NextInst; // used by XMRInstQueue | ||
112 | public XMRInstance m_PrevInst; | ||
113 | public XMRInstState m_IState; | ||
114 | |||
115 | public bool m_ForceRecomp = false; | ||
116 | public SceneObjectPart m_Part = null; | ||
117 | public uint m_LocalID = 0; | ||
118 | public TaskInventoryItem m_Item = null; | ||
119 | public UUID m_ItemID; | ||
120 | public UUID m_PartUUID; | ||
121 | private string m_CameFrom; | ||
122 | private string m_ScriptObjCodeKey; | ||
123 | |||
124 | private XMREngine m_Engine = null; | ||
125 | private string m_ScriptBasePath; | ||
126 | private string m_StateFileName; | ||
127 | public string m_SourceCode; | ||
128 | public bool m_PostOnRez; | ||
129 | private DetectParams[] m_DetectParams = null; | ||
130 | public int m_StartParam = 0; | ||
131 | public StateSource m_StateSource; | ||
132 | public string m_DescName; | ||
133 | private bool[] m_HaveEventHandlers; | ||
134 | public int m_StackSize; | ||
135 | public int m_HeapSize; | ||
136 | private ArrayList m_CompilerErrors; | ||
137 | private DateTime m_LastRanAt = DateTime.MinValue; | ||
138 | private string m_RunOnePhase = "hasn't run"; | ||
139 | private string m_CheckRunPhase = "hasn't checked"; | ||
140 | public int m_InstEHEvent = 0; // number of events dequeued (StartEventHandler called) | ||
141 | public int m_InstEHSlice = 0; // number of times handler timesliced (ResumeEx called) | ||
142 | public double m_CPUTime = 0; // accumulated CPU time (milliseconds) | ||
143 | |||
144 | // If code needs to have both m_QueueLock and m_RunLock, | ||
145 | // be sure to lock m_RunLock first then m_QueueLock, as | ||
146 | // that is the order used in RunOne(). | ||
147 | // These locks are currently separated to allow the script | ||
148 | // to call API routines that queue events back to the script. | ||
149 | // If we just had one lock, then the queuing would deadlock. | ||
150 | |||
151 | // guards m_DetachQuantum, m_EventQueue, m_EventCounts, m_Running, m_Suspended | ||
152 | public Object m_QueueLock = new Object(); | ||
153 | |||
154 | // true iff allowed to accept new events | ||
155 | public bool m_Running = true; | ||
156 | |||
157 | // queue of events that haven't been acted upon yet | ||
158 | public LinkedList<EventParams> m_EventQueue = new LinkedList<EventParams> (); | ||
159 | |||
160 | // number of events of each code currently in m_EventQueue. | ||
161 | private int[] m_EventCounts = new int[(int)ScriptEventCode.Size]; | ||
162 | |||
163 | // locked whilst running on the microthread stack (or about to run on it or just ran on it) | ||
164 | private Object m_RunLock = new Object(); | ||
165 | |||
166 | // script won't step while > 0. bus-atomic updates only. | ||
167 | private int m_SuspendCount = 0; | ||
168 | |||
169 | // don't run any of script until this time | ||
170 | // or until one of these events are queued | ||
171 | public DateTime m_SleepUntil = DateTime.MinValue; | ||
172 | public int m_SleepEventMask1 = 0; | ||
173 | public int m_SleepEventMask2 = 0; | ||
174 | |||
175 | private XMRLSL_Api m_XMRLSLApi; | ||
176 | |||
177 | /* | ||
178 | * We will use this microthread to run the scripts event handlers. | ||
179 | */ | ||
180 | private IScriptUThread microthread; | ||
181 | |||
182 | /* | ||
183 | * Set to perform migration. | ||
184 | */ | ||
185 | public bool stackFramesRestored; // set true by CheckRun() when stack has been | ||
186 | // restored and is about to suspend the microthread | ||
187 | public bool captureStackFrames; // set true to tell CheckRun() to throw a | ||
188 | // StackCaptureException() causing it to capture a | ||
189 | // snapshot of the script's stack | ||
190 | |||
191 | /* | ||
192 | * Makes sure migration data version is same on both ends. | ||
193 | */ | ||
194 | public static byte migrationVersion = 10; | ||
195 | |||
196 | // Incremented each time script gets reset. | ||
197 | public int m_ResetCount = 0; | ||
198 | |||
199 | // Scripts start suspended now. This means that event queues will | ||
200 | // accept events, but will not actually run them until the core | ||
201 | // tells it it's OK. This is needed to prevent loss of link messages | ||
202 | // in complex objects, where no event can be allowed to run until | ||
203 | // all possible link message receivers' queues are established. | ||
204 | // Guarded by m_QueueLock. | ||
205 | public bool m_Suspended = true; | ||
206 | |||
207 | // We really don't want to save state for a script that hasn't had | ||
208 | // a chance to run, because it's state will be blank. That would | ||
209 | // cause attachment state loss. | ||
210 | public bool m_HasRun = false; | ||
211 | |||
212 | // When llDie is executed within the attach(NULL_KEY) event of | ||
213 | // a script being detached to inventory, the DeleteSceneObject call | ||
214 | // it causes will delete the script instances before their state can | ||
215 | // be saved. Therefore, the instance needs to know that it's being | ||
216 | // detached to inventory, rather than to ground. | ||
217 | // Also, the attach(NULL_KEY) event needs to run with priority, and | ||
218 | // it also needs to have a limited quantum. | ||
219 | // If this is nonzero, we're detaching to inventory. | ||
220 | // Guarded by m_QueueLock. | ||
221 | private int m_DetachQuantum = 0; | ||
222 | |||
223 | // Finally, we need to wait until the quantum is done, or the script | ||
224 | // suspends itself. This should be efficient, so we use an event | ||
225 | // for it instead of spinning busy. | ||
226 | // It's born ready, but will be reset when the detach is posted. | ||
227 | // It will then be set again on suspend/completion | ||
228 | private ManualResetEvent m_DetachReady = new ManualResetEvent(true); | ||
229 | } | ||
230 | } | ||