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-29 13:53:40 -07:00
|
|
|
if (p->base == base) {
|
2008-06-21 14:55:32 -07:00
|
|
|
return p;
|
2008-06-29 13:53:40 -07:00
|
|
|
}
|
2008-06-21 14:55:32 -07:00
|
|
|
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 GC gc = GC();
|
2008-06-30 11:39:00 -07:00
|
|
|
static avmplus::AvmCore* core = new (&gc) avmplus::AvmCore();
|
2008-06-21 14:55:32 -07:00
|
|
|
|
|
|
|
#define LO ARGSIZE_LO
|
|
|
|
#define F ARGSIZE_F
|
|
|
|
#define Q ARGSIZE_Q
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define NAME(op) ,#op
|
|
|
|
#else
|
|
|
|
#define NAME(op)
|
|
|
|
#endif
|
|
|
|
|
2008-07-02 21:48:42 -07:00
|
|
|
#define builtin_DoubleToECMAInt32 js_DoubleToECMAInt32
|
|
|
|
#define builtin_DoubleToECMAUint32 js_DoubleToECMAUint32
|
2008-07-02 22:05:30 -07:00
|
|
|
#define builtin_CompareStrings js_CompareStrings
|
2008-07-02 21:48:42 -07:00
|
|
|
|
|
|
|
jsint builtin_StringLength(JSString* s)
|
|
|
|
{
|
|
|
|
return JSSTRING_LENGTH(s);
|
2008-07-02 14:38:12 -07:00
|
|
|
}
|
|
|
|
|
2008-07-02 22:05:30 -07:00
|
|
|
jsdouble builtin_dmod(jsdouble a, jsdouble b)
|
|
|
|
{
|
|
|
|
if (b == 0.0) {
|
|
|
|
jsdpun u;
|
|
|
|
u.s.hi = JSDOUBLE_HI32_EXPMASK | JSDOUBLE_HI32_MANTMASK;
|
|
|
|
u.s.lo = 0xffffffff;
|
|
|
|
return u.d;
|
|
|
|
}
|
|
|
|
jsdouble r;
|
|
|
|
#ifdef XP_WIN
|
|
|
|
/* Workaround MS fmod bug where 42 % (1/0) => NaN, not 42. */
|
|
|
|
if (!(JSDOUBLE_IS_FINITE(a) && JSDOUBLE_IS_INFINITE(b)))
|
|
|
|
r = a;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
r = fmod(a, b);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-07-02 14:38:12 -07:00
|
|
|
#define builtin_DOUBLE_IS_INT builtin_unimplemented
|
|
|
|
#define builtin_StringToDouble builtin_unimplemented
|
|
|
|
#define builtin_ObjectToDouble builtin_unimplemented
|
2008-07-02 22:05:30 -07:00
|
|
|
|
|
|
|
/* the following primitives are just placeholders and need to be broken down
|
|
|
|
further (we need a concrete specialization, not "value") */
|
|
|
|
|
|
|
|
#define builtin_ValueToNumber builtin_unimplemented
|
|
|
|
#define builtin_ValueToNonNullObject builtin_unimplemented
|
|
|
|
#define builtin_obj_default_value builtin_unimplemented
|
2008-07-02 14:38:12 -07:00
|
|
|
|
2008-07-02 21:48:42 -07:00
|
|
|
void builtin_unimplemented(void)
|
|
|
|
{
|
|
|
|
JS_ASSERT(0);
|
2008-07-02 14:38:12 -07:00
|
|
|
}
|
|
|
|
|
2008-06-22 19:58:24 -07:00
|
|
|
#define BUILTIN1(op, at0, atr, tr, t0, cse, fold) \
|
2008-07-02 14:38:12 -07:00
|
|
|
{ (intptr_t)&builtin_##op, (at0 << 2) | atr, cse, fold NAME(op) },
|
2008-06-22 19:58:24 -07:00
|
|
|
#define BUILTIN2(op, at0, at1, atr, tr, t0, t1, cse, fold) \
|
2008-07-02 22:05:30 -07:00
|
|
|
{ (intptr_t)&builtin_##op, (at0 << 4) | (at1 << 2) | atr, cse, fold NAME(op) },
|
2008-06-22 19:58:24 -07:00
|
|
|
#define BUILTIN3(op, at0, at1, at2, atr, tr, t0, t1, t2, cse, fold) \
|
2008-07-02 22:05:30 -07:00
|
|
|
{ (intptr_t)&builtin_##op, (at0 << 6) | (at1 << 4) | (at2 << 2) | atr, 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-07-02 17:19:07 -07:00
|
|
|
static void
|
|
|
|
buildTypeMap(JSStackFrame* entryFrame, JSStackFrame* fp, JSFrameRegs& regs, char* m);
|
|
|
|
|
|
|
|
TraceRecorder::TraceRecorder(JSContext* cx, Fragmento* fragmento, Fragment* _fragment)
|
2008-06-26 22:33:33 -07:00
|
|
|
{
|
2008-06-28 18:47:12 -07:00
|
|
|
this->cx = cx;
|
2008-07-02 17:19:07 -07:00
|
|
|
this->fragment = _fragment;
|
2008-06-28 18:47:12 -07:00
|
|
|
entryFrame = cx->fp;
|
2008-06-28 17:14:06 -07:00
|
|
|
entryRegs = *(entryFrame->regs);
|
2008-07-01 02:37:07 -07:00
|
|
|
|
2008-07-02 17:19:07 -07:00
|
|
|
fragment->calldepth = 0;
|
2008-06-27 18:06:50 -07:00
|
|
|
lirbuf = new (&gc) LirBuffer(fragmento, builtins);
|
2008-06-30 18:08:32 -07:00
|
|
|
fragment->lirbuf = lirbuf;
|
|
|
|
lir = lir_buf_writer = new (&gc) LirBufWriter(lirbuf);
|
2008-06-27 18:06:50 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
lirbuf->names = new (&gc) LirNameMap(&gc, builtins, fragmento->labels);
|
2008-06-30 18:08:32 -07:00
|
|
|
lir = verbose_filter = new (&gc) VerboseWriter(&gc, lir, lirbuf->names);
|
2008-06-27 18:06:50 -07:00
|
|
|
#endif
|
2008-06-30 18:08:32 -07:00
|
|
|
lir = cse_filter = new (&gc) CseFilter(lir, &gc);
|
|
|
|
lir = expr_filter = new (&gc) ExprFilter(lir);
|
2008-06-27 18:06:50 -07:00
|
|
|
lir->ins0(LIR_trace);
|
2008-07-01 19:43:10 -07:00
|
|
|
/* generate the entry map and stash it in the trace */
|
2008-07-02 14:38:12 -07:00
|
|
|
entryNativeFrameSlots = nativeFrameSlots(entryFrame, entryRegs);
|
2008-07-02 17:19:07 -07:00
|
|
|
maxNativeFrameSlots = entryNativeFrameSlots;
|
|
|
|
LIns* data = lir_buf_writer->skip(sizeof(VMFragmentInfo) + entryNativeFrameSlots * sizeof(char));
|
|
|
|
VMFragmentInfo* fi = (VMFragmentInfo*)data->payload();
|
|
|
|
buildTypeMap(entryFrame, entryFrame, entryRegs, fi->typeMap);
|
|
|
|
entryTypeMap = fi->typeMap;
|
|
|
|
fragment->vmprivate = fi;
|
2008-06-27 18:06:50 -07:00
|
|
|
fragment->param0 = lir->insImm8(LIR_param, Assembler::argRegs[0], 0);
|
|
|
|
fragment->param1 = lir->insImm8(LIR_param, Assembler::argRegs[1], 0);
|
2008-06-30 17:12:52 -07:00
|
|
|
fragment->sp = lir->insLoadi(fragment->param0, offsetof(InterpState, sp));
|
2008-07-02 14:38:12 -07:00
|
|
|
cx_ins = lir->insLoadi(fragment->param0, offsetof(InterpState, f));
|
2008-07-01 05:06:02 -07:00
|
|
|
#ifdef DEBUG
|
2008-07-01 19:43:10 -07:00
|
|
|
lirbuf->names->addName(fragment->param0, "state");
|
2008-07-01 05:06:02 -07:00
|
|
|
lirbuf->names->addName(fragment->sp, "sp");
|
2008-07-02 14:38:12 -07:00
|
|
|
lirbuf->names->addName(cx_ins, "cx");
|
2008-07-01 05:06:02 -07:00
|
|
|
#endif
|
2008-06-29 20:56:06 -07:00
|
|
|
|
2008-06-27 18:06:50 -07:00
|
|
|
JSStackFrame* fp = cx->fp;
|
|
|
|
unsigned n;
|
|
|
|
for (n = 0; n < fp->argc; ++n)
|
2008-07-02 15:14:43 -07:00
|
|
|
import(&fp->argv[n], "arg", n);
|
2008-06-27 18:06:50 -07:00
|
|
|
for (n = 0; n < fp->nvars; ++n)
|
2008-07-02 15:14:43 -07:00
|
|
|
import(&fp->vars[n], "var", n);
|
2008-06-28 17:14:06 -07:00
|
|
|
for (n = 0; n < (unsigned)(fp->regs->sp - fp->spbase); ++n)
|
2008-07-02 15:14:43 -07:00
|
|
|
import(&fp->spbase[n], "stack", n);
|
2008-06-27 18:06:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TraceRecorder::~TraceRecorder()
|
|
|
|
{
|
2008-06-30 18:08:32 -07:00
|
|
|
#ifdef DEBUG
|
2008-06-27 18:06:50 -07:00
|
|
|
delete lirbuf->names;
|
2008-06-30 18:08:32 -07:00
|
|
|
delete verbose_filter;
|
|
|
|
#endif
|
|
|
|
delete cse_filter;
|
|
|
|
delete expr_filter;
|
|
|
|
delete lir_buf_writer;
|
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
|
|
|
|
{
|
2008-06-28 18:47:12 -07:00
|
|
|
JSStackFrame* fp = cx->fp;
|
2008-06-28 17:14:06 -07:00
|
|
|
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
|
|
|
|
{
|
2008-06-28 18:47:12 -07:00
|
|
|
JSStackFrame* fp = cx->fp;
|
2008-06-28 17:14:06 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-06-30 09:36:10 -07:00
|
|
|
/* Calculate the total number of native frame slots we need from this frame
|
|
|
|
all the way back to the entry frame, including the current stack usage. */
|
2008-06-28 17:14:06 -07:00
|
|
|
unsigned
|
2008-07-01 19:43:10 -07:00
|
|
|
TraceRecorder::nativeFrameSlots(JSStackFrame* fp, JSFrameRegs& regs) const
|
2008-06-28 17:14:06 -07:00
|
|
|
{
|
2008-06-29 20:56:06 -07:00
|
|
|
unsigned size = 0;
|
2008-06-28 17:14:06 -07:00
|
|
|
while (1) {
|
2008-07-01 19:43:10 -07:00
|
|
|
size += fp->argc + fp->nvars + (regs.sp - fp->spbase);
|
2008-06-28 17:14:06 -07:00
|
|
|
if (fp == entryFrame)
|
|
|
|
return size;
|
|
|
|
fp = fp->down;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
2008-06-29 23:02:22 -07:00
|
|
|
unsigned offset = 0;
|
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]);
|
2008-07-01 05:11:49 -07:00
|
|
|
else if (p >= &fp->vars[0] && p < &fp->vars[fp->nvars])
|
2008-06-28 17:14:06 -07:00
|
|
|
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]));
|
|
|
|
}
|
2008-07-01 05:11:49 -07:00
|
|
|
if (fp != entryFrame)
|
2008-07-01 19:43:10 -07:00
|
|
|
offset += nativeFrameSlots(fp->down, *fp->regs);
|
2008-06-29 17:17:39 -07:00
|
|
|
return offset * sizeof(double);
|
2008-06-28 17:14:06 -07:00
|
|
|
}
|
|
|
|
|
2008-07-02 17:19:07 -07:00
|
|
|
/* Track the maximum number of native frame slots we need during
|
|
|
|
execution. */
|
|
|
|
void
|
|
|
|
TraceRecorder::trackNativeFrameUse(unsigned slots)
|
|
|
|
{
|
|
|
|
if (slots > maxNativeFrameSlots)
|
|
|
|
maxNativeFrameSlots = slots;
|
|
|
|
}
|
|
|
|
|
2008-07-02 02:53:24 -07:00
|
|
|
/* Return the tag of a jsval. Doubles are checked whether they actually
|
|
|
|
represent an int, in which case we treat them as JSVAL_INT. */
|
2008-06-29 23:02:22 -07:00
|
|
|
static inline int gettag(jsval v)
|
|
|
|
{
|
|
|
|
if (JSVAL_IS_INT(v))
|
|
|
|
return JSVAL_INT;
|
|
|
|
return JSVAL_TAG(v);
|
|
|
|
}
|
|
|
|
|
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. */
|
2008-07-02 17:19:07 -07:00
|
|
|
static void
|
|
|
|
buildTypeMap(JSStackFrame* entryFrame, JSStackFrame* fp, JSFrameRegs& regs, char* m)
|
2008-06-28 18:19:21 -07:00
|
|
|
{
|
|
|
|
if (fp != entryFrame)
|
2008-07-02 17:19:07 -07:00
|
|
|
buildTypeMap(entryFrame, fp->down, *fp->down->regs, m);
|
2008-06-28 18:19:21 -07:00
|
|
|
for (unsigned n = 0; n < fp->argc; ++n)
|
2008-06-29 23:02:22 -07:00
|
|
|
*m++ = gettag(fp->argv[n]);
|
2008-06-28 18:19:21 -07:00
|
|
|
for (unsigned n = 0; n < fp->nvars; ++n)
|
2008-06-29 23:02:22 -07:00
|
|
|
*m++ = gettag(fp->vars[n]);
|
2008-07-01 19:43:10 -07:00
|
|
|
for (jsval* sp = fp->spbase; sp < regs.sp; ++sp)
|
2008-06-29 23:02:22 -07:00
|
|
|
*m++ = gettag(*sp);
|
2008-06-28 18:19:21 -07:00
|
|
|
}
|
|
|
|
|
2008-07-02 15:14:43 -07:00
|
|
|
/* Make sure that all loop-carrying values have a stable type. */
|
2008-07-02 17:19:07 -07:00
|
|
|
static bool
|
|
|
|
verifyTypeStability(JSStackFrame* entryFrame, JSStackFrame* fp, JSFrameRegs& regs, char* m)
|
2008-07-02 15:14:43 -07:00
|
|
|
{
|
|
|
|
if (fp != entryFrame)
|
2008-07-02 17:19:07 -07:00
|
|
|
verifyTypeStability(entryFrame, fp->down, *fp->down->regs, m);
|
2008-07-02 15:14:43 -07:00
|
|
|
for (unsigned n = 0; n < fp->argc; ++n)
|
|
|
|
if (*m++ != gettag(fp->argv[n]))
|
|
|
|
return false;
|
|
|
|
for (unsigned n = 0; n < fp->nvars; ++n)
|
|
|
|
if (*m++ != gettag(fp->vars[n]))
|
|
|
|
return false;
|
|
|
|
for (jsval* sp = fp->spbase; sp < regs.sp; ++sp)
|
|
|
|
if (*m++ != gettag(*sp))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-30 09:36:10 -07:00
|
|
|
/* Unbox a jsval into a slot. Slots are wide enough to hold double values
|
|
|
|
directly (instead of storing a pointer to them). */
|
2008-07-02 17:19:07 -07:00
|
|
|
static bool
|
|
|
|
unbox_jsval(jsval v, int t, double* slot)
|
2008-06-29 20:56:06 -07:00
|
|
|
{
|
2008-06-29 23:02:22 -07:00
|
|
|
if (t != gettag(v))
|
2008-06-29 20:56:06 -07:00
|
|
|
return false;
|
2008-07-02 02:53:24 -07:00
|
|
|
switch (t) {
|
|
|
|
case JSVAL_BOOLEAN:
|
2008-06-29 20:56:06 -07:00
|
|
|
*(bool*)slot = JSVAL_TO_BOOLEAN(v);
|
2008-07-02 02:53:24 -07:00
|
|
|
break;
|
|
|
|
case JSVAL_INT:
|
2008-07-02 14:38:12 -07:00
|
|
|
*(jsint*)slot = JSVAL_TO_INT(v);
|
2008-07-02 02:53:24 -07:00
|
|
|
break;
|
|
|
|
case JSVAL_DOUBLE:
|
2008-06-29 20:56:06 -07:00
|
|
|
*(jsdouble*)slot = *JSVAL_TO_DOUBLE(v);
|
2008-07-02 02:53:24 -07:00
|
|
|
break;
|
|
|
|
case JSVAL_STRING:
|
|
|
|
*(JSString**)slot = JSVAL_TO_STRING(v);
|
|
|
|
break;
|
|
|
|
default:
|
2008-06-29 20:56:06 -07:00
|
|
|
JS_ASSERT(JSVAL_IS_GCTHING(v));
|
|
|
|
*(void**)slot = JSVAL_TO_GCTHING(v);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-02 02:53:24 -07:00
|
|
|
/* Box a value from the native stack back into the jsval format. Integers
|
|
|
|
that are too large to fit into a jsval are automatically boxed into
|
|
|
|
heap-allocated doubles. */
|
2008-07-02 17:19:07 -07:00
|
|
|
static bool
|
|
|
|
box_jsval(JSContext* cx, jsval* vp, int t, double* slot)
|
2008-06-29 23:02:22 -07:00
|
|
|
{
|
|
|
|
switch (t) {
|
|
|
|
case JSVAL_BOOLEAN:
|
|
|
|
*vp = BOOLEAN_TO_JSVAL(*(bool*)slot);
|
2008-07-02 14:38:12 -07:00
|
|
|
break;
|
2008-06-29 23:02:22 -07:00
|
|
|
case JSVAL_INT:
|
2008-07-02 02:53:24 -07:00
|
|
|
jsint i = *(jsint*)slot;
|
2008-07-02 14:38:12 -07:00
|
|
|
JS_ASSERT(INT_FITS_IN_JSVAL(i));
|
|
|
|
*vp = INT_TO_JSVAL(i);
|
|
|
|
break;
|
2008-06-29 23:02:22 -07:00
|
|
|
case JSVAL_DOUBLE:
|
|
|
|
return js_NewDoubleInRootedValue(cx, *slot, vp);
|
|
|
|
case JSVAL_STRING:
|
|
|
|
*vp = STRING_TO_JSVAL(*(JSString**)slot);
|
2008-07-02 14:38:12 -07:00
|
|
|
break;
|
2008-06-29 23:02:22 -07:00
|
|
|
default:
|
|
|
|
JS_ASSERT(t == JSVAL_OBJECT);
|
|
|
|
*vp = OBJECT_TO_JSVAL(*(JSObject**)slot);
|
2008-07-02 14:38:12 -07:00
|
|
|
break;
|
2008-06-29 23:02:22 -07:00
|
|
|
}
|
2008-07-02 14:38:12 -07:00
|
|
|
return true;
|
2008-06-29 23:02:22 -07:00
|
|
|
}
|
|
|
|
|
2008-06-29 20:56:06 -07:00
|
|
|
/* Attempt to unbox the given JS frame into a native frame, checking
|
|
|
|
along the way that the supplied typemap holds. */
|
2008-07-02 17:19:07 -07:00
|
|
|
static bool
|
|
|
|
unbox(JSStackFrame* fp, JSFrameRegs& regs, char* m, double* native)
|
2008-06-29 20:56:06 -07:00
|
|
|
{
|
|
|
|
jsval* vp;
|
|
|
|
for (vp = fp->argv; vp < fp->argv + fp->argc; ++vp)
|
|
|
|
if (!unbox_jsval(*vp, (JSType)*m++, native++))
|
|
|
|
return false;
|
|
|
|
for (vp = fp->vars; vp < fp->vars + fp->nvars; ++vp)
|
|
|
|
if (!unbox_jsval(*vp, (JSType)*m++, native++))
|
|
|
|
return false;
|
2008-07-01 19:43:10 -07:00
|
|
|
for (vp = fp->spbase; vp < regs.sp; ++vp)
|
2008-06-29 20:56:06 -07:00
|
|
|
if (!unbox_jsval(*vp, (JSType)*m++, native++))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-29 23:02:22 -07:00
|
|
|
/* Attempt to unbox the given JS frame into a native frame, checking
|
|
|
|
along the way that the supplied typemap holds. */
|
2008-07-02 17:19:07 -07:00
|
|
|
static bool
|
|
|
|
box(JSContext* cx, JSStackFrame* fp, JSFrameRegs& regs, char* m, double* native)
|
2008-06-29 23:02:22 -07:00
|
|
|
{
|
|
|
|
jsval* vp;
|
|
|
|
for (vp = fp->argv; vp < fp->argv + fp->argc; ++vp)
|
2008-07-02 17:19:07 -07:00
|
|
|
if (!box_jsval(cx, vp, (JSType)*m++, native++))
|
2008-06-29 23:02:22 -07:00
|
|
|
return false;
|
|
|
|
for (vp = fp->vars; vp < fp->vars + fp->nvars; ++vp)
|
2008-07-02 17:19:07 -07:00
|
|
|
if (!box_jsval(cx, vp, (JSType)*m++, native++))
|
2008-06-29 23:02:22 -07:00
|
|
|
return false;
|
2008-07-01 19:43:10 -07:00
|
|
|
for (vp = fp->spbase; vp < regs.sp; ++vp)
|
2008-07-02 17:19:07 -07:00
|
|
|
if (!box_jsval(cx, vp, (JSType)*m++, native++))
|
2008-06-29 23:02:22 -07:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-06-30 09:36:10 -07:00
|
|
|
/* Emit load instructions onto the trace that read the initial stack state. */
|
2008-06-26 22:58:57 -07:00
|
|
|
void
|
2008-07-02 15:14:43 -07:00
|
|
|
TraceRecorder::import(jsval* p, char *prefix, int index)
|
2008-06-26 22:19:11 -07:00
|
|
|
{
|
2008-06-28 17:14:06 -07:00
|
|
|
JS_ASSERT(onFrame(p));
|
2008-07-02 14:38:12 -07:00
|
|
|
LIns *ins = lir->insLoad(JSVAL_IS_DOUBLE(*p) ? LIR_ldq : LIR_ld,
|
|
|
|
fragment->sp, nativeFrameOffset(p));
|
2008-07-01 05:06:02 -07:00
|
|
|
tracker.set(p, ins);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (prefix) {
|
|
|
|
char name[16];
|
|
|
|
JS_ASSERT(strlen(prefix) < 10);
|
2008-07-01 15:58:47 -07:00
|
|
|
JS_snprintf(name, sizeof name, "$%s%d", prefix, index);
|
2008-07-01 05:06:02 -07:00
|
|
|
lirbuf->names->addName(ins, name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-26 22:19:11 -07:00
|
|
|
}
|
|
|
|
|
2008-06-30 09:36:10 -07:00
|
|
|
/* Update the tracker. If the value is part of any argv/vars/stack of any
|
|
|
|
currently active frame (onFrame), then issue a write back store. */
|
2008-06-26 22:58:57 -07:00
|
|
|
void
|
|
|
|
TraceRecorder::set(void* p, LIns* i)
|
2008-06-26 22:41:10 -07:00
|
|
|
{
|
2008-06-30 09:36:10 -07:00
|
|
|
tracker.set(p, i);
|
2008-07-02 14:38:12 -07:00
|
|
|
if (onFrame(p))
|
|
|
|
lir->insStorei(i, fragment->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
|
|
|
{
|
2008-07-02 14:38:12 -07:00
|
|
|
if (p == cx)
|
|
|
|
return cx_ins;
|
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-07-02 19:11:07 -07:00
|
|
|
void
|
|
|
|
TraceRecorder::choose(void* cond, void* iftrue, void* iffalse, void* v)
|
|
|
|
{
|
|
|
|
set(v, lir->ins_choose(get(cond), get(iftrue), get(iffalse), true));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TraceRecorder::choose_eqi(void* a, int32_t b, void* iftrue, void* iffalse, void* v)
|
|
|
|
{
|
|
|
|
set(v, lir->ins_choose(lir->ins2i(LIR_eq, get(a), b), get(iftrue), get(iffalse), true));
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-06-30 17:12:52 -07:00
|
|
|
/* Mark the current state of the interpreter in the side exit structure. This
|
|
|
|
is the state we want to return to if we have to bail out through a guard. */
|
|
|
|
void
|
|
|
|
TraceRecorder::mark()
|
2008-06-27 00:22:16 -07:00
|
|
|
{
|
2008-06-30 18:31:29 -07:00
|
|
|
markRegs = *cx->fp->regs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the interpreter to the last mark point. This is used when ending or
|
|
|
|
aborting the recorder, at which point the non-tracing interpreter will
|
|
|
|
re-execute the instruction. */
|
|
|
|
void
|
|
|
|
TraceRecorder::recover()
|
|
|
|
{
|
|
|
|
*cx->fp->regs = markRegs;
|
2008-06-27 00:22:16 -07:00
|
|
|
}
|
|
|
|
|
2008-07-01 19:43:10 -07:00
|
|
|
SideExit*
|
|
|
|
TraceRecorder::snapshot()
|
|
|
|
{
|
|
|
|
/* generate the entry map and stash it in the trace */
|
2008-07-02 17:19:07 -07:00
|
|
|
unsigned slots = nativeFrameSlots(cx->fp, markRegs);
|
|
|
|
trackNativeFrameUse(slots);
|
2008-07-02 18:06:24 -07:00
|
|
|
LIns* data = lir_buf_writer->skip(sizeof(VMSideExitInfo) + slots * sizeof(char));
|
|
|
|
VMSideExitInfo* si = (VMSideExitInfo*)data->payload();
|
|
|
|
buildTypeMap(entryFrame, cx->fp, markRegs, si->typeMap);
|
2008-07-01 19:43:10 -07:00
|
|
|
/* setup side exit structure */
|
|
|
|
memset(&exit, 0, sizeof(exit));
|
|
|
|
#ifdef DEBUG
|
|
|
|
exit.from = fragment;
|
|
|
|
#endif
|
|
|
|
exit.calldepth = calldepth();
|
|
|
|
exit.sp_adj = (markRegs.sp - entryRegs.sp + 1) * sizeof(double);
|
|
|
|
exit.ip_adj = markRegs.pc - entryRegs.pc;
|
2008-07-02 18:06:24 -07:00
|
|
|
exit.vmprivate = si;
|
2008-07-01 19:43:10 -07:00
|
|
|
return &exit;
|
|
|
|
}
|
|
|
|
|
2008-06-27 00:22:16 -07:00
|
|
|
void
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder::guard_0(bool expected, void* a)
|
2008-06-27 00:22:16 -07:00
|
|
|
{
|
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-07-01 19:43:10 -07:00
|
|
|
snapshot());
|
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 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-07-01 19:43:10 -07:00
|
|
|
snapshot());
|
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
|
|
|
{
|
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-07-01 19:43:10 -07:00
|
|
|
snapshot());
|
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
|
|
|
{
|
|
|
|
lir->insGuard(expected ? LIR_xf : LIR_xt,
|
|
|
|
lir->ins2(LIR_eq, get(a), get(b)),
|
2008-07-01 19:43:10 -07:00
|
|
|
snapshot());
|
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
|
|
|
{
|
|
|
|
lir->insGuard(expected ? LIR_xf : LIR_xt,
|
|
|
|
lir->ins2i(LIR_eq, get(a), i),
|
2008-07-01 19:43:10 -07:00
|
|
|
snapshot());
|
2008-06-27 20:58:06 -07:00
|
|
|
}
|
|
|
|
|
2008-06-27 18:06:50 -07:00
|
|
|
void
|
|
|
|
TraceRecorder::closeLoop(Fragmento* fragmento)
|
|
|
|
{
|
2008-07-02 17:19:07 -07:00
|
|
|
if (!verifyTypeStability(entryFrame, entryFrame, entryRegs, entryTypeMap)) {
|
2008-07-02 15:14:43 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Trace rejected: unstable loop variables.\n");
|
|
|
|
#endif
|
2008-07-02 15:31:40 -07:00
|
|
|
return;
|
2008-07-02 15:14:43 -07:00
|
|
|
}
|
2008-06-27 18:06:50 -07:00
|
|
|
fragment->lastIns = lir->ins0(LIR_loop);
|
2008-07-02 17:19:07 -07:00
|
|
|
((VMFragmentInfo*)fragment->vmprivate)->maxNativeFrameSlots = maxNativeFrameSlots;
|
2008-06-27 18:06:50 -07:00
|
|
|
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-07-02 17:19:07 -07:00
|
|
|
Fragment*
|
|
|
|
js_LookupFragment(JSContext* cx, jsbytecode* pc)
|
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-30 11:39:00 -07:00
|
|
|
Fragmento* fragmento = new (&gc) Fragmento(core);
|
2008-06-22 23:59:41 -07:00
|
|
|
#ifdef DEBUG
|
2008-06-30 11:39:00 -07:00
|
|
|
fragmento->labels = new (&gc) 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-07-02 17:19:07 -07:00
|
|
|
InterpState state;
|
|
|
|
state.ip = (FOpcodep)pc;
|
|
|
|
|
|
|
|
Fragment* f = tm->fragmento->getLoop(state);
|
|
|
|
|
|
|
|
if (!f->code())
|
|
|
|
return f;
|
|
|
|
|
|
|
|
VMFragmentInfo* fi = (VMFragmentInfo*)f->vmprivate;
|
|
|
|
double native[fi->maxNativeFrameSlots+1];
|
|
|
|
#ifdef DEBUG
|
|
|
|
*(uint64*)&native[fi->maxNativeFrameSlots] = 0xdeadbeefdeadbeefLL;
|
|
|
|
#endif
|
|
|
|
unbox(cx->fp, *cx->fp->regs, fi->typeMap, native);
|
|
|
|
state.sp = native;
|
|
|
|
state.rp = NULL;
|
|
|
|
state.f = (void*)cx;
|
|
|
|
union { NIns *code; GuardRecord* (FASTCALL *func)(InterpState*, Fragment*); } u;
|
|
|
|
u.code = f->code();
|
|
|
|
GuardRecord* lr = u.func(&state, NULL);
|
|
|
|
cx->fp->regs->sp += (((double*)state.sp - native) - 1);
|
|
|
|
cx->fp->regs->pc = (jsbytecode*)state.ip;
|
2008-07-02 18:06:24 -07:00
|
|
|
box(cx, cx->fp, *cx->fp->regs, ((VMSideExitInfo*)lr->vmprivate)->typeMap, native);
|
2008-07-02 17:19:07 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
JS_ASSERT(*(uint64*)&native[fi->maxNativeFrameSlots] == 0xdeadbeefdeadbeefLL);
|
|
|
|
#endif
|
|
|
|
return f;
|
|
|
|
}
|
2008-06-22 23:42:54 -07:00
|
|
|
|
2008-07-02 17:19:07 -07:00
|
|
|
bool
|
|
|
|
js_StartRecording(JSContext* cx, Fragment* fragment)
|
|
|
|
{
|
|
|
|
JSTraceMonitor* tm = &JS_TRACE_MONITOR(cx);
|
|
|
|
tm->recorder = new (&gc) TraceRecorder(cx, tm->fragmento, fragment);
|
2008-06-26 20:37:28 -07:00
|
|
|
return true;
|
2008-06-11 20:22:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-01 02:37:07 -07:00
|
|
|
static void
|
|
|
|
js_DeleteRecorder(JSContext* cx)
|
|
|
|
{
|
|
|
|
JSTraceMonitor* tm = &JS_TRACE_MONITOR(cx);
|
|
|
|
delete tm->recorder;
|
|
|
|
tm->recorder = NULL;
|
|
|
|
}
|
|
|
|
|
2008-06-28 18:19:21 -07:00
|
|
|
void
|
|
|
|
js_AbortRecording(JSContext* cx)
|
|
|
|
{
|
|
|
|
JSTraceMonitor* tm = &JS_TRACE_MONITOR(cx);
|
|
|
|
JS_ASSERT(tm->recorder != NULL);
|
2008-07-01 02:37:07 -07:00
|
|
|
//tm->recorder->abort();
|
2008-06-30 18:31:29 -07:00
|
|
|
tm->recorder->recover();
|
2008-07-01 02:37:07 -07:00
|
|
|
js_DeleteRecorder(cx);
|
2008-06-28 18:19:21 -07:00
|
|
|
}
|
|
|
|
|
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);
|
2008-07-01 02:37:07 -07:00
|
|
|
tm->recorder->recover();
|
|
|
|
js_DeleteRecorder(cx);
|
2008-06-11 17:59:28 -07:00
|
|
|
}
|