logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Looking for testers for the NWScript accelerator plugin
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Sun Jun 05, 2011 20:37    Post subject: Looking for testers for the NWScript accelerator plugin Reply with quote

Note: The release build and release thread can be found here: http://www.nwnx.org/phpBB2/viewtopic.php?t=1803

-- old/prerelease thread follows --

This is a pre-release build; I'll create a new thread when the plugin is fully released.

I'm looking for some PW admins willing to try out the new NWScript accelerator plugin (xp_AuroraServerNWScript). This plugin makes scripts run faster on the server by turning them into native code instead of running them in the comparatively slower NWScript interpreter. No changes to scripts should be necessary for them to work with the plugin; things should seamlessly be faster.

If you're willing to give the plugin a shot and give feedback if something goes wrong, here's a link to the current build with installation instructions:

http://valera-ext.nynaeve.net/~skywing/nwn2/AuroraServerNWScript.zip

Source code for plugin: http://valera-ext.nynaeve.net/~skywing/nwn2/AuroraServerNWScriptSrc.zip

(Some libraries from the NWN2 Datafile Accessor Library package are used; a link to the source code for those libraries is included in the readme.)

Internally, the plugin works by turning compiled NWScript script files (*.ncs) into .NET MSIL instructions, which the .NET runtime JIT's to native code. Scripts are compiled to native code on the fly the first time they are used by the server in a particular session, so there is no extra step required to update scripts on the module (other than to restart the server).

The plugin also fixes several other issues:

- Some unused debugging code in the server causes the server's CPU and memory usage to gradually rise while no players are logged on (dropping off again once a player logs on). This has been an issue in the game since 1.00; the plugin fixes this bug.
- The plugin fixes issues where malformed scripts can crash the server (or worse) through execution stack mismanagement. This has been a problem since 1.00.
- The plugin fixes an issue where using ExecuteScript on a script that takes parameters may crash the server, or cause garbage data to be returned for script arguments. It is still not recommended to rely on this, as servers without the plugin won't work correctly here. This has been a problem since 1.00.

--

I'm especially interested in the following:

- Problems installing the plugin or getting it setup correctly (bad/incomplete installation documentation?)

- Problems with scripts not running correctly? If so, please provide the scripts in question that are broken. You can set DebugLevel=3 in the ini file to help track this down (however, this causes the plugin log file to grow very fast, as every single engine function call has all parameters logged to the log file).


Last edited by Skywing on Tue Jul 05, 2011 22:00; edited 1 time in total
Back to top
View user's profile Send private message
Vanes^



Joined: 05 Jun 2011
Posts: 4

PostPosted: Sun Jun 05, 2011 22:21    Post subject: Reply with quote

Signing up for duty.
Back to top
View user's profile Send private message
PNJ



Joined: 30 Jun 2007
Posts: 67

PostPosted: Thu Jun 09, 2011 22:03    Post subject: Reply with quote

Testing it !

Edit : It seem, many script are not fired on the PW with it, gonna take a look for the log at home after work.
Back to top
View user's profile Send private message
PNJ



Joined: 30 Jun 2007
Posts: 67

PostPosted: Fri Jun 10, 2011 17:35    Post subject: Reply with quote

SkyWing, where can i send you , log with error and script associated to ?
Back to top
View user's profile Send private message
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Fri Jun 10, 2011 18:00    Post subject: Reply with quote

Sent you a PM; drop me a mail with it.
Back to top
View user's profile Send private message
Senalaya



Joined: 29 Dec 2004
Posts: 82
Location: Germany

PostPosted: Sun Jun 12, 2011 17:43    Post subject: Reply with quote

We've installed the plugin on our test server (Dragoncoast.org (TEST) - Depths of Norhaven) now and we'll keep you posted about findings.
Back to top
View user's profile Send private message
Developer Silver



Joined: 05 Jul 2011
Posts: 16

PostPosted: Tue Jul 05, 2011 17:22    Post subject: Reply with quote

Hi Skywing,
I've added this plugin in our PW, but suddenly I've encountered some errors and server crash: ASAP I'll try to reproduce errors in development environment and I'll send you the report: how can I contact you?

P.S.: everytime a groundbreaking plugin! Very Happy
_________________
Developer Silver
Faerūn Nights Admin
Back to top
View user's profile Send private message Visit poster's website
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Tue Jul 05, 2011 22:01    Post subject: Reply with quote

Please drop me the nwn2_servererrorlog.txt file from the NWN2 install dir, the minidump ("nwn2server" without extension in the NWN2 install dir, be sure to enable view extensions in Explorer to find it), and the plugin log file (from the NWNX4 install dir). You may need to click Show compatibility files for the NWN2 install dir parts.
Back to top
View user's profile Send private message
Developer Silver



Joined: 05 Jul 2011
Posts: 16

