ServerScriptContext::ServerScriptContext(ScriptContextDataIDL * contextData, ServerThreadContext* threadContextInfo) : m_contextData(*contextData), threadContextHolder(threadContextInfo), m_isPRNGSeeded(false), m_sourceCodeArena(_u("JITSourceCodeArena"), threadContextInfo->GetForegroundPageAllocator(), Js::Throw::OutOfMemory, nullptr), m_interpreterThunkBufferManager(&m_sourceCodeArena, threadContextInfo->GetThunkPageAllocators(), nullptr, threadContextInfo, _u("Interpreter thunk buffer"), GetThreadContext()->GetProcessHandle()), m_asmJsInterpreterThunkBufferManager(&m_sourceCodeArena, threadContextInfo->GetThunkPageAllocators(), nullptr, threadContextInfo, _u("Asm.js interpreter thunk buffer"), GetThreadContext()->GetProcessHandle()), m_domFastPathHelperMap(nullptr), m_moduleRecords(&HeapAllocator::Instance), m_codeGenAlloc(nullptr, nullptr, threadContextInfo, threadContextInfo->GetCodePageAllocators(), threadContextInfo->GetProcessHandle()), m_globalThisAddr(0), #ifdef PROFILE_EXEC m_codeGenProfiler(nullptr), #endif m_refCount(0), m_isClosed(false) { #if !TARGET_64 && _CONTROL_FLOW_GUARD m_codeGenAlloc.canCreatePreReservedSegment = threadContextInfo->CanCreatePreReservedSegment(); #endif #ifdef PROFILE_EXEC if (Js::Configuration::Global.flags.IsEnabled(Js::ProfileFlag)) { m_codeGenProfiler = HeapNew(Js::ScriptContextProfiler); } #endif m_domFastPathHelperMap = HeapNew(JITDOMFastPathHelperMap, &HeapAllocator::Instance, 17); }
WaiterList *SharedArrayBuffer::GetWaiterList(uint index) { if (sharedContents != nullptr) { // REVIEW: only lock creating the map and pass the lock to the map? // use one lock per instance? AutoCriticalSection autoCS(&csSharedArrayBuffer); if (sharedContents->indexToWaiterList == nullptr) { sharedContents->indexToWaiterList = HeapNew(IndexToWaitersMap, &HeapAllocator::Instance); } WaiterList * waiters = nullptr; if (!sharedContents->indexToWaiterList->TryGetValue(index, &waiters)) { waiters = HeapNew(WaiterList); sharedContents->indexToWaiterList->Add(index, waiters); } return waiters; } Assert(false); return nullptr; }
GLOBAL List *MakeNewList(Generic *item) { List *create = HeapNew(List); create->element = item; create->next = NULL; return (create); }
void JsrtRuntime::EnsureJsrtDebugManager() { if (this->jsrtDebugManager == nullptr) { this->jsrtDebugManager = HeapNew(JsrtDebugManager, this->threadContext); } Assert(this->jsrtDebugManager != nullptr); }
ServerScriptContext::ServerScriptContext(ScriptContextDataIDL * contextData) : m_contextData(*contextData), m_isPRNGSeeded(false), m_isClosed(false), m_moduleRecords(&HeapAllocator::Instance), #ifdef PROFILE_EXEC m_codeGenProfiler(nullptr), #endif m_activeJITCount(0) { #ifdef PROFILE_EXEC if (Js::Configuration::Global.flags.IsEnabled(Js::ProfileFlag)) { m_codeGenProfiler = HeapNew(Js::ScriptContextProfiler); } #endif m_domFastPathHelperMap = HeapNew(JITDOMFastPathHelperMap, &HeapAllocator::Instance, 17); }
void SharedContents::AddAgent(DWORD_PTR agent) { if (allowedAgents == nullptr) { allowedAgents = HeapNew(SharableAgents, &HeapAllocator::Instance); } allowedAgents->Add(agent); }
SharedArrayBuffer::SharedArrayBuffer(uint32 length, DynamicType * type, Allocator allocator) : ArrayBufferBase(type), sharedContents(nullptr) { BYTE * buffer = nullptr; if (length > MaxSharedArrayBufferLength) { JavascriptError::ThrowTypeError(GetScriptContext(), JSERR_FunctionArgument_Invalid); } else if (length > 0) { Recycler* recycler = GetType()->GetLibrary()->GetRecycler(); if (recycler->ReportExternalMemoryAllocation(length)) { buffer = (BYTE*)allocator(length); if (buffer == nullptr) { recycler->ReportExternalMemoryFree(length); } } if (buffer == nullptr) { recycler->CollectNow<CollectOnTypedArrayAllocation>(); if (recycler->ReportExternalMemoryAllocation(length)) { buffer = (BYTE*)allocator(length); if (buffer == nullptr) { recycler->ReportExternalMemoryFailure(length); } } else { JavascriptError::ThrowOutOfMemoryError(GetScriptContext()); } } if (buffer != nullptr) { ZeroMemory(buffer, length); sharedContents = HeapNew(SharedContents, buffer, length); if (sharedContents == nullptr) { recycler->ReportExternalMemoryFailure(length); // What else could we do? JavascriptError::ThrowOutOfMemoryError(GetScriptContext()); } #if DBG sharedContents->AddAgent((DWORD_PTR)GetScriptContext()); #endif } } }
DetachedStateBase* SharedArrayBuffer::GetSharableState(Var object) { Assert(SharedArrayBuffer::Is(object)); SharedArrayBuffer * sab = SharedArrayBuffer::FromVar(object); SharedContents * contents = sab->GetSharedContents(); #if _WIN64 if (sab->IsValidVirtualBufferLength(contents->bufferLength)) { return HeapNew(SharableState, contents, ArrayBufferAllocationType::MemAlloc); } else { return HeapNew(SharableState, contents, ArrayBufferAllocationType::Heap); } #else return HeapNew(SharableState, contents, ArrayBufferAllocationType::Heap); #endif }
WeakDiagStack * ProbeContainer::GetFramePointers() { if (framePointers == nullptr || this->debugSessionNumber < debugManager->GetDebugSessionNumber()) { UpdateFramePointers(/*fMatchWithCurrentScriptContext*/true); this->debugSessionNumber = debugManager->GetDebugSessionNumber(); } ReferencedArenaAdapter* pRefArena = debugManager->GetDiagnosticArena(); return HeapNew(WeakDiagStack,pRefArena,framePointers); }
WaiterList *SharedArrayBuffer::GetWaiterList(uint index) { if (sharedContents != nullptr) { if (sharedContents->indexToWaiterList == nullptr) { sharedContents->indexToWaiterList = HeapNew(IndexToWaitersMap, &HeapAllocator::Instance); } WaiterList * waiters = nullptr; if (!sharedContents->indexToWaiterList->TryGetValue(index, &waiters)) { waiters = HeapNew(WaiterList); sharedContents->indexToWaiterList->Add(index, waiters); } return waiters; } Assert(false); return nullptr; }
void SnapshotExtractor::BeginSnapshot(ThreadContext* threadContext, const JsUtil::List<Js::Var, HeapAllocator>& roots, const JsUtil::List<Js::ScriptContext*, HeapAllocator>& ctxs) { AssertMsg((this->m_pendingSnap == nullptr) & this->m_worklist.Empty(), "Something went wrong."); this->m_pendingSnap = HeapNew(SnapShot); UnorderedArrayList<NSSnapValues::SnapContext, TTD_ARRAY_LIST_SIZE_XSMALL>& snpCtxs = this->m_pendingSnap->GetContextList(); for(int32 i = 0; i < ctxs.Count(); ++i) { NSSnapValues::SnapContext* snpCtx = snpCtxs.NextOpenEntry(); NSSnapValues::ExtractScriptContext(snpCtx, ctxs.Item(i), this->m_pendingSnap->GetSnapshotSlabAllocator()); } }
void DebugManager::SetCurrentInterpreterLocation(InterpreterHaltState* pHaltState) { Assert(pHaltState); Assert(!pCurrentInterpreterLocation); pCurrentInterpreterLocation = pHaltState; AutoAllocatorObjectPtr<ArenaAllocator, HeapAllocator> pDiagArena(HeapNew(ArenaAllocator, _u("DiagHaltState"), this->pThreadContext->GetPageAllocator(), Js::Throw::OutOfMemory), &HeapAllocator::Instance); AutoAllocatorObjectPtr<ReferencedArenaAdapter, HeapAllocator> referencedDiagnosticArena(HeapNew(ReferencedArenaAdapter, pDiagArena), &HeapAllocator::Instance); pCurrentInterpreterLocation->referencedDiagnosticArena = referencedDiagnosticArena; pThreadContext->GetRecycler()->RegisterExternalGuestArena(pDiagArena); debugSessionNumber++; pDiagArena.Detach(); referencedDiagnosticArena.Detach(); }
NativeCodeData * NativeCodeData::Allocator::Finalize() { NativeCodeData * data = nullptr; if (this->chunkList != nullptr) { data = HeapNew(NativeCodeData, this->chunkList); this->chunkList = nullptr; #ifdef PERF_COUNTERS data->size = this->size; this->size = 0; #endif } #if DBG this->finalized = true; #endif return data; }
HRESULT ServerInitializeScriptContext( /* [in] */ handle_t binding, /* [in] */ __RPC__in ScriptContextDataIDL * scriptContextData, /* [in] */ intptr_t threadContextInfoAddress, /* [out] */ __RPC__out intptr_t * scriptContextInfoAddress) { AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow)); ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer((void*)threadContextInfoAddress); if (threadContextInfo == nullptr) { Assert(false); *scriptContextInfoAddress = 0; return RPC_S_INVALID_ARG; } if (!ServerContextManager::IsThreadContextAlive(threadContextInfo)) { Assert(false); *scriptContextInfoAddress = 0; return E_ACCESSDENIED; } return ServerCallWrapper(threadContextInfo, [&]()->HRESULT { ServerScriptContext * contextInfo = HeapNew(ServerScriptContext, scriptContextData, threadContextInfo); ServerContextManager::RegisterScriptContext(contextInfo); *scriptContextInfoAddress = (intptr_t)EncodePointer(contextInfo); #if !FLOATVAR // TODO: should move this to ServerInitializeThreadContext, also for the fields in IDL XProcNumberPageSegmentImpl::Initialize(contextInfo->IsRecyclerVerifyEnabled(), contextInfo->GetRecyclerVerifyPad()); #endif return S_OK; }); }
void ParseMsgDivisionEnd(void) { MAINFO mi; char *p; if (!do_marea) return; if (! *prefix) { printf("\n\aError! MsgDivisionEnd on line %d has no correspondig MsgDivisionBegin!\n", linenum); Compiling(-1, NULL, NULL); return; } /* Strip off the trailing dot */ prefix[strlen(prefix)-1]=0; /* Now set the prefix back to the prior area */ if ((p=strrchr(prefix, '.')) != NULL) p[1]=0; else *prefix=0; MsgAreaWrite(NULL, FALSE); memset(&mi, 0, sizeof mi); mi.marea=TRUE; HeapNew(&mi.h, MAX_MSG_HEAP); mi.ma.attribs = MA_DIVEND; mi.ma.division = --division; HeapAdd(&mi.h, &mi.ma.acs, ""); MsgAreaWrite(&mi, FALSE); HeapDelete(&mi.h); }
JsUtil::JobProcessor * ThreadBoundThreadContextManager::GetSharedJobProcessor() { #if ENABLE_BACKGROUND_JOB_PROCESSOR if (s_sharedJobProcessor == NULL) { // Don't use ThreadContext::GetCriticalSection() because it's also locked during thread detach while the loader lock is // held, and that may prevent the background job processor's thread from being started due to contention on the loader // lock, leading to a deadlock AutoCriticalSection lock(&s_sharedJobProcessorCreationLock); if (s_sharedJobProcessor == NULL) { // We don't need to have allocation policy manager for web worker. s_sharedJobProcessor = HeapNew(JsUtil::BackgroundJobProcessor, NULL, NULL, false /*disableParallelThreads*/); } } return s_sharedJobProcessor; #else return nullptr; #endif }
Js::ScriptContext* JsrtContextCore::EnsureScriptContext() { Assert(this->GetScriptContext() == nullptr); ThreadContext* localThreadContext = this->GetRuntime()->GetThreadContext(); AutoPtr<Js::ScriptContext> newScriptContext(Js::ScriptContext::New(localThreadContext)); newScriptContext->Initialize(); hostContext = HeapNew(ChakraCoreHostScriptContext, newScriptContext); newScriptContext->SetHostScriptContext(hostContext); this->SetScriptContext(newScriptContext.Detach()); Js::JavascriptLibrary *library = this->GetScriptContext()->GetLibrary(); Assert(library != nullptr); library->GetEvalFunctionObject()->SetEntryPoint(&Js::GlobalObject::EntryEval); library->GetFunctionConstructor()->SetEntryPoint(&Js::JavascriptFunction::NewInstance); return this->GetScriptContext(); }
ServerThreadContext::ServerThreadContext(ThreadContextDataIDL* data, ProcessContext* processContext) : m_threadContextData(*data), m_refCount(0), m_numericPropertyBV(nullptr), m_preReservedSectionAllocator(processContext->processHandle), m_sectionAllocator(processContext->processHandle), m_codePageAllocators(nullptr, ALLOC_XDATA, &m_sectionAllocator, &m_preReservedSectionAllocator, processContext->processHandle), m_thunkPageAllocators(nullptr, /* allocXData */ false, &m_sectionAllocator, nullptr, processContext->processHandle), #if defined(_CONTROL_FLOW_GUARD) && !defined(_M_ARM) m_jitThunkEmitter(this, &m_sectionAllocator, processContext->processHandle), #endif m_pageAlloc(nullptr, Js::Configuration::Global.flags, PageAllocatorType_BGJIT, AutoSystemInfo::Data.IsLowMemoryProcess() ? PageAllocator::DefaultLowMaxFreePageCount : PageAllocator::DefaultMaxFreePageCount ), processContext(processContext), m_canCreatePreReservedSegment(data->allowPrereserveAlloc != FALSE) { m_pid = GetProcessId(processContext->processHandle); m_numericPropertyBV = HeapNew(BVSparse<HeapAllocator>, &HeapAllocator::Instance); }
void ParseMsgDivisionBegin(char *name, char *acs, char *displayfile, char *descript) { MAINFO mi; char fullname[PATHLEN]; if (!do_marea) return; if (strchr(name, '.')) BadDivisionName(); strcpy(fullname, prefix); strcat(fullname, name); strcat(prefix, name); strcat(prefix, "."); MsgAreaWrite(NULL, FALSE); memset(&mi, 0, sizeof mi); mi.marea=TRUE; HeapNew(&mi.h, MAX_MSG_HEAP); HeapAdd(&mi.h, &mi.ma.name, fullname); HeapAdd(&mi.h, &mi.ma.descript, descript); HeapAdd(&mi.h, &mi.ma.acs, acs); HeapAdd(&mi.h, &mi.ma.path, displayfile); mi.ma.attribs = MA_DIVBEGIN; mi.ma.division = division++; MsgAreaWrite(&mi, FALSE); HeapDelete(&mi.h); }
ThreadContext * ThreadBoundThreadContextManager::EnsureContextForCurrentThread() { AutoCriticalSection lock(ThreadContext::GetCriticalSection()); ThreadContextTLSEntry * entry = ThreadContextTLSEntry::GetEntryForCurrentThread(); if (entry == NULL) { ThreadContextTLSEntry::CreateEntryForCurrentThread(); entry = ThreadContextTLSEntry::GetEntryForCurrentThread(); entries.Prepend(entry); } ThreadContext * threadContext = entry->GetThreadContext(); // An existing TLS entry may have a null ThreadContext // DllCanUnload may have cleaned out all the TLS entry when the module lock count is 0, // but the library didn't get unloaded because someone is holding onto ref count via LoadLibrary. // Just reinitialize the thread context. if (threadContext == nullptr) { threadContext = HeapNew(ThreadContext); threadContext->SetIsThreadBound(); if (!ThreadContextTLSEntry::TrySetThreadContext(threadContext)) { HeapDelete(threadContext); return NULL; } } Assert(threadContext != NULL); s_maxNumberActiveThreadContexts = max(s_maxNumberActiveThreadContexts, GetActiveThreadContextCount()); return threadContext; }
int ParseMsgArea(FILE *ctlfile, char *name) { char line[PATHLEN]; char fullname[PATHLEN]; static MAINFO mi; OVRLIST ol; struct _vbtab verbs[]= { {0, "acs", &mi.ma.acs}, {FiltPath, "path", &mi.ma.path}, {0, "tag", &mi.ma.echo_tag}, {0, "desc", &mi.ma.descript}, {0, "description", &mi.ma.descript}, {FiltOrigin, "origin", &mi.ma.origin}, #ifdef MAX_TRACKER {FiltOwner, "owner", NULL}, #endif {FiltMenuname,"menuname", NULL}, {FiltOverride,"override", NULL}, {FiltStyle, "style", NULL}, {FiltRenum, "renum", NULL}, {FiltBarricade,"barricade", NULL}, {0, "app", NULL}, {0, "application", NULL}, {0, "attachpath", &mi.ma.attachpath}, {0, NULL, NULL} }; if (strchr(name, '.')) BadDivisionName(); if (do_marea) { /* Make sure that area file is open */ MsgAreaWrite(NULL, FALSE); memset(&mi, 0, sizeof mi); mi.marea=TRUE; mi.ma.division=division; mi.ma.primary=prm.address[0]; mi.ma.seenby=prm.address[!!prm.address[0].point && prm.address[1].zone]; HeapNew(&mi.h, MAX_MSG_HEAP); strcpy(fullname, prefix); strcat(fullname, name); HeapAdd(&mi.h, &mi.ma.name, fullname); #ifdef MAX_TRACKER *toNewOwner=0; #endif } while (fgets(line, PATHLEN, ctlfile)) if (VerbParse(&mi, do_marea ? verbs : NULL, line)) break; if (do_marea) { MsgAreaWrite(&mi, FALSE); for (ol=mi.ol; ol; ol=ol->next) free(ol); HeapDelete(&mi.h); } return 0; }
NativeCodeGenerator * NewNativeCodeGenerator(Js::ScriptContext * scriptContext) { return HeapNew(NativeCodeGenerator, scriptContext); }
SnapShot* SnapShot::ParseSnapshotFromFile(FileReader* reader) { reader->ReadRecordStart(); reader->ReadDouble(NSTokens::Key::timeTotal); reader->ReadUInt64(NSTokens::Key::usedMemory, true); reader->ReadUInt64(NSTokens::Key::reservedMemory, true); reader->ReadDouble(NSTokens::Key::timeMark, true); reader->ReadDouble(NSTokens::Key::timeExtract, true); SnapShot* snap = HeapNew(SnapShot); uint32 ctxCount = reader->ReadLengthValue(true); reader->ReadSequenceStart_WDefaultKey(true); for(uint32 i = 0; i < ctxCount; ++i) { NSSnapValues::SnapContext* snpCtx = snap->m_ctxList.NextOpenEntry(); NSSnapValues::ParseSnapContext(snpCtx, i != 0, reader, snap->GetSnapshotSlabAllocator()); } reader->ReadSequenceEnd(); //// SnapShot::ParseListHelper(&NSSnapType::ParseSnapHandler, snap->m_handlerList, reader, snap->GetSnapshotSlabAllocator()); TTDIdentifierDictionary<TTD_PTR_ID, NSSnapType::SnapHandler*> handlerMap; handlerMap.Initialize(snap->m_handlerList.Count()); for(auto iter = snap->m_handlerList.GetIterator(); iter.IsValid(); iter.MoveNext()) { handlerMap.AddItem(iter.Current()->HandlerId, iter.Current()); } SnapShot::ParseListHelper_WMap(&NSSnapType::ParseSnapType, snap->m_typeList, reader, snap->GetSnapshotSlabAllocator(), handlerMap); TTDIdentifierDictionary<TTD_PTR_ID, NSSnapType::SnapType*> typeMap; typeMap.Initialize(snap->m_typeList.Count()); for(auto iter = snap->m_typeList.GetIterator(); iter.IsValid(); iter.MoveNext()) { typeMap.AddItem(iter.Current()->TypePtrId, iter.Current()); } //// uint32 bodyCount = reader->ReadLengthValue(true); reader->ReadSequenceStart_WDefaultKey(true); for(uint32 i = 0; i < bodyCount; ++i) { NSSnapValues::FunctionBodyResolveInfo* into = snap->m_functionBodyList.NextOpenEntry(); NSSnapValues::ParseFunctionBodyInfo(into, i != 0, reader, snap->GetSnapshotSlabAllocator()); } reader->ReadSequenceEnd(); SnapShot::ParseListHelper_WMap(&NSSnapValues::ParseSnapPrimitiveValue, snap->m_primitiveObjectList, reader, snap->GetSnapshotSlabAllocator(), typeMap); uint32 objCount = reader->ReadLengthValue(true); reader->ReadSequenceStart_WDefaultKey(true); for(uint32 i = 0; i < objCount; ++i) { NSSnapObjects::SnapObject* into = snap->m_compoundObjectList.NextOpenEntry(); NSSnapObjects::ParseObject(into, i != 0, reader, snap->GetSnapshotSlabAllocator(), snap->m_snapObjectVTableArray, typeMap); } reader->ReadSequenceEnd(); //// SnapShot::ParseListHelper(&NSSnapValues::ParseScriptFunctionScopeInfo, snap->m_scopeEntries, reader, snap->GetSnapshotSlabAllocator()); SnapShot::ParseListHelper(&NSSnapValues::ParseSlotArrayInfo, snap->m_slotArrayEntries, reader, snap->GetSnapshotSlabAllocator()); reader->ReadDouble(NSTokens::Key::timeWrite, true); reader->ReadRecordEnd(); return snap; }
void WaiterList::InitWaiterList() { Assert(m_waiters == nullptr); m_waiters = HeapNew(Waiters, &HeapAllocator::Instance); }