mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-28 06:06:41 +00:00
Encapsulate runtime creation.
- Makes it easier to change down the line (and change is coming) - Allows making g_ScriptRuntime thread-local easily. - Remove ParentRuntime, which is not used at the moment. Part of the SM52 migration, stage: SM45 compatible. Patch by: Itms Tested By: Freagarach Refs #4893 Differential Revision: https://code.wildfiregames.com/D3087 This was SVN commit r24171.
This commit is contained in:
@@ -23,7 +23,11 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#define STACK_CHUNK_SIZE 8192
|
||||
constexpr int STACK_CHUNK_SIZE = 8192;
|
||||
|
||||
// Those are minimal defaults. The runtime for the main game is larger and GCs upon a larger growth.
|
||||
constexpr int DEFAULT_RUNTIME_SIZE = 16 * 1024 * 1024;
|
||||
constexpr int DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER = 2 * 1024 * 1024;
|
||||
|
||||
/**
|
||||
* Abstraction around a SpiderMonkey JSRuntime.
|
||||
@@ -38,9 +42,21 @@
|
||||
class ScriptRuntime
|
||||
{
|
||||
public:
|
||||
ScriptRuntime(shared_ptr<ScriptRuntime> parentRuntime, int runtimeSize, int heapGrowthBytesGCTrigger);
|
||||
ScriptRuntime(int runtimeSize, int heapGrowthBytesGCTrigger);
|
||||
~ScriptRuntime();
|
||||
|
||||
/**
|
||||
* Returns a runtime, which can used to initialise any number of
|
||||
* ScriptInterfaces contexts. Values created in one context may be used
|
||||
* in any other context from the same runtime (but not any other runtime).
|
||||
* Each runtime should only ever be used on a single thread.
|
||||
* @param runtimeSize Maximum size in bytes of the new runtime
|
||||
* @param heapGrowthBytesGCTrigger Size in bytes of cumulated allocations after which a GC will be triggered
|
||||
*/
|
||||
static shared_ptr<ScriptRuntime> CreateRuntime(
|
||||
int runtimeSize = DEFAULT_RUNTIME_SIZE,
|
||||
int heapGrowthBytesGCTrigger = DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER);
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
Reference in New Issue
Block a user