PostPosted: Wed Jul 06, 2011 0:21    Post subject: Reply with quote

Ok, I can reproduce server crash in development environment, so I've deeply analyzed the problem. Smile
Crash occurs in OnPcLoaded script, when a PC login, only with xp_bugfix plugin enabled (version 1.0.10).
I've sliced my script in many little chunks and I've found a bunch of code lines causing crash, so I've reduced my script only to these lines. With this script server crashes, and every edit avoid the crash (every line is mandatory to crash Razz ).

In nwn2_server_errorlog.txt I've noticed
Quote:
Application Stage: Moving Player 0 to Area 1

as cause of server error, and in AuroraServerNWScript.log I've seen
Quote:
[2011-07-05 22:03:40] NWScriptProgram: Exception: 'StackPush failed.', stack: in NWScript.NWScriptProgram.PushVariablesToStack(INWScriptStack* Stack, Object[] Vars)
in NWScript.NWScriptProgram.PushSavedState(NWScriptSavedState SourceState, INWScriptStack* Stack, UInt32* ResumeMethodId, UInt32* ResumeMethodPC, UInt32* SaveGlobalCount, UInt32* SaveLocalCount, UInt32* CurrentActionObjectSelf).
[2011-07-05 22:03:40] ServerNWScriptPlugin::SaveStateToServerVMStack: ERROR: NWScriptRuntime::StoreSavedStateToStack failed with exception 'Failed to push script situation.'.

at the crash time.

This is my OnPcLoaded crashing script:
Code:

#include "nwnx_sql"

location LoadPGLocation(object oPC) {
    string sStartLoc = SQLLocationToString(GetStartingLocation());   // Generate a string from location (valid or invalid no matter)
   location lSaved = SQLStringToLocation(sStartLoc);            // Assign a location with SQLStringToLocation()
   lSaved = GetStartingLocation();                           // Reassign a valid location
   AssignCommand(oPC, ActionJumpToLocation(lSaved));            // Use location to Jump PC
   return lSaved;                                       // Return location
}


void main() {
   // Call a function with a location as returning value (ignored)
   LoadPGLocation(GetEnteringObject());
}


Here you'll find the files you've asked for: http://dl.dropbox.com/u/9981963/CrashReport.7z

If you need more information, I'm here. Smile
_________________
Developer Silver
Faerūn Nights Admin
Back to top
View user's profile Send private message Visit poster's website
Developer Silver



Joined: 05 Jul 2011
Posts: 16

PostPosted: Wed Jul 06, 2011 0:26    Post subject: Reply with quote

Developer Silver wrote:
with xp_bugfix plugin enabled (version 1.0.10)

I've just tested with xp_bugfix 1.0.13 (I've not seen it before Rolling Eyes ) and I've obtained same results.
_________________
Developer Silver
Faerūn Nights Admin
Back to top
View user's profile Send private message Visit poster's website
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Wed Jul 06, 2011 1:48    Post subject: Reply with quote

Thanks for the preliminary investigation, repro steps, and crash dump; this looks like a bug. I'll investigate further shortly; I suspect the problem relates to saving a script situation that deals with an engine structure in the local list as you are with the AssignCommand(..., ActionJumpToLocation(lSaved)).

