TTSnapshotExtractor.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "RuntimeDebugPch.h"
  6. #if ENABLE_TTD
  7. namespace TTD
  8. {
  9. void SnapshotExtractor::MarkVisitHandler(Js::DynamicTypeHandler* handler)
  10. {
  11. this->m_marks.MarkAndTestAddr<MarkTableTag::TypeHandlerTag>(handler);
  12. }
  13. void SnapshotExtractor::MarkVisitType(Js::Type* type)
  14. {
  15. //Must ensure this is de-serialized before you call this
  16. if(this->m_marks.MarkAndTestAddr<MarkTableTag::TypeTag>(type))
  17. {
  18. if(Js::DynamicType::Is(type->GetTypeId()))
  19. {
  20. Js::DynamicTypeHandler* handler = (static_cast<Js::DynamicType*>(type))->GetTypeHandler();
  21. this->MarkVisitHandler(handler);
  22. }
  23. Js::RecyclableObject* proto = type->GetPrototype();
  24. if(proto != nullptr)
  25. {
  26. this->MarkVisitVar(proto);
  27. }
  28. }
  29. }
  30. void SnapshotExtractor::MarkVisitStandardProperties(Js::RecyclableObject* obj)
  31. {
  32. TTDAssert(Js::DynamicType::Is(obj->GetTypeId()) || obj->GetPropertyCount() == 0, "Only dynamic objects should have standard properties.");
  33. if(Js::DynamicType::Is(obj->GetTypeId()))
  34. {
  35. Js::DynamicObject* dynObj = Js::DynamicObject::FromVar(obj);
  36. dynObj->GetDynamicType()->GetTypeHandler()->MarkObjectSlots_TTD(this, dynObj);
  37. Js::ArrayObject* parray = dynObj->GetObjectArray();
  38. if(parray != nullptr)
  39. {
  40. this->MarkVisitVar(parray);
  41. }
  42. }
  43. }
  44. void SnapshotExtractor::ExtractHandlerIfNeeded(Js::DynamicTypeHandler* handler, ThreadContext* threadContext)
  45. {
  46. if(this->m_marks.IsMarked(handler))
  47. {
  48. NSSnapType::SnapHandler* sHandler = this->m_pendingSnap->GetNextAvailableHandlerEntry();
  49. handler->ExtractSnapHandler(sHandler, threadContext, this->m_pendingSnap->GetSnapshotSlabAllocator());
  50. this->m_idToHandlerMap.AddItem(sHandler->HandlerId, sHandler);
  51. this->m_marks.ClearMark(handler);
  52. }
  53. }
  54. void SnapshotExtractor::ExtractTypeIfNeeded(Js::Type* jstype, ThreadContext* threadContext)
  55. {
  56. if(this->m_marks.IsMarked(jstype))
  57. {
  58. if(Js::DynamicType::Is(jstype->GetTypeId()))
  59. {
  60. this->ExtractHandlerIfNeeded(static_cast<Js::DynamicType*>(jstype)->GetTypeHandler(), threadContext);
  61. }
  62. NSSnapType::SnapHandler* sHandler = nullptr;
  63. if(Js::DynamicType::Is(jstype->GetTypeId()))
  64. {
  65. Js::DynamicTypeHandler* dhandler = static_cast<const Js::DynamicType*>(jstype)->GetTypeHandler();
  66. TTD_PTR_ID handlerId = TTD_CONVERT_TYPEINFO_TO_PTR_ID(dhandler);
  67. sHandler = this->m_idToHandlerMap.LookupKnownItem(handlerId);
  68. }
  69. NSSnapType::SnapType* sType = this->m_pendingSnap->GetNextAvailableTypeEntry();
  70. jstype->ExtractSnapType(sType, sHandler, this->m_pendingSnap->GetSnapshotSlabAllocator());
  71. this->m_idToTypeMap.AddItem(sType->TypePtrId, sType);
  72. this->m_marks.ClearMark(jstype);
  73. }
  74. }
  75. void SnapshotExtractor::ExtractSlotArrayIfNeeded(Js::ScriptContext* ctx, Js::Var* scope)
  76. {
  77. if(this->m_marks.IsMarked(scope))
  78. {
  79. NSSnapValues::SlotArrayInfo* slotInfo = this->m_pendingSnap->GetNextAvailableSlotArrayEntry();
  80. Js::ScopeSlots slots(scope);
  81. slotInfo->SlotId = TTD_CONVERT_VAR_TO_PTR_ID(scope);
  82. slotInfo->ScriptContextLogId = ctx->ScriptContextLogTag;
  83. slotInfo->SlotCount = static_cast<uint>(slots.GetCount());
  84. slotInfo->Slots = this->m_pendingSnap->GetSnapshotSlabAllocator().SlabAllocateArray<TTDVar>(slotInfo->SlotCount);
  85. for(uint32 j = 0; j < slotInfo->SlotCount; ++j)
  86. {
  87. slotInfo->Slots[j] = slots.Get(j);
  88. }
  89. if(slots.IsFunctionScopeSlotArray())
  90. {
  91. Js::FunctionBody* fb = slots.GetFunctionInfo()->GetFunctionBody();
  92. slotInfo->isFunctionBodyMetaData = true;
  93. slotInfo->OptFunctionBodyId = TTD_CONVERT_FUNCTIONBODY_TO_PTR_ID(fb);
  94. slotInfo->OptDebugScopeId = TTD_INVALID_PTR_ID;
  95. slotInfo->OptWellKnownDbgScope = TTD_INVALID_WELLKNOWN_TOKEN;
  96. Js::PropertyId* propertyIds = fb->GetPropertyIdsForScopeSlotArray();
  97. slotInfo->PIDArray = this->m_pendingSnap->GetSnapshotSlabAllocator().SlabAllocateArray<Js::PropertyId>(slotInfo->SlotCount);
  98. js_memcpy_s(slotInfo->PIDArray, sizeof(Js::PropertyId) * slotInfo->SlotCount, propertyIds, sizeof(Js::PropertyId) * slots.GetCount());
  99. }
  100. else
  101. {
  102. Js::DebuggerScope* dbgScope = slots.GetDebuggerScope();
  103. slotInfo->isFunctionBodyMetaData = false;
  104. slotInfo->OptFunctionBodyId = TTD_INVALID_PTR_ID;
  105. TTD_WELLKNOWN_TOKEN wellKnownToken = ctx->TTDWellKnownInfo->ResolvePathForKnownDbgScopeIfExists(dbgScope);
  106. if(wellKnownToken == TTD_INVALID_WELLKNOWN_TOKEN)
  107. {
  108. slotInfo->OptDebugScopeId = TTD_CONVERT_DEBUGSCOPE_TO_PTR_ID(dbgScope);
  109. slotInfo->OptWellKnownDbgScope = TTD_INVALID_WELLKNOWN_TOKEN;
  110. }
  111. else
  112. {
  113. slotInfo->OptDebugScopeId = TTD_INVALID_PTR_ID;
  114. slotInfo->OptWellKnownDbgScope = this->m_pendingSnap->GetSnapshotSlabAllocator().CopyRawNullTerminatedStringInto(wellKnownToken);
  115. }
  116. slotInfo->PIDArray = this->m_pendingSnap->GetSnapshotSlabAllocator().SlabAllocateArray<Js::PropertyId>(slotInfo->SlotCount);
  117. for(uint32 j = 0; j < slotInfo->SlotCount; ++j)
  118. {
  119. slotInfo->PIDArray[j] = dbgScope->GetPropertyIdForSlotIndex_TTD(j);
  120. }
  121. }
  122. this->m_marks.ClearMark(scope);
  123. }
  124. }
  125. void SnapshotExtractor::ExtractScopeIfNeeded(Js::ScriptContext* ctx, Js::FrameDisplay* environment)
  126. {
  127. if(this->m_marks.IsMarked(environment))
  128. {
  129. TTDAssert(environment->GetLength() > 0, "This doesn't make sense");
  130. NSSnapValues::ScriptFunctionScopeInfo* funcScopeInfo = this->m_pendingSnap->GetNextAvailableFunctionScopeEntry();
  131. funcScopeInfo->ScopeId = TTD_CONVERT_ENV_TO_PTR_ID(environment);
  132. funcScopeInfo->ScriptContextLogId = ctx->ScriptContextLogTag;
  133. funcScopeInfo->ScopeCount = environment->GetLength();
  134. funcScopeInfo->ScopeArray = this->m_pendingSnap->GetSnapshotSlabAllocator().SlabAllocateArray<NSSnapValues::ScopeInfoEntry>(funcScopeInfo->ScopeCount);
  135. for(uint16 i = 0; i < funcScopeInfo->ScopeCount; ++i)
  136. {
  137. void* scope = environment->GetItem(i);
  138. NSSnapValues::ScopeInfoEntry* entryInfo = (funcScopeInfo->ScopeArray + i);
  139. entryInfo->Tag = environment->GetScopeType(scope);
  140. switch(entryInfo->Tag)
  141. {
  142. case Js::ScopeType::ScopeType_ActivationObject:
  143. case Js::ScopeType::ScopeType_WithScope:
  144. entryInfo->IDValue = TTD_CONVERT_VAR_TO_PTR_ID((Js::Var)scope);
  145. break;
  146. case Js::ScopeType::ScopeType_SlotArray:
  147. {
  148. this->ExtractSlotArrayIfNeeded(ctx, (Js::Var*)scope);
  149. entryInfo->IDValue = TTD_CONVERT_SLOTARRAY_TO_PTR_ID((Js::Var*)scope);
  150. break;
  151. }
  152. default:
  153. TTDAssert(false, "Unknown scope kind");
  154. entryInfo->IDValue = TTD_INVALID_PTR_ID;
  155. break;
  156. }
  157. }
  158. this->m_marks.ClearMark(environment);
  159. }
  160. }
  161. void SnapshotExtractor::ExtractScriptFunctionEnvironmentIfNeeded(Js::ScriptFunction* function)
  162. {
  163. Js::FrameDisplay* environment = function->GetEnvironment();
  164. if(environment->GetLength() != 0)
  165. {
  166. this->ExtractScopeIfNeeded(function->GetScriptContext(), environment);
  167. }
  168. }
  169. void SnapshotExtractor::UnloadDataFromExtractor()
  170. {
  171. this->m_marks.Clear();
  172. this->m_worklist.Clear();
  173. this->m_idToHandlerMap.Unload();
  174. this->m_idToTypeMap.Unload();
  175. this->m_pendingSnap = nullptr;
  176. }
  177. SnapshotExtractor::SnapshotExtractor()
  178. : m_marks(), m_worklist(&HeapAllocator::Instance),
  179. m_idToHandlerMap(), m_idToTypeMap(),
  180. m_pendingSnap(nullptr),
  181. m_snapshotsTakenCount(0),
  182. m_totalMarkMillis(0.0), m_totalExtractMillis(0.0),
  183. m_maxMarkMillis(0.0), m_maxExtractMillis(0.0),
  184. m_lastMarkMillis(0.0), m_lastExtractMillis(0.0)
  185. {
  186. ;
  187. }
  188. SnapshotExtractor::~SnapshotExtractor()
  189. {
  190. this->UnloadDataFromExtractor();
  191. }
  192. SnapShot* SnapshotExtractor::GetPendingSnapshot()
  193. {
  194. TTDAssert(this->m_pendingSnap != nullptr, "Should only call if we are extracting a snapshot");
  195. return this->m_pendingSnap;
  196. }
  197. SlabAllocator& SnapshotExtractor::GetActiveSnapshotSlabAllocator()
  198. {
  199. TTDAssert(this->m_pendingSnap != nullptr, "Should only call if we are extracting a snapshot");
  200. return this->m_pendingSnap->GetSnapshotSlabAllocator();
  201. }
  202. void SnapshotExtractor::MarkVisitVar(Js::Var var)
  203. {
  204. TTDAssert(var != nullptr, "I don't think this should happen but not 100% sure.");
  205. TTDAssert(Js::JavascriptOperators::GetTypeId(var) < Js::TypeIds_Limit || Js::RecyclableObject::FromVar(var)->CanHaveInterceptors(), "Not cool.");
  206. //We don't need to visit tagged things
  207. if(JsSupport::IsVarTaggedInline(var))
  208. {
  209. return;
  210. }
  211. if(JsSupport::IsVarPrimitiveKind(var))
  212. {
  213. if(this->m_marks.MarkAndTestAddr<MarkTableTag::PrimitiveObjectTag>(var))
  214. {
  215. Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(var);
  216. this->MarkVisitType(obj->GetType());
  217. }
  218. }
  219. else
  220. {
  221. TTDAssert(JsSupport::IsVarComplexKind(var), "Shouldn't be anything else");
  222. if(this->m_marks.MarkAndTestAddr<MarkTableTag::CompoundObjectTag>(var))
  223. {
  224. Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(var);
  225. //do this here instead of in mark visit type as it wants the dynamic object as well
  226. if(Js::DynamicType::Is(obj->GetTypeId()))
  227. {
  228. Js::DynamicObject* dynObj = Js::DynamicObject::FromVar(obj);
  229. if(dynObj->GetDynamicType()->GetTypeHandler()->IsDeferredTypeHandler())
  230. {
  231. dynObj->GetDynamicType()->GetTypeHandler()->EnsureObjectReady(dynObj);
  232. }
  233. }
  234. this->MarkVisitType(obj->GetType());
  235. this->m_worklist.Enqueue(obj);
  236. }
  237. }
  238. }
  239. void SnapshotExtractor::MarkFunctionBody(Js::FunctionBody* fb)
  240. {
  241. if(this->m_marks.MarkAndTestAddr<MarkTableTag::FunctionBodyTag>(fb))
  242. {
  243. Js::FunctionBody* currfb = fb->GetScriptContext()->TTDContextInfo->ResolveParentBody(fb);
  244. while(currfb != nullptr && this->m_marks.MarkAndTestAddr<MarkTableTag::FunctionBodyTag>(currfb))
  245. {
  246. currfb = currfb->GetScriptContext()->TTDContextInfo->ResolveParentBody(currfb);
  247. }
  248. }
  249. }
  250. void SnapshotExtractor::MarkScriptFunctionScopeInfo(Js::FrameDisplay* environment)
  251. {
  252. if(this->m_marks.MarkAndTestAddr<MarkTableTag::EnvironmentTag>(environment))
  253. {
  254. uint32 scopeCount = environment->GetLength();
  255. for(uint32 i = 0; i < scopeCount; ++i)
  256. {
  257. void* scope = environment->GetItem(i);
  258. switch(environment->GetScopeType(scope))
  259. {
  260. case Js::ScopeType::ScopeType_ActivationObject:
  261. case Js::ScopeType::ScopeType_WithScope:
  262. {
  263. this->MarkVisitVar((Js::Var)scope);
  264. break;
  265. }
  266. case Js::ScopeType::ScopeType_SlotArray:
  267. {
  268. if(this->m_marks.MarkAndTestAddr<MarkTableTag::SlotArrayTag>(scope))
  269. {
  270. Js::ScopeSlots slotArray = (Js::Var*)scope;
  271. uint slotArrayCount = static_cast<uint>(slotArray.GetCount());
  272. if(slotArray.IsFunctionScopeSlotArray())
  273. {
  274. this->MarkFunctionBody(slotArray.GetFunctionInfo()->GetFunctionBody());
  275. }
  276. for(uint j = 0; j < slotArrayCount; j++)
  277. {
  278. Js::Var sval = slotArray.Get(j);
  279. this->MarkVisitVar(sval);
  280. }
  281. }
  282. break;
  283. }
  284. default:
  285. TTDAssert(false, "Unknown scope kind");
  286. }
  287. }
  288. }
  289. }
  290. void SnapshotExtractor::BeginSnapshot(ThreadContext* threadContext, double gcTime)
  291. {
  292. TTDAssert((this->m_pendingSnap == nullptr) & this->m_worklist.Empty(), "Something went wrong.");
  293. this->m_pendingSnap = TT_HEAP_NEW(SnapShot, gcTime);
  294. }
  295. void SnapshotExtractor::DoMarkWalk(ThreadContext* threadContext)
  296. {
  297. TTDTimer timer;
  298. double startTime = timer.Now();
  299. //Add the global roots
  300. for(auto iter = threadContext->TTDContext->GetRootTagToObjectMap().GetIterator(); iter.IsValid(); iter.MoveNext())
  301. {
  302. Js::Var root = iter.CurrentValue();
  303. this->MarkVisitVar(root);
  304. }
  305. while(!this->m_worklist.Empty())
  306. {
  307. Js::RecyclableObject* nobj = this->m_worklist.Dequeue();
  308. TTDAssert(JsSupport::IsVarComplexKind(nobj), "Should only be these two options");
  309. this->MarkVisitStandardProperties(nobj);
  310. nobj->MarkVisitKindSpecificPtrs(this);
  311. }
  312. //Mark all of the well known objects/types
  313. for(int32 i = 0; i < threadContext->TTDContext->GetTTDContexts().Count(); ++i)
  314. {
  315. threadContext->TTDContext->GetTTDContexts().Item(i)->TTDWellKnownInfo->MarkWellKnownObjects_TTD(this->m_marks);
  316. }
  317. double endTime = timer.Now();
  318. this->m_pendingSnap->MarkTime = (endTime - startTime) / 1000.0;
  319. }
  320. void SnapshotExtractor::EvacuateMarkedIntoSnapshot(ThreadContext* threadContext)
  321. {
  322. TTDTimer timer;
  323. double startTime = timer.Now();
  324. SnapShot* snap = this->m_pendingSnap;
  325. SlabAllocator& alloc = this->m_pendingSnap->GetSnapshotSlabAllocator();
  326. //invert the root map for extracting
  327. JsUtil::BaseDictionary<Js::RecyclableObject*, TTD_LOG_PTR_ID, HeapAllocator> objToLogIdMap(&HeapAllocator::Instance);
  328. threadContext->TTDContext->LoadInvertedRootMap(objToLogIdMap);
  329. UnorderedArrayList<NSSnapValues::SnapContext, TTD_ARRAY_LIST_SIZE_XSMALL>& snpCtxs = this->m_pendingSnap->GetContextList();
  330. for(int32 i = 0; i < threadContext->TTDContext->GetTTDContexts().Count(); ++i)
  331. {
  332. NSSnapValues::SnapContext* snpCtx = snpCtxs.NextOpenEntry();
  333. NSSnapValues::ExtractScriptContext(snpCtx, threadContext->TTDContext->GetTTDContexts().Item(i), objToLogIdMap, snap->GetSnapshotSlabAllocator());
  334. }
  335. //extract the thread context symbol map info
  336. JsUtil::BaseDictionary<Js::HashedCharacterBuffer<char16>*, const Js::PropertyRecord*, Recycler, PowerOf2SizePolicy, Js::PropertyRecordStringHashComparer>* tcSymbolRegistrationMap = threadContext->GetSymbolRegistrationMap_TTD();
  337. UnorderedArrayList<Js::PropertyId, TTD_ARRAY_LIST_SIZE_XSMALL>& tcSymbolMapInfo = this->m_pendingSnap->GetTCSymbolMapInfoList();
  338. for(auto iter = tcSymbolRegistrationMap->GetIterator(); iter.IsValid(); iter.MoveNext())
  339. {
  340. Js::PropertyId* tcpid = tcSymbolMapInfo.NextOpenEntry();
  341. *tcpid = iter.CurrentValue()->GetPropertyId();
  342. }
  343. //We extract all the global code function bodies with the context so clear their marks now
  344. JsUtil::List<TopLevelFunctionInContextRelation, HeapAllocator> topLevelScriptLoad(&HeapAllocator::Instance);
  345. JsUtil::List<TopLevelFunctionInContextRelation, HeapAllocator> topLevelNewFunction(&HeapAllocator::Instance);
  346. JsUtil::List<TopLevelFunctionInContextRelation, HeapAllocator> topLevelEval(&HeapAllocator::Instance);
  347. for(int32 i = 0; i < threadContext->TTDContext->GetTTDContexts().Count(); ++i)
  348. {
  349. topLevelScriptLoad.Clear();
  350. topLevelNewFunction.Clear();
  351. topLevelEval.Clear();
  352. Js::ScriptContext* ctx = threadContext->TTDContext->GetTTDContexts().Item(i);
  353. ctx->TTDContextInfo->GetLoadedSources(topLevelScriptLoad, topLevelNewFunction, topLevelEval);
  354. for(int32 j = 0; j < topLevelScriptLoad.Count(); ++j)
  355. {
  356. Js::FunctionBody* body = TTD_COERCE_PTR_ID_TO_FUNCTIONBODY(topLevelScriptLoad.Item(j).ContextSpecificBodyPtrId);
  357. this->m_marks.ClearMark(body);
  358. }
  359. for(int32 j = 0; j < topLevelNewFunction.Count(); ++j)
  360. {
  361. Js::FunctionBody* body = TTD_COERCE_PTR_ID_TO_FUNCTIONBODY(topLevelNewFunction.Item(j).ContextSpecificBodyPtrId);
  362. this->m_marks.ClearMark(body);
  363. }
  364. for(int32 j = 0; j < topLevelEval.Count(); ++j)
  365. {
  366. Js::FunctionBody* body = TTD_COERCE_PTR_ID_TO_FUNCTIONBODY(topLevelEval.Item(j).ContextSpecificBodyPtrId);
  367. this->m_marks.ClearMark(body);
  368. }
  369. }
  370. this->m_idToHandlerMap.Initialize(this->m_marks.GetCountForTag<MarkTableTag::TypeHandlerTag>());
  371. this->m_idToTypeMap.Initialize(this->m_marks.GetCountForTag<MarkTableTag::TypeTag>());
  372. //walk all the marked objects
  373. this->m_marks.InitializeIter();
  374. MarkTableTag tag = this->m_marks.GetTagValue();
  375. while(tag != MarkTableTag::Clear)
  376. {
  377. switch(tag & MarkTableTag::AllKindMask)
  378. {
  379. case MarkTableTag::TypeHandlerTag:
  380. this->ExtractHandlerIfNeeded(this->m_marks.GetPtrValue<Js::DynamicTypeHandler*>(), threadContext);
  381. break;
  382. case MarkTableTag::TypeTag:
  383. this->ExtractTypeIfNeeded(this->m_marks.GetPtrValue<Js::Type*>(), threadContext);
  384. break;
  385. case MarkTableTag::PrimitiveObjectTag:
  386. {
  387. this->ExtractTypeIfNeeded(this->m_marks.GetPtrValue<Js::RecyclableObject*>()->GetType(), threadContext);
  388. NSSnapValues::ExtractSnapPrimitiveValue(snap->GetNextAvailablePrimitiveObjectEntry(), this->m_marks.GetPtrValue<Js::RecyclableObject*>(), this->m_marks.GetTagValueIsWellKnown(), this->m_idToTypeMap, alloc);
  389. break;
  390. }
  391. case MarkTableTag::CompoundObjectTag:
  392. {
  393. this->ExtractTypeIfNeeded(this->m_marks.GetPtrValue<Js::RecyclableObject*>()->GetType(), threadContext);
  394. if(Js::ScriptFunction::Is(this->m_marks.GetPtrValue<Js::RecyclableObject*>()))
  395. {
  396. this->ExtractScriptFunctionEnvironmentIfNeeded(this->m_marks.GetPtrValue<Js::ScriptFunction*>());
  397. }
  398. NSSnapObjects::ExtractCompoundObject(snap->GetNextAvailableCompoundObjectEntry(), this->m_marks.GetPtrValue<Js::RecyclableObject*>(), this->m_marks.GetTagValueIsWellKnown(), this->m_idToTypeMap, alloc);
  399. break;
  400. }
  401. case MarkTableTag::FunctionBodyTag:
  402. NSSnapValues::ExtractFunctionBodyInfo(snap->GetNextAvailableFunctionBodyResolveInfoEntry(), this->m_marks.GetPtrValue<Js::FunctionBody*>(), this->m_marks.GetTagValueIsWellKnown(), alloc);
  403. break;
  404. case MarkTableTag::EnvironmentTag:
  405. case MarkTableTag::SlotArrayTag:
  406. break; //should be handled with the associated script function
  407. default:
  408. TTDAssert(false, "If this isn't true then we have an unknown tag");
  409. break;
  410. }
  411. this->m_marks.MoveToNextAddress();
  412. tag = this->m_marks.GetTagValue();
  413. }
  414. //Extract the roots
  415. ThreadContextTTD* txctx = threadContext->TTDContext;
  416. UnorderedArrayList<NSSnapValues::SnapRootInfoEntry, TTD_ARRAY_LIST_SIZE_MID>& rootlist = this->m_pendingSnap->GetRootList();
  417. for(auto iter = threadContext->TTDContext->GetRootTagToObjectMap().GetIterator(); iter.IsValid(); iter.MoveNext())
  418. {
  419. NSSnapValues::SnapRootInfoEntry* spe = rootlist.NextOpenEntry();
  420. spe->LogObject = TTD_CONVERT_VAR_TO_PTR_ID(iter.CurrentValue());
  421. spe->LogId = iter.CurrentKey();
  422. spe->MaybeLongLivedRoot = txctx->ResolveIsLongLivedForExtract(spe->LogId);
  423. }
  424. if(threadContext->TTDContext->GetActiveScriptContext() == nullptr)
  425. {
  426. this->m_pendingSnap->SetActiveScriptContext(TTD_INVALID_LOG_PTR_ID);
  427. }
  428. else
  429. {
  430. TTD_LOG_PTR_ID ctxId = threadContext->TTDContext->GetActiveScriptContext()->ScriptContextLogTag;
  431. this->m_pendingSnap->SetActiveScriptContext(ctxId);
  432. }
  433. double endTime = timer.Now();
  434. snap->ExtractTime = (endTime - startTime) / 1000.0;
  435. }
  436. SnapShot* SnapshotExtractor::CompleteSnapshot()
  437. {
  438. SnapShot* snap = this->m_pendingSnap;
  439. this->UnloadDataFromExtractor();
  440. this->m_snapshotsTakenCount++;
  441. this->m_totalMarkMillis += snap->MarkTime;
  442. this->m_totalExtractMillis += snap->ExtractTime;
  443. if(this->m_maxMarkMillis < snap->MarkTime)
  444. {
  445. this->m_maxMarkMillis = snap->MarkTime;
  446. }
  447. if(this->m_maxExtractMillis < snap->ExtractTime)
  448. {
  449. this->m_maxExtractMillis = snap->ExtractTime;
  450. }
  451. this->m_lastMarkMillis = snap->MarkTime;
  452. this->m_lastExtractMillis = snap->ExtractTime;
  453. return snap;
  454. }
  455. void SnapshotExtractor::DoResetWeakCollectionPinSet(ThreadContext* threadContext)
  456. {
  457. //Add the roots
  458. for(auto iter = threadContext->TTDContext->GetRootTagToObjectMap().GetIterator(); iter.IsValid(); iter.MoveNext())
  459. {
  460. Js::Var root = iter.CurrentValue();
  461. this->MarkVisitVar(root);
  462. }
  463. while(!this->m_worklist.Empty())
  464. {
  465. Js::RecyclableObject* nobj = this->m_worklist.Dequeue();
  466. TTDAssert(JsSupport::IsVarComplexKind(nobj), "Should only be these two options");
  467. this->MarkVisitStandardProperties(nobj);
  468. nobj->MarkVisitKindSpecificPtrs(this);
  469. }
  470. this->UnloadDataFromExtractor();
  471. }
  472. }
  473. #endif