TTSnapshotExtractor.cpp 23 KB

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