0:000> .cxr 0018f36c
eax=000006aa ebx=0000000d ecx=10e4b698 edx=000006ab esi=10e4b698 edi=09e08608
eip=00436150 esp=0018f654 ebp=10e4b698 iopl=0 nv up ei pl nz na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00210206
nwn2server!CExoString::operator=+0x20:
00436150 8a08 mov cl,byte ptr [eax] ds:002b:000006aa=??
0:000> .exr 0018f31c
ExceptionAddress: 00436150 (nwn2server!CExoString::operator=+0x00000020)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 00000000
Parameter[1]: 000006aa
Attempt to read from address 000006aa
0:000> k
*** Stack trace for last set context - .thread/.cxr resets it
ChildEBP RetAddr
0018f65c 00727cce nwn2server!CExoString::operator=+0x20
0018f674 00728322 nwn2server!CVirtualMachineStack::CopyFromStack+0x27e
0018f6ac 006b52b5 nwn2server!CVirtualMachine::StackPopCommand_Internal+0x142
0018f6c8 0067c8c8 nwn2server!CNWVirtualMachineCommands::ExecuteCommandAssignCommand+0x45
0018f6d8 73e8fdfa nwn2server!CNWVirtualMachineCommands::ExecuteCommand+0x28
0018f748 73e905fc xp_AuroraServerNWScript!NWScriptBridge::ExecuteActionServiceHandler+0x1c [c:\users\skywing\documents\source\nwn2dev\auroraservernwscript\nwscriptbridge.cpp @ 1137]
0018f87c 081f030c xp_AuroraServerNWScript!NWScriptBridge::OnExecuteActionFromJITFast+0x132 [c:\users\skywing\documents\source\nwn2dev\auroraservernwscript\nwscriptbridge.cpp @ 326]
WARNING: Frame IP not in any known module. Following frames may be wrong.
0018f8e4 73e9142b 0x81f030c
0018f9c0 679f2122 xp_AuroraServerNWScript!swutil::SharedPtr<NWScriptJITLib::Program>::~SharedPtr<NWScriptJITLib::Program>+0x12 [c:\users\skywing\documents\source\nwn2dev\skywingutils\ref\ref.h @ 557]
0018f9d0 73e93190 clr!IJWNOADThunkJumpTarget+0x17
0018fa2c 73e9433f xp_AuroraServerNWScript!NWScriptJITLib::ExecuteScript+0xa1 [c:\users\skywing\documents\source\nwn2dev\nwnscriptjit\nwscriptjitlib.h @ 205]
0018fb4c 73e94887 xp_AuroraServerNWScript!NWScriptRuntime::ExecuteScriptForServer+0x3f9 [c:\users\skywing\documents\source\nwn2dev\auroraservernwscript\nwscriptruntime.cpp @ 365]
0018fb8c 73e8e42b xp_AuroraServerNWScript!ServerNWScriptPlugin::ExecuteScriptForServer+0x48 [c:\users\skywing\documents\source\nwn2dev\auroraservernwscript\servernwscript.cpp @ 660]
0018fba4 00729f86 xp_AuroraServerNWScript!NWN2Server::CVirtualMachine::ExecuteCode+0x26 [c:\users\skywing\documents\source\nwn2dev\auroraservernwscript\hooks.cpp @ 96]
0018fbd8 0072b207 nwn2server!CVirtualMachine::RunScriptFile+0x66
0018fbfc 0072b3b0 nwn2server!CVirtualMachine::RunScript+0x1b7
0018fc24 006121dd nwn2server!CVirtualMachine::RunScript+0x30
0018fc54 0066f28e nwn2server!CNWSModule::EventHandler+0x43d
0018fd50 0059a550 nwn2server!CServerAIMaster::UpdateState+0x27e
0018fd70 0054a3bf nwn2server!CServerExoAppInternal::MainLoop+0x100
0018fd78 0040b19d nwn2server!CServerExoApp::MainLoop+0xf
0018fe5c 0040b42f nwn2server!WinMainInternal+0x11ad [d:\nwn2\code_123\game\nwserver\main.cpp @ 573]
0018fe9c 00748390 nwn2server!WinMain+0x4f [d:\nwn2\code_123\game\nwserver\main.cpp @ 311]
0018ff2c 10002999 nwn2server!__tmainCRTStartup+0x140 [f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 589]
0018ff88 74a533ca NWNX4_Hook+0x2999
0018ff94 770c9ed2 kernel32!BaseThreadInitThunk+0xe
0018ffd4 770c9ea5 ntdll!__RtlUserThreadStart+0x70
0018ffec 00000000 ntdll!_RtlUserThreadStart+0x1b
Back to top
View user's profile Send private message
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Wed Jul 06, 2011 3:24    Post subject: Reply with quote

The problem here relates to a situation where:

a) A script situation is created (i.e. call to engine function with an argument of type 'action'), and
b) The current function returns a value of an engine structure type

In this case the compiler is directing the script execution environment to save the return value (retval) as a part of the script situation locals, even though the script situation never writes to or reads from that local. The retval local is never initialized from its default value prior to the script situation being created as it is only written during the epilog sequence for the script function. Normally this is ok, but the script situation save code in the JIT requires that all engine structures be initialized to a default engine structure and not NULL, which doesn't happen here as we never observed a write to the engine structure before the script situation.

The fact that the server crashed afterwards is a separate bug with a failed attempt to set up a script situation not being rolled back correctly by the code that interfaces the JIT system with the BioWare script VM.

Here's the native code we're emitting for LoadPGLocation():

Code:


