//------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #include "RuntimeBasePch.h" namespace Js { template TempArenaAllocatorWrapper* TempArenaAllocatorWrapper::Create(ThreadContext * threadContext) { Recycler * recycler = threadContext->GetRecycler(); TempArenaAllocatorWrapper * wrapper = RecyclerNewFinalizedLeaf(recycler, Js::TempArenaAllocatorWrapper, _u("temp"), threadContext->GetPageAllocator(), Js::Throw::OutOfMemory); if (isGuestArena) { wrapper->recycler = recycler; wrapper->AdviseInUse(); } return wrapper; } template TempArenaAllocatorWrapper::TempArenaAllocatorWrapper(__in LPCWSTR name, PageAllocator * pageAllocator, void (*outOfMemoryFunc)()) : allocator(name, pageAllocator, outOfMemoryFunc), recycler(nullptr), externalGuestArenaRef(nullptr) { } template void TempArenaAllocatorWrapper::Dispose(bool isShutdown) { allocator.Clear(); if (isGuestArena && externalGuestArenaRef != nullptr) { this->recycler->UnregisterExternalGuestArena(externalGuestArenaRef); externalGuestArenaRef = nullptr; } Assert(allocator.AllocatedSize() == 0); } template void TempArenaAllocatorWrapper::AdviseInUse() { if (isGuestArena) { if (externalGuestArenaRef == nullptr) { externalGuestArenaRef = this->recycler->RegisterExternalGuestArena(this->GetAllocator()); if (externalGuestArenaRef == nullptr) { Js::Throw::OutOfMemory(); } } } } template void TempArenaAllocatorWrapper::AdviseNotInUse() { this->allocator.Reset(); if (isGuestArena) { Assert(externalGuestArenaRef != nullptr); this->recycler->UnregisterExternalGuestArena(externalGuestArenaRef); externalGuestArenaRef = nullptr; } } // Explicit instantiation template class TempArenaAllocatorWrapper; template class TempArenaAllocatorWrapper; } // namespace Js