Move the recorder functionality into TraceRecorder to unclutter trace inlines.

This commit is contained in:
Andreas Gal 2008-06-26 21:58:57 -08:00
parent 0c98250a90
commit f357ff14f0
3 changed files with 110 additions and 96 deletions

View File

@ -214,29 +214,78 @@ TraceRecorder::TraceRecorder(JSStackFrame& _stackFrame, JSFrameRegs& _entryState
entryState = _entryState;
}
void TraceRecorder::load(void* p)
void
TraceRecorder::load(void* p)
{
JS_ASSERT(frameStack.contains(p));
tracker.set(p, lir->insLoadi(tracker.get(&entryState.sp), frameStack.nativeOffset(p)));
}
void TraceRecorder::init(void* p, LIns* i)
void
TraceRecorder::init(void* p, LIns* i)
{
tracker.set(p, i);
}
void TraceRecorder::set(void* p, LIns* i)
void
TraceRecorder::set(void* p, LIns* i)
{
init(p, i);
if (frameStack.contains(p))
lir->insStorei(i, get(&entryState.sp), frameStack.nativeOffset(p));
}
LIns* TraceRecorder::get(void* p)
LIns*
TraceRecorder::get(void* p)
{
return tracker.get(p);
}
void
TraceRecorder::copy(void* a, void* v)
{
set(v, get(a));
}
void
TraceRecorder::unary(nanojit::LOpcode op, void* a, void* v)
{
set(v, lir->ins1(op, get(a)));
}
void
TraceRecorder::binary(nanojit::LOpcode op, void* a, void* b, void* v)
{
set(v, lir->ins2(op, get(a), get(b)));
}
void
TraceRecorder::call(int id, void* a, void* v)
{
LInsp args[] = { get(a) };
set(v, lir->insCall(id, args));
}
void
TraceRecorder::call(int id, void* a, void* b, void* v)
{
LInsp args[] = { get(a), get(b) };
set(v, lir->insCall(id, args));
}
void
TraceRecorder::call(int id, void* a, void* b, void* c, void* v)
{
LInsp args[] = { get(a), get(b), get(c) };
set(v, lir->insCall(id, args));
}
void
TraceRecorder::iinc(void* a, int incr, void* v)
{
set(v, lir->ins2(LIR_add, get(a), lir->insImm(incr)));
}
bool
js_StartRecording(JSContext* cx, JSFrameRegs& regs)
{

View File

@ -42,12 +42,7 @@
#include "jsstddef.h"
#include "jslock.h"
namespace nanojit {
class LIns;
class Fragmento;
class Fragment;
class LirWriter;
}
#include "nanojit/nanojit.h"
/*
* Tracker is used to keep track of values being manipulated by the
@ -109,6 +104,15 @@ public:
nanojit::LIns* get(void* p);
void load(void*);
void copy(void* a, void* v);
void unary(nanojit::LOpcode op, void* a, void* v);
void binary(nanojit::LOpcode op, void* a, void* b, void* v);
void call(int id, void* a, void* v);
void call(int id, void* a, void* b, void* v);
void call(int id, void* a, void* b, void* c, void* v);
void iinc(void* a, int32_t incr, void* v);
};
/*

View File

@ -53,45 +53,6 @@ recorder(JSContext* cx)
return JS_TRACE_MONITOR(cx).recorder;
}
static inline void
copy(JSContext* cx, void* a, void* v)
{
recorder(cx)->set(v, recorder(cx)->get(a));
}
static inline void
unary(JSContext* cx, nanojit::LOpcode op, void* a, void* v)
{
recorder(cx)->set(v, recorder(cx)->lir->ins1(op, recorder(cx)->get(a)));
}
static inline void
binary(JSContext* cx, nanojit::LOpcode op, void* a, void* b, void* v)
{
recorder(cx)->set(v, recorder(cx)->lir->ins2(op, recorder(cx)->get(a), recorder(cx)->get(b)));
}
static inline void
call(JSContext* cx, int id, void* a, void* v)
{
LInsp args[] = { recorder(cx)->get(a) };
recorder(cx)->set(v, recorder(cx)->lir->insCall(id, args));
}
static inline void
call(JSContext* cx, int id, void* a, void* b, void* v)
{
LInsp args[] = { recorder(cx)->get(a), recorder(cx)->get(b) };
recorder(cx)->set(v, recorder(cx)->lir->insCall(id, args));
}
static inline void
call(JSContext* cx, int id, void* a, void* b, void* c, void* v)
{
LInsp args[] = { recorder(cx)->get(a), recorder(cx)->get(b), recorder(cx)->get(c) };
recorder(cx)->set(v, recorder(cx)->lir->insCall(id, args));
}
static inline SideExit*
snapshot(JSContext* cx, JSFrameRegs& regs, SideExit& exit)
{
@ -104,7 +65,7 @@ static inline void
prim_copy(JSContext* cx, jsval& from, jsval& to)
{
interp_prim_copy(cx, from, to);
copy(cx, &from, &to);
recorder(cx)->copy(&from, &to);
}
static inline void
@ -168,28 +129,28 @@ static inline void
prim_boolean_to_jsval(JSContext* cx, JSBool& b, jsval& v)
{
interp_prim_boolean_to_jsval(cx, b, v);
copy(cx, &b, &v);
recorder(cx)->copy(&b, &v);
}
static inline void
prim_string_to_jsval(JSContext* cx, JSString*& str, jsval& v)
{
interp_prim_string_to_jsval(cx, str, v);
copy(cx, &str, &v);
recorder(cx)->copy(&str, &v);
}
static inline void
prim_object_to_jsval(JSContext* cx, JSObject*& obj, jsval& v)
{
interp_prim_object_to_jsval(cx, obj, v);
copy(cx, &obj, &v);
recorder(cx)->copy(&obj, &v);
}
static inline void
prim_id_to_jsval(JSContext* cx, jsid& id, jsval& v)
{
interp_prim_id_to_jsval(cx, id, v);
copy(cx, &id, &v);
recorder(cx)->copy(&id, &v);
}
static inline bool
@ -198,12 +159,12 @@ guard_jsdouble_is_int_and_int_fits_in_jsval(JSContext* cx, JSFrameRegs& regs, js
bool ok = interp_guard_jsdouble_is_int_and_int_fits_in_jsval(cx, regs, d, i);
/* We do not box in trace code, so ints always fit and we only check
that it is actually an int. */
call(cx, F_DOUBLE_IS_INT, &d, &ok);
recorder(cx)->call(F_DOUBLE_IS_INT, &d, &ok);
SideExit exit;
recorder(cx)->lir->insGuard(G(ok),
recorder(cx)->get(&ok),
snapshot(cx, regs, exit));
unary(cx, LIR_callh, &ok, &i);
recorder(cx)->unary(LIR_callh, &ok, &i);
return ok;
}
@ -211,14 +172,14 @@ static inline void
prim_int_to_jsval(JSContext* cx, jsint& i, jsval& v)
{
interp_prim_int_to_jsval(cx, i, v);
copy(cx, &i, &v);
recorder(cx)->copy(&i, &v);
}
static inline bool
call_NewDoubleInRootedValue(JSContext* cx, jsdouble& d, jsval& v)
{
bool ok = interp_call_NewDoubleInRootedValue(cx, d, v);
copy(cx, &d, &v);
recorder(cx)->copy(&d, &v);
return ok;
}
@ -233,7 +194,7 @@ static inline void
prim_int_to_double(JSContext* cx, jsint& i, jsdouble& d)
{
interp_prim_int_to_double(cx, i, d);
unary(cx, LIR_i2f, &i, &d);
recorder(cx)->unary(LIR_i2f, &i, &d);
}
static inline bool
@ -247,14 +208,14 @@ static inline void
prim_uint_to_jsval(JSContext* cx, uint32& u, jsval& v)
{
interp_prim_uint_to_jsval(cx, u, v);
copy(cx, &u, &v);
recorder(cx)->copy(&u, &v);
}
static inline void
prim_uint_to_double(JSContext* cx, uint32& u, jsdouble& d)
{
interp_prim_uint_to_double(cx, u, d);
unary(cx, LIR_u2f, &u, &d);
recorder(cx)->unary(LIR_u2f, &u, &d);
}
static inline bool
@ -268,7 +229,7 @@ static inline void
prim_jsval_to_int(JSContext* cx, jsval& v, jsint& i)
{
interp_prim_jsval_to_int(cx, v, i);
copy(cx, &v, &i);
recorder(cx)->copy(&v, &i);
}
static inline bool
@ -282,14 +243,14 @@ static inline void
prim_jsval_to_double(JSContext* cx, jsval& v, jsdouble& d)
{
interp_prim_jsval_to_double(cx, v, d);
copy(cx, &v, &d);
recorder(cx)->copy(&v, &d);
}
static inline void
call_ValueToNumber(JSContext* cx, jsval& v, jsdouble& d)
{
interp_call_ValueToNumber(cx, v, d);
call(cx, F_ValueToNumber, cx, &v, &d);
recorder(cx)->call(F_ValueToNumber, cx, &v, &d);
}
static inline bool
@ -309,21 +270,21 @@ static inline void
call_ValueToECMAInt32(JSContext* cx, jsval& v, jsint& i)
{
interp_call_ValueToECMAInt32(cx, v, i);
call(cx, F_ValueToECMAInt32, cx, &v, &i);
recorder(cx)->call(F_ValueToECMAInt32, cx, &v, &i);
}
static inline void
prim_int_to_uint(JSContext* cx, jsint& i, uint32& u)
{
interp_prim_int_to_uint(cx, i, u);
copy(cx, &i, &u);
recorder(cx)->copy(&i, &u);
}
static inline void
call_ValueToECMAUint32(JSContext* cx, jsval& v, uint32& u)
{
interp_call_ValueToECMAUint32(cx, v, u);
call(cx, F_ValueToECMAUint32, cx, &v, &u);
recorder(cx)->call(F_ValueToECMAUint32, cx, &v, &u);
}
static inline void
@ -344,14 +305,14 @@ static inline void
prim_jsval_to_boolean(JSContext* cx, jsval& v, JSBool& b)
{
interp_prim_jsval_to_boolean(cx, v, b);
copy(cx, &v, &b);
recorder(cx)->copy(&v, &b);
}
static inline void
call_ValueToBoolean(JSContext* cx, jsval& v, JSBool& b)
{
interp_call_ValueToBoolean(cx, v, b);
call(cx, F_ValueToBoolean, cx, &v, &b);
recorder(cx)->call(F_ValueToBoolean, cx, &v, &b);
}
static inline bool
@ -365,7 +326,7 @@ static inline void
prim_jsval_to_object(JSContext* cx, jsval& v, JSObject*& obj)
{
interp_prim_jsval_to_object(cx, v, obj);
copy(cx, &v, &obj);
recorder(cx)->copy(&v, &obj);
}
static inline bool
@ -374,7 +335,7 @@ guard_obj_is_null(JSContext* cx, JSFrameRegs& regs, JSObject*& obj)
bool ok = interp_guard_obj_is_null(cx, regs, obj);
SideExit exit;
recorder(cx)->lir->insGuard(G(ok),
recorder(cx)->lir->ins2(LIR_eq, recorder(cx)->get(&obj), recorder(cx)->lir->insImm(0)),
recorder(cx)->lir->ins_eq0(recorder(cx)->get(&obj)),
snapshot(cx, regs, exit));
return ok;
}
@ -383,7 +344,7 @@ static inline void
call_ValueToNonNullObject(JSContext* cx, jsval& v, JSObject*& obj)
{
interp_call_ValueToNonNullObject(cx, v, obj);
call(cx, F_ValueToNonNullObject, cx, &v, &obj);
recorder(cx)->call(F_ValueToNonNullObject, cx, &v, &obj);
}
static inline bool
@ -391,7 +352,7 @@ call_obj_default_value(JSContext* cx, JSObject*& obj, JSType hint,
jsval& v)
{
bool ok = interp_call_obj_default_value(cx, obj, hint, v);
call(cx, F_obj_default_value, cx, &obj, recorder(cx)->lir->insImm(hint), &v);
recorder(cx)->call(F_obj_default_value, cx, &obj, recorder(cx)->lir->insImm(hint), &v);
return ok;
}
@ -399,21 +360,21 @@ static inline void
prim_dadd(JSContext* cx, jsdouble& a, jsdouble& b, jsdouble& r)
{
interp_prim_dadd(cx, a, b, r);
binary(cx, LIR_fadd, &a, &b, &r);
recorder(cx)->binary(LIR_fadd, &a, &b, &r);
}
static inline void
prim_dsub(JSContext* cx, jsdouble& a, jsdouble& b, jsdouble& r)
{
interp_prim_dsub(cx, a, b, r);
binary(cx, LIR_fsub, &a, &b, &r);
recorder(cx)->binary(LIR_fsub, &a, &b, &r);
}
static inline void
prim_dmul(JSContext* cx, jsdouble& a, jsdouble& b, jsdouble& r)
{
interp_prim_dmul(cx, a, b, r);
binary(cx, LIR_fmul, &a, &b, &r);
recorder(cx)->binary(LIR_fmul, &a, &b, &r);
}
static inline bool
@ -421,7 +382,7 @@ prim_ddiv(JSContext* cx, JSRuntime* rt, JSFrameRegs& regs, int n,
jsdouble& a, jsdouble& b)
{
bool ok = interp_prim_ddiv(cx, rt, regs, n, a, b);
binary(cx, LIR_fdiv, &a, &b, &regs.sp[n]);
recorder(cx)->binary(LIR_fdiv, &a, &b, &regs.sp[n]);
return ok;
}
@ -430,7 +391,7 @@ prim_dmod(JSContext* cx, JSRuntime* rt, JSFrameRegs& regs, int n,
jsdouble& a, jsdouble& b)
{
bool ok = interp_prim_dmod(cx, rt, regs, n, a, b);
call(cx, F_dmod, &a, &b, &regs.sp[n]);
recorder(cx)->call(F_dmod, &a, &b, &regs.sp[n]);
return ok;
}
@ -438,42 +399,42 @@ static inline void
prim_ior(JSContext* cx, jsint& a, jsint& b, jsint& r)
{
interp_prim_ior(cx, a, b, r);
binary(cx, LIR_or, &a, &b, &r);
recorder(cx)->binary(LIR_or, &a, &b, &r);
}
static inline void
prim_ixor(JSContext* cx, jsint& a, jsint& b, jsint& r)
{
interp_prim_ixor(cx, a, b, r);
binary(cx, LIR_xor, &a, &b, &r);
recorder(cx)->binary(LIR_xor, &a, &b, &r);
}
static inline void
prim_iand(JSContext* cx, jsint& a, jsint& b, jsint& r)
{
interp_prim_iand(cx, a, b, r);
binary(cx, LIR_and, &a, &b, &r);
recorder(cx)->binary(LIR_and, &a, &b, &r);
}
static inline void
prim_ilsh(JSContext* cx, jsint& a, jsint& b, jsint& r)
{
interp_prim_ilsh(cx, a, b, r);
binary(cx, LIR_lsh, &a, &b, &r);
recorder(cx)->binary(LIR_lsh, &a, &b, &r);
}
static inline void
prim_irsh(JSContext* cx, jsint& a, jsint& b, jsint& r)
{
interp_prim_irsh(cx, a, b, r);
binary(cx, LIR_rsh, &a, &b, &r);
recorder(cx)->binary(LIR_rsh, &a, &b, &r);
}
static inline void
prim_ursh(JSContext* cx, uint32& a, jsint& b, uint32& r)
{
interp_prim_ursh(cx, a, b, r);
binary(cx, LIR_ush, &a, &b, &r);
recorder(cx)->binary(LIR_ush, &a, &b, &r);
}
static inline bool
@ -482,7 +443,7 @@ guard_boolean_is_true(JSContext* cx, JSFrameRegs& regs, JSBool& cond)
bool ok = interp_guard_boolean_is_true(cx, regs, cond);
SideExit exit;
recorder(cx)->lir->insGuard(G(ok),
recorder(cx)->lir->ins2(LIR_eq, recorder(cx)->get(&cond), recorder(cx)->lir->insImm(0)),
recorder(cx)->lir->ins_eq0(recorder(cx)->get(&cond)),
snapshot(cx, regs, exit));
return ok;
}
@ -491,56 +452,56 @@ static inline void
prim_icmp_lt(JSContext* cx, jsint& a, jsint& b, JSBool& r)
{
interp_prim_icmp_lt(cx, a, b, r);
binary(cx, LIR_lt, &a, &b, &r);
recorder(cx)->binary(LIR_lt, &a, &b, &r);
}
static inline void
prim_icmp_le(JSContext* cx, jsint& a, jsint& b, JSBool& r)
{
interp_prim_icmp_le(cx, a, b, r);
binary(cx, LIR_le, &a, &b, &r);
recorder(cx)->binary(LIR_le, &a, &b, &r);
}
static inline void
prim_icmp_gt(JSContext* cx, jsint& a, jsint& b, JSBool& r)
{
interp_prim_icmp_gt(cx, a, b, r);
binary(cx, LIR_gt, &a, &b, &r);
recorder(cx)->binary(LIR_gt, &a, &b, &r);
}
static inline void
prim_icmp_ge(JSContext* cx, jsint& a, jsint& b, JSBool& r)
{
interp_prim_icmp_ge(cx, a, b, r);
binary(cx, LIR_ge, &a, &b, &r);
recorder(cx)->binary(LIR_ge, &a, &b, &r);
}
static inline void
prim_dcmp_lt(JSContext* cx, bool ifnan, jsdouble& a, jsdouble& b, JSBool& r)
{
interp_prim_dcmp_lt(cx, ifnan, a, b, r);
binary(cx, LIR_lt, &a, &b, &r); // TODO: check ifnan handling
recorder(cx)->binary(LIR_lt, &a, &b, &r); // TODO: check ifnan handling
}
static inline void
prim_dcmp_le(JSContext* cx, bool ifnan, jsdouble& a, jsdouble& b, JSBool& r)
{
interp_prim_dcmp_le(cx, ifnan, a, b, r);
binary(cx, LIR_le, &a, &b, &r); // TODO: check ifnan handling
recorder(cx)->binary(LIR_le, &a, &b, &r); // TODO: check ifnan handling
}
static inline void
prim_dcmp_gt(JSContext* cx, bool ifnan, jsdouble& a, jsdouble& b, JSBool& r)
{
interp_prim_dcmp_gt(cx, ifnan, a, b, r);
binary(cx, LIR_gt, &a, &b, &r); // TODO: check ifnan handling
recorder(cx)->binary(LIR_gt, &a, &b, &r); // TODO: check ifnan handling
}
static inline void
prim_dcmp_ge(JSContext* cx, bool ifnan, jsdouble& a, jsdouble& b, JSBool& r)
{
interp_prim_dcmp_ge(cx, ifnan, a, b, r);
binary(cx, LIR_ge, &a, &b, &r); // TODO: check ifnan handling
recorder(cx)->binary(LIR_ge, &a, &b, &r); // TODO: check ifnan handling
}
static inline void
@ -554,14 +515,14 @@ static inline void
prim_jsval_to_string(JSContext* cx, jsval& v, JSString*& str)
{
interp_prim_jsval_to_string(cx, v, str);
copy(cx, &v, &str);
recorder(cx)->copy(&v, &str);
}
static inline void
call_CompareStrings(JSContext* cx, JSString*& a, JSString*& b, jsint& r)
{
interp_call_CompareStrings(cx, a, b, r);
call(cx, F_CompareStrings, &a, &b, &r);
recorder(cx)->call(F_CompareStrings, &a, &b, &r);
}
static inline bool
@ -608,7 +569,7 @@ static inline void
prim_do_fast_inc_dec(JSContext* cx, jsval& a, jsval incr, jsval& r)
{
interp_prim_do_fast_inc_dec(cx, a, incr, r);
recorder(cx)->set(&r, recorder(cx)->lir->ins2(LIR_add, recorder(cx)->get(&a), recorder(cx)->lir->insImm(incr/2)));
recorder(cx)->iinc(&a, incr/2, &r);
}
#undef G