2008-05-30 18:58:43 -07:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2008-07-07 02:55:03 -07:00
|
|
|
* vim: set ts=8 sw=4 et tw=99 ft=cpp:
|
2008-05-30 18:58:43 -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-30 18:58:43 -07:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2008-06-28 09:58:15 -07:00
|
|
|
* Andreas Gal <gal@mozilla.com>
|
2008-07-15 15:05:16 -07:00
|
|
|
* Mike Shaver <shaver@mozilla.org>
|
|
|
|
* David Anderson <danderson@mozilla.com>
|
2008-05-30 18:58:43 -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 ***** */
|
|
|
|
|
2008-05-31 15:29:54 -07:00
|
|
|
#ifndef jstracer_h___
|
|
|
|
#define jstracer_h___
|
2008-05-30 18:58:43 -07:00
|
|
|
|
|
|
|
#include "jsstddef.h"
|
|
|
|
#include "jslock.h"
|
2008-07-02 14:38:12 -07:00
|
|
|
#include "jsnum.h"
|
2008-07-03 22:08:13 -07:00
|
|
|
#include "jsinterp.h"
|
2008-05-30 18:58:43 -07:00
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
#include "nanojit/nanojit.h"
|
2008-06-21 14:55:32 -07:00
|
|
|
|
2008-07-05 16:28:03 -07:00
|
|
|
/*
|
2008-07-07 02:21:04 -07:00
|
|
|
* We use a magic boxed pointer value to represent error conditions that
|
2008-07-07 02:55:03 -07:00
|
|
|
* trigger a side exit. The address is so low that it should never be actually
|
|
|
|
* in use. If it is, a performance regression occurs, not an actual runtime
|
|
|
|
* error.
|
2008-07-05 16:28:03 -07:00
|
|
|
*/
|
|
|
|
#define JSVAL_ERROR_COOKIE OBJECT_TO_JSVAL((void*)0x10)
|
|
|
|
|
|
|
|
/*
|
2008-07-07 02:55:03 -07:00
|
|
|
* We also need a magic unboxed 32-bit integer that signals an error. Again if
|
|
|
|
* this number is hit we experience a performance regression, not a runtime
|
|
|
|
* error.
|
2008-07-05 16:28:03 -07:00
|
|
|
*/
|
|
|
|
#define INT32_ERROR_COOKIE 0xffffabcd
|
|
|
|
|
2008-06-21 14:55:32 -07:00
|
|
|
/*
|
2008-07-07 02:55:03 -07:00
|
|
|
* Tracker is used to keep track of values being manipulated by the interpreter
|
|
|
|
* during trace recording.
|
2008-06-21 14:55:32 -07:00
|
|
|
*/
|
2008-07-07 02:55:03 -07:00
|
|
|
class Tracker {
|
2008-06-21 14:55:32 -07:00
|
|
|
struct Page {
|
2008-07-05 11:18:26 -07:00
|
|
|
struct Page* next;
|
|
|
|
jsuword base;
|
2008-07-10 18:42:04 -07:00
|
|
|
nanojit::LIns* map[1];
|
2008-06-21 14:55:32 -07:00
|
|
|
};
|
|
|
|
struct Page* pagelist;
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-05 11:18:26 -07:00
|
|
|
jsuword getPageBase(const void* v) const;
|
2008-06-26 20:46:51 -07:00
|
|
|
struct Page* findPage(const void* v) const;
|
|
|
|
struct Page* addPage(const void* v);
|
2008-07-07 02:21:04 -07:00
|
|
|
public:
|
2008-06-21 14:55:32 -07:00
|
|
|
Tracker();
|
|
|
|
~Tracker();
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-10 18:42:04 -07:00
|
|
|
nanojit::LIns* get(const void* v) const;
|
|
|
|
void set(const void* v, nanojit::LIns* ins);
|
2008-06-26 20:44:23 -07:00
|
|
|
void clear();
|
2008-06-21 14:55:32 -07:00
|
|
|
};
|
|
|
|
|
2008-07-16 21:41:03 -07:00
|
|
|
class VMFragmentInfo {
|
|
|
|
public:
|
|
|
|
VMFragmentInfo() {
|
|
|
|
typeMap = NULL;
|
|
|
|
gslots = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~VMFragmentInfo() {
|
|
|
|
if (typeMap) free(typeMap);
|
|
|
|
if (gslots) free(gslots);
|
|
|
|
}
|
|
|
|
|
2008-07-06 20:25:49 -07:00
|
|
|
unsigned entryNativeFrameSlots;
|
2008-07-04 13:23:42 -07:00
|
|
|
unsigned maxNativeFrameSlots;
|
2008-07-05 11:18:26 -07:00
|
|
|
size_t nativeStackBase;
|
2008-07-14 19:12:50 -07:00
|
|
|
unsigned maxCallDepth;
|
2008-07-15 01:08:13 -07:00
|
|
|
uint32 globalShape;
|
2008-07-15 01:53:39 -07:00
|
|
|
unsigned ngslots;
|
2008-07-15 01:03:49 -07:00
|
|
|
uint8 *typeMap;
|
2008-07-15 01:53:39 -07:00
|
|
|
uint16 *gslots;
|
2008-07-04 13:23:42 -07:00
|
|
|
};
|
|
|
|
|
2008-07-08 23:48:06 -07:00
|
|
|
extern struct nanojit::CallInfo builtins[];
|
|
|
|
|
2008-07-06 22:35:19 -07:00
|
|
|
#define TYPEMAP_GET_TYPE(x) ((x) & JSVAL_TAGMASK)
|
2008-07-07 01:05:53 -07:00
|
|
|
#define TYPEMAP_SET_TYPE(x, t) (x = (x & 0xf0) | t)
|
2008-07-06 22:35:19 -07:00
|
|
|
#define TYPEMAP_GET_FLAG(x, flag) ((x) & flag)
|
|
|
|
#define TYPEMAP_SET_FLAG(x, flag) do { (x) |= flag; } while (0)
|
|
|
|
|
2008-07-07 17:21:54 -07:00
|
|
|
#define TYPEMAP_TYPE_ANY 7
|
|
|
|
|
2008-07-06 22:35:19 -07:00
|
|
|
#define TYPEMAP_FLAG_DEMOTE 0x10 /* try to record as int */
|
|
|
|
#define TYPEMAP_FLAG_DONT_DEMOTE 0x20 /* do not try to record as int */
|
2008-07-06 20:25:49 -07:00
|
|
|
|
2008-06-26 20:49:04 -07:00
|
|
|
class TraceRecorder {
|
2008-06-28 18:47:12 -07:00
|
|
|
JSContext* cx;
|
2008-07-14 16:40:38 -07:00
|
|
|
JSObject* globalObj;
|
2008-07-10 18:42:04 -07:00
|
|
|
Tracker tracker;
|
2008-07-02 14:38:12 -07:00
|
|
|
char* entryTypeMap;
|
2008-06-28 17:14:06 -07:00
|
|
|
struct JSStackFrame* entryFrame;
|
|
|
|
struct JSFrameRegs entryRegs;
|
2008-07-10 21:55:09 -07:00
|
|
|
JSAtom** atoms;
|
2008-06-26 20:37:28 -07:00
|
|
|
nanojit::Fragment* fragment;
|
2008-07-04 13:23:42 -07:00
|
|
|
VMFragmentInfo* fragmentInfo;
|
2008-06-27 18:06:50 -07:00
|
|
|
nanojit::LirBuffer* lirbuf;
|
2008-06-26 20:37:28 -07:00
|
|
|
nanojit::LirWriter* lir;
|
2008-07-01 19:43:10 -07:00
|
|
|
nanojit::LirBufWriter* lir_buf_writer;
|
2008-06-30 18:08:32 -07:00
|
|
|
nanojit::LirWriter* verbose_filter;
|
|
|
|
nanojit::LirWriter* cse_filter;
|
|
|
|
nanojit::LirWriter* expr_filter;
|
2008-07-06 11:48:41 -07:00
|
|
|
nanojit::LirWriter* exit_filter;
|
2008-07-05 23:21:53 -07:00
|
|
|
nanojit::LirWriter* func_filter;
|
2008-07-02 14:38:12 -07:00
|
|
|
nanojit::LIns* cx_ins;
|
2008-06-30 17:12:52 -07:00
|
|
|
nanojit::SideExit exit;
|
2008-07-06 22:35:19 -07:00
|
|
|
bool recompileFlag;
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-09 00:29:23 -07:00
|
|
|
JSStackFrame* findFrame(jsval* p) const;
|
|
|
|
bool onFrame(jsval* p) const;
|
|
|
|
bool isGlobal(jsval* p) const;
|
|
|
|
size_t nativeFrameOffset(jsval* p) const;
|
2008-07-15 16:04:08 -07:00
|
|
|
void import(jsval* p, uint8& t, const char *prefix, int index);
|
2008-07-02 17:19:07 -07:00
|
|
|
void trackNativeFrameUse(unsigned slots);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-05 19:15:00 -07:00
|
|
|
unsigned getCallDepth() const;
|
2008-07-17 02:00:23 -07:00
|
|
|
nanojit::LIns* guard(bool expected, nanojit::LIns* cond);
|
|
|
|
nanojit::LIns* addName(nanojit::LIns* ins, const char* name);
|
2008-06-30 17:12:52 -07:00
|
|
|
|
2008-07-15 01:27:14 -07:00
|
|
|
nanojit::LIns* get(jsval* p);
|
2008-07-09 00:29:23 -07:00
|
|
|
void set(jsval* p, nanojit::LIns* l);
|
2008-07-06 11:48:41 -07:00
|
|
|
|
2008-07-06 22:35:19 -07:00
|
|
|
bool checkType(jsval& v, uint8& type);
|
2008-07-08 16:29:23 -07:00
|
|
|
bool verifyTypeStability(JSStackFrame* entryFrame, JSStackFrame* currentFrame, uint8* m);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-04 03:06:18 -07:00
|
|
|
jsval& argval(unsigned n) const;
|
|
|
|
jsval& varval(unsigned n) const;
|
|
|
|
jsval& stackval(int n) const;
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-04 03:06:18 -07:00
|
|
|
nanojit::LIns* arg(unsigned n);
|
2008-07-04 15:21:56 -07:00
|
|
|
void arg(unsigned n, nanojit::LIns* i);
|
2008-07-04 03:06:18 -07:00
|
|
|
nanojit::LIns* var(unsigned n);
|
2008-07-04 15:21:56 -07:00
|
|
|
void var(unsigned n, nanojit::LIns* i);
|
2008-07-04 03:06:18 -07:00
|
|
|
nanojit::LIns* stack(int n);
|
|
|
|
void stack(int n, nanojit::LIns* i);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-06 15:55:04 -07:00
|
|
|
nanojit::LIns* f2i(nanojit::LIns* f);
|
|
|
|
|
2008-07-10 20:35:19 -07:00
|
|
|
bool ifop();
|
2008-07-09 15:15:32 -07:00
|
|
|
bool inc(jsval& v, jsint incr, bool pre = true);
|
2008-07-04 03:06:18 -07:00
|
|
|
bool cmp(nanojit::LOpcode op, bool negate = false);
|
2008-07-06 13:16:34 -07:00
|
|
|
|
|
|
|
bool unary(nanojit::LOpcode op);
|
|
|
|
bool binary(nanojit::LOpcode op);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
|
|
|
bool ibinary(nanojit::LOpcode op);
|
2008-07-05 22:04:58 -07:00
|
|
|
bool iunary(nanojit::LOpcode op);
|
2008-07-07 02:21:04 -07:00
|
|
|
bool bbinary(nanojit::LOpcode op);
|
2008-07-05 23:21:53 -07:00
|
|
|
void demote(jsval& v, jsdouble result);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-04 23:53:29 -07:00
|
|
|
bool map_is_native(JSObjectMap* map, nanojit::LIns* map_ins);
|
2008-07-06 09:15:55 -07:00
|
|
|
bool test_property_cache(JSObject* obj, nanojit::LIns* obj_ins, JSObject*& obj2,
|
|
|
|
JSPropCacheEntry*& entry);
|
2008-07-09 11:42:31 -07:00
|
|
|
bool test_property_cache_direct_slot(JSObject* obj, nanojit::LIns* obj_ins, uint32& slot);
|
2008-07-07 02:21:04 -07:00
|
|
|
void stobj_set_slot(nanojit::LIns* obj_ins, unsigned slot,
|
2008-07-07 02:55:03 -07:00
|
|
|
nanojit::LIns*& dslots_ins, nanojit::LIns* v_ins);
|
2008-07-07 02:21:04 -07:00
|
|
|
nanojit::LIns* stobj_get_slot(nanojit::LIns* obj_ins, unsigned slot,
|
2008-07-07 02:55:03 -07:00
|
|
|
nanojit::LIns*& dslots_ins);
|
2008-07-07 02:21:04 -07:00
|
|
|
bool native_set(nanojit::LIns* obj_ins, JSScopeProperty* sprop,
|
2008-07-07 02:55:03 -07:00
|
|
|
nanojit::LIns*& dslots_ins, nanojit::LIns* v_ins);
|
2008-07-07 02:21:04 -07:00
|
|
|
bool native_get(nanojit::LIns* obj_ins, nanojit::LIns* pobj_ins, JSScopeProperty* sprop,
|
2008-07-07 02:55:03 -07:00
|
|
|
nanojit::LIns*& dslots_ins, nanojit::LIns*& v_ins);
|
2008-07-06 10:38:55 -07:00
|
|
|
|
2008-07-16 14:36:50 -07:00
|
|
|
bool getProp(JSObject* obj, nanojit::LIns* obj_ins);
|
|
|
|
bool getProp(jsval& v);
|
|
|
|
bool getThis(nanojit::LIns*& this_ins);
|
|
|
|
|
2008-07-06 13:59:59 -07:00
|
|
|
bool box_jsval(jsval v, nanojit::LIns*& v_ins);
|
2008-07-06 10:38:55 -07:00
|
|
|
bool unbox_jsval(jsval v, nanojit::LIns*& v_ins);
|
2008-07-11 17:59:10 -07:00
|
|
|
bool guardThatObjectHasClass(JSObject* obj, nanojit::LIns* obj_ins,
|
|
|
|
JSClass* cls, nanojit::LIns*& dslots_ins);
|
2008-07-07 02:55:03 -07:00
|
|
|
bool guardThatObjectIsDenseArray(JSObject* obj, nanojit::LIns* obj_ins,
|
|
|
|
nanojit::LIns*& dslots_ins);
|
|
|
|
bool guardDenseArrayIndexWithinBounds(JSObject* obj, jsint idx, nanojit::LIns* obj_ins,
|
|
|
|
nanojit::LIns*& dslots_ins, nanojit::LIns* idx_ins);
|
2008-07-03 23:57:57 -07:00
|
|
|
public:
|
2008-07-16 21:49:42 -07:00
|
|
|
TraceRecorder(JSContext* cx, nanojit::Fragment*, uint8* typemap);
|
2008-07-03 23:57:57 -07:00
|
|
|
~TraceRecorder();
|
|
|
|
|
2008-07-07 00:43:40 -07:00
|
|
|
nanojit::SideExit* snapshot();
|
2008-07-17 01:29:41 -07:00
|
|
|
nanojit::Fragment* getFragment() const { return fragment; }
|
|
|
|
void closeLoop(nanojit::Fragmento* fragmento);
|
|
|
|
|
2008-07-16 23:00:59 -07:00
|
|
|
bool record_EnterFrame();
|
2008-07-16 17:29:08 -07:00
|
|
|
|
2008-07-07 02:21:04 -07:00
|
|
|
#define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
|
2008-07-10 21:55:09 -07:00
|
|
|
bool record_##op();
|
2008-07-07 02:21:04 -07:00
|
|
|
# include "jsopcode.tbl"
|
|
|
|
#undef OPDEF
|
2008-06-22 09:30:04 -07:00
|
|
|
};
|
|
|
|
|
2008-06-27 08:41:59 -07:00
|
|
|
#define TRACING_ENABLED(cx) JS_HAS_OPTION(cx, JSOPTION_JIT)
|
2008-05-30 18:58:43 -07:00
|
|
|
|
2008-07-16 22:58:06 -07:00
|
|
|
#define RECORD(x) \
|
|
|
|
JS_BEGIN_MACRO \
|
|
|
|
TraceRecorder* r = JS_TRACE_MONITOR(cx).recorder; \
|
|
|
|
if (!r->record_##x()) { \
|
|
|
|
js_AbortRecording(cx, #x); \
|
|
|
|
ENABLE_TRACER(0); \
|
|
|
|
} \
|
|
|
|
JS_END_MACRO
|
|
|
|
|
2008-07-04 01:10:57 -07:00
|
|
|
extern bool
|
2008-07-04 15:07:05 -07:00
|
|
|
js_LoopEdge(JSContext* cx);
|
2008-06-11 17:21:15 -07:00
|
|
|
|
2008-06-28 18:19:21 -07:00
|
|
|
extern void
|
2008-07-04 01:10:57 -07:00
|
|
|
js_AbortRecording(JSContext* cx, const char* reason);
|
2008-06-28 18:19:21 -07:00
|
|
|
|
2008-07-05 19:15:00 -07:00
|
|
|
extern void
|
|
|
|
js_InitJIT(JSContext* cx);
|
|
|
|
|
2008-07-17 10:22:40 -07:00
|
|
|
extern void
|
|
|
|
js_DestroyJIT(JSContext* cx);
|
|
|
|
|
2008-05-31 15:29:54 -07:00
|
|
|
#endif /* jstracer_h___ */
|