0:000> !u 20220301
Normal JIT generated code
NWScript.JITCode.gui_satest1.ScriptProgram.NWScriptSubroutine_29(UInt32)
Begin 20220200, size 13b
20220200 55              push    ebp
20220201 8bec            mov     ebp,esp
20220203 57              push    edi
20220204 56              push    esi
20220205 53              push    ebx
20220206 83ec10          sub     esp,10h
20220209 33c0            xor     eax,eax
2022020b 8945ec          mov     dword ptr [ebp-14h],eax
2022020e 8955f0          mov     dword ptr [ebp-10h],edx
20220211 8bf1            mov     esi,ecx
20220213 8b4610          mov     eax,dword ptr [esi+10h]
20220216 40              inc     eax
20220217 894610          mov     dword ptr [esi+10h],eax
2022021a 3d80000000      cmp     eax,80h
2022021f 0f83ea000000    jae     2022030f
20220225 8b4e08          mov     ecx,dword ptr [esi+8]
20220228 6a00            push    0
2022022a ba9b010000      mov     edx,19Bh
2022022f ff1510602220    call    dword ptr ds:[20226010h]
20220235 8b4e04          mov     ecx,dword ptr [esi+4]
20220238 3909            cmp     dword ptr [ecx],ecx
2022023a e8e100dbf7      call    17fd0320 (NWScript.NWScriptJITIntrinsics.Intrinsic_VMStackPopEngineStructure2(), mdToken: 0600007c)
2022023f 8945e4          mov     dword ptr [ebp-1Ch],eax
20220242 8bd0            mov     edx,eax
20220244 8bce            mov     ecx,esi
20220246 ff1560dc2220    call    dword ptr ds:[2022DC60h] (NWScript.JITCode.gui_satest1.ScriptProgram.NWScriptSubroutine_163(NWScript.NWScriptEngineStructure2), mdToken: 06000006)
2022024c 8945e8          mov     dword ptr [ebp-18h],eax
2022024f 8b4e04          mov     ecx,dword ptr [esi+4]
20220252 3909            cmp     dword ptr [ecx],ecx
20220254 e8c730dbf7      call    17fd3320 (NWScript.NWScriptJITIntrinsics.Intrinsic_CreateEngineStructure2(), mdToken: 0600007e)
20220259 8b55e8          mov     edx,dword ptr [ebp-18h]
2022025c 8bce            mov     ecx,esi
2022025e ff156cdc2220    call    dword ptr ds:[2022DC6Ch] (NWScript.JITCode.gui_satest1.ScriptProgram.NWScriptSubroutine_496(System.String), mdToken: 06000007)
20220264 8b4e08          mov     ecx,dword ptr [esi+8]
20220267 6a00            push    0
20220269 ba9b010000      mov     edx,19Bh
2022026e ff1514602220    call    dword ptr ds:[20226014h]
20220274 8b4e04          mov     ecx,dword ptr [esi+4]
20220277 3909            cmp     dword ptr [ecx],ecx
20220279 e8a200dbf7      call    17fd0320 (NWScript.NWScriptJITIntrinsics.Intrinsic_VMStackPopEngineStructure2(), mdToken: 0600007c)
2022027e 8bf8            mov     edi,eax
20220280 897de4          mov     dword ptr [ebp-1Ch],edi
20220283 ba04000000      mov     edx,4
20220288 b9e242356d      mov     ecx,offset mscorlib_ni+0x42e2 (6d3542e2)
2022028d e8c21e30f2      call    12522154 (JitHelp: CORINFO_HELP_NEWARR_1_OBJ)
20220292 8bd8            mov     ebx,eax
20220294 57              push    edi
20220295 8bcb            mov     ecx,ebx
20220297 33d2            xor     edx,edx
20220299 e89625074e      call    clr!JIT_Stelem_Ref (6e292834)
2022029e ff75e8          push    dword ptr [ebp-18h]
202202a1 8bcb            mov     ecx,ebx
202202a3 ba01000000      mov     edx,1
202202a8 e88725074e      call    clr!JIT_Stelem_Ref (6e292834)
202202ad b9e49f666d      mov     ecx,offset mscorlib_ni+0x319fe4 (6d669fe4) (MT: System.UInt32)
202202b2 e8691d30f2      call    12522020 (JitHelp: CORINFO_HELP_NEWSFAST)
202202b7 8bf8            mov     edi,eax
202202b9 8b45f0          mov     eax,dword ptr [ebp-10h]
202202bc 894704          mov     dword ptr [edi+4],eax
202202bf 57              push    edi
202202c0 8bcb            mov     ecx,ebx
202202c2 ba02000000      mov     edx,2
202202c7 e86825074e      call    clr!JIT_Stelem_Ref (6e292834)
202202cc ff75ec          push    dword ptr [ebp-14h]
202202cf 8bcb            mov     ecx,ebx
202202d1 ba03000000      mov     edx,3
202202d6 e85925074e      call    clr!JIT_Stelem_Ref (6e292834)
202202db 8b7e08          mov     edi,dword ptr [esi+8]
202202de 53              push    ebx
202202df 6a5d            push    5Dh
202202e1 6a00            push    0
202202e3 8bce            mov     ecx,esi
202202e5 ff1564dd2220    call    dword ptr ds:[2022DD64h] (NWScript.JITCode.gui_satest1.ScriptProgram.CloneScriptProgram(), mdToken: 06000002)
202202eb 50              push    eax
202202ec 8bcf            mov     ecx,edi
202202ee 33d2            xor     edx,edx
202202f0 ff1518602220    call    dword ptr ds:[20226018h]
202202f6 8b55f0          mov     edx,dword ptr [ebp-10h]
202202f9 8bce            mov     ecx,esi
202202fb ff1590dc2220    call    dword ptr ds:[2022DC90h] (NWScript.JITCode.gui_satest1.ScriptProgram.ExecuteActionService_6_1_AssignCommand(UInt32), mdToken: 0600000a)
>>> 20220301 ff4e10          dec     dword ptr [esi+10h]
20220304 8b45e4          mov     eax,dword ptr [ebp-1Ch]
20220307 8d65f4          lea     esp,[ebp-0Ch]
2022030a 5b              pop     ebx
2022030b 5e              pop     esi
2022030c 5f              pop     edi
2022030d 5d              pop     ebp
2022030e c3              ret
2022030f b98cfb666d      mov     ecx,offset mscorlib_ni+0x31fb8c (6d66fb8c) (MT: System.Exception)
20220314 e8071d30f2      call    12522020 (JitHelp: CORINFO_HELP_NEWSFAST)
20220319 8bf0            mov     esi,eax
2022031b ba58b92220      mov     edx,2022B958h
20220320 b905000070      mov     ecx,offset comctl32!_imp__RegCloseKey <PERF> (comctl32+0x5) (70000005)
20220325 e81f320f4e      call    clr!JIT_StrCns (6e313549)
2022032a 8bd0            mov     edx,eax
2022032c 8bce            mov     ecx,esi
2022032e e821118f4d      call    mscorlib_ni+0x7c1454 (6db11454) (System.Exception..ctor(System.String), mdToken: 0600001e)
20220333 8bce            mov     ecx,esi
20220335 e854fb0e4e      call    clr!IL_Throw (6e30fe8e)
2022033a cc              int     3


