Fiddle loop table slot interface and impl in hope of freeing slots over time.

This commit is contained in:
Brendan Eich 2008-06-02 18:06:33 -07:00
Родитель 78f3265003
Коммит 05c00565e0
5 изменённых файлов: 38 добавлений и 15 удалений

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

@ -126,6 +126,7 @@ struct JSThread {
/* Property cache for faster call/get/set invocation. */
JSPropertyCache propertyCache;
/* Trace-tree recorder/interpreter state. */
JSTraceMonitor traceMonitor;
};
@ -410,7 +411,7 @@ struct JSRuntime {
* loop table that tracks loop statistics is per-thread in a multi-threaded
* environment.
*/
uint32 loopTableIndexGen;
uint32 loopTableSlotGen;
/*
* Object shape (property cache structural type) identifier generator.

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

@ -2801,14 +2801,14 @@ JS_INTERPRET(JSContext *cx)
BEGIN_CASE(JSOP_HEADER)
{
uint32 index = GET_UINT24(regs.pc);
JS_ASSERT(index < rt->loopTableIndexGen);
slot = GET_UINT24(regs.pc);
JS_ASSERT(slot < rt->loopTableSlotGen);
JSTraceMonitor *tm = &JS_TRACE_MONITOR(cx);
if (index >= tm->loopTableSize && !js_GrowLoopTable(cx, index))
if (slot >= tm->loopTableSize && !js_GrowLoopTable(cx, slot))
goto error;
vp = &JS_TRACE_MONITOR(cx).loopTable[index];
vp = &JS_TRACE_MONITOR(cx).loopTable[slot];
rval = *vp;
if (JSVAL_IS_INT(rval)) {
/*

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

@ -535,17 +535,19 @@ js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic)
if (!ok)
goto error;
jsbytecode *pc = code;
jsbytecode *end = pc + length;
while (pc < end) {
if (script->loopHeaders) {
/* Assign a new loop table slot for every JSOP_HEADER opcode. */
if ((JSOp)*pc == JSOP_HEADER) {
uint32 slot = js_AllocateLoopTableSlot(cx->runtime);
SET_UINT24(pc, slot);
jsbytecode *pc = code;
jsbytecode *end = pc + length;
while (pc < end) {
if ((JSOp)*pc == JSOP_HEADER) {
uint32 slot = js_AllocateLoopTableSlot(cx->runtime);
SET_UINT24(pc, slot);
}
pc += js_OpLength(pc);
}
pc += js_OpLength(pc);
}
if (!JS_XDRBytes(xdr, (char *)notes, nsrcnotes * sizeof(jssrcnote)) ||
!JS_XDRCStringOrNull(xdr, (char **)&script->filename) ||
!JS_XDRUint32(xdr, &lineno) ||
@ -1572,6 +1574,17 @@ js_DestroyScript(JSContext *cx, JSScript *script)
js_FlushPropertyCacheForScript(cx, script);
}
if (script->loopHeaders) {
/* Free the loop table slot for every JSOP_HEADER opcode. */
jsbytecode *pc = script->code;
jsbytecode *end = pc + script->length;
while (pc < end) {
if ((JSOp)*pc == JSOP_HEADER)
js_FreeLoopTableSlot(cx->runtime, GET_UINT24(pc));
pc += js_OpLength(pc);
}
}
JS_free(cx, script);
}

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

@ -47,7 +47,15 @@ js_InitTracer(JSRuntime *rt)
}
uint32
js_AllocateLoopTableSlot(JSContext *cx)
js_AllocateLoopTableSlot(JSRuntime *rt)
{
uint32 slot = JS_ATOMIC_INCREMENT(&rt->loopTableSlotGen);
JS_ASSERT(slot != 0);
return slot - 1;
}
void
js_FreeLoopTableSlot(JSRuntime *rt, uint32 slot)
{
}

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

@ -55,7 +55,7 @@
* that loop.
*/
struct JSTraceMonitor {
jsval *loopTable;
jsval *loopTable;
uint32 loopTableSize;
};
@ -63,6 +63,7 @@ struct JSTraceMonitor {
JSBool js_InitTracer(JSRuntime *rt);
uint32 js_AllocateLoopTableSlot(JSRuntime *rt);
void js_FreeLoopTableSlot(JSRuntime *rt, uint32 slot);
JSBool js_GrowLoopTable(JSContext *cx, uint32 index);
#endif /* jstracer_h___ */