@@ -112,6 +112,44 @@ std::unordered_map<std::string, std::string> &GetJitHelperNameMap()
112112 return map;
113113}
114114
115+ void DeclareAndRetrieveDeferredJitCalls (const std::string &codeToDeclare)
116+ {
117+ // Step 1: Declare the DeferredJitCall functions to the interpreter
118+ // We use ProcessLine to ensure meta functionality (e.g. autoloading) is
119+ // processed when needed.
120+ // If instead we used Declare, builds with runtime_cxxmodules=OFF would fail
121+ // in jitted actions with custom helpers with errors like:
122+ // error: 'MyHelperType' is an incomplete type
123+ // return std::make_unique<Action_t>(Helper_t(std::move(*h)), bl, std::move(prevNode), colRegister);
124+ // ^
125+ gInterpreter ->ProcessLine (codeToDeclare.c_str ());
126+
127+ // Step 2: Retrieve the declared functions as function pointers, cache them
128+ // for later use in RunDeferredCalls
129+ auto &funcMap = GetJitHelperFuncMap ();
130+ auto &nameMap = GetJitHelperNameMap ();
131+ auto clinfo = gInterpreter ->ClassInfo_Factory (" R_rdf" );
132+ assert (gInterpreter ->ClassInfo_IsValid (clinfo));
133+
134+ for (auto &codeAndName : nameMap) {
135+ if (auto it = funcMap.find (codeAndName.second ); it == funcMap.end ()) {
136+ // fast fetch of the address via gInterpreter
137+ // (faster than gInterpreter->Evaluate(function name, ret), ret->GetAsPointer())
138+ // Retrieve the JIT helper function we registered via RegisterJitHelperCall
139+ auto declid = gInterpreter ->GetFunction (clinfo, codeAndName.second .c_str ());
140+ assert (declid);
141+ auto minfo = gInterpreter ->MethodInfo_Factory (declid);
142+ assert (gInterpreter ->MethodInfo_IsValid (minfo));
143+ auto mname = gInterpreter ->MethodInfo_GetMangledName (minfo);
144+ auto res =
145+ funcMap.insert ({codeAndName.second , reinterpret_cast <JitHelperFunc_t>(gInterpreter ->FindSym (mname))});
146+ assert (res.second );
147+ gInterpreter ->MethodInfo_Delete (minfo);
148+ }
149+ }
150+ gInterpreter ->ClassInfo_Delete (clinfo);
151+ }
152+
115153void ThrowIfNSlotsChanged (unsigned int nSlots)
116154{
117155 const auto currentSlots = RDFInternal::GetNSlots ();
@@ -805,33 +843,7 @@ void RLoopManager::Jit()
805843 TStopwatch s;
806844 s.Start ();
807845 if (!codeToDeclare.empty ()) {
808- // This takes care of autoloading when needed
809- // If instead we used gInterpreter->Declare, builds with runtime_cxxmodules=OFF would fail in
810- // jitted actions with custom helpers with errors like:
811- // error: 'MyHelperType' is an incomplete type
812- // return std::make_unique<Action_t>(Helper_t(std::move(*h)), bl, std::move(prevNode), colRegister);
813- // ^
814- gInterpreter ->ProcessLine (codeToDeclare.c_str ());
815- auto &funcMap = GetJitHelperFuncMap ();
816- auto &nameMap = GetJitHelperNameMap ();
817- auto clinfo = gInterpreter ->ClassInfo_Factory (" R_rdf" );
818- assert (gInterpreter ->ClassInfo_IsValid (clinfo));
819- for (auto &codeAndName : nameMap) {
820- JitHelperFunc_t &addr = funcMap[codeAndName.second ];
821- if (!addr) {
822- // fast fetch of the address via gInterpreter
823- // (faster than gInterpreter->Evaluate(function name, ret), ret->GetAsPointer())
824- // Retrieve the JIT helper function we registered via RegisterJitHelperCall
825- auto declid = gInterpreter ->GetFunction (clinfo, codeAndName.second .c_str ());
826- assert (declid);
827- auto minfo = gInterpreter ->MethodInfo_Factory (declid);
828- assert (gInterpreter ->MethodInfo_IsValid (minfo));
829- auto mname = gInterpreter ->MethodInfo_GetMangledName (minfo);
830- addr = reinterpret_cast <JitHelperFunc_t>(gInterpreter ->FindSym (mname));
831- gInterpreter ->MethodInfo_Delete (minfo);
832- }
833- }
834- gInterpreter ->ClassInfo_Delete (clinfo);
846+ DeclareAndRetrieveDeferredJitCalls (codeToDeclare);
835847 }
836848 if (!code.empty ()) {
837849 RDFInternal::InterpreterCalc (code, " RLoopManager::Run" );
@@ -887,11 +899,15 @@ void RLoopManager::Run(bool jit)
887899 // Change value of TTree::GetMaxTreeSize only for this scope. Revert when #6640 will be solved.
888900 MaxTreeSizeRAII ctxtmts;
889901
902+ R__LOG_INFO (RDFLogChannel ()) << " Starting event loop number " << fNRuns << ' .' ;
903+
890904 ThrowIfNSlotsChanged (GetNSlots ());
891905
892906 if (jit)
893907 Jit ();
894908
909+ // Called here since in a RunGraphs run, multiple RLoopManager runs could be
910+ // triggered from different threads.
895911 RunDeferredCalls ();
896912
897913 InitNodes ();
0 commit comments