SourceContextInfo.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "RuntimeBasePch.h"
  6. #include "Language/SourceDynamicProfileManager.h"
  7. using namespace Js;
  8. // The general idea is that nextLocalFunctionId is assigned sequentially during parse
  9. // EnsureInitialized does one things:
  10. // - It ensures that the startup function bit vector on the profile manager has sufficient capacity
  11. // The startup function bitvector might have to be resized when we call this function
  12. void SourceContextInfo::EnsureInitialized()
  13. {
  14. #if ENABLE_PROFILE_INFO
  15. uint oldFunctionBodyArraySize = (this->sourceDynamicProfileManager ? this->sourceDynamicProfileManager->GetStartupFunctionsLength() : 0);
  16. if (oldFunctionBodyArraySize >= this->nextLocalFunctionId)
  17. {
  18. return;
  19. }
  20. // Match the dictionaries resize policy in calculating the amount to grow by
  21. uint newFunctionBodyCount = max(this->nextLocalFunctionId, UInt32Math::Add(oldFunctionBodyArraySize, oldFunctionBodyArraySize / 3));
  22. if(sourceDynamicProfileManager)
  23. {
  24. sourceDynamicProfileManager->EnsureStartupFunctions(newFunctionBodyCount);
  25. }
  26. #endif
  27. }
  28. bool SourceContextInfo::IsSourceProfileLoaded() const
  29. {
  30. #if ENABLE_PROFILE_INFO
  31. return sourceDynamicProfileManager != nullptr && sourceDynamicProfileManager->IsProfileLoaded();
  32. #else
  33. return false;
  34. #endif
  35. }
  36. SourceContextInfo* SourceContextInfo::Clone(Js::ScriptContext* scriptContext) const
  37. {
  38. SimpleDataCacheWrapper* profileCache = NULL;
  39. #if ENABLE_PROFILE_INFO
  40. if (this->sourceDynamicProfileManager != NULL)
  41. {
  42. profileCache = this->sourceDynamicProfileManager->GetProfileCache();
  43. }
  44. #endif
  45. SourceContextInfo * newSourceContextInfo = scriptContext->GetSourceContextInfo(dwHostSourceContext, profileCache);
  46. if (newSourceContextInfo == nullptr)
  47. {
  48. char16 const * oldUrl = this->url;
  49. char16 const * oldSourceMapUrl = this->sourceMapUrl;
  50. newSourceContextInfo = scriptContext->CreateSourceContextInfo(
  51. dwHostSourceContext,
  52. oldUrl,
  53. oldUrl? wcslen(oldUrl) : 0,
  54. NULL,
  55. oldSourceMapUrl,
  56. oldSourceMapUrl ? wcslen(oldSourceMapUrl) : 0);
  57. newSourceContextInfo->nextLocalFunctionId = this->nextLocalFunctionId;
  58. newSourceContextInfo->sourceContextId = this->sourceContextId;
  59. newSourceContextInfo->EnsureInitialized();
  60. }
  61. return newSourceContextInfo;
  62. }