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-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-06 12:03:51 -07:00
|
|
|
template <typename T>
|
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-06 10:59:55 -07:00
|
|
|
T map[0];
|
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-06 10:59:55 -07:00
|
|
|
T get(const void* v) const;
|
|
|
|
void set(const void* v, T ins);
|
2008-06-26 20:44:23 -07:00
|
|
|
void clear();
|
2008-06-21 14:55:32 -07:00
|
|
|
};
|
|
|
|
|
2008-07-04 13:23:42 -07:00
|
|
|
struct VMFragmentInfo {
|
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-06 22:35:19 -07:00
|
|
|
uint8 typeMap[0];
|
2008-07-04 13:23:42 -07:00
|
|
|
};
|
|
|
|
|
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-07 17:21:54 -07:00
|
|
|
JSStackFrame* global;
|
2008-07-06 10:59:55 -07:00
|
|
|
Tracker<nanojit::LIns*> 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-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-01 19:43:10 -07:00
|
|
|
JSStackFrame* findFrame(void* p) const;
|
2008-07-03 17:02:19 -07:00
|
|
|
bool onFrame(void* p) const;
|
2008-07-07 15:15:56 -07:00
|
|
|
bool isGlobal(void* p) const;
|
2008-07-01 19:43:10 -07:00
|
|
|
unsigned nativeFrameSlots(JSStackFrame* fp, JSFrameRegs& regs) const;
|
2008-07-06 22:35:19 -07:00
|
|
|
size_t nativeFrameOffset(void* p) const;
|
2008-07-07 17:21:54 -07:00
|
|
|
void import(jsval* p, uint8& t, 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-06 15:55:04 -07:00
|
|
|
void guard(bool expected, nanojit::LIns* cond);
|
2008-06-30 17:12:52 -07:00
|
|
|
|
2008-06-26 22:41:10 -07:00
|
|
|
void set(void* 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-04 03:06:18 -07:00
|
|
|
void closeLoop(nanojit::Fragmento* fragmento);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-07 15:15:56 -07:00
|
|
|
jsval& gvarval(unsigned n) const;
|
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-07 15:15:56 -07:00
|
|
|
nanojit::LIns* gvar(unsigned n);
|
|
|
|
void gvar(unsigned n, nanojit::LIns* i);
|
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-05 22:23:34 -07:00
|
|
|
bool ifop(bool sense);
|
2008-07-04 03:06:18 -07:00
|
|
|
bool inc(jsval& v, jsint incr, bool pre);
|
|
|
|
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-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-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-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:
|
|
|
|
TraceRecorder(JSContext* cx, nanojit::Fragmento*, nanojit::Fragment*);
|
|
|
|
~TraceRecorder();
|
|
|
|
|
2008-07-07 18:35:38 -07:00
|
|
|
JSStackFrame* getGlobalFrame() const;
|
2008-07-06 11:48:41 -07:00
|
|
|
JSStackFrame* getEntryFrame() const;
|
|
|
|
JSStackFrame* getFp() const;
|
|
|
|
JSFrameRegs& getRegs() const;
|
2008-07-07 00:10:22 -07:00
|
|
|
nanojit::Fragment* getFragment() const;
|
2008-07-07 00:43:40 -07:00
|
|
|
nanojit::SideExit* snapshot();
|
2008-07-06 11:48:41 -07:00
|
|
|
|
|
|
|
nanojit::LIns* get(void* p);
|
2008-07-07 02:21:04 -07:00
|
|
|
|
2008-07-05 19:15:00 -07:00
|
|
|
bool loopEdge();
|
|
|
|
void stop();
|
2008-07-07 02:21:04 -07:00
|
|
|
|
|
|
|
#define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
|
|
|
|
bool op();
|
|
|
|
# include "jsopcode.tbl"
|
|
|
|
#undef OPDEF
|
2008-06-22 09:30:04 -07:00
|
|
|
};
|
|
|
|
|
2008-07-05 16:28:03 -07:00
|
|
|
FASTCALL jsdouble builtin_dmod(jsdouble a, jsdouble b);
|
2008-07-06 15:55:04 -07:00
|
|
|
FASTCALL jsval builtin_BoxDouble(JSContext* cx, jsdouble d);
|
|
|
|
FASTCALL jsval builtin_BoxInt32(JSContext* cx, jsint i);
|
|
|
|
FASTCALL jsdouble builtin_UnboxDouble(jsval v);
|
|
|
|
FASTCALL jsint builtin_UnboxInt32(jsval v);
|
|
|
|
FASTCALL int32 builtin_doubleToInt32(jsdouble d);
|
|
|
|
FASTCALL int32 builtin_doubleToUint32(jsdouble d);
|
2008-07-05 16:28:03 -07:00
|
|
|
|
2008-06-11 13:07:24 -07:00
|
|
|
/*
|
2008-07-07 02:55:03 -07:00
|
|
|
* Trace monitor. Every JSThread (if JS_THREADSAFE) or JSRuntime (if not
|
|
|
|
* JS_THREADSAFE) has an associated trace monitor that keeps track of loop
|
|
|
|
* frequencies for all JavaScript code loaded into that runtime.
|
2008-05-30 18:58:43 -07:00
|
|
|
*/
|
|
|
|
struct JSTraceMonitor {
|
2008-06-26 18:13:54 -07:00
|
|
|
nanojit::Fragmento* fragmento;
|
2008-06-30 17:12:52 -07:00
|
|
|
TraceRecorder* recorder;
|
2008-05-30 18:58:43 -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-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-05-31 15:29:54 -07:00
|
|
|
#endif /* jstracer_h___ */
|