Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Script::Context Class Reference

#include <Context.h>

Public Member Functions

 Context (int contextSize=DEFAULT_CONTEXT_SIZE, uint32_t heapGrowthBytesGCTrigger=DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER)
 Returns a context, in which any number of ScriptInterfaces compartments can live. More...
 
 ~Context ()
 
void MaybeIncrementalGC ()
 MaybeIncrementalGC checks if running a GC is worth the time that will take. More...
 
void ShrinkingGC ()
 Does a non-incremental, shrinking GC. More...
 
void RegisterRealm (JS::Realm *realm)
 This is used to keep track of realms which should be prepared for a GC. More...
 
void UnRegisterRealm (JS::Realm *realm)
 
void RunJobs ()
 Runs the promise continuation. More...
 
JSContext * GetGeneralJSContext () const
 GetGeneralJSContext returns the context without starting a GC request and without entering any compartment. More...
 

Private Member Functions

void PrepareZonesForIncrementalGC () const
 

Private Attributes

JSContext * m_cx
 
const std::unique_ptr< JobQueue > m_JobQueue
 
std::list< JS::Realm * > m_Realms
 
int m_ContextSize
 
uint32_t m_HeapGrowthBytesGCTrigger
 
uint32_t m_LastGCBytes {0}
 

Constructor & Destructor Documentation

◆ Context()

Script::Context::Context ( int  contextSize = DEFAULT_CONTEXT_SIZE,
uint32_t  heapGrowthBytesGCTrigger = DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER 
)

Returns a context, in which any number of ScriptInterfaces compartments can live.

Each context should only ever be used on a single thread.

Parameters
parentContextParent context from the parent thread, with which we share some thread-safe data
contextSizeMaximum size in bytes of the new context
heapGrowthBytesGCTriggerSize in bytes of cumulated allocations after which a GC will be triggered

◆ ~Context()

Script::Context::~Context ( )

Member Function Documentation

◆ GetGeneralJSContext()

JSContext * Script::Context::GetGeneralJSContext ( ) const
inline

GetGeneralJSContext returns the context without starting a GC request and without entering any compartment.

It should only be used in specific situations, such as creating a new compartment, or when initializing a persistent rooted. If you need the compartmented context of a Interface, you should create a Request and use the context from that.

◆ MaybeIncrementalGC()

void Script::Context::MaybeIncrementalGC ( )

MaybeIncrementalGC checks if running a GC is worth the time that will take.

The logic is custom as Spidermonkey tends to assume 'idle time' will exist, which is a thing in websites but not really in 0 A.D. This can have a few behaviours:

  • doing nothing
  • starting a new incremental GC
  • running a GC slice
  • finishing the incremental GC For details, check the SM doc in e.g. GC.cpp and GCapi.cpp

◆ PrepareZonesForIncrementalGC()

void Script::Context::PrepareZonesForIncrementalGC ( ) const
private

◆ RegisterRealm()

void Script::Context::RegisterRealm ( JS::Realm *  realm)

This is used to keep track of realms which should be prepared for a GC.

◆ RunJobs()

void Script::Context::RunJobs ( )

Runs the promise continuation.

On contexts where promises can be used this function has to be called. This function has to be called frequently.

◆ ShrinkingGC()

void Script::Context::ShrinkingGC ( )

Does a non-incremental, shrinking GC.

A shrinking GC dumps JIT code and tries to defragment memory.

◆ UnRegisterRealm()

void Script::Context::UnRegisterRealm ( JS::Realm *  realm)

Member Data Documentation

◆ m_ContextSize

int Script::Context::m_ContextSize
private

◆ m_cx

JSContext* Script::Context::m_cx
private

◆ m_HeapGrowthBytesGCTrigger

uint32_t Script::Context::m_HeapGrowthBytesGCTrigger
private

◆ m_JobQueue

const std::unique_ptr<JobQueue> Script::Context::m_JobQueue
private

◆ m_LastGCBytes

uint32_t Script::Context::m_LastGCBytes {0}
private

◆ m_Realms

std::list<JS::Realm*> Script::Context::m_Realms
private

The documentation for this class was generated from the following files: