New Generated Constructor & JIT Issue

Started by
7 comments, last by gjl 1 week, 4 days ago

Hi,

It has been a pretty long time…! I am finally updating to the latest WIP version, and I found an issue with the new generated copy constructor when using the JIT (still using the forked BlingMind JIT here).

When trying to JIT Compile these generated methods, the address returned by func->scriptData->byteCode.AddressOf() is NULL. func is the asScriptFunction returned by function->GetEngine()->GetFunctionById(asBC_INTARG(pOp)) on a asBC_CALL, and function is the function currently being compiled by the JIT in CompileFunction().

It used to crash the JIT compiler, but if I fix it and return false (because it cannot be compiled by the JIT), I get a warning for all copy constructors: "Function '%s' appears to have been compiled without JIT entry points".

This makes sense, but I guess there must be something wrong here. I have currently disabled this new capability, but maybe you want to have a look at it (or I need to change the way the JIT works?).

Advertisement

Thanks for letting me know. I'll check it, but I most likely just forgot to add the JIT entry for the auto generated copy constructor.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

No, that was not it.

JIT entries are being added in the new auto generated copy constructors too.

I don't know how BlindMind JIT is working, but it is possible that they didn't check what type of function it is before calling func→scriptData→byteCode.AddressOf(). The scriptData is only there for functions with function type asFUNC_SCRIPT, so maybe the function being called is actually a bound registered function (asFUNC_SYSTEM), or an interface method (asFUNC_INTERFACE), or a virtual method (asFUNC_VIRTUAL).

This is not new so I would assume BlindMind already had proper logic for handling this, but perhaps the new generated copy constructors somehow triggered a bug in the JIT compiler.

I don't discard a possible bug in my code, but I need more input from you to understand in what situation this happens. Can you provide a small script that reproduces the issue, and tell me for what script function the crash happens? That would help me investigate a bit further.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks for your explanation. It is indeed probably be a bug in the JIT compiler: it seems that upon asBC_ALLOC, it assumes that the constructor has to be a script (which used to be the case, indeed). It does not check the type of function and gets the bytecode directly. I managed to fix the crash by checking the bytecode, and in this case it fallbacks to the script engine - which is fine, but it triggers a warning from the script engine. I don't know (yet) how to avoid the warning!

Here is the smallest script that I could come up with that triggers the problem, which is a warning with the fix that checks if there is any bytecode, instead of crashing:

Warning: Function 'WarningIssue::WarningIssue(const WarningIssue&inout)' appears to have been compiled without JIT entry points in (0:0)

class WarningIssue
{
    file    f; // removing the file field fixes the problem
    int i=0;
};

WarningIssue  issue;

Actually maybe I am not understanding the signification of the warning well. It seems to be supposed to occur only if the JIT is called whereas the asEP_INCLUDE_JIT_INSTRUCTIONS flag is not set, and it is definitely set here.

angelcode 2014-02-09 16:19:57
Added a warning if JIT compiler is used without asEP_INCLUDE_JIT_INSTRUCTIONS turned on

	// as_scriptfunction.cpp line 1598
	if( !foundJitEntry )
	{
		asCString msg;
		msg.Format(TXT_NO_JIT_IN_FUNC_s, GetDeclaration());
		engine->WriteMessage("", 0, 0, asMSGTYPE_WARNING, msg.AddressOf());
	}

So maybe it is just a problem with the generated copy constructor that should not be JIT compiled or is missing some JIT entry points?

Thanks for the code snippet. It helped me find the bug.

The problem was that the auto generated copy constructor was not properly removed from the module when there was an error that prevented it from being generated (in this case the file type was not copyable). This lead to the attempt to JIT compile the malformed copy constructor that really shouldn't exist.

I've fixed this in revision 2913

https://sourceforge.net/p/angelscript/code/2913/

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks, will try it out!

Seems to be working perfectly fine now! Thanks a lot!

Advertisement