Pyrogenesis  trunk
Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ScriptRuntime Class Reference

Abstraction around a SpiderMonkey JSRuntime. More...

#include <ScriptRuntime.h>

Public Member Functions

 ScriptRuntime (shared_ptr< ScriptRuntime > parentRuntime, int runtimeSize, int heapGrowthBytesGCTrigger)
 
 ~ScriptRuntime ()
 
void MaybeIncrementalGC (double delay)
 MaybeIncrementalRuntimeGC tries to determine whether a runtime-wide garbage collection would free up enough memory to be worth the amount of time it would take. More...
 
void ShrinkingGC ()
 
void RegisterContext (JSContext *cx)
 
void UnRegisterContext (JSContext *cx)
 
void AddDeferredFinalizationObject (const std::shared_ptr< void > &obj)
 Registers an object to be freed/finalized by the ScriptRuntime. More...
 

Public Attributes

JSRuntime * m_rt
 

Private Member Functions

void PrepareContextsForIncrementalGC ()
 
void GCCallbackMember ()
 

Static Private Member Functions

static void GCCallback (JSRuntime *rt, JSGCStatus status, void *data)
 

Private Attributes

std::list< JSContext * > m_Contexts
 
std::vector< std::shared_ptr< void > > m_FinalizationListObjectIdCache
 
int m_RuntimeSize
 
int m_HeapGrowthBytesGCTrigger
 
int m_LastGCBytes
 
double m_LastGCCheck
 

Detailed Description

Abstraction around a SpiderMonkey JSRuntime.

Each ScriptRuntime can be used to initialize several ScriptInterface contexts which can then share data, but a single ScriptRuntime should only be used on a single thread.

(One means to share data between threads and runtimes is to create a ScriptInterface::StructuredClone.)

Constructor & Destructor Documentation

ScriptRuntime::ScriptRuntime ( shared_ptr< ScriptRuntime parentRuntime,
int  runtimeSize,
int  heapGrowthBytesGCTrigger 
)
ScriptRuntime::~ScriptRuntime ( )

Member Function Documentation

void ScriptRuntime::AddDeferredFinalizationObject ( const std::shared_ptr< void > &  obj)

Registers an object to be freed/finalized by the ScriptRuntime.

Freeing is guaranteed to happen after the next minor GC has completed, but might also happen a bit later. This is only needed in very special situations and you should only use it if you know exactly why you need it! Specify a deleter for the shared_ptr to free the void pointer correctly (by casting to the right type before calling delete for example).

void ScriptRuntime::GCCallback ( JSRuntime *  rt,
JSGCStatus  status,
void *  data 
)
staticprivate
void ScriptRuntime::GCCallbackMember ( )
private
void ScriptRuntime::MaybeIncrementalGC ( double  delay)

MaybeIncrementalRuntimeGC tries to determine whether a runtime-wide garbage collection would free up enough memory to be worth the amount of time it would take.

It does this with our own logic and NOT some predefined JSAPI logic because such functionality currently isn't available out of the box. It does incremental GC which means it will collect one slice each time it's called until the garbage collection is done. This can and should be called quite regularly. The delay parameter allows you to specify a minimum time since the last GC in seconds (the delay should be a fraction of a second in most cases though). It will only start a new incremental GC or another GC slice if this time is exceeded. The user of this function is responsible for ensuring that GC can run with a small enough delay to get done with the work.

void ScriptRuntime::PrepareContextsForIncrementalGC ( )
private
void ScriptRuntime::RegisterContext ( JSContext *  cx)
void ScriptRuntime::ShrinkingGC ( )
void ScriptRuntime::UnRegisterContext ( JSContext *  cx)

Member Data Documentation

std::list<JSContext*> ScriptRuntime::m_Contexts
private
std::vector<std::shared_ptr<void> > ScriptRuntime::m_FinalizationListObjectIdCache
private
int ScriptRuntime::m_HeapGrowthBytesGCTrigger
private
int ScriptRuntime::m_LastGCBytes
private
double ScriptRuntime::m_LastGCCheck
private
JSRuntime* ScriptRuntime::m_rt
int ScriptRuntime::m_RuntimeSize
private

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