- allocate VMFunction's PrintableName from the ClassDataAllocator arena.

This avoids execution order issues on shutdown. VMFunction should not use FString.
This commit is contained in:
Christoph Oelckers 2023-05-23 23:01:17 +02:00
parent 7d30f1921c
commit 213bdbadad
15 changed files with 28 additions and 20 deletions

View file

@ -9151,7 +9151,7 @@ FxExpression *FxVMFunctionCall::Resolve(FCompileContext& ctx)
// [Player701] Catch attempts to call abstract functions directly at compile time
if (NoVirtual && Function->Variants[0].Implementation->VarFlags & VARF_Abstract)
{
ScriptPosition.Message(MSG_ERROR, "Cannot call abstract function %s", Function->Variants[0].Implementation->PrintableName.GetChars());
ScriptPosition.Message(MSG_ERROR, "Cannot call abstract function %s", Function->Variants[0].Implementation->PrintableName);
delete this;
return nullptr;
}

View file

@ -790,7 +790,7 @@ VMFunction *FFunctionBuildList::AddFunction(PNamespace *gnspc, const VersionInfo
it.PrintableName = name;
it.Function = new VMScriptFunction;
it.Function->Name = functype->SymbolName;
it.Function->PrintableName = name;
it.Function->PrintableName = ClassDataAllocator.Strdup(name);
it.Function->ImplicitArgs = functype->GetImplicitArgs();
it.Proto = nullptr;
it.FromDecorate = fromdecorate;

View file

@ -198,7 +198,7 @@ void InitImports()
{
assert(afunc->VMPointer != NULL);
*(afunc->VMPointer) = new VMNativeFunction(afunc->Function, afunc->FuncName);
(*(afunc->VMPointer))->PrintableName.Format("%s.%s [Native]", afunc->ClassName+1, afunc->FuncName);
(*(afunc->VMPointer))->PrintableName = ClassDataAllocator.Strdup(FStringf("%s.%s [Native]", afunc->ClassName+1, afunc->FuncName));
(*(afunc->VMPointer))->DirectNativeCall = afunc->DirectNative;
AFTable.Push(*afunc);
});

View file

@ -221,5 +221,5 @@ void FScopeBarrier::ValidateCall(PClass* selftype, VMFunction *calledfunc, int o
{
int innerside = FScopeBarrier::SideFromObjectFlags(selftype->VMType->ScopeFlags);
if ((outerside != innerside) && (innerside != FScopeBarrier::Side_PlainData))
ThrowAbortException(X_OTHER, "Cannot call %s function %s from %s context", FScopeBarrier::StringFromSide(innerside), calledfunc->PrintableName.GetChars(), FScopeBarrier::StringFromSide(outerside));
ThrowAbortException(X_OTHER, "Cannot call %s function %s from %s context", FScopeBarrier::StringFromSide(innerside), calledfunc->PrintableName, FScopeBarrier::StringFromSide(outerside));
}

View file

@ -528,7 +528,7 @@ void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction
}
else if (code[i].op == OP_CALL_K && callfunc)
{
printf_wrapper(out, " [%s]\n", callfunc->PrintableName.GetChars());
printf_wrapper(out, " [%s]\n", callfunc->PrintableName);
}
else
{

View file

@ -2798,7 +2798,7 @@ void ZCCCompiler::InitFunctions()
{
if (v->VarFlags & VARF_Abstract)
{
Error(c->cls, "Non-abstract class %s must override abstract function %s", c->Type()->TypeName.GetChars(), v->PrintableName.GetChars());
Error(c->cls, "Non-abstract class %s must override abstract function %s", c->Type()->TypeName.GetChars(), v->PrintableName);
}
}
}

View file

@ -35,7 +35,7 @@ JitFuncPtr JitCompile(VMScriptFunction *sfunc)
catch (const CRecoverableError &e)
{
OutputJitLog(logger);
Printf("%s: Unexpected JIT error: %s\n",sfunc->PrintableName.GetChars(), e.what());
Printf("%s: Unexpected JIT error: %s\n",sfunc->PrintableName, e.what());
return nullptr;
}
}
@ -237,7 +237,7 @@ void JitCompiler::Setup()
cc.comment(marks, 56);
FString funcname;
funcname.Format("Function: %s", sfunc->PrintableName.GetChars());
funcname.Format("Function: %s", sfunc->PrintableName);
cc.comment(funcname.GetChars(), funcname.Len());
cc.comment(marks, 56);
@ -364,7 +364,7 @@ void JitCompiler::SetupSimpleFrame()
if (errorDetails)
{
I_FatalError("JIT: inconsistent number of %s for function %s", errorDetails, sfunc->PrintableName.GetChars());
I_FatalError("JIT: inconsistent number of %s for function %s", errorDetails, sfunc->PrintableName);
}
for (int i = regd; i < sfunc->NumRegD; i++)

View file

@ -97,7 +97,7 @@ void JitCompiler::EmitVMCall(asmjit::X86Gp vmfunc, VMFunction *target)
call->setArg(2, Imm(B));
call->setArg(3, GetCallReturns());
call->setArg(4, Imm(C));
call->setInlineComment(target ? target->PrintableName.GetChars() : "VMCall");
call->setInlineComment(target ? target->PrintableName : "VMCall");
LoadInOuts();
LoadReturns(pc + 1, C);
@ -360,7 +360,7 @@ void JitCompiler::EmitNativeCall(VMNativeFunction *target)
asmjit::CBNode *cursorBefore = cc.getCursor();
auto call = cc.call(imm_ptr(target->DirectNativeCall), CreateFuncSignature());
call->setInlineComment(target->PrintableName.GetChars());
call->setInlineComment(target->PrintableName);
asmjit::CBNode *cursorAfter = cc.getCursor();
cc.setCursor(cursorBefore);

View file

@ -306,7 +306,7 @@ void *AddJitFunction(asmjit::CodeHolder* code, JitCompiler *compiler)
if (result == 0)
I_Error("RtlAddFunctionTable failed");
JitDebugInfo.Push({ compiler->GetScriptFunction()->PrintableName, compiler->GetScriptFunction()->SourceFileName, compiler->LineInfo, startaddr, endaddr });
JitDebugInfo.Push({ FString(compiler->GetScriptFunction()->PrintableName), compiler->GetScriptFunction()->SourceFileName, compiler->LineInfo, startaddr, endaddr });
#endif
return p;

View file

@ -450,7 +450,7 @@ public:
FName Name;
const uint8_t *RegTypes = nullptr;
TArray<TypedVMValue> DefaultArgs;
FString PrintableName; // so that the VM can print meaningful info if something in this function goes wrong.
const char * PrintableName = nullptr; // so that the VM can print meaningful info if something in this function goes wrong. (allocated from the memory arena)
class PPrototype *Proto;
TArray<uint32_t> ArgFlags; // Should be the same length as Proto->ArgumentTypes

View file

@ -895,7 +895,7 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
catch (CVMAbortException &err)
{
err.MaybePrintMessage();
err.stacktrace.AppendFormat("Called from %s\n", call->PrintableName.GetChars());
err.stacktrace.AppendFormat("Called from %s\n", call->PrintableName);
// PrintParameters(reg.param + f->NumParam - B, B);
throw;
}
@ -2000,7 +2000,7 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
catch (CVMAbortException &err)
{
err.MaybePrintMessage();
err.stacktrace.AppendFormat("Called from %s at %s, line %d\n", sfunc->PrintableName.GetChars(), sfunc->SourceFileName.GetChars(), sfunc->PCToLine(pc));
err.stacktrace.AppendFormat("Called from %s at %s, line %d\n", sfunc->PrintableName, sfunc->SourceFileName.GetChars(), sfunc->PCToLine(pc));
// PrintParameters(reg.param + f->NumParam - B, B);
throw;
}

View file

@ -277,7 +277,7 @@ static bool CanJit(VMScriptFunction *func)
if (func->NumRegA + func->NumRegD + func->NumRegF + func->NumRegS < maxregs)
return true;
Printf(TEXTCOLOR_ORANGE "%s is using too many registers (%d of max %d)! Function will not use native code.\n", func->PrintableName.GetChars(), func->NumRegA + func->NumRegD + func->NumRegF + func->NumRegS, maxregs);
Printf(TEXTCOLOR_ORANGE "%s is using too many registers (%d of max %d)! Function will not use native code.\n", func->PrintableName, func->NumRegA + func->NumRegD + func->NumRegF + func->NumRegS, maxregs);
return false;
}
@ -289,7 +289,7 @@ int VMScriptFunction::FirstScriptCall(VMFunction *func, VMValue *params, int num
// rather than let GZDoom crash.
if (func->VarFlags & VARF_Abstract)
{
ThrowAbortException(X_OTHER, "attempt to call abstract function %s.", func->PrintableName.GetChars());
ThrowAbortException(X_OTHER, "attempt to call abstract function %s.", func->PrintableName);
}
#ifdef HAVE_VM_JIT
if (vm_jit && CanJit(static_cast<VMScriptFunction*>(func)))
@ -320,7 +320,7 @@ int VMNativeFunction::NativeScriptCall(VMFunction *func, VMValue *params, int nu
catch (CVMAbortException &err)
{
err.MaybePrintMessage();
err.stacktrace.AppendFormat("Called from %s\n", func->PrintableName.GetChars());
err.stacktrace.AppendFormat("Called from %s\n", func->PrintableName);
throw;
}
}
@ -702,7 +702,7 @@ void CVMAbortException::MaybePrintMessage()
CVMAbortException err(reason, moreinfo, ap);
err.stacktrace.AppendFormat("Called from %s at %s, line %d\n", sfunc->PrintableName.GetChars(), sfunc->SourceFileName.GetChars(), sfunc->PCToLine(line));
err.stacktrace.AppendFormat("Called from %s at %s, line %d\n", sfunc->PrintableName, sfunc->SourceFileName.GetChars(), sfunc->PCToLine(line));
throw err;
}

View file

@ -132,6 +132,13 @@ void* FMemArena::Calloc(size_t size)
return mem;
}
const char* FMemArena::Strdup(const char* str)
{
char* p = (char*)Alloc(strlen(str) + 1);
strcpy(p, str);
return p;
}
//==========================================================================
//
// FMemArena :: FreeAll

View file

@ -45,6 +45,7 @@ public:
void *Alloc(size_t size);
void* Calloc(size_t size);
const char* Strdup(const char*);
void FreeAll();
void FreeAllBlocks();
FString DumpInfo();

View file

@ -198,7 +198,7 @@ bool initspriteforspawn(DDukeActor* act)
IFVIRTUALPTR(act, DDukeActor, TriggerSwitch)
{
if (func->PrintableName.CompareNoCase("DukeActor.TriggerSwitch") != 0)
if (stricmp(func->PrintableName, "DukeActor.TriggerSwitch") != 0)
overrideswitch = true;
}