Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/scriptinterface/ScriptContext.h
Show All 17 Lines | |||||
#ifndef INCLUDED_SCRIPTCONTEXT | #ifndef INCLUDED_SCRIPTCONTEXT | ||||
#define INCLUDED_SCRIPTCONTEXT | #define INCLUDED_SCRIPTCONTEXT | ||||
#include "ScriptTypes.h" | #include "ScriptTypes.h" | ||||
#include "ScriptExtraHeaders.h" | #include "ScriptExtraHeaders.h" | ||||
#include <sstream> | #include <sstream> | ||||
constexpr int STACK_CHUNK_SIZE = 8192; | |||||
// Those are minimal defaults. The runtime for the main game is larger and GCs upon a larger growth. | // Those are minimal defaults. The runtime for the main game is larger and GCs upon a larger growth. | ||||
constexpr int DEFAULT_CONTEXT_SIZE = 16 * 1024 * 1024; | constexpr int DEFAULT_CONTEXT_SIZE = 16 * 1024 * 1024; | ||||
constexpr int DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER = 2 * 1024 * 1024; | constexpr int DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER = 2 * 1024 * 1024; | ||||
/** | /** | ||||
* Abstraction around a SpiderMonkey JSRuntime/JSContext. | * Abstraction around a SpiderMonkey JSContext. | ||||
* | * | ||||
* A single ScriptContext, with the associated runtime and context, | * A single ScriptContext, with the associated context, | ||||
* should only be used on a single thread. | * should only be used on a single thread. | ||||
* | * | ||||
* (One means to share data between threads and contexts is to create | * (One means to share data between threads and contexts is to create | ||||
* a ScriptInterface::StructuredClone.) | * a ScriptInterface::StructuredClone.) | ||||
*/ | */ | ||||
class ScriptContext | class ScriptContext | ||||
{ | { | ||||
Show All 27 Lines | public: | ||||
void ShrinkingGC(); | void ShrinkingGC(); | ||||
/** | /** | ||||
* This is used to keep track of compartments which should be prepared for a GC. | * This is used to keep track of compartments which should be prepared for a GC. | ||||
*/ | */ | ||||
void RegisterCompartment(JSCompartment* cmpt); | void RegisterCompartment(JSCompartment* cmpt); | ||||
void UnRegisterCompartment(JSCompartment* cmpt); | void UnRegisterCompartment(JSCompartment* cmpt); | ||||
JSRuntime* GetJSRuntime() const { return m_rt; } | |||||
/** | /** | ||||
* GetGeneralJSContext returns the context without starting a GC request and without | * GetGeneralJSContext returns the context without starting a GC request and without | ||||
* entering any compartment. It should only be used in specific situations, such as | * entering any compartment. It should only be used in specific situations, such as | ||||
* creating a new compartment, or as an unsafe alternative to GetJSRuntime. | * creating a new compartment, or when initializing a persistent rooted. | ||||
* If you need the compartmented context of a ScriptInterface, you should create a | * If you need the compartmented context of a ScriptInterface, you should create a | ||||
* ScriptRequest and use the context from that. | * ScriptRequest and use the context from that. | ||||
*/ | */ | ||||
JSContext* GetGeneralJSContext() const { return m_cx; } | JSContext* GetGeneralJSContext() const { return m_cx; } | ||||
private: | private: | ||||
JSRuntime* m_rt; | |||||
JSContext* m_cx; | JSContext* m_cx; | ||||
void PrepareCompartmentsForIncrementalGC() const; | void PrepareCompartmentsForIncrementalGC() const; | ||||
std::list<JSCompartment*> m_Compartments; | std::list<JSCompartment*> m_Compartments; | ||||
int m_ContextSize; | int m_ContextSize; | ||||
int m_HeapGrowthBytesGCTrigger; | int m_HeapGrowthBytesGCTrigger; | ||||
int m_LastGCBytes; | int m_LastGCBytes; | ||||
double m_LastGCCheck; | double m_LastGCCheck; | ||||
}; | }; | ||||
#endif // INCLUDED_SCRIPTCONTEXT | #endif // INCLUDED_SCRIPTCONTEXT |
Wildfire Games · Phabricator