Move script_filename_table into JSRuntime where it belongs (235145, r=shaver).

This commit is contained in:
brendan%mozilla.org 2004-02-22 03:21:15 +00:00
Родитель ebb5371b41
Коммит e18fed3f6a
5 изменённых файлов: 41 добавлений и 31 удалений

Просмотреть файл

@ -645,8 +645,6 @@ JS_NewRuntime(uint32 maxbytes)
JS_END_MACRO;
#endif /* DEBUG */
if (!js_InitScriptGlobals())
return NULL;
if (!js_InitStringGlobals())
return NULL;
rt = (JSRuntime *) malloc(sizeof(JSRuntime));
@ -744,7 +742,6 @@ JS_ShutDown(void)
{
JS_ArenaShutDown();
js_FinishDtoa();
js_FreeScriptGlobals();
js_FreeStringGlobals();
#ifdef JS_THREADSAFE
js_CleanupLocks();

Просмотреть файл

@ -138,6 +138,8 @@ js_NewContext(JSRuntime *rt, size_t stackChunkSize)
ok = js_InitScanner(cx);
if (ok)
ok = js_InitRuntimeNumberState(cx);
if (ok)
ok = js_InitRuntimeScriptState(cx);
if (ok)
ok = js_InitRuntimeStringState(cx);
if (!ok) {
@ -238,6 +240,9 @@ js_DestroyContext(JSContext *cx, JSGCMode gcmode)
if (rt->atomState.liveAtoms == 0)
js_FreeAtomState(cx, &rt->atomState);
/* Now after the last GC can we free the script filename table. */
js_FinishRuntimeScriptState(cx);
/* Take the runtime down, now that it has no contexts or atoms. */
JS_LOCK_GC(rt);
rt->state = JSRTS_DOWN;

Просмотреть файл

@ -209,6 +209,12 @@ struct JSRuntime {
JSScopeProperty *propertyFreeList;
JSArenaPool propertyArenaPool;
/* Script filename table. */
struct JSHashTable *scriptFilenameTable;
#ifdef JS_THREADSAFE
PRLock *scriptFilenameTableLock;
#endif
#ifdef DEBUG
/* Function invocation metering. */
jsrefcount inlineCalls;

Просмотреть файл

@ -872,11 +872,6 @@ js_InitScriptClass(JSContext *cx, JSObject *obj)
/*
* Shared script filename management.
*/
static JSHashTable *script_filename_table;
#ifdef JS_THREADSAFE
static JSLock *script_filename_table_lock;
#endif
JS_STATIC_DLL_CALLBACK(int)
js_compare_strings(const void *k1, const void *k2)
{
@ -921,41 +916,47 @@ static JSHashAllocOps table_alloc_ops = {
};
JSBool
js_InitScriptGlobals()
js_InitRuntimeScriptState(JSContext *cx)
{
JSRuntime *rt = cx->runtime;
#ifdef JS_THREADSAFE
/* Must come through here once in primordial thread to init safely! */
if (!script_filename_table_lock) {
script_filename_table_lock = JS_NEW_LOCK();
if (!script_filename_table_lock)
if (!rt->scriptFilenameTableLock) {
rt->scriptFilenameTableLock = JS_NEW_LOCK();
if (!rt->scriptFilenameTableLock)
return JS_FALSE;
}
#endif
if (!script_filename_table) {
JS_ACQUIRE_LOCK(script_filename_table_lock);
if (!script_filename_table) {
script_filename_table =
if (!rt->scriptFilenameTable) {
JS_ACQUIRE_LOCK(rt->scriptFilenameTableLock);
if (!rt->scriptFilenameTable) {
rt->scriptFilenameTable =
JS_NewHashTable(16, JS_HashString, js_compare_strings, NULL,
&table_alloc_ops, NULL);
}
JS_RELEASE_LOCK(script_filename_table_lock);
if (!script_filename_table)
JS_RELEASE_LOCK(rt->scriptFilenameTableLock);
if (!rt->scriptFilenameTable) {
js_FinishRuntimeScriptState(cx); /* free lock if threadsafe */
return JS_FALSE;
}
}
return JS_TRUE;
}
void
js_FreeScriptGlobals()
js_FinishRuntimeScriptState(JSContext *cx)
{
if (script_filename_table) {
JS_HashTableDestroy(script_filename_table);
script_filename_table = NULL;
JSRuntime *rt = cx->runtime;
if (rt->scriptFilenameTable) {
JS_HashTableDestroy(rt->scriptFilenameTable);
rt->scriptFilenameTable = NULL;
}
#ifdef JS_THREADSAFE
if (script_filename_table_lock) {
JS_DESTROY_LOCK(script_filename_table_lock);
script_filename_table_lock = NULL;
if (rt->scriptFilenameTableLock) {
JS_DESTROY_LOCK(rt->scriptFilenameTableLock);
rt->scriptFilenameTableLock = NULL;
}
#endif
}
@ -967,13 +968,14 @@ size_t sft_savings = 0;
const char *
js_SaveScriptFilename(JSContext *cx, const char *filename)
{
JSRuntime *rt = cx->runtime;
JSHashTable *table;
JSHashNumber hash;
JSHashEntry **hep;
ScriptFilenameEntry *sfe;
JS_ACQUIRE_LOCK(script_filename_table_lock);
table = script_filename_table;
JS_ACQUIRE_LOCK(rt->scriptFilenameTableLock);
table = rt->scriptFilenameTable;
hash = JS_HashString(filename);
hep = JS_HashTableRawLookup(table, hash, filename);
sfe = (ScriptFilenameEntry *) *hep;
@ -989,7 +991,7 @@ js_SaveScriptFilename(JSContext *cx, const char *filename)
JS_ASSERT(!sfe->mark);
}
}
JS_RELEASE_LOCK(script_filename_table_lock);
JS_RELEASE_LOCK(rt->scriptFilenameTableLock);
if (!sfe) {
JS_ReportOutOfMemory(cx);
return NULL;
@ -1029,7 +1031,7 @@ js_script_filename_sweeper(JSHashEntry *he, intN i, void *arg)
void
js_SweepScriptFilenames(JSRuntime *rt)
{
JS_HashTableEnumerateEntries(script_filename_table,
JS_HashTableEnumerateEntries(rt->scriptFilenameTable,
js_script_filename_sweeper,
rt);
#ifdef DEBUG_brendan

Просмотреть файл

@ -102,10 +102,10 @@ extern JSObject *
js_InitScriptClass(JSContext *cx, JSObject *obj);
extern JSBool
js_InitScriptGlobals();
js_InitRuntimeScriptState(JSContext *cx);
extern void
js_FreeScriptGlobals();
js_FinishRuntimeScriptState(JSContext *cx);
extern const char *
js_SaveScriptFilename(JSContext *cx, const char *filename);