2008-05-28 19:07:25 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2008-06-03 14:48:47 -07:00
|
|
|
* vim: set ts=8 sw=4 et tw=79:
|
2008-05-28 19:07:25 -07:00
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
|
|
|
|
* May 28, 2008.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2008-06-28 09:58:15 -07:00
|
|
|
* Brendan Eich <brendan@mozilla.org>
|
2008-05-28 19:07:25 -07:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2008-06-28 09:58:15 -07:00
|
|
|
* Andreas Gal <gal@mozilla.com>
|
2008-05-28 19:07:25 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#define jstracer_cpp___
|
|
|
|
|
2008-06-21 14:55:32 -07:00
|
|
|
#include "nanojit/avmplus.h"
|
|
|
|
#include "nanojit/nanojit.h"
|
|
|
|
|
|
|
|
using namespace nanojit;
|
|
|
|
|
2008-05-28 19:07:25 -07:00
|
|
|
#include "jsinterp.cpp"
|
2008-05-30 10:11:56 -07:00
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
Tracker::Tracker()
|
2008-06-03 21:01:23 -07:00
|
|
|
{
|
2008-06-21 14:55:32 -07:00
|
|
|
pagelist = 0;
|
|
|
|
}
|
2008-06-10 21:40:47 -07:00
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
Tracker::~Tracker()
|
2008-06-21 14:55:32 -07:00
|
|
|
{
|
|
|
|
clear();
|
2008-06-03 21:01:23 -07:00
|
|
|
}
|
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
long
|
|
|
|
Tracker::getPageBase(const void* v) const
|
2008-06-03 21:01:23 -07:00
|
|
|
{
|
2008-06-21 14:55:32 -07:00
|
|
|
return ((long)v) & (~(NJ_PAGE_SIZE-1));
|
2008-06-04 00:09:57 -07:00
|
|
|
}
|
2008-06-11 11:29:35 -07:00
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
struct Tracker::Page*
|
|
|
|
Tracker::findPage(const void* v) const
|
2008-06-11 11:29:35 -07:00
|
|
|
{
|
2008-06-21 14:55:32 -07:00
|
|
|
long base = getPageBase(v);
|
|
|
|
struct Tracker::Page* p = pagelist;
|
|
|
|
while (p) {
|
2008-06-22 23:42:54 -07:00
|
|
|
if (p->base == base)
|
2008-06-21 14:55:32 -07:00
|
|
|
return p;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
struct Tracker::Page*
|
|
|
|
Tracker::addPage(const void* v) {
|
2008-06-21 14:55:32 -07:00
|
|
|
long base = getPageBase(v);
|
2008-06-26 20:44:23 -07:00
|
|
|
struct Tracker::Page* p = (struct Tracker::Page*)
|
|
|
|
GC::Alloc(sizeof(struct Tracker::Page) + (NJ_PAGE_SIZE >> 2) * sizeof(LInsp));
|
2008-06-21 14:55:32 -07:00
|
|
|
p->base = base;
|
|
|
|
p->next = pagelist;
|
|
|
|
pagelist = p;
|
|
|
|
return p;
|
2008-06-11 11:29:35 -07:00
|
|
|
}
|
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
void
|
|
|
|
Tracker::clear()
|
2008-06-11 11:29:35 -07:00
|
|
|
{
|
2008-06-21 14:55:32 -07:00
|
|
|
while (pagelist) {
|
|
|
|
Page* p = pagelist;
|
|
|
|
pagelist = pagelist->next;
|
|
|
|
GC::Free(p);
|
|
|
|
}
|
2008-06-11 11:29:35 -07:00
|
|
|
}
|
2008-06-11 17:59:28 -07:00
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
LIns*
|
|
|
|
Tracker::get(const void* v) const
|
2008-06-21 14:55:32 -07:00
|
|
|
{
|
2008-06-26 20:44:23 -07:00
|
|
|
struct Tracker::Page* p = findPage(v);
|
2008-06-21 14:55:32 -07:00
|
|
|
JS_ASSERT(p != 0); /* we must have a page for the slot we are looking for */
|
2008-06-26 20:44:23 -07:00
|
|
|
LIns* i = p->map[(((long)v) & 0xfff) >> 2];
|
2008-06-22 19:58:24 -07:00
|
|
|
JS_ASSERT(i != 0);
|
|
|
|
return i;
|
2008-06-21 14:55:32 -07:00
|
|
|
}
|
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
void
|
|
|
|
Tracker::set(const void* v, LIns* ins)
|
2008-06-11 20:22:00 -07:00
|
|
|
{
|
2008-06-21 14:55:32 -07:00
|
|
|
struct Tracker::Page* p = findPage(v);
|
2008-06-22 23:42:54 -07:00
|
|
|
if (!p)
|
2008-06-21 14:55:32 -07:00
|
|
|
p = addPage(v);
|
2008-06-26 20:44:23 -07:00
|
|
|
p->map[(((long)v) & 0xfff) >> 2] = ins;
|
2008-06-11 20:22:00 -07:00
|
|
|
}
|
|
|
|
|
2008-06-21 14:55:32 -07:00
|
|
|
using namespace avmplus;
|
|
|
|
using namespace nanojit;
|
|
|
|
|
|
|
|
static avmplus::AvmCore* core = new avmplus::AvmCore();
|
|
|
|
static GC gc = GC();
|
|
|
|
|
|
|
|
#define LO ARGSIZE_LO
|
|
|
|
#define F ARGSIZE_F
|
|
|
|
#define Q ARGSIZE_Q
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define NAME(op) ,#op
|
|
|
|
#else
|
|
|
|
#define NAME(op)
|
|
|
|
#endif
|
|
|
|
|
2008-06-22 19:58:24 -07:00
|
|
|
#define BUILTIN1(op, at0, atr, tr, t0, cse, fold) \
|
|
|
|
{ 0, (at0 | (atr << 2)), cse, fold NAME(op) },
|
|
|
|
#define BUILTIN2(op, at0, at1, atr, tr, t0, t1, cse, fold) \
|
|
|
|
{ 0, (at0 | (at1 << 2) | (atr << 4)), cse, fold NAME(op) },
|
|
|
|
#define BUILTIN3(op, at0, at1, at2, atr, tr, t0, t1, t2, cse, fold) \
|
|
|
|
{ 0, (at0 | (at1 << 2) | (at2 << 4) | (atr << 6)), cse, fold NAME(op) },
|
2008-06-21 14:55:32 -07:00
|
|
|
|
|
|
|
static struct CallInfo builtins[] = {
|
|
|
|
#include "builtins.tbl"
|
2008-06-22 23:42:54 -07:00
|
|
|
};
|
2008-06-21 14:55:32 -07:00
|
|
|
|
2008-06-22 23:42:54 -07:00
|
|
|
#undef NAME
|
2008-06-21 14:55:32 -07:00
|
|
|
#undef BUILTIN1
|
|
|
|
#undef BUILTIN2
|
2008-06-22 23:42:54 -07:00
|
|
|
#undef BUILTIN3
|
2008-06-21 14:55:32 -07:00
|
|
|
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder::TraceRecorder(JSContext* cx, Fragmento* fragmento)
|
2008-06-26 22:33:33 -07:00
|
|
|
{
|
2008-06-28 17:14:06 -07:00
|
|
|
entryFrame = currentFrame = cx->fp;
|
|
|
|
entryRegs = *(entryFrame->regs);
|
|
|
|
|
2008-06-27 18:06:50 -07:00
|
|
|
InterpState state;
|
2008-06-28 17:14:06 -07:00
|
|
|
state.ip = (FOpcodep)entryFrame->regs->pc;
|
|
|
|
state.sp = entryFrame->regs->sp;
|
2008-06-27 18:06:50 -07:00
|
|
|
state.rp = NULL;
|
|
|
|
state.f = NULL;
|
|
|
|
|
|
|
|
fragment = fragmento->getLoop(state);
|
|
|
|
lirbuf = new (&gc) LirBuffer(fragmento, builtins);
|
|
|
|
#ifdef DEBUG
|
|
|
|
lirbuf->names = new (&gc) LirNameMap(&gc, builtins, fragmento->labels);
|
|
|
|
#endif
|
|
|
|
fragment->lirbuf = lirbuf;
|
|
|
|
lir = new (&gc) LirBufWriter(lirbuf);
|
|
|
|
lir->ins0(LIR_trace);
|
|
|
|
fragment->param0 = lir->insImm8(LIR_param, Assembler::argRegs[0], 0);
|
|
|
|
fragment->param1 = lir->insImm8(LIR_param, Assembler::argRegs[1], 0);
|
|
|
|
|
|
|
|
init(&cx, lir->insLoadi(fragment->param0, 0));
|
2008-06-28 17:14:06 -07:00
|
|
|
init(&entryRegs.sp, lir->insLoadi(fragment->param0, 4));
|
2008-06-27 18:06:50 -07:00
|
|
|
|
|
|
|
JSStackFrame* fp = cx->fp;
|
|
|
|
unsigned n;
|
|
|
|
for (n = 0; n < fp->argc; ++n)
|
2008-06-27 20:58:06 -07:00
|
|
|
readstack(&fp->argv[n]);
|
2008-06-27 18:06:50 -07:00
|
|
|
for (n = 0; n < fp->nvars; ++n)
|
2008-06-27 20:58:06 -07:00
|
|
|
readstack(&fp->vars[n]);
|
2008-06-28 17:14:06 -07:00
|
|
|
for (n = 0; n < (unsigned)(fp->regs->sp - fp->spbase); ++n)
|
2008-06-27 20:58:06 -07:00
|
|
|
readstack(&fp->spbase[n]);
|
2008-06-27 18:06:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TraceRecorder::~TraceRecorder()
|
|
|
|
{
|
|
|
|
delete lir;
|
|
|
|
#ifdef DEBUG
|
|
|
|
delete lirbuf->names;
|
|
|
|
#endif
|
|
|
|
delete lirbuf;
|
|
|
|
delete fragment;
|
2008-06-26 22:33:33 -07:00
|
|
|
}
|
|
|
|
|
2008-06-28 17:14:06 -07:00
|
|
|
/* Determine the current call depth (starting with the entry frame.) */
|
|
|
|
unsigned
|
|
|
|
TraceRecorder::calldepth() const
|
|
|
|
{
|
|
|
|
JSStackFrame* fp = currentFrame;
|
|
|
|
unsigned depth = 0;
|
|
|
|
while (fp != entryFrame) {
|
|
|
|
++depth;
|
|
|
|
fp = fp->down;
|
|
|
|
}
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the frame that this address belongs to (if any). */
|
|
|
|
JSStackFrame*
|
|
|
|
TraceRecorder::findFrame(void* p) const
|
|
|
|
{
|
|
|
|
JSStackFrame* fp = currentFrame;
|
|
|
|
while (1) {
|
|
|
|
if ((p >= &fp->argv[0] && p < &fp->argv[fp->argc]) ||
|
|
|
|
(p >= &fp->vars[0] && p < &fp->vars[fp->nvars]) ||
|
|
|
|
(p >= &fp->spbase[0] && p < &fp->spbase[fp->script->depth]))
|
|
|
|
return fp;
|
|
|
|
if (fp == entryFrame)
|
|
|
|
return NULL;
|
|
|
|
fp = fp->down;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine whether an address is part of a currently active frame. */
|
|
|
|
bool
|
|
|
|
TraceRecorder::onFrame(void* p) const
|
|
|
|
{
|
|
|
|
return findFrame(p) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
TraceRecorder::nativeFrameSize(JSStackFrame* fp) const
|
|
|
|
{
|
|
|
|
unsigned size;
|
|
|
|
while (1) {
|
|
|
|
size += fp->argc + fp->nvars + (fp->regs->sp - fp->spbase);
|
|
|
|
if (fp == entryFrame)
|
|
|
|
return size;
|
|
|
|
fp = fp->down;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
TraceRecorder::nativeFrameSize() const
|
|
|
|
{
|
|
|
|
return nativeFrameSize(currentFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the offset in the native frame (marshal) for an address
|
|
|
|
that is part of a currently active frame. */
|
|
|
|
unsigned
|
|
|
|
TraceRecorder::nativeFrameOffset(void* p) const
|
|
|
|
{
|
|
|
|
JSStackFrame* fp = findFrame(p);
|
|
|
|
JS_ASSERT(fp != NULL); // must be on the frame somewhere
|
|
|
|
unsigned offset;
|
2008-06-28 18:19:21 -07:00
|
|
|
if (fp != entryFrame)
|
|
|
|
offset += nativeFrameSize(fp->down);
|
2008-06-28 17:14:06 -07:00
|
|
|
if (p >= &fp->argv[0] && p < &fp->argv[fp->argc])
|
|
|
|
offset = unsigned((jsval*)p - &fp->argv[0]);
|
|
|
|
if (p >= &fp->vars[0] && p < &fp->vars[fp->nvars])
|
|
|
|
offset = (fp->argc + unsigned((jsval*)p - &fp->vars[0]));
|
|
|
|
else {
|
|
|
|
JS_ASSERT((p >= &fp->spbase[0] && p < &fp->spbase[fp->script->depth]));
|
|
|
|
offset = (fp->argc + fp->nvars + unsigned((jsval*)p - &fp->spbase[0]));
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2008-06-28 18:19:21 -07:00
|
|
|
/* Write out a type map for the current scopes and all outer scopes,
|
|
|
|
up until the entry scope. */
|
|
|
|
void
|
|
|
|
TraceRecorder::typeMap(JSStackFrame* fp, char* m) const
|
|
|
|
{
|
|
|
|
if (fp != entryFrame)
|
|
|
|
typeMap(fp->down, m);
|
|
|
|
for (unsigned n = 0; n < fp->argc; ++n)
|
|
|
|
*m = JSVAL_TAG(fp->argv[n]);
|
|
|
|
for (unsigned n = 0; n < fp->nvars; ++n)
|
|
|
|
*m = JSVAL_TAG(fp->vars[n]);
|
|
|
|
for (jsval* sp = fp->spbase; sp < fp->regs->sp; ++sp)
|
|
|
|
*m = JSVAL_TAG(*sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TraceRecorder::typeMap(char* m) const
|
|
|
|
{
|
|
|
|
typeMap(currentFrame, m);
|
|
|
|
}
|
2008-06-28 17:14:06 -07:00
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
void
|
2008-06-27 20:58:06 -07:00
|
|
|
TraceRecorder::readstack(void* p)
|
2008-06-26 22:19:11 -07:00
|
|
|
{
|
2008-06-28 17:14:06 -07:00
|
|
|
JS_ASSERT(onFrame(p));
|
|
|
|
tracker.set(p, lir->insLoadi(tracker.get(&entryRegs.sp),
|
|
|
|
nativeFrameOffset(p)));
|
2008-06-26 22:19:11 -07:00
|
|
|
}
|
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
void
|
|
|
|
TraceRecorder::init(void* p, LIns* i)
|
2008-06-26 22:41:10 -07:00
|
|
|
{
|
|
|
|
tracker.set(p, i);
|
|
|
|
}
|
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
void
|
|
|
|
TraceRecorder::set(void* p, LIns* i)
|
2008-06-26 22:41:10 -07:00
|
|
|
{
|
|
|
|
init(p, i);
|
2008-06-28 17:14:06 -07:00
|
|
|
if (onFrame(p))
|
|
|
|
lir->insStorei(i, get(&entryRegs.sp),
|
|
|
|
nativeFrameOffset(p));
|
2008-06-26 22:41:10 -07:00
|
|
|
}
|
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
LIns*
|
|
|
|
TraceRecorder::get(void* p)
|
2008-06-26 22:41:10 -07:00
|
|
|
{
|
|
|
|
return tracker.get(p);
|
|
|
|
}
|
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
void
|
|
|
|
TraceRecorder::copy(void* a, void* v)
|
|
|
|
{
|
|
|
|
set(v, get(a));
|
|
|
|
}
|
|
|
|
|
2008-06-27 00:22:16 -07:00
|
|
|
void
|
|
|
|
TraceRecorder::imm(jsint i, void* v)
|
|
|
|
{
|
|
|
|
set(v, lir->insImm(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TraceRecorder::imm(jsdouble d, void* v)
|
|
|
|
{
|
|
|
|
set(v, lir->insImmq(*(uint64_t*)&d));
|
|
|
|
}
|
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
void
|
2008-06-28 09:58:15 -07:00
|
|
|
TraceRecorder::unary(LOpcode op, void* a, void* v)
|
2008-06-26 22:58:57 -07:00
|
|
|
{
|
|
|
|
set(v, lir->ins1(op, get(a)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-28 09:58:15 -07:00
|
|
|
TraceRecorder::binary(LOpcode op, void* a, void* b, void* v)
|
2008-06-26 22:58:57 -07:00
|
|
|
{
|
|
|
|
set(v, lir->ins2(op, get(a), get(b)));
|
|
|
|
}
|
|
|
|
|
2008-06-27 06:53:10 -07:00
|
|
|
void
|
2008-06-28 09:58:15 -07:00
|
|
|
TraceRecorder::binary0(LOpcode op, void* a, void* v)
|
2008-06-27 06:53:10 -07:00
|
|
|
{
|
|
|
|
set(v, lir->ins2i(op, get(a), 0));
|
|
|
|
}
|
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
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
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder::iinc(void* a, int incr, void* v)
|
2008-06-27 00:22:16 -07:00
|
|
|
{
|
|
|
|
LIns* ov = lir->ins2(LIR_add, get(a), lir->insImm(incr));
|
2008-06-27 07:28:10 -07:00
|
|
|
// This check is actually supposed to happen before iinc, however,
|
|
|
|
// we arrive at iinc only if CAN_DO_INC_DEC passed, so we know that the
|
|
|
|
// inverse of it (overflow check) must evaluate to false in the trace.
|
|
|
|
// We delay setting v to the result of the calculation until after the
|
|
|
|
// guard to make sure the result is not communicated to the interpreter
|
|
|
|
// in case this guard fails (as it was supposed to execute _before_ the
|
|
|
|
// add, not after.)
|
2008-06-28 17:14:06 -07:00
|
|
|
guard_ov(false, a);
|
2008-06-27 00:22:16 -07:00
|
|
|
set(v, ov);
|
|
|
|
}
|
|
|
|
|
|
|
|
SideExit*
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder::snapshot(SideExit& exit)
|
2008-06-27 00:22:16 -07:00
|
|
|
{
|
|
|
|
memset(&exit, 0, sizeof(exit));
|
|
|
|
exit.from = fragment;
|
2008-06-28 17:14:06 -07:00
|
|
|
exit.calldepth = calldepth();
|
|
|
|
exit.sp_adj = ((char*)currentFrame->regs->sp) - ((char*)entryRegs.sp);
|
|
|
|
exit.ip_adj = ((char*)currentFrame->regs->pc) - ((char*)entryRegs.pc);
|
2008-06-27 00:22:16 -07:00
|
|
|
return &exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder::guard_0(bool expected, void* a)
|
2008-06-27 00:22:16 -07:00
|
|
|
{
|
|
|
|
SideExit exit;
|
2008-06-27 07:28:10 -07:00
|
|
|
lir->insGuard(expected ? LIR_xf : LIR_xt,
|
2008-06-27 00:34:50 -07:00
|
|
|
get(a),
|
2008-06-28 17:14:06 -07:00
|
|
|
snapshot(exit));
|
2008-06-27 00:22:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder::guard_h(bool expected, void* a)
|
2008-06-26 22:58:57 -07:00
|
|
|
{
|
2008-06-27 00:22:16 -07:00
|
|
|
SideExit exit;
|
2008-06-27 07:28:10 -07:00
|
|
|
lir->insGuard(expected ? LIR_xf : LIR_xt,
|
2008-06-27 00:34:50 -07:00
|
|
|
lir->ins1(LIR_callh, get(a)),
|
2008-06-28 17:14:06 -07:00
|
|
|
snapshot(exit));
|
2008-06-27 00:34:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder::guard_ov(bool expected, void* a)
|
2008-06-27 00:34:50 -07:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
SideExit exit;
|
2008-06-27 07:28:10 -07:00
|
|
|
lir->insGuard(expected ? LIR_xf : LIR_xt,
|
2008-06-27 00:34:50 -07:00
|
|
|
lir->ins1(LIR_ov, get(a)),
|
2008-06-28 17:14:06 -07:00
|
|
|
snapshot(exit));
|
2008-06-27 00:34:50 -07:00
|
|
|
#endif
|
2008-06-26 22:58:57 -07:00
|
|
|
}
|
|
|
|
|
2008-06-27 20:58:06 -07:00
|
|
|
void
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder::guard_eq(bool expected, void* a, void* b)
|
2008-06-27 20:58:06 -07:00
|
|
|
{
|
|
|
|
SideExit exit;
|
|
|
|
lir->insGuard(expected ? LIR_xf : LIR_xt,
|
|
|
|
lir->ins2(LIR_eq, get(a), get(b)),
|
2008-06-28 17:14:06 -07:00
|
|
|
snapshot(exit));
|
2008-06-27 20:58:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder::guard_eqi(bool expected, void* a, int i)
|
2008-06-27 20:58:06 -07:00
|
|
|
{
|
|
|
|
SideExit exit;
|
|
|
|
lir->insGuard(expected ? LIR_xf : LIR_xt,
|
|
|
|
lir->ins2i(LIR_eq, get(a), i),
|
2008-06-28 17:14:06 -07:00
|
|
|
snapshot(exit));
|
2008-06-27 20:58:06 -07:00
|
|
|
}
|
|
|
|
|
2008-06-27 18:06:50 -07:00
|
|
|
void
|
|
|
|
TraceRecorder::closeLoop(Fragmento* fragmento)
|
|
|
|
{
|
|
|
|
fragment->lastIns = lir->ins0(LIR_loop);
|
|
|
|
compile(fragmento->assm(), fragment);
|
|
|
|
}
|
|
|
|
|
2008-06-27 20:58:06 -07:00
|
|
|
void
|
|
|
|
TraceRecorder::load(void* a, int32_t i, void* v)
|
|
|
|
{
|
|
|
|
set(v, lir->insLoadi(get(a), i));
|
|
|
|
}
|
|
|
|
|
2008-06-26 20:37:28 -07:00
|
|
|
bool
|
2008-06-28 17:14:06 -07:00
|
|
|
js_StartRecording(JSContext* cx)
|
2008-06-11 20:22:00 -07:00
|
|
|
{
|
2008-06-22 23:42:54 -07:00
|
|
|
JSTraceMonitor* tm = &JS_TRACE_MONITOR(cx);
|
2008-06-26 20:37:28 -07:00
|
|
|
|
2008-06-21 14:55:32 -07:00
|
|
|
if (!tm->fragmento) {
|
2008-06-28 09:58:15 -07:00
|
|
|
Fragmento* fragmento = new Fragmento(core);
|
2008-06-22 23:59:41 -07:00
|
|
|
#ifdef DEBUG
|
2008-06-28 09:58:15 -07:00
|
|
|
fragmento->labels = new LabelMap(core, NULL);
|
2008-06-22 23:59:41 -07:00
|
|
|
#endif
|
2008-06-21 23:45:16 -07:00
|
|
|
fragmento->assm()->setCallTable(builtins);
|
|
|
|
tm->fragmento = fragmento;
|
2008-06-22 23:42:54 -07:00
|
|
|
}
|
2008-06-21 14:55:32 -07:00
|
|
|
|
2008-06-28 17:14:06 -07:00
|
|
|
tm->recorder = new TraceRecorder(cx, tm->fragmento);
|
2008-06-22 23:42:54 -07:00
|
|
|
|
2008-06-26 20:37:28 -07:00
|
|
|
return true;
|
2008-06-11 20:22:00 -07:00
|
|
|
}
|
|
|
|
|
2008-06-28 18:19:21 -07:00
|
|
|
void
|
|
|
|
js_AbortRecording(JSContext* cx)
|
|
|
|
{
|
|
|
|
JSTraceMonitor* tm = &JS_TRACE_MONITOR(cx);
|
|
|
|
JS_ASSERT(tm->recorder != NULL);
|
|
|
|
delete tm->recorder;
|
|
|
|
tm->recorder = NULL;
|
|
|
|
}
|
|
|
|
|
2008-06-11 20:22:00 -07:00
|
|
|
void
|
2008-06-28 17:14:06 -07:00
|
|
|
js_EndRecording(JSContext* cx)
|
2008-06-11 20:22:00 -07:00
|
|
|
{
|
2008-06-22 23:42:54 -07:00
|
|
|
JSTraceMonitor* tm = &JS_TRACE_MONITOR(cx);
|
2008-06-28 18:19:21 -07:00
|
|
|
JS_ASSERT(tm->recorder != NULL);
|
|
|
|
tm->recorder->closeLoop(tm->fragmento);
|
|
|
|
js_AbortRecording(cx);
|
2008-06-11 17:59:28 -07:00
|
|
|
}
|