Note in particular the code here in setup for a script situation save:

Code:
202202cc ff75ec          push    dword ptr [ebp-14h]
202202cf 8bcb            mov     ecx,ebx
202202d1 ba03000000      mov     edx,3
202202d6 e85925074e      call    clr!JIT_Stelem_Ref (6e292834)


[ebp-14h] only being initialized to NULL at the top and never written before:

Code:
20220209 33c0            xor     eax,eax
2022020b 8945ec          mov     dword ptr [ebp-14h],eax


This matches the MSIL emitted for the function (note V_0/loc.0 never written before IL_00ce, with V_0/loc.0 corresponding to [ebp-14h] in the JIT'd code):

Code:
.method private instance class [NWNScriptJITIntrinsics]NWScript.NWScriptEngineStructure2
        NWScriptSubroutine_LoadPGLocation(uint32 A_1) cil managed
{
  // Code size       291 (0x123)
  .maxstack  14
  .locals init (class [NWNScriptJITIntrinsics]NWScript.NWScriptEngineStructure2 V_0,
           uint32 V_1,
           string V_2,
           class [NWNScriptJITIntrinsics]NWScript.NWScriptEngineStructure2 V_3,
           string V_4,
           class [NWNScriptJITIntrinsics]NWScript.NWScriptEngineStructure2 V_5,
           object[] V_6,
           object[] V_7)
  IL_0000:  ldarg.0
  IL_0001:  ldarg.0
  IL_0002:  ldfld      uint32 NWScript.JITCode.gui_satest1.ScriptProgram::m_CallDepth
  IL_0007:  ldc.i4.1
  IL_0008:  add
  IL_0009:  dup
  IL_000a:  stloc.1
  IL_000b:  stfld      uint32 NWScript.JITCode.gui_satest1.ScriptProgram::m_CallDepth
  IL_0010:  ldloc.1
  IL_0011:  ldc.i4     0x80
  IL_0016:  clt.un
  IL_0018:  brtrue.s   IL_0025
  IL_001a:  ldstr      "Maximum call depth exceeded."
  IL_001f:  newobj     instance void [mscorlib]System.Exception::.ctor(string)
  IL_0024:  throw
  IL_0025:  ldstr      ""
  IL_002a:  stloc.2
  IL_002b:  ldarg.0
  IL_002c:  ldfld      class [NWNScriptJITIntrinsics]NWScript.INWScriptProgram NWScript.JITCode.gui_satest1.ScriptProgram::m_ProgramInterface
  IL_0031:  ldc.i4     0x19b
  IL_0036:  conv.u4
  IL_0037:  ldc.i4     0x0
  IL_003c:  conv.u4
  IL_003d:  callvirt   instance void [NWNScriptJITIntrinsics]NWScript.INWScriptProgram::Intrinsic_ExecuteActionService(uint32,
                                                                                                                       uint32)
  IL_0042:  ldarg.0
  IL_0043:  ldfld      class [NWNScriptJITIntrinsics]NWScript.NWScriptJITIntrinsics NWScript.JITCode.gui_satest1.ScriptProgram::m_ProgramJITIntrinsics
  IL_0048:  callvirt   instance class [NWNScriptJITIntrinsics]NWScript.NWScriptEngineStructure2 [NWNScriptJITIntrinsics]NWScript.NWScriptJITIntrinsics::Intrinsic_VMStackPopEngineStructure2()
  IL_004d:  stloc.3
  IL_004e:  ldarg.0
  IL_004f:  ldloc.3
  IL_0050:  call       instance string NWScript.JITCode.gui_satest1.ScriptProgram::NWScriptSubroutine_SQLLocationToString(class [NWNScriptJITIntrinsics]NWScript.NWScriptEngineStructure2)
  IL_0055:  stloc.2
  IL_0056:  ldarg.0
  IL_0057:  ldfld      class [NWNScriptJITIntrinsics]NWScript.NWScriptJITIntrinsics NWScript.JITCode.gui_satest1.ScriptProgram::m_ProgramJITIntrinsics
  IL_005c:  callvirt   instance class [NWNScriptJITIntrinsics]NWScript.NWScriptEngineStructure2 [NWNScriptJITIntrinsics]NWScript.NWScriptJITIntrinsics::Intrinsic_CreateEngineStructure2()
  IL_0061:  stloc.3
  IL_0062:  ldloc.2
  IL_0063:  stloc.s    V_4
  IL_0065:  ldarg.0
  IL_0066:  ldloc.s    V_4
  IL_0068:  call       instance class [NWNScriptJITIntrinsics]NWScript.NWScriptEngineStructure2 NWScript.JITCode.gui_satest1.ScriptProgram::NWScriptSubroutine_SQLStringToLocation(string)
  IL_006d:  stloc.3
  IL_006e:  ldarg.0
  IL_006f:  ldfld      class [NWNScriptJITIntrinsics]NWScript.INWScriptProgram NWScript.JITCode.gui_satest1.ScriptProgram::m_ProgramInterface
  IL_0074:  ldc.i4     0x19b
  IL_0079:  conv.u4
  IL_007a:  ldc.i4     0x0
  IL_007f:  conv.u4
  IL_0080:  callvirt   instance void [NWNScriptJITIntrinsics]NWScript.INWScriptProgram::Intrinsic_ExecuteActionService(uint32,
                                                                                                                       uint32)
  IL_0085:  ldarg.0
  IL_0086:  ldfld      class [NWNScriptJITIntrinsics]NWScript.NWScriptJITIntrinsics NWScript.JITCode.gui_satest1.ScriptProgram::m_ProgramJITIntrinsics
  IL_008b:  callvirt   instance class [NWNScriptJITIntrinsics]NWScript.NWScriptEngineStructure2 [NWNScriptJITIntrinsics]NWScript.NWScriptJITIntrinsics::Intrinsic_VMStackPopEngineStructure2()
  IL_0090:  stloc.s    V_5
  IL_0092:  ldloc.s    V_5
  IL_0094:  stloc.3
  IL_0095:  ldnull
  IL_0096:  stloc.s    V_7
  IL_0098:  ldc.i4     0x4
  IL_009d:  newarr     [mscorlib]System.Object
  IL_00a2:  stloc.s    V_6
  IL_00a4:  ldloc.s    V_6
  IL_00a6:  ldc.i4     0x0
  IL_00ab:  ldloc.3
  IL_00ac:  stelem.ref
  IL_00ad:  ldloc.s    V_6
  IL_00af:  ldc.i4     0x1
  IL_00b4:  ldloc.2
  IL_00b5:  stelem.ref
  IL_00b6:  ldloc.s    V_6
  IL_00b8:  ldc.i4     0x2
  IL_00bd:  ldarg      A_1
  IL_00c1:  box        [mscorlib]System.UInt32
  IL_00c6:  stelem.ref
  IL_00c7:  ldloc.s    V_6
  IL_00c9:  ldc.i4     0x3
  IL_00ce:  ldloc.0
  IL_00cf:  stelem.ref
  IL_00d0:  ldarg.0
  IL_00d1:  ldfld      class [NWNScriptJITIntrinsics]NWScript.INWScriptProgram NWScript.JITCode.gui_satest1.ScriptProgram::m_ProgramInterface
  IL_00d6:  ldloc.s    V_7
  IL_00d8:  ldloc.s    V_6
  IL_00da:  ldc.i4     0x5d
  IL_00df:  conv.u4
  IL_00e0:  ldc.i4     0x0
  IL_00e5:  conv.u4
  IL_00e6:  ldarg.0
  IL_00e7:  call       instance class [NWNScriptJITIntrinsics]NWScript.IGeneratedScriptProgram NWScript.JITCode.gui_satest1.ScriptProgram::CloneScriptProgram()
  IL_00ec:  callvirt   instance void [NWNScriptJITIntrinsics]NWScript.INWScriptProgram::Intrinsic_StoreState(object[],
                                                                                                             object[],
                                                                                                             uint32,
                                                                                                             uint32,
                                                                                                             class [NWNScriptJITIntrinsics]NWScript.IGeneratedScriptProgram)
  IL_00f1:  ldnull
  IL_00f2:  stloc.s    V_7
  IL_00f4:  ldnull
  IL_00f5:  stloc.s    V_6
  IL_00f7:  br         IL_00fc
  IL_00fc:  ldarg      A_1
  IL_0100:  stloc.1
  IL_0101:  ldarg.0
  IL_0102:  ldloc.1
  IL_0103:  call       instance void NWScript.JITCode.gui_satest1.ScriptProgram::ExecuteActionService_6_1_AssignCommand(uint32)
  IL_0108:  ldloc.3
  IL_0109:  stloc.s    V_5
  IL_010b:  ldloc.s    V_5
  IL_010d:  stloc.0
  IL_010e:  br         IL_0113
  IL_0113:  ldarg.0
  IL_0114:  ldarg.0
  IL_0115:  ldfld      uint32 NWScript.JITCode.gui_satest1.ScriptProgram::m_CallDepth
  IL_011a:  ldc.i4.m1
  IL_011b:  add
  IL_011c:  stfld      uint32 NWScript.JITCode.gui_satest1.ScriptProgram::m_CallDepth
  IL_0121:  ldloc.0
  IL_0122:  ret
} // end of method ScriptProgram::NWScriptSubroutine_LoadPGLocation


This matches the IR the analyzer emitted for LoadPGLocation. Here, 00000001026CF550 correspond to the MSIL V_0/loc.0:

Code:
Printing IR for function 0000001D (LoadPGLocation)
label 0000001D:
0000001D: CREATE 00000001026CFBD0 ( string )
0000001D: INITIALIZE 00000001026CFBD0 ( string )
0000001F: CREATE 00000001026CFD10 ( temp SSA location )
0000001F: ACTION 019B (GetStartingLocation) (0) 00000001026CFD10 ( temp SSA location )
00000024: CALL   000000A3 (SQLLocationToString) 00000001026CFBD0 ( string ), 00000001026CFD10 ( temp SSA location )
00000024: DELETE 00000001026CFD10 ( temp SSA location )
0000002A: CREATE 00000001026CFDD0 ( location )
0000002A: INITIALIZE 00000001026CFDD0 ( location )
0000002C: CREATE 00000001026CFE90 ( temp SSA string )
0000002C: ASSIGN 00000001026CFE90 ( temp SSA string ), 00000001026CFBD0 ( string )
00000034: CALL   000001F0 (SQLStringToLocation) 00000001026CFDD0 ( location ), 00000001026CFE90 ( temp SSA string )
00000034: DELETE 00000001026CFE90 ( temp SSA string )
0000003A: CREATE 00000001026D0050 ( temp SSA location )
0000003A: ACTION 019B (GetStartingLocation) (0) 00000001026D0050 ( temp SSA location )
0000003F: ASSIGN 00000001026CFDD0 ( location ), 00000001026D0050 ( temp SSA location )
00000047: DELETE 00000001026D0050 ( temp SSA location )
0000004D: SAVE_STATE 0000005D () 00000001026CFDD0 ( location ), 00000001026CFBD0 ( string ), 00000001026CF590 ( param object ), 00000001026CF550 ( retval location )
          goto   0000006C
label 0000006C:
0000006C: CREATE 00000001026D01D0 ( temp SSA object )
0000006C: ASSIGN 00000001026D01D0 ( temp SSA object ), 00000001026CF590 ( param object )
00000074: ACTION 0006 (AssignCommand) (2) 00000001026D01D0 ( temp SSA object )
00000074: DELETE 00000001026D01D0 ( temp SSA object )
00000079: CREATE 00000001026D0310 ( temp SSA location )
00000079: ASSIGN 00000001026D0310 ( temp SSA location ), 00000001026CFDD0 ( location )
00000081: ASSIGN 00000001026CF550 ( retval location ), 00000001026D0310 ( temp SSA location )
00000089: DELETE 00000001026D0310 ( temp SSA location )
00000089: DELETE 00000001026CFDD0 ( location )
00000089: DELETE 00000001026CFBD0 ( string )
          goto   0000009B
label 0000009B:
0000009B: DELETE 00000001026CF590 ( param object )
000000A1: RETN   


Note in particular that the return value "00000001026CF550" is visible to the script situation and requested to be saved by the IR at 0000004D, but we don't write to the return value until later on at 00000081.

As expected the script situation restore code at 0000005D doesn't use the retval that was saved:

Code:
Printing IR for function 0000005D (script situation) ()
label 0000005D:
0000005D: CREATE 00000001026EC4F0 ( temp SSA location )
0000005D: ASSIGN 00000001026EC4F0 ( temp SSA location ), 00000001026CF6D0 ( param location )
00000065: ACTION 00D6 (ActionJumpToLocation) (1) 00000001026EC4F0 ( temp SSA location )
00000065: DELETE 00000001026EC4F0 ( temp SSA location )
0000006A: RETN   


This corresponds to the NWScript instructions the compiler emitted:

Code:
0000002A 02 05                    RSADDS
0000002C 05 00 019B 00            ACTION GetStartingLocation(019B), 00
00000031 1E 00 0000007F           JSR fn_000000B0
00000037 02 12                    RSADDLOC
00000039 03 01 FFFFFFF8 0004      CPTOPSP FFFFFFF8, 0004
00000041 1E 00 000001BC           JSR fn_000001FD
00000047 05 00 019B 00            ACTION GetStartingLocation(019B), 00
0000004C 01 01 FFFFFFF8 0004      CPDOWNSP FFFFFFF8, 0004
00000054 1B 00 FFFFFFFC           MOVSP FFFFFFFC
0000005A 2C 10 00000000 00000010  STORE_STATE 10, 00000000, 00000010 << note saving 0x10 worth of stack space (0x10/4 == 0x4 elements on the stack, including return value)
00000064 1D 00 00000015           JMP off_00000079 << skip over script situation while in function body
0000006A 03 01 FFFFFFFC 0004      CPTOPSP FFFFFFFC, 0004 << script situation code here, takes topmost stack value (i.e. lSaved)
00000072 05 00 00D6 01            ACTION ActionJumpToLocation(00D6), 01
00000077 20 00                    RETN
00000079 03 01 FFFFFFF4 0004      CPTOPSP FFFFFFF4, 0004 << resume function body
00000081 05 00 0006 02            ACTION AssignCommand(0006), 02
00000086 03 01 FFFFFFFC 0004      CPTOPSP FFFFFFFC, 0004
0000008E 01 01 FFFFFFEC 0004      CPDOWNSP FFFFFFEC, 0004 << assign to retval
00000096 1B 00 FFFFFFF4           MOVSP FFFFFFF4
0000009C 1D 00 0000000C           JMP off_000000A8
000000A2 1B 00 FFFFFFF8           MOVSP FFFFFFF8
000000A8 1B 00 FFFFFFFC           MOVSP FFFFFFFC
000000AE 20 00                    RETN
Back to top
View user's profile Send private message
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Wed Jul 06, 2011 3:55    Post subject: Reply with quote

I've posted a patch release here:

http://www.nynaeve.net/Skywing/nwn2/xp_AuroraServerNWScript/AuroraServerNWScript.zip

Be sure to copy over all of the DLLs including NWNScriptJIT.dll.

- Fixes a code generation issue relating to scripts with a script function that both returns a return value of an engine structure type and calls an engine function with a parameter of type 'action'. For example, "location testfunc1() { AssignCommand(OBJECT_SELF, ActionWait(0.0f)); return GetStartingLocation(); }".

This should fix your issue. Thanks for the report; good find. (The fix is to emit code to preinitialize the return value of a function that creates a saved state and which has at least one return value of type engine structure.)
Back to top
View user's profile Send private message
Developer Silver



Joined: 05 Jul 2011
Posts: 16

PostPosted: Wed Jul 06, 2011 12:31    Post subject: Reply with quote

Skywing wrote:
I've posted a patch release [...] This should fix your issue

Ok, I've tried the new version in development environment and all scripts ran without problems. Smile
Now I've uploaded new plugin in PW and I'll let it run as long as possible to have extensive community test. Very Happy
Thank you very much for the lightning-fast fix! Cool
_________________
Developer Silver
Faerūn Nights Admin
Back to top
View user's profile Send private message Visit poster's website
Developer Silver



Joined: 05 Jul 2011
Posts: 16

PostPosted: Tue Jul 12, 2011 15:46    Post subject: Reply with quote

Uhm, today I've installed Release 2 of NWScript Accelerator plugin but suddenly NWNX hangs at boot time Shocked
It stalls at "* Loading plugins..." without any chance to go forward...

I've updated both files xp_AuroraServerNWScript.dll and AuroraServerNWScript.ini, but then I noticed also NWNScriptJIT.dll and NWNScriptJITIntrinsics.dll have changed, so I've updated these too, but nothing seems to resolve boot problem.
Any idea? Wink

P.S.: may I suggest to implement a new configuration key to make an excluding list from recompilation? Often there are a bunch of script which will never run more than 1 time (ex. OnModuleLoad) that will waste memory (our OnModuleLoad script allocate about 12Mb of memory ) Sad
_________________
Developer Silver
Faerūn Nights Admin
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group