@@ -29,7 +29,7 @@ ServerScriptContext::ServerScriptContext(ScriptContextDataIDL * contextData, Ser
2929 m_codeGenAlloc(nullptr , nullptr , threadContextInfo, threadContextInfo->GetCodePageAllocators (), threadContextInfo->GetProcessHandle()),
3030 m_globalThisAddr(0 ),
3131#ifdef PROFILE_EXEC
32- m_codeGenProfiler (nullptr ),
32+ codeGenProfiler (nullptr ),
3333#endif
3434 m_refCount (0 ),
3535 m_isClosed(false )
@@ -39,12 +39,6 @@ ServerScriptContext::ServerScriptContext(ScriptContextDataIDL * contextData, Ser
3939 m_codeGenAlloc.canCreatePreReservedSegment = threadContextInfo->CanCreatePreReservedSegment ();
4040#endif
4141
42- #ifdef PROFILE_EXEC
43- if (Js::Configuration::Global.flags .IsEnabled (Js::ProfileFlag))
44- {
45- m_codeGenProfiler = HeapNew (Js::ScriptContextProfiler);
46- }
47- #endif
4842 m_domFastPathHelperMap = HeapNew (JITDOMFastPathHelperMap, &HeapAllocator::Instance, 17 );
4943}
5044
@@ -57,9 +51,11 @@ ServerScriptContext::~ServerScriptContext()
5751 });
5852
5953#ifdef PROFILE_EXEC
60- if (m_codeGenProfiler )
54+ while ( this -> codeGenProfiler )
6155 {
62- HeapDelete (m_codeGenProfiler);
56+ Js::ScriptContextProfiler* profiler = this ->codeGenProfiler ;
57+ this ->codeGenProfiler = this ->codeGenProfiler ->next ;
58+ HeapDelete (profiler);
6359 }
6460#endif
6561}
@@ -416,14 +412,46 @@ ServerScriptContext::AddModuleRecordInfo(unsigned int moduleId, __int64 localExp
416412 m_moduleRecords.Add (moduleId, record);
417413}
418414
419- Js::ScriptContextProfiler *
420- ServerScriptContext::GetCodeGenProfiler () const
421- {
422415#ifdef PROFILE_EXEC
423- return m_codeGenProfiler;
424- #else
416+ Js::ScriptContextProfiler*
417+ ServerScriptContext::GetCodeGenProfiler (_In_ PageAllocator* pageAllocator)
418+ {
419+ if (Js::Configuration::Global.flags .IsEnabled (Js::ProfileFlag))
420+ {
421+ AutoCriticalSection cs (&this ->profilerCS );
422+
423+ Js::ScriptContextProfiler* profiler = this ->codeGenProfiler ;
424+ while (profiler)
425+ {
426+ if (profiler->pageAllocator == pageAllocator)
427+ {
428+ if (!profiler->IsInitialized ())
429+ {
430+ profiler->Initialize (pageAllocator, nullptr );
431+ }
432+ return profiler;
433+ }
434+ profiler = profiler->next ;
435+ }
436+
437+ // If we didn't find a profiler, allocate a new one
438+
439+ profiler = HeapNew (Js::ScriptContextProfiler);
440+ profiler->Initialize (pageAllocator, nullptr );
441+ profiler->next = this ->codeGenProfiler ;
442+
443+ this ->codeGenProfiler = profiler;
444+
445+ return profiler;
446+ }
425447 return nullptr ;
426- #endif
427448}
428449
429- #endif
450+ Js::ScriptContextProfiler*
451+ ServerScriptContext::GetFirstCodeGenProfiler () const
452+ {
453+ return this ->codeGenProfiler ;
454+ }
455+ #endif // PROFILE_EXEC
456+
457+ #endif // ENABLE_OOP_NATIVE_CODEGEN
0 commit comments