2008-05-30 18:58:43 -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 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-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
|
|
|
|
|
|
|
/*
|
|
|
|
* Tracker is used to keep track of values being manipulated by the
|
|
|
|
* interpreter during trace recording.
|
|
|
|
*/
|
|
|
|
class Tracker
|
|
|
|
{
|
|
|
|
struct Page {
|
|
|
|
struct Page* next;
|
|
|
|
long base;
|
2008-06-26 20:44:23 -07:00
|
|
|
nanojit::LIns* map[0];
|
2008-06-21 14:55:32 -07:00
|
|
|
};
|
|
|
|
struct Page* pagelist;
|
|
|
|
|
2008-06-26 20:46:51 -07:00
|
|
|
long getPageBase(const void* v) const;
|
|
|
|
struct Page* findPage(const void* v) const;
|
|
|
|
struct Page* addPage(const void* v);
|
2008-06-21 14:55:32 -07:00
|
|
|
public:
|
|
|
|
Tracker();
|
|
|
|
~Tracker();
|
|
|
|
|
2008-06-26 20:44:23 -07:00
|
|
|
nanojit::LIns* get(const void* v) const;
|
|
|
|
void set(const void* v, nanojit::LIns* ins);
|
|
|
|
void clear();
|
2008-06-21 14:55:32 -07:00
|
|
|
};
|
|
|
|
|
2008-06-26 20:49:04 -07:00
|
|
|
class TraceRecorder {
|
2008-06-28 18:47:12 -07:00
|
|
|
JSContext* cx;
|
2008-06-26 22:41:10 -07:00
|
|
|
Tracker tracker;
|
2008-07-02 14:38:12 -07:00
|
|
|
char* entryTypeMap;
|
|
|
|
unsigned entryNativeFrameSlots;
|
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-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-02 14:38:12 -07:00
|
|
|
nanojit::LIns* cx_ins;
|
2008-06-30 18:31:29 -07:00
|
|
|
struct JSFrameRegs markRegs;
|
2008-06-30 17:12:52 -07:00
|
|
|
nanojit::SideExit exit;
|
2008-06-26 20:37:28 -07:00
|
|
|
|
2008-07-01 19:43:10 -07:00
|
|
|
JSStackFrame* findFrame(void* p) const;
|
|
|
|
bool TraceRecorder::onFrame(void* p) const;
|
|
|
|
unsigned nativeFrameSlots(JSStackFrame* fp, JSFrameRegs& regs) const;
|
|
|
|
unsigned nativeFrameOffset(void* p) const;
|
|
|
|
void buildTypeMap(JSStackFrame* fp, JSFrameRegs& regs, char* m) const;
|
2008-07-02 15:14:43 -07:00
|
|
|
bool verifyTypeStability(JSStackFrame* fp, JSFrameRegs& regs, char* m) const;
|
2008-07-01 19:43:10 -07:00
|
|
|
bool unbox_jsval(jsval v, int t, double* slot) const;
|
|
|
|
bool box_jsval(jsval* vp, int t, double* slot) const;
|
|
|
|
bool unbox(JSStackFrame* fp, JSFrameRegs& regs, char* m, double* native) const;
|
|
|
|
bool box(JSStackFrame* fp, JSFrameRegs& regs, char* m, double* native) const;
|
2008-07-02 15:14:43 -07:00
|
|
|
void import(jsval*, char *prefix = NULL, int index = 0);
|
2008-07-01 19:43:10 -07:00
|
|
|
|
|
|
|
nanojit::SideExit* snapshot();
|
2008-06-27 18:06:50 -07:00
|
|
|
public:
|
2008-06-28 17:14:06 -07:00
|
|
|
TraceRecorder(JSContext* cx, nanojit::Fragmento*);
|
2008-06-27 18:06:50 -07:00
|
|
|
~TraceRecorder();
|
|
|
|
|
2008-06-28 09:58:15 -07:00
|
|
|
inline jsbytecode* entryPC() const
|
2008-06-27 18:06:50 -07:00
|
|
|
{
|
2008-06-28 17:14:06 -07:00
|
|
|
return entryRegs.pc;
|
2008-06-27 18:06:50 -07:00
|
|
|
}
|
2008-06-26 22:33:33 -07:00
|
|
|
|
2008-06-30 17:12:52 -07:00
|
|
|
void mark();
|
2008-06-30 18:31:29 -07:00
|
|
|
void recover();
|
2008-07-01 02:37:07 -07:00
|
|
|
|
|
|
|
void abort();
|
2008-06-30 18:31:29 -07:00
|
|
|
|
2008-06-28 17:14:06 -07:00
|
|
|
unsigned calldepth() const;
|
2008-06-30 17:12:52 -07:00
|
|
|
|
2008-06-26 22:41:10 -07:00
|
|
|
void set(void* p, nanojit::LIns* l);
|
|
|
|
nanojit::LIns* get(void* p);
|
|
|
|
|
2008-06-26 22:58:57 -07:00
|
|
|
void copy(void* a, void* v);
|
2008-06-27 00:22:16 -07:00
|
|
|
void imm(jsint i, void* v);
|
|
|
|
void imm(jsdouble d, void* v);
|
2008-06-26 22:58:57 -07:00
|
|
|
void unary(nanojit::LOpcode op, void* a, void* v);
|
|
|
|
void binary(nanojit::LOpcode op, void* a, void* b, void* v);
|
2008-06-27 06:53:10 -07:00
|
|
|
void binary0(nanojit::LOpcode op, void* a, void* v);
|
2008-06-26 22:58:57 -07:00
|
|
|
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);
|
|
|
|
|
2008-06-28 17:14:06 -07:00
|
|
|
void iinc(void* a, int32_t incr, void* v);
|
2008-06-27 00:22:16 -07:00
|
|
|
|
2008-06-28 18:47:12 -07:00
|
|
|
void load(void* a, int32_t i, void* v);
|
|
|
|
|
2008-06-28 17:14:06 -07:00
|
|
|
void guard_0(bool expected, void* a);
|
|
|
|
void guard_h(bool expected, void* a);
|
|
|
|
void guard_ov(bool expected, void* a);
|
|
|
|
void guard_eq(bool expected, void* a, void* b);
|
|
|
|
void guard_eqi(bool expected, void* a, int i);
|
2008-06-27 18:06:50 -07:00
|
|
|
|
|
|
|
void closeLoop(nanojit::Fragmento* fragmento);
|
2008-06-22 09:30:04 -07:00
|
|
|
};
|
|
|
|
|
2008-06-11 13:07:24 -07:00
|
|
|
/*
|
2008-06-03 23:52:28 -07:00
|
|
|
* Trace monitor. Every runtime is associated with a trace monitor that keeps
|
|
|
|
* track of loop frequencies for all JavaScript code loaded into that runtime.
|
|
|
|
* For this we use a loop table. Adjacent slots in the loop table, one for each
|
|
|
|
* loop header in a given script, are requested using lock-free synchronization
|
|
|
|
* from the runtime-wide loop table slot space, when the script is compiled.
|
2008-06-11 13:07:24 -07:00
|
|
|
*
|
2008-06-03 23:52:28 -07:00
|
|
|
* The loop table also doubles as trace tree pointer table once a loop achieves
|
|
|
|
* a certain number of iterations and we recorded a tree for that loop.
|
2008-05-30 18:58:43 -07:00
|
|
|
*/
|
|
|
|
struct JSTraceMonitor {
|
2008-06-26 18:13:54 -07:00
|
|
|
int freq;
|
|
|
|
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-06-10 16:49:05 -07:00
|
|
|
#define TRACE_TRIGGER_MASK 0x3f
|
2008-05-30 18:58:43 -07:00
|
|
|
|
2008-06-26 20:37:28 -07:00
|
|
|
extern bool
|
2008-06-28 17:14:06 -07:00
|
|
|
js_StartRecording(JSContext* cx);
|
2008-06-11 17:21:15 -07:00
|
|
|
|
2008-06-28 18:19:21 -07:00
|
|
|
extern void
|
|
|
|
js_AbortRecording(JSContext* cx);
|
|
|
|
|
2008-06-21 14:55:32 -07:00
|
|
|
extern void
|
2008-06-28 17:14:06 -07:00
|
|
|
js_EndRecording(JSContext* cx);
|
2008-06-11 17:59:28 -07:00
|
|
|
|
2008-05-31 15:29:54 -07:00
|
|
|
#endif /* jstracer_h___ */
|